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> | |
a577aaab | 24 | |
c04c30b3 | 25 | class OpenGl_PointSprite; |
26 | class OpenGl_ShaderProgram; | |
2166f0fa | 27 | |
b6472664 | 28 | //! The element holding Graphic3d_AspectMarker3d. |
2166f0fa SK |
29 | class OpenGl_AspectMarker : public OpenGl_Element |
30 | { | |
a577aaab | 31 | public: |
2166f0fa | 32 | |
b6472664 | 33 | //! Empty constructor. |
595a42a4 | 34 | Standard_EXPORT OpenGl_AspectMarker(); |
2166f0fa | 35 | |
b6472664 | 36 | //! Create and assign parameters. |
37 | Standard_EXPORT OpenGl_AspectMarker (const Handle(Graphic3d_AspectMarker3d)& theAspect); | |
2166f0fa | 38 | |
b6472664 | 39 | //! Return the aspect. |
40 | const Handle(Graphic3d_AspectMarker3d)& Aspect() const { return myAspect; } | |
fd4a6963 | 41 | |
b6472664 | 42 | //! Assign new aspect. |
43 | Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect); | |
fd4a6963 | 44 | |
45 | //! @return marker size | |
b6472664 | 46 | Standard_ShortReal MarkerSize() const { return myMarkerSize; } |
fd4a6963 | 47 | |
48 | //! Init and return OpenGl point sprite resource. | |
49 | //! @return point sprite texture. | |
8625ef7e | 50 | const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const |
fd4a6963 | 51 | { |
30f0ad28 | 52 | if (!myResources.IsSpriteReady()) |
fd4a6963 | 53 | { |
b6472664 | 54 | myResources.BuildSprites (theCtx, |
55 | myAspect->GetMarkerImage(), | |
56 | myAspect->Type(), | |
57 | myAspect->Scale(), | |
58 | myAspect->ColorRGBA(), | |
59 | myMarkerSize); | |
30f0ad28 | 60 | myResources.SetSpriteReady(); |
fd4a6963 | 61 | } |
62 | ||
30f0ad28 | 63 | return myResources.Sprite; |
fd4a6963 | 64 | } |
65 | ||
66 | //! Init and return OpenGl highlight point sprite resource. | |
67 | //! @return point sprite texture for highlight. | |
8625ef7e | 68 | const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const |
fd4a6963 | 69 | { |
30f0ad28 | 70 | if (!myResources.IsSpriteReady()) |
fd4a6963 | 71 | { |
b6472664 | 72 | myResources.BuildSprites (theCtx, |
73 | myAspect->GetMarkerImage(), | |
74 | myAspect->Type(), | |
75 | myAspect->Scale(), | |
76 | myAspect->ColorRGBA(), | |
77 | myMarkerSize); | |
30f0ad28 | 78 | myResources.SetSpriteReady(); |
fd4a6963 | 79 | } |
80 | ||
30f0ad28 | 81 | return myResources.SpriteA; |
82 | } | |
83 | ||
84 | //! Init and return OpenGl shader program resource. | |
85 | //! @return shader program resource. | |
8625ef7e | 86 | const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const |
30f0ad28 | 87 | { |
88 | if (!myResources.IsShaderReady()) | |
89 | { | |
b6472664 | 90 | myResources.BuildShader (theCtx, myAspect->ShaderProgram()); |
30f0ad28 | 91 | myResources.SetShaderReady(); |
92 | } | |
93 | ||
94 | return myResources.ShaderProgram; | |
fd4a6963 | 95 | } |
2166f0fa | 96 | |
595a42a4 | 97 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; |
10b9c7df | 98 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext); |
2166f0fa | 99 | |
b6472664 | 100 | protected: |
30f0ad28 | 101 | |
102 | //! OpenGl resources | |
103 | mutable struct Resources | |
104 | { | |
105 | public: | |
106 | ||
107 | Resources() : | |
108 | SpriteKey (""), | |
109 | SpriteAKey (""), | |
110 | myIsSpriteReady (Standard_False), | |
111 | myIsShaderReady (Standard_False) {} | |
112 | ||
113 | Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; } | |
114 | Standard_Boolean IsShaderReady() const { return myIsShaderReady; } | |
115 | void SetSpriteReady() { myIsSpriteReady = Standard_True; } | |
116 | void SetShaderReady() { myIsShaderReady = Standard_True; } | |
f85399e5 | 117 | void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; } |
118 | void ResetShaderReadiness() { myIsShaderReady = Standard_False; } | |
30f0ad28 | 119 | |
8625ef7e | 120 | Standard_EXPORT void BuildSprites (const Handle(OpenGl_Context)& theCtx, |
595a42a4 | 121 | const Handle(Graphic3d_MarkerImage)& theMarkerImage, |
122 | const Aspect_TypeOfMarker theType, | |
123 | const Standard_ShortReal theScale, | |
b6472664 | 124 | const Graphic3d_Vec4& theColor, |
595a42a4 | 125 | Standard_ShortReal& theMarkerSize); |
126 | ||
8625ef7e | 127 | Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx, |
595a42a4 | 128 | const Handle(Graphic3d_ShaderProgram)& theShader); |
129 | ||
130 | Standard_EXPORT void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage, | |
131 | const Aspect_TypeOfMarker theType, | |
132 | const Standard_ShortReal theScale, | |
b6472664 | 133 | const Graphic3d_Vec4& theColor, |
595a42a4 | 134 | TCollection_AsciiString& theKey, |
135 | TCollection_AsciiString& theKeyA); | |
fd4a6963 | 136 | |
30f0ad28 | 137 | Handle(OpenGl_PointSprite) Sprite; |
138 | TCollection_AsciiString SpriteKey; | |
fd4a6963 | 139 | |
30f0ad28 | 140 | Handle(OpenGl_PointSprite) SpriteA; |
141 | TCollection_AsciiString SpriteAKey; | |
fd4a6963 | 142 | |
30f0ad28 | 143 | Handle(OpenGl_ShaderProgram) ShaderProgram; |
144 | TCollection_AsciiString ShaderProgramId; | |
145 | ||
146 | private: | |
147 | ||
148 | Standard_Boolean myIsSpriteReady; | |
149 | Standard_Boolean myIsShaderReady; | |
fd4a6963 | 150 | |
30f0ad28 | 151 | } myResources; |
2166f0fa | 152 | |
b6472664 | 153 | Handle(Graphic3d_AspectMarker3d) myAspect; |
154 | mutable Standard_ShortReal myMarkerSize; | |
155 | ||
a577aaab | 156 | public: |
2166f0fa | 157 | |
1c35b92f | 158 | DEFINE_STANDARD_ALLOC |
a577aaab | 159 | |
2166f0fa SK |
160 | }; |
161 | ||
a577aaab | 162 | #endif // OpenGl_AspectMarker_Header |