1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 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_AspectLine.hxx>
19 #include <OpenGl_Context.hxx>
20 #include <OpenGl_ShaderManager.hxx>
21 #include <OpenGl_ShaderProgram.hxx>
22 #include <OpenGl_Workspace.hxx>
26 static const TCollection_AsciiString THE_EMPTY_KEY;
29 // =======================================================================
30 // function : OpenGl_AspectLine
32 // =======================================================================
33 OpenGl_AspectLine::OpenGl_AspectLine()
34 : myAspect (new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0))
39 // =======================================================================
40 // function : OpenGl_AspectLine
42 // =======================================================================
43 OpenGl_AspectLine::OpenGl_AspectLine (const Handle(Graphic3d_AspectLine3d)& theAspect)
45 SetAspect (theAspect);
48 // =======================================================================
49 // function : SetAspect
51 // =======================================================================
52 void OpenGl_AspectLine::SetAspect (const Handle(Graphic3d_AspectLine3d)& theAspect)
55 const TCollection_AsciiString& aShaderKey = myAspect->ShaderProgram().IsNull() ? THE_EMPTY_KEY : myAspect->ShaderProgram()->GetId();
56 if (aShaderKey.IsEmpty() || myResources.ShaderProgramId != aShaderKey)
58 myResources.ResetShaderReadiness();
62 // =======================================================================
65 // =======================================================================
66 void OpenGl_AspectLine::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
68 theWorkspace->SetAspectLine (this);
71 // =======================================================================
74 // =======================================================================
75 void OpenGl_AspectLine::Release (OpenGl_Context* theContext)
77 if (!myResources.ShaderProgram.IsNull()
80 theContext->ShaderManager()->Unregister (myResources.ShaderProgramId,
81 myResources.ShaderProgram);
83 myResources.ShaderProgramId.Clear();
84 myResources.ResetShaderReadiness();
87 // =======================================================================
88 // function : BuildShader
90 // =======================================================================
91 void OpenGl_AspectLine::Resources::BuildShader (const Handle(OpenGl_Context)& theCtx,
92 const Handle(Graphic3d_ShaderProgram)& theShader)
94 if (theCtx->core20fwd == NULL)
99 // release old shader program resources
100 if (!ShaderProgram.IsNull())
102 theCtx->ShaderManager()->Unregister (ShaderProgramId, ShaderProgram);
103 ShaderProgramId.Clear();
104 ShaderProgram.Nullify();
106 if (theShader.IsNull())
111 theCtx->ShaderManager()->Create (theShader, ShaderProgramId, ShaderProgram);