File indexing completed on 2026-05-12 08:47:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _OpenGl_MatrixState_H__
0017 #define _OpenGl_MatrixState_H__
0018
0019 #include <OpenGl_Vec.hxx>
0020 #include <NCollection_Vector.hxx>
0021 #include <Standard_Dump.hxx>
0022
0023
0024 template <class T>
0025 class OpenGl_MatrixState
0026 {
0027 public:
0028
0029 OpenGl_MatrixState()
0030 : myStack(8),
0031 myStackHead(-1)
0032 {
0033
0034 }
0035
0036
0037 void Push()
0038 {
0039 if (++myStackHead >= myStack.Size())
0040 {
0041 myStack.Append(myCurrent);
0042 }
0043 else
0044 {
0045 myStack.SetValue(myStackHead, myCurrent);
0046 }
0047 }
0048
0049
0050 void Pop()
0051 {
0052 Standard_ASSERT_RETURN(myStackHead != -1,
0053 "Matrix stack already empty when MatrixState.Pop() called.", );
0054 myCurrent = myStack.Value(myStackHead--);
0055 }
0056
0057
0058 const typename OpenGl::MatrixType<T>::Mat4& Current() { return myCurrent; }
0059
0060
0061 void SetCurrent(const typename OpenGl::MatrixType<T>::Mat4& theNewCurrent)
0062 {
0063 myCurrent = theNewCurrent;
0064 }
0065
0066
0067 typename OpenGl::MatrixType<T>::Mat4& ChangeCurrent() { return myCurrent; }
0068
0069
0070 template <typename Other_t>
0071 void SetCurrent(const typename OpenGl::MatrixType<Other_t>::Mat4& theNewCurrent)
0072 {
0073 myCurrent.Convert(theNewCurrent);
0074 }
0075
0076
0077 void SetIdentity() { myCurrent = typename OpenGl::MatrixType<T>::Mat4(); }
0078
0079
0080 void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
0081 {
0082 (void)theDepth;
0083 OCCT_DUMP_FIELD_VALUES_NUMERICAL(theOStream,
0084 "myCurrent",
0085 16,
0086 myCurrent.GetValue(0, 0),
0087 myCurrent.GetValue(0, 1),
0088 myCurrent.GetValue(0, 2),
0089 myCurrent.GetValue(0, 3),
0090 myCurrent.GetValue(1, 0),
0091 myCurrent.GetValue(1, 1),
0092 myCurrent.GetValue(1, 2),
0093 myCurrent.GetValue(1, 3),
0094 myCurrent.GetValue(2, 0),
0095 myCurrent.GetValue(2, 1),
0096 myCurrent.GetValue(2, 2),
0097 myCurrent.GetValue(2, 3),
0098 myCurrent.GetValue(3, 0),
0099 myCurrent.GetValue(3, 1),
0100 myCurrent.GetValue(3, 2),
0101 myCurrent.GetValue(3, 3))
0102
0103 OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myStack.Size())
0104 OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myStackHead)
0105 }
0106
0107 private:
0108
0109 NCollection_Vector<typename OpenGl::MatrixType<T>::Mat4> myStack;
0110
0111 typename OpenGl::MatrixType<T>::Mat4 myCurrent;
0112 Standard_Integer myStackHead;
0113 };
0114
0115 #endif