0024001: Stereographic rendering support
[occt.git] / src / OpenGl / OpenGl_AspectMarker.hxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef OpenGl_AspectMarker_Header
17#define OpenGl_AspectMarker_Header
18
bf75be98 19#include <InterfaceGraphic_Graphic3d.hxx>
2166f0fa 20#include <Aspect_TypeOfMarker.hxx>
a577aaab 21#include <Graphic3d_CGroup.hxx>
22#include <TCollection_AsciiString.hxx>
2166f0fa
SK
23
24#include <OpenGl_Element.hxx>
a577aaab 25#include <Handle_OpenGl_PointSprite.hxx>
30f0ad28 26#include <Handle_OpenGl_ShaderProgram.hxx>
a577aaab 27
28#include <Image_PixMap_Handle.hxx>
2166f0fa
SK
29
30class OpenGl_AspectMarker : public OpenGl_Element
31{
a577aaab 32public:
2166f0fa 33
a577aaab 34 OpenGl_AspectMarker();
2166f0fa 35
fd4a6963 36 //! Copy parameters
37 void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect);
2166f0fa 38
fd4a6963 39 //! @return marker color
40 const TEL_COLOUR& Color() const
41 {
42 return myColor;
43 }
44
45 //! @return maker type
46 Aspect_TypeOfMarker Type() const
47 {
48 return myType;
49 }
50
51 //! @return marker scale
52 Standard_ShortReal Scale() const
53 {
54 return myScale;
55 }
56
57 //! @return marker size
58 Standard_ShortReal MarkerSize() const
59 {
60 return myMarkerSize;
61 }
62
63 //! Init and return OpenGl point sprite resource.
64 //! @return point sprite texture.
30f0ad28 65 const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Workspace)& theWorkspace) const
fd4a6963 66 {
30f0ad28 67 if (!myResources.IsSpriteReady())
fd4a6963 68 {
30f0ad28 69 myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize);
70 myResources.SetSpriteReady();
fd4a6963 71 }
72
30f0ad28 73 return myResources.Sprite;
fd4a6963 74 }
75
76 //! Init and return OpenGl highlight point sprite resource.
77 //! @return point sprite texture for highlight.
30f0ad28 78 const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Workspace)& theWorkspace) const
fd4a6963 79 {
30f0ad28 80 if (!myResources.IsSpriteReady())
fd4a6963 81 {
30f0ad28 82 myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize);
83 myResources.SetSpriteReady();
fd4a6963 84 }
85
30f0ad28 86 return myResources.SpriteA;
87 }
88
89 //! Init and return OpenGl shader program resource.
90 //! @return shader program resource.
91 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
92 {
93 if (!myResources.IsShaderReady())
94 {
95 myResources.BuildShader (theWorkspace, myShaderProgram);
96 myResources.SetShaderReady();
97 }
98
99 return myResources.ShaderProgram;
fd4a6963 100 }
2166f0fa 101
5e27df78 102 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
103 virtual void Release (const Handle(OpenGl_Context)& theContext);
2166f0fa 104
30f0ad28 105protected: //! @name ordinary aspect properties
106
107 TEL_COLOUR myColor;
108 Aspect_TypeOfMarker myType;
109 Standard_ShortReal myScale;
110 mutable Standard_ShortReal myMarkerSize;
111 Handle(Graphic3d_MarkerImage) myMarkerImage;
112 Handle(Graphic3d_ShaderProgram) myShaderProgram;
a577aaab 113
30f0ad28 114protected: //! @name OpenGl resources
115
116 //! OpenGl resources
117 mutable struct Resources
118 {
119 public:
120
121 Resources() :
122 SpriteKey (""),
123 SpriteAKey (""),
124 myIsSpriteReady (Standard_False),
125 myIsShaderReady (Standard_False) {}
126
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; }
f85399e5 131 void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; }
132 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
30f0ad28 133
134 void BuildSprites (const Handle(OpenGl_Workspace)& theWS,
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);
140
141 void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
142
143 void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
fd4a6963 144 const Aspect_TypeOfMarker theType,
145 const Standard_ShortReal theScale,
146 const TEL_COLOUR& theColor,
147 TCollection_AsciiString& theKey,
30f0ad28 148 TCollection_AsciiString& theKeyA);
fd4a6963 149
30f0ad28 150 Handle(OpenGl_PointSprite) Sprite;
151 TCollection_AsciiString SpriteKey;
fd4a6963 152
30f0ad28 153 Handle(OpenGl_PointSprite) SpriteA;
154 TCollection_AsciiString SpriteAKey;
fd4a6963 155
30f0ad28 156 Handle(OpenGl_ShaderProgram) ShaderProgram;
157 TCollection_AsciiString ShaderProgramId;
158
159 private:
160
161 Standard_Boolean myIsSpriteReady;
162 Standard_Boolean myIsShaderReady;
fd4a6963 163
30f0ad28 164 } myResources;
2166f0fa 165
a577aaab 166public:
2166f0fa 167
1c35b92f 168 DEFINE_STANDARD_ALLOC
a577aaab 169
2166f0fa
SK
170};
171
a577aaab 172#endif // OpenGl_AspectMarker_Header