Samples update
[occt.git] / src / Graphic3d / Graphic3d_ShaderProgram.cxx
CommitLineData
30f0ad28 1// Created on: 2013-09-20
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2013 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20#include <Standard_Atomic.hxx>
21#include <Standard_Assert.hxx>
22
23#include <Graphic3d_GraphicDriver.hxx>
24#include <Graphic3d_ShaderObject.hxx>
25#include <Graphic3d_ShaderProgram.hxx>
26
27namespace
28{
29 static volatile Standard_Integer THE_PROGRAM_OBJECT_COUNTER = 0;
30};
31
32IMPLEMENT_STANDARD_HANDLE (Graphic3d_ShaderProgram, Standard_Transient)
33IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ShaderProgram, Standard_Transient)
34
35// =======================================================================
36// function : Graphic3d_ShaderProgram
37// purpose : Creates new empty program object
38// =======================================================================
39Graphic3d_ShaderProgram::Graphic3d_ShaderProgram()
40{
41 myID = TCollection_AsciiString ("Graphic3d_ShaderProgram_")
42 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_PROGRAM_OBJECT_COUNTER));
43}
44
45// =======================================================================
46// function : ~Graphic3d_ShaderProgram
47// purpose : Releases resources of program object
48// =======================================================================
49Graphic3d_ShaderProgram::~Graphic3d_ShaderProgram()
50{
51 Destroy();
52}
53
54// =======================================================================
55// function : Destroy
56// purpose : Releases resources of program object
57// =======================================================================
58void Graphic3d_ShaderProgram::Destroy() const
59{ }
60
61// =======================================================================
62// function : IsDone
63// purpose : Checks if the program object is valid or not
64// =======================================================================
65Standard_Boolean Graphic3d_ShaderProgram::IsDone() const
66{
67 if (myShaderObjects.IsEmpty())
68 {
69 return Standard_False;
70 }
71
72 for (Graphic3d_ShaderObjectList::Iterator anIt (myShaderObjects); anIt.More(); anIt.Next())
73 {
74 if (!anIt.Value()->IsDone())
75 return Standard_False;
76 }
77
78 return Standard_True;
79}
80
81// =======================================================================
82// function : AttachShader
83// purpose : Attaches shader object to the program object
84// =======================================================================
85Standard_Boolean Graphic3d_ShaderProgram::AttachShader (const Handle(Graphic3d_ShaderObject)& theShader)
86{
87 if (theShader.IsNull())
88 {
89 return Standard_False;
90 }
91
92 for (Graphic3d_ShaderObjectList::Iterator anIt (myShaderObjects); anIt.More(); anIt.Next())
93 {
94 if (anIt.Value() == theShader)
95 return Standard_False;
96 }
97
98 myShaderObjects.Append (theShader);
99 return Standard_True;
100}
101
102// =======================================================================
103// function : DetachShader
104// purpose : Detaches shader object from the program object
105// =======================================================================
106Standard_Boolean Graphic3d_ShaderProgram::DetachShader (const Handle(Graphic3d_ShaderObject)& theShader)
107{
108 if (theShader.IsNull())
109 {
110 return Standard_False;
111 }
112
113 for (Graphic3d_ShaderObjectList::Iterator anIt (myShaderObjects); anIt.More(); anIt.Next())
114 {
115 if (anIt.Value() == theShader)
116 {
117 myShaderObjects.Remove (anIt);
118 return Standard_True;
119 }
120 }
121
122 return Standard_False;
123}
124
125// =======================================================================
126// function : ClearVariables
127// purpose : Removes all custom uniform variables from the program
128// =======================================================================
129void Graphic3d_ShaderProgram::ClearVariables()
130{
131 myVariables.Clear();
132}