| 1 | // Created on: 2011-07-13 |
| 2 | // Created by: Sergey ZERCHANINOV |
| 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
| 4 | // |
| 5 | // This file is part of Open CASCADE Technology software library. |
| 6 | // |
| 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. |
| 12 | // |
| 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 14 | // commercial license or contractual agreement. |
| 15 | |
| 16 | #ifndef OpenGl_AspectMarker_Header |
| 17 | #define OpenGl_AspectMarker_Header |
| 18 | |
| 19 | #include <InterfaceGraphic_Graphic3d.hxx> |
| 20 | #include <Aspect_TypeOfMarker.hxx> |
| 21 | #include <Graphic3d_CGroup.hxx> |
| 22 | #include <TCollection_AsciiString.hxx> |
| 23 | |
| 24 | #include <OpenGl_Element.hxx> |
| 25 | #include <Handle_OpenGl_PointSprite.hxx> |
| 26 | #include <Handle_OpenGl_ShaderProgram.hxx> |
| 27 | |
| 28 | #include <Image_PixMap_Handle.hxx> |
| 29 | |
| 30 | class OpenGl_AspectMarker : public OpenGl_Element |
| 31 | { |
| 32 | public: |
| 33 | |
| 34 | OpenGl_AspectMarker(); |
| 35 | |
| 36 | //! Copy parameters |
| 37 | void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect); |
| 38 | |
| 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. |
| 65 | const Handle(OpenGl_PointSprite)& SpriteRes (const Handle(OpenGl_Workspace)& theWorkspace) const |
| 66 | { |
| 67 | if (!myResources.IsSpriteReady()) |
| 68 | { |
| 69 | myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize); |
| 70 | myResources.SetSpriteReady(); |
| 71 | } |
| 72 | |
| 73 | return myResources.Sprite; |
| 74 | } |
| 75 | |
| 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_Workspace)& theWorkspace) const |
| 79 | { |
| 80 | if (!myResources.IsSpriteReady()) |
| 81 | { |
| 82 | myResources.BuildSprites (theWorkspace, myMarkerImage, myType, myScale, myColor, myMarkerSize); |
| 83 | myResources.SetSpriteReady(); |
| 84 | } |
| 85 | |
| 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; |
| 100 | } |
| 101 | |
| 102 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; |
| 103 | virtual void Release (const Handle(OpenGl_Context)& theContext); |
| 104 | |
| 105 | protected: //! @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; |
| 113 | |
| 114 | protected: //! @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; } |
| 131 | void ResetSpriteReadiness() { myIsSpriteReady = Standard_False; } |
| 132 | void ResetShaderReadiness() { myIsShaderReady = Standard_False; } |
| 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, |
| 144 | const Aspect_TypeOfMarker theType, |
| 145 | const Standard_ShortReal theScale, |
| 146 | const TEL_COLOUR& theColor, |
| 147 | TCollection_AsciiString& theKey, |
| 148 | TCollection_AsciiString& theKeyA); |
| 149 | |
| 150 | Handle(OpenGl_PointSprite) Sprite; |
| 151 | TCollection_AsciiString SpriteKey; |
| 152 | |
| 153 | Handle(OpenGl_PointSprite) SpriteA; |
| 154 | TCollection_AsciiString SpriteAKey; |
| 155 | |
| 156 | Handle(OpenGl_ShaderProgram) ShaderProgram; |
| 157 | TCollection_AsciiString ShaderProgramId; |
| 158 | |
| 159 | private: |
| 160 | |
| 161 | Standard_Boolean myIsSpriteReady; |
| 162 | Standard_Boolean myIsShaderReady; |
| 163 | |
| 164 | } myResources; |
| 165 | |
| 166 | public: |
| 167 | |
| 168 | DEFINE_STANDARD_ALLOC |
| 169 | |
| 170 | }; |
| 171 | |
| 172 | #endif // OpenGl_AspectMarker_Header |