| 1 | // Created on: 2013-10-02 |
| 2 | // Created by: Denis BOGOLEPOV |
| 3 | // Copyright (c) 2013-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_State_HeaderFile |
| 17 | #define _OpenGl_State_HeaderFile |
| 18 | |
| 19 | #include <InterfaceGraphic_tgl_all.hxx> |
| 20 | |
| 21 | #include <OpenGl_Element.hxx> |
| 22 | #include <OpenGl_Light.hxx> |
| 23 | #include <OpenGl_Vec.hxx> |
| 24 | |
| 25 | #include <NCollection_List.hxx> |
| 26 | |
| 27 | //! Defines interface for OpenGL state. |
| 28 | class OpenGl_StateInterface |
| 29 | { |
| 30 | public: |
| 31 | |
| 32 | //! Creates new OCCT state. |
| 33 | OpenGl_StateInterface(); |
| 34 | |
| 35 | //! Returns current state index. |
| 36 | Standard_Size Index() const; |
| 37 | |
| 38 | //! Updates current state. |
| 39 | void Update(); |
| 40 | |
| 41 | //! Reverts current state. |
| 42 | void Revert(); |
| 43 | |
| 44 | protected: |
| 45 | |
| 46 | Standard_Size myIndex; //!< Current state index |
| 47 | Standard_Size myNextIndex; //!< Next state index |
| 48 | NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states. |
| 49 | |
| 50 | }; |
| 51 | |
| 52 | //! Defines state of OCCT projection transformation. |
| 53 | class OpenGl_ProjectionState : public OpenGl_StateInterface |
| 54 | { |
| 55 | public: |
| 56 | |
| 57 | //! Creates uninitialized projection state. |
| 58 | OpenGl_ProjectionState(); |
| 59 | |
| 60 | //! Sets new projection matrix. |
| 61 | void Set (const OpenGl_Mat4& theProjectionMatrix); |
| 62 | |
| 63 | //! Returns current projection matrix. |
| 64 | const OpenGl_Mat4& ProjectionMatrix() const; |
| 65 | |
| 66 | //! Returns inverse of current projection matrix. |
| 67 | const OpenGl_Mat4& ProjectionMatrixInverse() const; |
| 68 | |
| 69 | private: |
| 70 | |
| 71 | OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix |
| 72 | mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix |
| 73 | bool myInverseNeedUpdate; //!< Is inversed matrix outdated? |
| 74 | |
| 75 | }; |
| 76 | |
| 77 | //! Defines state of OCCT model-world transformation. |
| 78 | class OpenGl_ModelWorldState : public OpenGl_StateInterface |
| 79 | { |
| 80 | public: |
| 81 | |
| 82 | //! Creates uninitialized model-world state. |
| 83 | OpenGl_ModelWorldState(); |
| 84 | |
| 85 | //! Sets new model-world matrix. |
| 86 | void Set (const OpenGl_Mat4& theModelWorldMatrix); |
| 87 | |
| 88 | //! Returns current model-world matrix. |
| 89 | const OpenGl_Mat4& ModelWorldMatrix() const; |
| 90 | |
| 91 | //! Returns inverse of current model-world matrix. |
| 92 | const OpenGl_Mat4& ModelWorldMatrixInverse() const; |
| 93 | |
| 94 | private: |
| 95 | |
| 96 | OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix |
| 97 | mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix |
| 98 | bool myInverseNeedUpdate; //!< Is inversed matrix outdated? |
| 99 | |
| 100 | }; |
| 101 | |
| 102 | //! Defines state of OCCT world-view transformation. |
| 103 | class OpenGl_WorldViewState : public OpenGl_StateInterface |
| 104 | { |
| 105 | public: |
| 106 | |
| 107 | //! Creates uninitialized world-view state. |
| 108 | OpenGl_WorldViewState(); |
| 109 | |
| 110 | //! Sets new world-view matrix. |
| 111 | void Set (const OpenGl_Mat4& theWorldViewMatrix); |
| 112 | |
| 113 | //! Returns current world-view matrix. |
| 114 | const OpenGl_Mat4& WorldViewMatrix() const; |
| 115 | |
| 116 | //! Returns inverse of current world-view matrix. |
| 117 | const OpenGl_Mat4& WorldViewMatrixInverse() const; |
| 118 | |
| 119 | private: |
| 120 | |
| 121 | OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix |
| 122 | mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix |
| 123 | bool myInverseNeedUpdate; //!< Is inversed matrix outdated? |
| 124 | |
| 125 | }; |
| 126 | |
| 127 | //! Defines state of OCCT light sources. |
| 128 | class OpenGl_LightSourceState : public OpenGl_StateInterface |
| 129 | { |
| 130 | public: |
| 131 | |
| 132 | //! Creates uninitialized state of light sources. |
| 133 | OpenGl_LightSourceState(); |
| 134 | |
| 135 | //! Sets new light sources. |
| 136 | void Set (const OpenGl_ListOfLight* theLightSources); |
| 137 | |
| 138 | //! Returns current list of light sources. |
| 139 | const OpenGl_ListOfLight* LightSources() const; |
| 140 | |
| 141 | private: |
| 142 | |
| 143 | const OpenGl_ListOfLight* myLightSources; //!< List of OCCT light sources |
| 144 | |
| 145 | }; |
| 146 | |
| 147 | //! Defines generic state of OCCT material properties. |
| 148 | class OpenGl_MaterialState : public OpenGl_StateInterface |
| 149 | { |
| 150 | public: |
| 151 | |
| 152 | //! Creates new material state. |
| 153 | OpenGl_MaterialState (const OpenGl_Element* theAspect = NULL); |
| 154 | |
| 155 | //! Sets new material aspect. |
| 156 | void Set (const OpenGl_Element* theAspect); |
| 157 | |
| 158 | //! Returns material aspect. |
| 159 | const OpenGl_Element* Aspect() const; |
| 160 | |
| 161 | private: |
| 162 | |
| 163 | const OpenGl_Element* myAspect; //!< OCCT material aspect |
| 164 | |
| 165 | }; |
| 166 | |
| 167 | //! Defines generic state of OCCT clipping state. |
| 168 | class OpenGl_ClippingState : public OpenGl_StateInterface |
| 169 | { |
| 170 | public: |
| 171 | |
| 172 | //! Creates new clipping state. |
| 173 | OpenGl_ClippingState(); |
| 174 | |
| 175 | }; |
| 176 | |
| 177 | #endif // _OpenGl_State_HeaderFile |