Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa SK |
16 | #ifndef OpenGl_AspectMarker_Header |
17 | #define OpenGl_AspectMarker_Header | |
18 | ||
2166f0fa | 19 | #include <Aspect_TypeOfMarker.hxx> |
b6472664 | 20 | #include <Graphic3d_AspectMarker3d.hxx> |
a577aaab | 21 | #include <TCollection_AsciiString.hxx> |
2166f0fa SK |
22 | |
23 | #include <OpenGl_Element.hxx> | |
cc8cbabe | 24 | #include <OpenGl_TextureSet.hxx> |
a577aaab | 25 | |
c04c30b3 | 26 | class OpenGl_PointSprite; |
27 | class OpenGl_ShaderProgram; | |
2166f0fa | 28 | |
b6472664 | 29 | //! The element holding Graphic3d_AspectMarker3d. |
2166f0fa SK |
30 | class OpenGl_AspectMarker : public OpenGl_Element |
31 | { | |
a577aaab | 32 | public: |
2166f0fa | 33 | |
b6472664 | 34 | //! Empty constructor. |
595a42a4 | 35 | Standard_EXPORT OpenGl_AspectMarker(); |
2166f0fa | 36 | |
b6472664 | 37 | //! Create and assign parameters. |
38 | Standard_EXPORT OpenGl_AspectMarker (const Handle(Graphic3d_AspectMarker3d)& theAspect); | |
2166f0fa | 39 | |
b6472664 | 40 | //! Return the aspect. |
41 | const Handle(Graphic3d_AspectMarker3d)& Aspect() const { return myAspect; } | |
fd4a6963 | 42 | |
b6472664 | 43 | //! Assign new aspect. |
44 | Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect); | |
fd4a6963 | 45 | |
46 | //! @return marker size | |
b6472664 | 47 | Standard_ShortReal MarkerSize() const { return myMarkerSize; } |
fd4a6963 | 48 | |
49 | //! Init and return OpenGl point sprite resource. | |
50 | //! @return point sprite texture. | |
cc8cbabe | 51 | const Handle(OpenGl_TextureSet)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const |
fd4a6963 | 52 | { |
30f0ad28 | 53 | if (!myResources.IsSpriteReady()) |
fd4a6963 | 54 | { |
b6472664 | 55 | myResources.BuildSprites (theCtx, |
56 | myAspect->GetMarkerImage(), | |
57 | myAspect->Type(), | |
58 | myAspect->Scale(), | |
59 | myAspect->ColorRGBA(), | |
60 | myMarkerSize); | |
30f0ad28 | 61 | myResources.SetSpriteReady(); |
fd4a6963 | 62 | } |
63 | ||
cc8cbabe | 64 | return myResources.Sprite(); |
fd4a6963 | 65 | } |
66 | ||
67 | //! Init and return OpenGl highlight point sprite resource. | |
68 | //! @return point sprite texture for highlight. | |
cc8cbabe | 69 | const Handle(OpenGl_TextureSet)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const |
fd4a6963 | 70 | { |
30f0ad28 | 71 | if (!myResources.IsSpriteReady()) |
fd4a6963 | 72 | { |
b6472664 | 73 | myResources.BuildSprites (theCtx, |
74 | myAspect->GetMarkerImage(), | |
75 | myAspect->Type(), | |
76 | myAspect->Scale(), | |
77 | myAspect->ColorRGBA(), | |
78 | myMarkerSize); | |
30f0ad28 | 79 | myResources.SetSpriteReady(); |
fd4a6963 | 80 | } |
81 | ||
cc8cbabe | 82 | return myResources.SpriteA(); |
30f0ad28 | 83 | } |
84 | ||
85 | //! Init and return OpenGl shader program resource. | |
86 | //! @return shader program resource. | |
8625ef7e | 87 | const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const |
30f0ad28 | 88 | { |
89 | if (!myResources.IsShaderReady()) | |
90 | { | |
b6472664 | 91 | myResources.BuildShader (theCtx, myAspect->ShaderProgram()); |
30f0ad28 | 92 | myResources.SetShaderReady(); |
93 | } | |
94 | ||
cc8cbabe | 95 | return myResources.ShaderProgram(); |
fd4a6963 | 96 | } |
2166f0fa | 97 | |
eaac0866 | 98 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE; |
99 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE; | |
100 | ||
101 | //! Update presentation aspects parameters after their modification. | |
102 | virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); } | |
2166f0fa | 103 | |
b6472664 | 104 | protected: |
30f0ad28 | 105 | |
106 | //! OpenGl resources | |
107 | mutable struct Resources | |
108 | { | |
109 | public: | |
110 | ||
cc8cbabe | 111 | //! Empty constructor. |
112 | Resources() | |
113 | : myIsSpriteReady (Standard_False), | |
114 | myIsShaderReady (Standard_False) {} | |
115 | ||
116 | const Handle(OpenGl_TextureSet)& Sprite() const { return mySprite; } | |
117 | const Handle(OpenGl_TextureSet)& SpriteA() const { return mySpriteA; } | |
118 | const Handle(OpenGl_ShaderProgram)& ShaderProgram() const { return myShaderProgram; } | |
30f0ad28 | 119 | |
120 | Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; } | |
121 | Standard_Boolean IsShaderReady() const { return myIsShaderReady; } | |
122 | void SetSpriteReady() { myIsSpriteReady = Standard_True; } | |
123 | void SetShaderReady() { myIsShaderReady = Standard_True; } | |
30f0ad28 | 124 | |
cc8cbabe | 125 | //! Update texture resource up-to-date state. |
126 | Standard_EXPORT void UpdateTexturesRediness (const Handle(Graphic3d_AspectMarker3d)& theAspect, | |
127 | Standard_ShortReal& theMarkerSize); | |
128 | ||
129 | //! Update shader resource up-to-date state. | |
130 | Standard_EXPORT void UpdateShaderRediness (const Handle(Graphic3d_AspectMarker3d)& theAspect); | |
131 | ||
132 | //! Release texture resource. | |
133 | Standard_EXPORT void ReleaseTextures (OpenGl_Context* theCtx); | |
134 | ||
135 | //! Release shader resource. | |
136 | Standard_EXPORT void ReleaseShaders (OpenGl_Context* theCtx); | |
137 | ||
138 | //! Build texture resources. | |
8625ef7e | 139 | Standard_EXPORT void BuildSprites (const Handle(OpenGl_Context)& theCtx, |
595a42a4 | 140 | const Handle(Graphic3d_MarkerImage)& theMarkerImage, |
141 | const Aspect_TypeOfMarker theType, | |
142 | const Standard_ShortReal theScale, | |
b6472664 | 143 | const Graphic3d_Vec4& theColor, |
595a42a4 | 144 | Standard_ShortReal& theMarkerSize); |
145 | ||
cc8cbabe | 146 | //! Build shader resources. |
8625ef7e | 147 | Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx, |
595a42a4 | 148 | const Handle(Graphic3d_ShaderProgram)& theShader); |
149 | ||
cc8cbabe | 150 | private: |
fd4a6963 | 151 | |
cc8cbabe | 152 | //! Generate resource keys for a sprite. |
153 | static void spriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage, | |
154 | const Aspect_TypeOfMarker theType, | |
155 | const Standard_ShortReal theScale, | |
156 | const Graphic3d_Vec4& theColor, | |
157 | TCollection_AsciiString& theKey, | |
158 | TCollection_AsciiString& theKeyA); | |
30f0ad28 | 159 | |
160 | private: | |
161 | ||
cc8cbabe | 162 | Handle(OpenGl_TextureSet) mySprite; |
163 | Handle(OpenGl_TextureSet) mySpriteA; | |
164 | Handle(OpenGl_ShaderProgram) myShaderProgram; | |
165 | TCollection_AsciiString myShaderProgramId; | |
166 | Standard_Boolean myIsSpriteReady; | |
167 | Standard_Boolean myIsShaderReady; | |
fd4a6963 | 168 | |
30f0ad28 | 169 | } myResources; |
2166f0fa | 170 | |
b6472664 | 171 | Handle(Graphic3d_AspectMarker3d) myAspect; |
172 | mutable Standard_ShortReal myMarkerSize; | |
173 | ||
a577aaab | 174 | public: |
2166f0fa | 175 | |
1c35b92f | 176 | DEFINE_STANDARD_ALLOC |
a577aaab | 177 | |
2166f0fa SK |
178 | }; |
179 | ||
a577aaab | 180 | #endif // OpenGl_AspectMarker_Header |