0025133: TKOpenGl - Crash on closing a view containing presentations with capping
[occt.git] / src / OpenGl / OpenGl_AspectLine.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//
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
bf75be98 21#include <InterfaceGraphic_Graphic3d.hxx>
2166f0fa 22#include <Aspect_TypeOfLine.hxx>
b64d84be 23#include <Graphic3d_CAspectLine.hxx>
2166f0fa 24
30f0ad28 25#include <Handle_OpenGl_ShaderProgram.hxx>
26
2166f0fa
SK
27#include <OpenGl_Element.hxx>
28
29class OpenGl_AspectLine : public OpenGl_Element
30{
595a42a4 31public:
32
33 Standard_EXPORT OpenGl_AspectLine();
2166f0fa 34
595a42a4 35 Standard_EXPORT OpenGl_AspectLine (const OpenGl_AspectLine &AnOther);
2166f0fa 36
595a42a4 37 Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTLINE& theAspect);
2166f0fa
SK
38
39 const TEL_COLOUR & Color() const { return myColor; }
40 Aspect_TypeOfLine Type() const { return myType; }
41 float Width() const { return myWidth; }
42
30f0ad28 43 //! Init and return OpenGl shader program resource.
44 //! @return shader program resource.
45 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Workspace)& theWorkspace) const
46 {
47 if (!myResources.IsShaderReady())
48 {
49 myResources.BuildShader (theWorkspace, myShaderProgram);
50 myResources.SetShaderReady();
51 }
52
53 return myResources.ShaderProgram;
54 }
55
595a42a4 56 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
10b9c7df 57 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
2166f0fa 58
30f0ad28 59protected:
60
61 TEL_COLOUR myColor;
62 Aspect_TypeOfLine myType;
63 float myWidth;
64 Handle(Graphic3d_ShaderProgram) myShaderProgram;
65
66protected:
67
68 //! OpenGl resources
69 mutable struct Resources
70 {
71 public:
72 Resources() : myIsShaderReady (Standard_False) {}
73
74 Standard_Boolean IsShaderReady() const { return myIsShaderReady; }
f85399e5 75 void SetShaderReady() { myIsShaderReady = Standard_True; }
76 void ResetShaderReadiness() { myIsShaderReady = Standard_False; }
30f0ad28 77
595a42a4 78 Standard_EXPORT void BuildShader (const Handle(OpenGl_Workspace)& theWS, const Handle(Graphic3d_ShaderProgram)& theShader);
30f0ad28 79
80 Handle(OpenGl_ShaderProgram) ShaderProgram;
81 TCollection_AsciiString ShaderProgramId;
82
83 private:
84
85 Standard_Boolean myIsShaderReady;
2166f0fa 86
30f0ad28 87 } myResources;
2166f0fa
SK
88
89 public:
1c35b92f 90 DEFINE_STANDARD_ALLOC
2166f0fa
SK
91};
92
93#endif //_OpenGl_AspectLine_Header