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>
24 #include <OpenGl_TextureSet.hxx>
26 class OpenGl_PointSprite;
27 class OpenGl_ShaderProgram;
29 //! The element holding Graphic3d_AspectMarker3d.
30 class OpenGl_AspectMarker : public OpenGl_Element
34 //! Empty constructor.
35 Standard_EXPORT OpenGl_AspectMarker();
37 //! Create and assign parameters.
38 Standard_EXPORT OpenGl_AspectMarker (const Handle(Graphic3d_AspectMarker3d)& theAspect);
40 //! Return the aspect.
41 const Handle(Graphic3d_AspectMarker3d)& Aspect() const { return myAspect; }
43 //! Assign new aspect.
44 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect);
46 //! @return marker size
47 Standard_ShortReal MarkerSize() const { return myMarkerSize; }
49 //! Init and return OpenGl point sprite resource.
50 //! @return point sprite texture.
51 const Handle(OpenGl_TextureSet)& SpriteRes (const Handle(OpenGl_Context)& theCtx) const
53 if (!myResources.IsSpriteReady())
55 myResources.BuildSprites (theCtx,
56 myAspect->GetMarkerImage(),
59 myAspect->ColorRGBA(),
61 myResources.SetSpriteReady();
64 return myResources.Sprite();
67 //! Init and return OpenGl highlight point sprite resource.
68 //! @return point sprite texture for highlight.
69 const Handle(OpenGl_TextureSet)& SpriteHighlightRes (const Handle(OpenGl_Context)& theCtx) const
71 if (!myResources.IsSpriteReady())
73 myResources.BuildSprites (theCtx,
74 myAspect->GetMarkerImage(),
77 myAspect->ColorRGBA(),
79 myResources.SetSpriteReady();
82 return myResources.SpriteA();
85 //! Init and return OpenGl shader program resource.
86 //! @return shader program resource.
87 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
89 if (!myResources.IsShaderReady())
91 myResources.BuildShader (theCtx, myAspect->ShaderProgram());
92 myResources.SetShaderReady();
95 return myResources.ShaderProgram();
98 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
99 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
104 mutable struct Resources
108 //! Empty constructor.
110 : myIsSpriteReady (Standard_False),
111 myIsShaderReady (Standard_False) {}
113 const Handle(OpenGl_TextureSet)& Sprite() const { return mySprite; }
114 const Handle(OpenGl_TextureSet)& SpriteA() const { return mySpriteA; }
115 const Handle(OpenGl_ShaderProgram)& ShaderProgram() const { return myShaderProgram; }
117 Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; }
118 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
119 void SetSpriteReady() { myIsSpriteReady = Standard_True; }
120 void SetShaderReady() { myIsShaderReady = Standard_True; }
122 //! Update texture resource up-to-date state.
123 Standard_EXPORT void UpdateTexturesRediness (const Handle(Graphic3d_AspectMarker3d)& theAspect,
124 Standard_ShortReal& theMarkerSize);
126 //! Update shader resource up-to-date state.
127 Standard_EXPORT void UpdateShaderRediness (const Handle(Graphic3d_AspectMarker3d)& theAspect);
129 //! Release texture resource.
130 Standard_EXPORT void ReleaseTextures (OpenGl_Context* theCtx);
132 //! Release shader resource.
133 Standard_EXPORT void ReleaseShaders (OpenGl_Context* theCtx);
135 //! Build texture resources.
136 Standard_EXPORT void BuildSprites (const Handle(OpenGl_Context)& theCtx,
137 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
138 const Aspect_TypeOfMarker theType,
139 const Standard_ShortReal theScale,
140 const Graphic3d_Vec4& theColor,
141 Standard_ShortReal& theMarkerSize);
143 //! Build shader resources.
144 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
145 const Handle(Graphic3d_ShaderProgram)& theShader);
149 //! Generate resource keys for a sprite.
150 static void spriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
151 const Aspect_TypeOfMarker theType,
152 const Standard_ShortReal theScale,
153 const Graphic3d_Vec4& theColor,
154 TCollection_AsciiString& theKey,
155 TCollection_AsciiString& theKeyA);
159 Handle(OpenGl_TextureSet) mySprite;
160 Handle(OpenGl_TextureSet) mySpriteA;
161 Handle(OpenGl_ShaderProgram) myShaderProgram;
162 TCollection_AsciiString myShaderProgramId;
163 Standard_Boolean myIsSpriteReady;
164 Standard_Boolean myIsShaderReady;
168 Handle(Graphic3d_AspectMarker3d) myAspect;
169 mutable Standard_ShortReal myMarkerSize;
173 DEFINE_STANDARD_ALLOC
177 #endif // OpenGl_AspectMarker_Header