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>
25 #include <Handle_OpenGl_PointSprite.hxx>
26 #include <Handle_OpenGl_ShaderProgram.hxx>
28 #include <Image_PixMap_Handle.hxx>
30 class OpenGl_AspectMarker : public OpenGl_Element
34 Standard_EXPORT OpenGl_AspectMarker();
37 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect);
39 //! @return marker color
40 const TEL_COLOUR& Color() const
45 //! @return maker type
46 Aspect_TypeOfMarker Type() const
51 //! @return marker scale
52 Standard_ShortReal Scale() const
57 //! @return marker size
58 Standard_ShortReal MarkerSize() const
63 //! Init and return OpenGl point sprite resource.
64 //! @return point sprite texture.
65 const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const
67 if (!myResources.IsSpriteReady())
69 myResources.BuildSprites (theCtx, myMarkerImage, myType, myScale, myColor, myMarkerSize);
70 myResources.SetSpriteReady();
73 return myResources.Sprite;
76 //! Init and return OpenGl highlight point sprite resource.
77 //! @return point sprite texture for highlight.
78 const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const
80 if (!myResources.IsSpriteReady())
82 myResources.BuildSprites (theCtx, myMarkerImage, myType, myScale, myColor, myMarkerSize);
83 myResources.SetSpriteReady();
86 return myResources.SpriteA;
89 //! Init and return OpenGl shader program resource.
90 //! @return shader program resource.
91 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
93 if (!myResources.IsShaderReady())
95 myResources.BuildShader (theCtx, myShaderProgram);
96 myResources.SetShaderReady();
99 return myResources.ShaderProgram;
102 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
103 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
105 protected: //! @name ordinary aspect properties
108 Aspect_TypeOfMarker myType;
109 Standard_ShortReal myScale;
110 mutable Standard_ShortReal myMarkerSize;
111 Handle(Graphic3d_MarkerImage) myMarkerImage;
112 Handle(Graphic3d_ShaderProgram) myShaderProgram;
114 protected: //! @name OpenGl resources
117 mutable struct Resources
124 myIsSpriteReady (Standard_False),
125 myIsShaderReady (Standard_False) {}
127 Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; }
128 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
129 void SetSpriteReady() { myIsSpriteReady = Standard_True; }
130 void SetShaderReady() { myIsShaderReady = Standard_True; }
131 void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; }
132 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
134 Standard_EXPORT void BuildSprites (const Handle(OpenGl_Context)& theCtx,
135 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
136 const Aspect_TypeOfMarker theType,
137 const Standard_ShortReal theScale,
138 const TEL_COLOUR& theColor,
139 Standard_ShortReal& theMarkerSize);
141 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
142 const Handle(Graphic3d_ShaderProgram)& theShader);
144 Standard_EXPORT void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
145 const Aspect_TypeOfMarker theType,
146 const Standard_ShortReal theScale,
147 const TEL_COLOUR& theColor,
148 TCollection_AsciiString& theKey,
149 TCollection_AsciiString& theKeyA);
151 Handle(OpenGl_PointSprite) Sprite;
152 TCollection_AsciiString SpriteKey;
154 Handle(OpenGl_PointSprite) SpriteA;
155 TCollection_AsciiString SpriteAKey;
157 Handle(OpenGl_ShaderProgram) ShaderProgram;
158 TCollection_AsciiString ShaderProgramId;
162 Standard_Boolean myIsSpriteReady;
163 Standard_Boolean myIsShaderReady;
169 DEFINE_STANDARD_ALLOC
173 #endif // OpenGl_AspectMarker_Header