0032147: Documentation - drop mentioning of WOK from build_3rdparty
[occt.git] / src / OpenGl / OpenGl_MatrixState.hxx
CommitLineData
825aa485 1// Created on: 2014-09-30
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _OpenGl_MatrixState_H__
17#define _OpenGl_MatrixState_H__
18
19#include <OpenGl_Vec.hxx>
20#include <NCollection_Vector.hxx>
bc73b006 21#include <Standard_Dump.hxx>
825aa485 22
23//! Software implementation for OpenGL matrix stack.
24template<class T>
25class OpenGl_MatrixState
26{
27public:
28
29 //! Constructs matrix state object.
30 OpenGl_MatrixState()
31 : myStack (8),
32 myStackHead (-1)
33 {
34 //
35 }
36
37 //! Pushes current matrix into stack.
38 void Push()
39 {
40 if (++myStackHead >= myStack.Size())
41 {
42 myStack.Append (myCurrent);
43 }
44 else
45 {
46 myStack.SetValue (myStackHead, myCurrent);
47 }
48 }
49
50 //! Pops matrix from stack to current.
51 void Pop()
52 {
53 Standard_ASSERT_RETURN (myStackHead != -1, "Matrix stack already empty when MatrixState.Pop() called.", );
54 myCurrent = myStack.Value (myStackHead--);
55 }
56
57 //! @return current matrix.
58 const typename OpenGl::MatrixType<T>::Mat4& Current()
59 {
60 return myCurrent;
61 }
62
63 //! Sets given matrix as current.
64 void SetCurrent (const typename OpenGl::MatrixType<T>::Mat4& theNewCurrent)
65 {
66 myCurrent = theNewCurrent;
67 }
68
1f7f5a90 69 //! Change current matrix.
70 typename OpenGl::MatrixType<T>::Mat4& ChangeCurrent()
71 {
72 return myCurrent;
73 }
74
825aa485 75 //! Sets given matrix as current.
76 template <typename Other_t>
77 void SetCurrent (const typename OpenGl::MatrixType<Other_t>::Mat4& theNewCurrent)
78 {
79 myCurrent.Convert (theNewCurrent);
80 }
81
82 //! Sets current matrix to identity.
83 void SetIdentity()
84 {
85 myCurrent = typename OpenGl::MatrixType<T>::Mat4();
86 }
87
bc73b006 88 //! Dumps the content of me into the stream
89 void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
90 {
91 (void)theDepth;
92 OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "myCurrent", 16,
93 myCurrent.GetValue (0, 0), myCurrent.GetValue (0, 1), myCurrent.GetValue (0, 2), myCurrent.GetValue (0, 3),
94 myCurrent.GetValue (1, 0), myCurrent.GetValue (1, 1), myCurrent.GetValue (1, 2), myCurrent.GetValue (1, 3),
95 myCurrent.GetValue (2, 0), myCurrent.GetValue (2, 1), myCurrent.GetValue (2, 2), myCurrent.GetValue (2, 3),
96 myCurrent.GetValue (3, 0), myCurrent.GetValue (3, 1), myCurrent.GetValue (3, 2), myCurrent.GetValue (3, 3))
97
98 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myStack.Size())
99 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myStackHead)
100 }
101
825aa485 102private:
103
104 NCollection_Vector<typename OpenGl::MatrixType<T>::Mat4> myStack; //!< Collection used to maintenance matrix stack
105 typename OpenGl::MatrixType<T>::Mat4 myCurrent; //!< Current matrix
106 Standard_Integer myStackHead; //!< Index of stack head
107};
108
109#endif // _OpenGl_MatrixState_H__