1 // Created on: 2013-09-25
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013 OPEN CASCADE SAS
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.
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.
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.
20 #ifndef _Graphic3d_ShaderVariable_HeaderFile
21 #define _Graphic3d_ShaderVariable_HeaderFile
23 #include <OpenGl_Vec.hxx>
24 #include <Standard_Transient.hxx>
25 #include <TCollection_AsciiString.hxx>
27 #include <Graphic3d_ShaderVariable_Handle.hxx>
29 //! Interface for generic variable value.
30 struct Graphic3d_ValueInterface
32 //! Releases memory resources of variable value.
33 Standard_EXPORT virtual ~Graphic3d_ValueInterface();
35 //! Returns unique identifier of value type.
36 virtual Standard_Size TypeID() const = 0;
38 //! Returns variable value casted to specified type.
39 template <class T> T& As();
41 //! Returns variable value casted to specified type.
42 template <class T> const T& As() const;
45 //! Generates unique type identifier for variable value.
47 struct Graphic3d_UniformValueTypeID {
52 struct Graphic3d_UniformValueTypeID<int> {
53 static const Standard_Size ID = __LINE__;
57 struct Graphic3d_UniformValueTypeID<float> {
58 static const Standard_Size ID = __LINE__;
62 struct Graphic3d_UniformValueTypeID<OpenGl_Vec2> {
63 static const Standard_Size ID = __LINE__;
67 struct Graphic3d_UniformValueTypeID<OpenGl_Vec3> {
68 static const Standard_Size ID = __LINE__;
72 struct Graphic3d_UniformValueTypeID<OpenGl_Vec4> {
73 static const Standard_Size ID = __LINE__;
77 struct Graphic3d_UniformValueTypeID<OpenGl_Vec2i> {
78 static const Standard_Size ID = __LINE__;
82 struct Graphic3d_UniformValueTypeID<OpenGl_Vec3i> {
83 static const Standard_Size ID = __LINE__;
87 struct Graphic3d_UniformValueTypeID<OpenGl_Vec4i> {
88 static const Standard_Size ID = __LINE__;
91 //! Describes specific value of custom uniform variable.
93 struct Graphic3d_UniformValue : public Graphic3d_ValueInterface
95 //! Creates new variable value.
96 Graphic3d_UniformValue (const T& theValue) : Value (theValue) { }
98 //! Returns unique identifier of value type.
99 virtual Standard_Size TypeID() const;
101 //! Value of custom uniform variable.
105 //! Integer uniform value.
106 typedef Graphic3d_UniformValue<int> Graphic3d_UniformInt;
108 //! Integer uniform 2D vector.
109 typedef Graphic3d_UniformValue<OpenGl_Vec2i> Graphic3d_UniformVec2i;
111 //! Integer uniform 3D vector.
112 typedef Graphic3d_UniformValue<OpenGl_Vec3i> Graphic3d_UniformVec3i;
114 //! Integer uniform 4D vector.
115 typedef Graphic3d_UniformValue<OpenGl_Vec4i> Graphic3d_UniformVec4i;
117 //! Floating-point uniform value.
118 typedef Graphic3d_UniformValue<float> Graphic3d_UniformFloat;
120 //! Floating-point uniform 2D vector.
121 typedef Graphic3d_UniformValue<OpenGl_Vec2> Graphic3d_UniformVec2;
123 //! Floating-point uniform 3D vector.
124 typedef Graphic3d_UniformValue<OpenGl_Vec3> Graphic3d_UniformVec3;
126 //! Floating-point uniform 4D vector.
127 typedef Graphic3d_UniformValue<OpenGl_Vec4> Graphic3d_UniformVec4;
129 //! Describes custom uniform shader variable.
130 class Graphic3d_ShaderVariable : public Standard_Transient
134 //! Releases resources of shader variable.
135 Standard_EXPORT virtual ~Graphic3d_ShaderVariable();
137 //! Returns name of shader variable.
138 Standard_EXPORT const TCollection_AsciiString& Name() const;
140 //! Checks if the shader variable is valid or not.
141 Standard_EXPORT Standard_Boolean IsDone() const;
143 //! Returns interface of shader variable value.
144 Standard_EXPORT Graphic3d_ValueInterface* Value();
146 //! Creates new initialized shader variable.
148 static Graphic3d_ShaderVariable* Create (const TCollection_AsciiString& theName,
153 DEFINE_STANDARD_RTTI (Graphic3d_ShaderVariable)
157 //! Creates new uninitialized shader variable.
158 Standard_EXPORT Graphic3d_ShaderVariable (const TCollection_AsciiString& theName);
162 //! The name of uniform shader variable.
163 TCollection_AsciiString myName;
165 //! The generic value of shader variable.
166 Graphic3d_ValueInterface* myValue;
169 #include <Graphic3d_ShaderVariable.lxx>
171 #endif // _Graphic3d_ShaderVariable_HeaderFile