1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_AspectMarker_Header
17 #define OpenGl_AspectMarker_Header
19 #include <InterfaceGraphic_Graphic3d.hxx>
20 #include <Aspect_TypeOfMarker.hxx>
21 #include <Graphic3d_CAspectMarker.hxx>
22 #include <TCollection_AsciiString.hxx>
24 #include <OpenGl_Element.hxx>
26 class OpenGl_PointSprite;
27 class OpenGl_ShaderProgram;
29 class OpenGl_AspectMarker : public OpenGl_Element
33 Standard_EXPORT OpenGl_AspectMarker();
36 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect);
38 //! @return marker color
39 const TEL_COLOUR& Color() const
44 //! @return maker type
45 Aspect_TypeOfMarker Type() const
50 //! @return marker scale
51 Standard_ShortReal Scale() const
56 //! @return marker size
57 Standard_ShortReal MarkerSize() const
62 //! Init and return OpenGl point sprite resource.
63 //! @return point sprite texture.
64 const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const
66 if (!myResources.IsSpriteReady())
68 myResources.BuildSprites (theCtx, myMarkerImage, myType, myScale, myColor, myMarkerSize);
69 myResources.SetSpriteReady();
72 return myResources.Sprite;
75 //! Init and return OpenGl highlight point sprite resource.
76 //! @return point sprite texture for highlight.
77 const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const
79 if (!myResources.IsSpriteReady())
81 myResources.BuildSprites (theCtx, myMarkerImage, myType, myScale, myColor, myMarkerSize);
82 myResources.SetSpriteReady();
85 return myResources.SpriteA;
88 //! Init and return OpenGl shader program resource.
89 //! @return shader program resource.
90 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
92 if (!myResources.IsShaderReady())
94 myResources.BuildShader (theCtx, myShaderProgram);
95 myResources.SetShaderReady();
98 return myResources.ShaderProgram;
101 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
102 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
104 protected: //! @name ordinary aspect properties
107 Aspect_TypeOfMarker myType;
108 Standard_ShortReal myScale;
109 mutable Standard_ShortReal myMarkerSize;
110 Handle(Graphic3d_MarkerImage) myMarkerImage;
111 Handle(Graphic3d_ShaderProgram) myShaderProgram;
113 protected: //! @name OpenGl resources
116 mutable struct Resources
123 myIsSpriteReady (Standard_False),
124 myIsShaderReady (Standard_False) {}
126 Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; }
127 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
128 void SetSpriteReady() { myIsSpriteReady = Standard_True; }
129 void SetShaderReady() { myIsShaderReady = Standard_True; }
130 void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; }
131 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
133 Standard_EXPORT void BuildSprites (const Handle(OpenGl_Context)& theCtx,
134 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
135 const Aspect_TypeOfMarker theType,
136 const Standard_ShortReal theScale,
137 const TEL_COLOUR& theColor,
138 Standard_ShortReal& theMarkerSize);
140 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
141 const Handle(Graphic3d_ShaderProgram)& theShader);
143 Standard_EXPORT void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
144 const Aspect_TypeOfMarker theType,
145 const Standard_ShortReal theScale,
146 const TEL_COLOUR& theColor,
147 TCollection_AsciiString& theKey,
148 TCollection_AsciiString& theKeyA);
150 Handle(OpenGl_PointSprite) Sprite;
151 TCollection_AsciiString SpriteKey;
153 Handle(OpenGl_PointSprite) SpriteA;
154 TCollection_AsciiString SpriteAKey;
156 Handle(OpenGl_ShaderProgram) ShaderProgram;
157 TCollection_AsciiString ShaderProgramId;
161 Standard_Boolean myIsSpriteReady;
162 Standard_Boolean myIsShaderReady;
168 DEFINE_STANDARD_ALLOC
172 #endif // OpenGl_AspectMarker_Header