1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #ifndef OpenGl_AspectMarker_Header
21 #define OpenGl_AspectMarker_Header
23 #include <InterfaceGraphic_Graphic3d.hxx>
24 #include <Aspect_TypeOfMarker.hxx>
25 #include <Graphic3d_CGroup.hxx>
26 #include <TCollection_AsciiString.hxx>
28 #include <OpenGl_Element.hxx>
29 #include <Handle_OpenGl_PointSprite.hxx>
30 #include <Handle_OpenGl_ShaderProgram.hxx>
32 #include <Image_PixMap_Handle.hxx>
34 class OpenGl_AspectMarker : public OpenGl_Element
38 OpenGl_AspectMarker();
41 void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect);
43 //! @return marker color
44 const TEL_COLOUR& Color() const
49 //! @return maker type
50 Aspect_TypeOfMarker Type() const
55 //! @return marker scale
56 Standard_ShortReal Scale() const
61 //! @return marker size
62 Standard_ShortReal MarkerSize() const
67 //! Init and return OpenGl point sprite resource.
68 //! @return point sprite texture.
69 const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Workspace)& theWorkspace) const
71 if (!myResources.IsSpriteReady())
73 myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize);
74 myResources.SetSpriteReady();
77 return myResources.Sprite;
80 //! Init and return OpenGl highlight point sprite resource.
81 //! @return point sprite texture for highlight.
82 const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Workspace)& theWorkspace) const
84 if (!myResources.IsSpriteReady())
86 myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize);
87 myResources.SetSpriteReady();
90 return myResources.SpriteA;
93 //! Init and return OpenGl shader program resource.
94 //! @return shader program resource.
95 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
97 if (!myResources.IsShaderReady())
99 myResources.BuildShader (theWorkspace, myShaderProgram);
100 myResources.SetShaderReady();
103 return myResources.ShaderProgram;
106 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
107 virtual void Release (const Handle(OpenGl_Context)& theContext);
109 protected: //! @name ordinary aspect properties
112 Aspect_TypeOfMarker myType;
113 Standard_ShortReal myScale;
114 mutable Standard_ShortReal myMarkerSize;
115 Handle(Graphic3d_MarkerImage) myMarkerImage;
116 Handle(Graphic3d_ShaderProgram) myShaderProgram;
118 protected: //! @name OpenGl resources
121 mutable struct Resources
128 myIsSpriteReady (Standard_False),
129 myIsShaderReady (Standard_False) {}
131 Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; }
132 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
133 void SetSpriteReady() { myIsSpriteReady = Standard_True; }
134 void SetShaderReady() { myIsShaderReady = Standard_True; }
135 void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; }
136 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
138 void BuildSprites (const Handle(OpenGl_Workspace)& theWS,
139 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
140 const Aspect_TypeOfMarker theType,
141 const Standard_ShortReal theScale,
142 const TEL_COLOUR& theColor,
143 Standard_ShortReal& theMarkerSize);
145 void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
147 void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
148 const Aspect_TypeOfMarker theType,
149 const Standard_ShortReal theScale,
150 const TEL_COLOUR& theColor,
151 TCollection_AsciiString& theKey,
152 TCollection_AsciiString& theKeyA);
154 Handle(OpenGl_PointSprite) Sprite;
155 TCollection_AsciiString SpriteKey;
157 Handle(OpenGl_PointSprite) SpriteA;
158 TCollection_AsciiString SpriteAKey;
160 Handle(OpenGl_ShaderProgram) ShaderProgram;
161 TCollection_AsciiString ShaderProgramId;
165 Standard_Boolean myIsSpriteReady;
166 Standard_Boolean myIsShaderReady;
172 DEFINE_STANDARD_ALLOC
176 #endif // OpenGl_AspectMarker_Header