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 <Aspect_TypeOfMarker.hxx>
20 #include <Graphic3d_AspectMarker3d.hxx>
21 #include <TCollection_AsciiString.hxx>
23 #include <OpenGl_Element.hxx>
25 class OpenGl_PointSprite;
26 class OpenGl_ShaderProgram;
28 //! The element holding Graphic3d_AspectMarker3d.
29 class OpenGl_AspectMarker : public OpenGl_Element
33 //! Empty constructor.
34 Standard_EXPORT OpenGl_AspectMarker();
36 //! Create and assign parameters.
37 Standard_EXPORT OpenGl_AspectMarker (const Handle(Graphic3d_AspectMarker3d)& theAspect);
39 //! Return the aspect.
40 const Handle(Graphic3d_AspectMarker3d)& Aspect() const { return myAspect; }
42 //! Assign new aspect.
43 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect);
45 //! @return marker size
46 Standard_ShortReal MarkerSize() const { return myMarkerSize; }
48 //! Init and return OpenGl point sprite resource.
49 //! @return point sprite texture.
50 const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const
52 if (!myResources.IsSpriteReady())
54 myResources.BuildSprites (theCtx,
55 myAspect->GetMarkerImage(),
58 myAspect->ColorRGBA(),
60 myResources.SetSpriteReady();
63 return myResources.Sprite;
66 //! Init and return OpenGl highlight point sprite resource.
67 //! @return point sprite texture for highlight.
68 const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const
70 if (!myResources.IsSpriteReady())
72 myResources.BuildSprites (theCtx,
73 myAspect->GetMarkerImage(),
76 myAspect->ColorRGBA(),
78 myResources.SetSpriteReady();
81 return myResources.SpriteA;
84 //! Init and return OpenGl shader program resource.
85 //! @return shader program resource.
86 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
88 if (!myResources.IsShaderReady())
90 myResources.BuildShader (theCtx, myAspect->ShaderProgram());
91 myResources.SetShaderReady();
94 return myResources.ShaderProgram;
97 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
98 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
103 mutable struct Resources
110 myIsSpriteReady (Standard_False),
111 myIsShaderReady (Standard_False) {}
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; }
117 void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; }
118 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
120 Standard_EXPORT void BuildSprites (const Handle(OpenGl_Context)& theCtx,
121 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
122 const Aspect_TypeOfMarker theType,
123 const Standard_ShortReal theScale,
124 const Graphic3d_Vec4& theColor,
125 Standard_ShortReal& theMarkerSize);
127 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
128 const Handle(Graphic3d_ShaderProgram)& theShader);
130 Standard_EXPORT void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
131 const Aspect_TypeOfMarker theType,
132 const Standard_ShortReal theScale,
133 const Graphic3d_Vec4& theColor,
134 TCollection_AsciiString& theKey,
135 TCollection_AsciiString& theKeyA);
137 Handle(OpenGl_PointSprite) Sprite;
138 TCollection_AsciiString SpriteKey;
140 Handle(OpenGl_PointSprite) SpriteA;
141 TCollection_AsciiString SpriteAKey;
143 Handle(OpenGl_ShaderProgram) ShaderProgram;
144 TCollection_AsciiString ShaderProgramId;
148 Standard_Boolean myIsSpriteReady;
149 Standard_Boolean myIsShaderReady;
153 Handle(Graphic3d_AspectMarker3d) myAspect;
154 mutable Standard_ShortReal myMarkerSize;
158 DEFINE_STANDARD_ALLOC
162 #endif // OpenGl_AspectMarker_Header