1 // Created on: 2014-09-30
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_MatrixState_H__
17 #define _OpenGl_MatrixState_H__
19 #include <OpenGl_Vec.hxx>
20 #include <NCollection_Vector.hxx>
22 //! Software implementation for OpenGL matrix stack.
24 class OpenGl_MatrixState
28 //! Constructs matrix state object.
36 //! Pushes current matrix into stack.
39 if (++myStackHead >= myStack.Size())
41 myStack.Append (myCurrent);
45 myStack.SetValue (myStackHead, myCurrent);
49 //! Pops matrix from stack to current.
52 Standard_ASSERT_RETURN (myStackHead != -1, "Matrix stack already empty when MatrixState.Pop() called.", );
53 myCurrent = myStack.Value (myStackHead--);
56 //! @return current matrix.
57 const typename OpenGl::MatrixType<T>::Mat4& Current()
62 //! Sets given matrix as current.
63 void SetCurrent (const typename OpenGl::MatrixType<T>::Mat4& theNewCurrent)
65 myCurrent = theNewCurrent;
68 //! Change current matrix.
69 typename OpenGl::MatrixType<T>::Mat4& ChangeCurrent()
74 //! Sets given matrix as current.
75 template <typename Other_t>
76 void SetCurrent (const typename OpenGl::MatrixType<Other_t>::Mat4& theNewCurrent)
78 myCurrent.Convert (theNewCurrent);
81 //! Sets current matrix to identity.
84 myCurrent = typename OpenGl::MatrixType<T>::Mat4();
89 NCollection_Vector<typename OpenGl::MatrixType<T>::Mat4> myStack; //!< Collection used to maintenance matrix stack
90 typename OpenGl::MatrixType<T>::Mat4 myCurrent; //!< Current matrix
91 Standard_Integer myStackHead; //!< Index of stack head
94 #endif // _OpenGl_MatrixState_H__