1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <OpenGl_AspectsProgram.hxx>
16 #include <OpenGl_Context.hxx>
17 #include <OpenGl_ShaderManager.hxx>
18 #include <OpenGl_ShaderProgram.hxx>
22 static const TCollection_AsciiString THE_EMPTY_KEY;
25 // =======================================================================
28 // =======================================================================
29 void OpenGl_AspectsProgram::Release (OpenGl_Context* theCtx)
31 if (!myShaderProgram.IsNull() && theCtx != NULL)
33 theCtx->ShaderManager()->Unregister (myShaderProgramId,
36 myShaderProgramId.Clear();
37 myIsShaderReady = Standard_False;
40 // =======================================================================
41 // function : UpdateRediness
43 // =======================================================================
44 void OpenGl_AspectsProgram::UpdateRediness (const Handle(Graphic3d_Aspects)& theAspect)
46 const TCollection_AsciiString& aShaderKey = theAspect->ShaderProgram().IsNull() ? THE_EMPTY_KEY : theAspect->ShaderProgram()->GetId();
47 if (aShaderKey.IsEmpty() || myShaderProgramId != aShaderKey)
49 myIsShaderReady = Standard_False;
53 // =======================================================================
56 // =======================================================================
57 void OpenGl_AspectsProgram::build (const Handle(OpenGl_Context)& theCtx,
58 const Handle(Graphic3d_ShaderProgram)& theShader)
60 if (theCtx->core20fwd == NULL)
65 // release old shader program resources
66 if (!myShaderProgram.IsNull())
68 theCtx->ShaderManager()->Unregister (myShaderProgramId, myShaderProgram);
69 myShaderProgramId.Clear();
70 myShaderProgram.Nullify();
72 if (theShader.IsNull())
77 theCtx->ShaderManager()->Create (theShader, myShaderProgramId, myShaderProgram);