0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / OpenGl / OpenGl_AspectMarker.hxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
2166f0fa
SK
20#ifndef OpenGl_AspectMarker_Header
21#define OpenGl_AspectMarker_Header
22
bf75be98 23#include <InterfaceGraphic_Graphic3d.hxx>
2166f0fa 24#include <Aspect_TypeOfMarker.hxx>
a577aaab 25#include <Graphic3d_CGroup.hxx>
26#include <TCollection_AsciiString.hxx>
2166f0fa
SK
27
28#include <OpenGl_Element.hxx>
a577aaab 29#include <Handle_OpenGl_PointSprite.hxx>
30f0ad28 30#include <Handle_OpenGl_ShaderProgram.hxx>
a577aaab 31
32#include <Image_PixMap_Handle.hxx>
2166f0fa
SK
33
34class OpenGl_AspectMarker : public OpenGl_Element
35{
a577aaab 36public:
2166f0fa 37
a577aaab 38 OpenGl_AspectMarker();
2166f0fa 39
fd4a6963 40 //! Copy parameters
41 void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect);
2166f0fa 42
fd4a6963 43 //! @return marker color
44 const TEL_COLOUR& Color() const
45 {
46 return myColor;
47 }
48
49 //! @return maker type
50 Aspect_TypeOfMarker Type() const
51 {
52 return myType;
53 }
54
55 //! @return marker scale
56 Standard_ShortReal Scale() const
57 {
58 return myScale;
59 }
60
61 //! @return marker size
62 Standard_ShortReal MarkerSize() const
63 {
64 return myMarkerSize;
65 }
66
67 //! Init and return OpenGl point sprite resource.
68 //! @return point sprite texture.
30f0ad28 69 const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Workspace)& theWorkspace) const
fd4a6963 70 {
30f0ad28 71 if (!myResources.IsSpriteReady())
fd4a6963 72 {
30f0ad28 73 myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize);
74 myResources.SetSpriteReady();
fd4a6963 75 }
76
30f0ad28 77 return myResources.Sprite;
fd4a6963 78 }
79
80 //! Init and return OpenGl highlight point sprite resource.
81 //! @return point sprite texture for highlight.
30f0ad28 82 const Handle(OpenGl_PointSprite)& SpriteHighlightRes (const Handle(OpenGl_Workspace)& theWorkspace) const
fd4a6963 83 {
30f0ad28 84 if (!myResources.IsSpriteReady())
fd4a6963 85 {
30f0ad28 86 myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize);
87 myResources.SetSpriteReady();
fd4a6963 88 }
89
30f0ad28 90 return myResources.SpriteA;
91 }
92
93 //! Init and return OpenGl shader program resource.
94 //! @return shader program resource.
95 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
96 {
97 if (!myResources.IsShaderReady())
98 {
99 myResources.BuildShader (theWorkspace, myShaderProgram);
100 myResources.SetShaderReady();
101 }
102
103 return myResources.ShaderProgram;
fd4a6963 104 }
2166f0fa 105
5e27df78 106 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
107 virtual void Release (const Handle(OpenGl_Context)& theContext);
2166f0fa 108
30f0ad28 109protected: //! @name ordinary aspect properties
110
111 TEL_COLOUR myColor;
112 Aspect_TypeOfMarker myType;
113 Standard_ShortReal myScale;
114 mutable Standard_ShortReal myMarkerSize;
115 Handle(Graphic3d_MarkerImage) myMarkerImage;
116 Handle(Graphic3d_ShaderProgram) myShaderProgram;
a577aaab 117
30f0ad28 118protected: //! @name OpenGl resources
119
120 //! OpenGl resources
121 mutable struct Resources
122 {
123 public:
124
125 Resources() :
126 SpriteKey (""),
127 SpriteAKey (""),
128 myIsSpriteReady (Standard_False),
129 myIsShaderReady (Standard_False) {}
130
131 Standard_Boolean IsSpriteReady() const { return myIsSpriteReady; }
132 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
133 void SetSpriteReady() { myIsSpriteReady = Standard_True; }
134 void SetShaderReady() { myIsShaderReady = Standard_True; }
f85399e5 135 void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; }
136 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
30f0ad28 137
138 void BuildSprites (const Handle(OpenGl_Workspace)& theWS,
139 const Handle(Graphic3d_MarkerImage)& theMarkerImage,
140 const Aspect_TypeOfMarker theType,
141 const Standard_ShortReal theScale,
142 const TEL_COLOUR& theColor,
143 Standard_ShortReal& theMarkerSize);
144
145 void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
146
147 void SpriteKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage,
fd4a6963 148 const Aspect_TypeOfMarker theType,
149 const Standard_ShortReal theScale,
150 const TEL_COLOUR& theColor,
151 TCollection_AsciiString& theKey,
30f0ad28 152 TCollection_AsciiString& theKeyA);
fd4a6963 153
30f0ad28 154 Handle(OpenGl_PointSprite) Sprite;
155 TCollection_AsciiString SpriteKey;
fd4a6963 156
30f0ad28 157 Handle(OpenGl_PointSprite) SpriteA;
158 TCollection_AsciiString SpriteAKey;
fd4a6963 159
30f0ad28 160 Handle(OpenGl_ShaderProgram) ShaderProgram;
161 TCollection_AsciiString ShaderProgramId;
162
163 private:
164
165 Standard_Boolean myIsSpriteReady;
166 Standard_Boolean myIsShaderReady;
fd4a6963 167
30f0ad28 168 } myResources;
2166f0fa 169
a577aaab 170public:
2166f0fa 171
1c35b92f 172 DEFINE_STANDARD_ALLOC
a577aaab 173
2166f0fa
SK
174};
175
a577aaab 176#endif // OpenGl_AspectMarker_Header