0029528: Visualization, TKOpenGl - allow defining sRGB textures
[occt.git] / src / OpenGl / OpenGl_AspectsProgram.cxx
CommitLineData
bf5f0ca2 1// Copyright (c) 2019 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <OpenGl_AspectsProgram.hxx>
15
16#include <OpenGl_Context.hxx>
17#include <OpenGl_ShaderManager.hxx>
18#include <OpenGl_ShaderProgram.hxx>
19
20namespace
21{
22 static const TCollection_AsciiString THE_EMPTY_KEY;
23}
24
25// =======================================================================
26// function : Release
27// purpose :
28// =======================================================================
29void OpenGl_AspectsProgram::Release (OpenGl_Context* theCtx)
30{
31 if (!myShaderProgram.IsNull() && theCtx != NULL)
32 {
33 theCtx->ShaderManager()->Unregister (myShaderProgramId,
34 myShaderProgram);
35 }
36 myShaderProgramId.Clear();
37 myIsShaderReady = Standard_False;
38}
39
40// =======================================================================
41// function : UpdateRediness
42// purpose :
43// =======================================================================
44void OpenGl_AspectsProgram::UpdateRediness (const Handle(Graphic3d_Aspects)& theAspect)
45{
46 const TCollection_AsciiString& aShaderKey = theAspect->ShaderProgram().IsNull() ? THE_EMPTY_KEY : theAspect->ShaderProgram()->GetId();
47 if (aShaderKey.IsEmpty() || myShaderProgramId != aShaderKey)
48 {
49 myIsShaderReady = Standard_False;
50 }
51}
52
53// =======================================================================
54// function : build
55// purpose :
56// =======================================================================
57void OpenGl_AspectsProgram::build (const Handle(OpenGl_Context)& theCtx,
58 const Handle(Graphic3d_ShaderProgram)& theShader)
59{
60 if (theCtx->core20fwd == NULL)
61 {
62 return;
63 }
64
65 // release old shader program resources
66 if (!myShaderProgram.IsNull())
67 {
68 theCtx->ShaderManager()->Unregister (myShaderProgramId, myShaderProgram);
69 myShaderProgramId.Clear();
70 myShaderProgram.Nullify();
71 }
72 if (theShader.IsNull())
73 {
74 return;
75 }
76
77 theCtx->ShaderManager()->Create (theShader, myShaderProgramId, myShaderProgram);
78}