1 // Created on: 2013-09-25
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-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 #ifndef _Graphic3d_ShaderVariable_HeaderFile
17 #define _Graphic3d_ShaderVariable_HeaderFile
19 #include <Graphic3d_Vec.hxx>
20 #include <Standard_Transient.hxx>
21 #include <TCollection_AsciiString.hxx>
23 #include <Graphic3d_ShaderVariable_Handle.hxx>
25 //! Interface for generic variable value.
26 struct Graphic3d_ValueInterface
28 //! Releases memory resources of variable value.
29 Standard_EXPORT virtual ~Graphic3d_ValueInterface();
31 //! Returns unique identifier of value type.
32 virtual Standard_Size TypeID() const = 0;
34 //! Returns variable value casted to specified type.
35 template <class T> T& As();
37 //! Returns variable value casted to specified type.
38 template <class T> const T& As() const;
41 //! Generates unique type identifier for variable value.
43 struct Graphic3d_UniformValueTypeID {
48 struct Graphic3d_UniformValueTypeID<Standard_Integer> {
49 static const Standard_Size ID = __LINE__;
53 struct Graphic3d_UniformValueTypeID<Standard_ShortReal> {
54 static const Standard_Size ID = __LINE__;
58 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2> {
59 static const Standard_Size ID = __LINE__;
63 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3> {
64 static const Standard_Size ID = __LINE__;
68 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4> {
69 static const Standard_Size ID = __LINE__;
73 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2i> {
74 static const Standard_Size ID = __LINE__;
78 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3i> {
79 static const Standard_Size ID = __LINE__;
83 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4i> {
84 static const Standard_Size ID = __LINE__;
87 //! Describes specific value of custom uniform variable.
89 struct Graphic3d_UniformValue : public Graphic3d_ValueInterface
91 //! Creates new variable value.
92 Graphic3d_UniformValue (const T& theValue) : Value (theValue) { }
94 //! Returns unique identifier of value type.
95 virtual Standard_Size TypeID() const;
97 //! Value of custom uniform variable.
101 //! Integer uniform value.
102 typedef Graphic3d_UniformValue<Standard_Integer> Graphic3d_UniformInt;
104 //! Integer uniform 2D vector.
105 typedef Graphic3d_UniformValue<Graphic3d_Vec2i> Graphic3d_UniformVec2i;
107 //! Integer uniform 3D vector.
108 typedef Graphic3d_UniformValue<Graphic3d_Vec3i> Graphic3d_UniformVec3i;
110 //! Integer uniform 4D vector.
111 typedef Graphic3d_UniformValue<Graphic3d_Vec4i> Graphic3d_UniformVec4i;
113 //! Floating-point uniform value.
114 typedef Graphic3d_UniformValue<Standard_ShortReal> Graphic3d_UniformFloat;
116 //! Floating-point uniform 2D vector.
117 typedef Graphic3d_UniformValue<Graphic3d_Vec2> Graphic3d_UniformVec2;
119 //! Floating-point uniform 3D vector.
120 typedef Graphic3d_UniformValue<Graphic3d_Vec3> Graphic3d_UniformVec3;
122 //! Floating-point uniform 4D vector.
123 typedef Graphic3d_UniformValue<Graphic3d_Vec4> Graphic3d_UniformVec4;
125 //! Describes custom uniform shader variable.
126 class Graphic3d_ShaderVariable : public Standard_Transient
130 //! Releases resources of shader variable.
131 Standard_EXPORT virtual ~Graphic3d_ShaderVariable();
133 //! Returns name of shader variable.
134 Standard_EXPORT const TCollection_AsciiString& Name() const;
136 //! Checks if the shader variable is valid or not.
137 Standard_EXPORT Standard_Boolean IsDone() const;
139 //! Returns interface of shader variable value.
140 Standard_EXPORT Graphic3d_ValueInterface* Value();
142 //! Creates new initialized shader variable.
144 static Graphic3d_ShaderVariable* Create (const TCollection_AsciiString& theName,
149 DEFINE_STANDARD_RTTI (Graphic3d_ShaderVariable)
153 //! Creates new uninitialized shader variable.
154 Standard_EXPORT Graphic3d_ShaderVariable (const TCollection_AsciiString& theName);
158 //! The name of uniform shader variable.
159 TCollection_AsciiString myName;
161 //! The generic value of shader variable.
162 Graphic3d_ValueInterface* myValue;
165 #include <Graphic3d_ShaderVariable.lxx>
167 #endif // _Graphic3d_ShaderVariable_HeaderFile