Commit | Line | Data |
---|---|---|
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 | // |
d5f74e42 | 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 | |
973c2be1 | 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_AspectLine_Header |
17 | #define _OpenGl_AspectLine_Header | |
18 | ||
30f0ad28 | 19 | #include <TCollection_AsciiString.hxx> |
20 | ||
b6472664 | 21 | #include <Graphic3d_AspectLine3d.hxx> |
2166f0fa SK |
22 | #include <OpenGl_Element.hxx> |
23 | ||
c04c30b3 | 24 | class OpenGl_ShaderProgram; |
25 | ||
b6472664 | 26 | //! The element holding Graphic3d_AspectLine3d. |
2166f0fa SK |
27 | class OpenGl_AspectLine : public OpenGl_Element |
28 | { | |
595a42a4 | 29 | public: |
30 | ||
b6472664 | 31 | //! Empty constructor. |
595a42a4 | 32 | Standard_EXPORT OpenGl_AspectLine(); |
2166f0fa | 33 | |
b6472664 | 34 | //! Create and assign line aspect. |
35 | Standard_EXPORT OpenGl_AspectLine (const Handle(Graphic3d_AspectLine3d)& theAspect); | |
2166f0fa | 36 | |
b6472664 | 37 | //! Return line aspect. |
38 | const Handle(Graphic3d_AspectLine3d)& Aspect() const { return myAspect; } | |
2166f0fa | 39 | |
b6472664 | 40 | //! Assign line aspect. |
41 | Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectLine3d)& theAspect); | |
2166f0fa | 42 | |
30f0ad28 | 43 | //! Init and return OpenGl shader program resource. |
44 | //! @return shader program resource. | |
8625ef7e | 45 | const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const |
30f0ad28 | 46 | { |
47 | if (!myResources.IsShaderReady()) | |
48 | { | |
b6472664 | 49 | myResources.BuildShader (theCtx, myAspect->ShaderProgram()); |
30f0ad28 | 50 | myResources.SetShaderReady(); |
51 | } | |
52 | ||
53 | return myResources.ShaderProgram; | |
54 | } | |
55 | ||
eaac0866 | 56 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE; |
57 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE; | |
58 | ||
59 | //! Update presentation aspects parameters after their modification. | |
60 | virtual void SynchronizeAspects() Standard_OVERRIDE { SetAspect (myAspect); } | |
2166f0fa | 61 | |
30f0ad28 | 62 | protected: |
63 | ||
64 | //! OpenGl resources | |
65 | mutable struct Resources | |
66 | { | |
67 | public: | |
68 | Resources() : myIsShaderReady (Standard_False) {} | |
69 | ||
70 | Standard_Boolean IsShaderReady() const { return myIsShaderReady; } | |
f85399e5 | 71 | void SetShaderReady() { myIsShaderReady = Standard_True; } |
72 | void ResetShaderReadiness() { myIsShaderReady = Standard_False; } | |
30f0ad28 | 73 | |
8625ef7e | 74 | Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx, |
75 | const Handle(Graphic3d_ShaderProgram)& theShader); | |
30f0ad28 | 76 | |
77 | Handle(OpenGl_ShaderProgram) ShaderProgram; | |
78 | TCollection_AsciiString ShaderProgramId; | |
79 | ||
80 | private: | |
81 | ||
82 | Standard_Boolean myIsShaderReady; | |
2166f0fa | 83 | |
30f0ad28 | 84 | } myResources; |
b6472664 | 85 | Handle(Graphic3d_AspectLine3d) myAspect; |
2166f0fa SK |
86 | |
87 | public: | |
1c35b92f | 88 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
89 | }; |
90 | ||
91 | #endif //_OpenGl_AspectLine_Header |