1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_ShaderProgram.hxx>
18 #include <OpenGl_AspectText.hxx>
19 #include <OpenGl_Context.hxx>
20 #include <OpenGl_Workspace.hxx>
21 #include <OpenGl_ShaderManager.hxx>
22 #include <OpenGl_ShaderProgram.hxx>
26 static const TCollection_AsciiString THE_EMPTY_KEY;
29 // =======================================================================
30 // function : OpenGl_AspectText
32 // =======================================================================
33 OpenGl_AspectText::OpenGl_AspectText()
34 : myAspect (new Graphic3d_AspectText3d (Quantity_Color (Quantity_NOC_WHITE), "Courier", 1.0, 0.0))
39 // =======================================================================
40 // function : OpenGl_AspectText
42 // =======================================================================
43 OpenGl_AspectText::OpenGl_AspectText (const Handle(Graphic3d_AspectText3d)& theAspect)
45 SetAspect (theAspect);
48 // =======================================================================
49 // function : ~OpenGl_AspectText
51 // =======================================================================
52 OpenGl_AspectText::~OpenGl_AspectText()
57 // =======================================================================
58 // function : SetAspect
60 // =======================================================================
61 void OpenGl_AspectText::SetAspect (const Handle(Graphic3d_AspectText3d)& theAspect)
64 const TCollection_AsciiString& aShaderKey = myAspect->ShaderProgram().IsNull() ? THE_EMPTY_KEY : myAspect->ShaderProgram()->GetId();
65 if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey)
67 myResources.ResetShaderReadiness();
71 // =======================================================================
74 // =======================================================================
75 void OpenGl_AspectText::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
77 theWorkspace->SetAspectText (this);
80 // =======================================================================
83 // =======================================================================
84 void OpenGl_AspectText::Release (OpenGl_Context* theContext)
86 if (!myResources.ShaderProgram.IsNull()
89 theContext->ShaderManager()->Unregister (myResources.ShaderProgramId,
90 myResources.ShaderProgram);
92 myResources.ShaderProgramId.Clear();
93 myResources.ResetShaderReadiness();
96 // =======================================================================
97 // function : BuildShader
99 // =======================================================================
100 void OpenGl_AspectText::Resources::BuildShader (const Handle(OpenGl_Context)& theCtx,
101 const Handle(Graphic3d_ShaderProgram)& theShader)
103 if (theCtx->core20fwd == NULL)
108 // release old shader program resources
109 if (!ShaderProgram.IsNull())
111 theCtx->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram);
112 ShaderProgramId.Clear();
113 ShaderProgram.Nullify();
115 if (theShader.IsNull())
120 theCtx->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram);