Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-08 10:23:57

0001 // Created on: 2014-09-30
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _OpenGl_MatrixState_H__
0017 #define _OpenGl_MatrixState_H__
0018 
0019 #include <OpenGl_Vec.hxx>
0020 #include <NCollection_DynamicArray.hxx>
0021 #include <Standard_Dump.hxx>
0022 
0023 //! Software implementation for OpenGL matrix stack.
0024 template <class T>
0025 class OpenGl_MatrixState
0026 {
0027 public:
0028   //! Constructs matrix state object.
0029   OpenGl_MatrixState()
0030       : myStack(8),
0031         myStackHead(-1)
0032   {
0033     //
0034   }
0035 
0036   //! Pushes current matrix into stack.
0037   void Push()
0038   {
0039     if (++myStackHead >= myStack.Length())
0040     {
0041       myStack.Append(myCurrent);
0042     }
0043     else
0044     {
0045       myStack.SetValue(myStackHead, myCurrent);
0046     }
0047   }
0048 
0049   //! Pops matrix from stack to current.
0050   void Pop()
0051   {
0052     Standard_ASSERT_RETURN(myStackHead != -1,
0053                            "Matrix stack already empty when MatrixState.Pop() called.",
0054                            Standard_VOID_RETURN);
0055     myCurrent = myStack.Value(myStackHead--);
0056   }
0057 
0058   //! @return current matrix.
0059   const typename OpenGl::MatrixType<T>::Mat4& Current() { return myCurrent; }
0060 
0061   //! Sets given matrix as current.
0062   void SetCurrent(const typename OpenGl::MatrixType<T>::Mat4& theNewCurrent)
0063   {
0064     myCurrent = theNewCurrent;
0065   }
0066 
0067   //! Change current matrix.
0068   typename OpenGl::MatrixType<T>::Mat4& ChangeCurrent() { return myCurrent; }
0069 
0070   //! Sets given matrix as current.
0071   template <typename Other_t>
0072   void SetCurrent(const typename OpenGl::MatrixType<Other_t>::Mat4& theNewCurrent)
0073   {
0074     myCurrent.Convert(theNewCurrent);
0075   }
0076 
0077   //! Sets current matrix to identity.
0078   void SetIdentity() { myCurrent = typename OpenGl::MatrixType<T>::Mat4(); }
0079 
0080   //! Dumps the content of me into the stream
0081   void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const
0082   {
0083     (void)theDepth;
0084     OCCT_DUMP_FIELD_VALUES_NUMERICAL(theOStream,
0085                                      "myCurrent",
0086                                      16,
0087                                      myCurrent.GetValue(0, 0),
0088                                      myCurrent.GetValue(0, 1),
0089                                      myCurrent.GetValue(0, 2),
0090                                      myCurrent.GetValue(0, 3),
0091                                      myCurrent.GetValue(1, 0),
0092                                      myCurrent.GetValue(1, 1),
0093                                      myCurrent.GetValue(1, 2),
0094                                      myCurrent.GetValue(1, 3),
0095                                      myCurrent.GetValue(2, 0),
0096                                      myCurrent.GetValue(2, 1),
0097                                      myCurrent.GetValue(2, 2),
0098                                      myCurrent.GetValue(2, 3),
0099                                      myCurrent.GetValue(3, 0),
0100                                      myCurrent.GetValue(3, 1),
0101                                      myCurrent.GetValue(3, 2),
0102                                      myCurrent.GetValue(3, 3))
0103 
0104     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myStack.Length())
0105     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myStackHead)
0106   }
0107 
0108 private:
0109   // clang-format off
0110   NCollection_DynamicArray<typename OpenGl::MatrixType<T>::Mat4> myStack;     //!< Collection used to maintenance matrix stack
0111   // clang-format on
0112   typename OpenGl::MatrixType<T>::Mat4 myCurrent;   //!< Current matrix
0113   int                                  myStackHead; //!< Index of stack head
0114 };
0115 
0116 #endif // _OpenGl_MatrixState_H__