30f0ad28 |
1 | // Created on: 2013-09-25 |
2 | // Created by: Denis BOGOLEPOV |
d5f74e42 |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
30f0ad28 |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
30f0ad28 |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
30f0ad28 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
30f0ad28 |
15 | |
16 | #ifndef _Graphic3d_ShaderVariable_HeaderFile |
17 | #define _Graphic3d_ShaderVariable_HeaderFile |
18 | |
c4a8a6bb |
19 | #include <Graphic3d_Vec.hxx> |
30f0ad28 |
20 | #include <Standard_Transient.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
22 | |
30f0ad28 |
23 | //! Interface for generic variable value. |
24 | struct Graphic3d_ValueInterface |
25 | { |
26 | //! Releases memory resources of variable value. |
27 | Standard_EXPORT virtual ~Graphic3d_ValueInterface(); |
28 | |
29 | //! Returns unique identifier of value type. |
30 | virtual Standard_Size TypeID() const = 0; |
31 | |
32 | //! Returns variable value casted to specified type. |
33 | template <class T> T& As(); |
34 | |
35 | //! Returns variable value casted to specified type. |
36 | template <class T> const T& As() const; |
37 | }; |
38 | |
39 | //! Generates unique type identifier for variable value. |
40 | template<class T> |
41 | struct Graphic3d_UniformValueTypeID { |
42 | /* Not implemented */ |
43 | }; |
44 | |
45 | template<> |
c4a8a6bb |
46 | struct Graphic3d_UniformValueTypeID<Standard_Integer> { |
30f0ad28 |
47 | static const Standard_Size ID = __LINE__; |
48 | }; |
49 | |
50 | template<> |
c4a8a6bb |
51 | struct Graphic3d_UniformValueTypeID<Standard_ShortReal> { |
30f0ad28 |
52 | static const Standard_Size ID = __LINE__; |
53 | }; |
54 | |
55 | template<> |
c4a8a6bb |
56 | struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2> { |
30f0ad28 |
57 | static const Standard_Size ID = __LINE__; |
58 | }; |
59 | |
60 | template<> |
c4a8a6bb |
61 | struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3> { |
30f0ad28 |
62 | static const Standard_Size ID = __LINE__; |
63 | }; |
64 | |
65 | template<> |
c4a8a6bb |
66 | struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4> { |
30f0ad28 |
67 | static const Standard_Size ID = __LINE__; |
68 | }; |
69 | |
70 | template<> |
c4a8a6bb |
71 | struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2i> { |
30f0ad28 |
72 | static const Standard_Size ID = __LINE__; |
73 | }; |
74 | |
75 | template<> |
c4a8a6bb |
76 | struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3i> { |
30f0ad28 |
77 | static const Standard_Size ID = __LINE__; |
78 | }; |
79 | |
80 | template<> |
c4a8a6bb |
81 | struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4i> { |
30f0ad28 |
82 | static const Standard_Size ID = __LINE__; |
83 | }; |
84 | |
85 | //! Describes specific value of custom uniform variable. |
86 | template <class T> |
87 | struct Graphic3d_UniformValue : public Graphic3d_ValueInterface |
88 | { |
89 | //! Creates new variable value. |
90 | Graphic3d_UniformValue (const T& theValue) : Value (theValue) { } |
91 | |
92 | //! Returns unique identifier of value type. |
93 | virtual Standard_Size TypeID() const; |
94 | |
95 | //! Value of custom uniform variable. |
96 | T Value; |
97 | }; |
98 | |
99 | //! Integer uniform value. |
c4a8a6bb |
100 | typedef Graphic3d_UniformValue<Standard_Integer> Graphic3d_UniformInt; |
30f0ad28 |
101 | |
102 | //! Integer uniform 2D vector. |
c4a8a6bb |
103 | typedef Graphic3d_UniformValue<Graphic3d_Vec2i> Graphic3d_UniformVec2i; |
30f0ad28 |
104 | |
105 | //! Integer uniform 3D vector. |
c4a8a6bb |
106 | typedef Graphic3d_UniformValue<Graphic3d_Vec3i> Graphic3d_UniformVec3i; |
30f0ad28 |
107 | |
108 | //! Integer uniform 4D vector. |
c4a8a6bb |
109 | typedef Graphic3d_UniformValue<Graphic3d_Vec4i> Graphic3d_UniformVec4i; |
30f0ad28 |
110 | |
111 | //! Floating-point uniform value. |
c4a8a6bb |
112 | typedef Graphic3d_UniformValue<Standard_ShortReal> Graphic3d_UniformFloat; |
30f0ad28 |
113 | |
114 | //! Floating-point uniform 2D vector. |
c4a8a6bb |
115 | typedef Graphic3d_UniformValue<Graphic3d_Vec2> Graphic3d_UniformVec2; |
30f0ad28 |
116 | |
117 | //! Floating-point uniform 3D vector. |
c4a8a6bb |
118 | typedef Graphic3d_UniformValue<Graphic3d_Vec3> Graphic3d_UniformVec3; |
30f0ad28 |
119 | |
120 | //! Floating-point uniform 4D vector. |
c4a8a6bb |
121 | typedef Graphic3d_UniformValue<Graphic3d_Vec4> Graphic3d_UniformVec4; |
30f0ad28 |
122 | |
123 | //! Describes custom uniform shader variable. |
124 | class Graphic3d_ShaderVariable : public Standard_Transient |
125 | { |
126 | public: |
127 | |
128 | //! Releases resources of shader variable. |
129 | Standard_EXPORT virtual ~Graphic3d_ShaderVariable(); |
130 | |
131 | //! Returns name of shader variable. |
132 | Standard_EXPORT const TCollection_AsciiString& Name() const; |
133 | |
134 | //! Checks if the shader variable is valid or not. |
135 | Standard_EXPORT Standard_Boolean IsDone() const; |
136 | |
137 | //! Returns interface of shader variable value. |
138 | Standard_EXPORT Graphic3d_ValueInterface* Value(); |
139 | |
140 | //! Creates new initialized shader variable. |
141 | template<class T> |
142 | static Graphic3d_ShaderVariable* Create (const TCollection_AsciiString& theName, |
143 | const T& theValue); |
144 | |
145 | public: |
146 | |
92efcf78 |
147 | DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderVariable,Standard_Transient) |
30f0ad28 |
148 | |
149 | protected: |
150 | |
151 | //! Creates new uninitialized shader variable. |
152 | Standard_EXPORT Graphic3d_ShaderVariable (const TCollection_AsciiString& theName); |
153 | |
154 | protected: |
155 | |
156 | //! The name of uniform shader variable. |
157 | TCollection_AsciiString myName; |
158 | |
159 | //! The generic value of shader variable. |
160 | Graphic3d_ValueInterface* myValue; |
161 | }; |
162 | |
494782f6 |
163 | DEFINE_STANDARD_HANDLE (Graphic3d_ShaderVariable, Standard_Transient) |
164 | |
30f0ad28 |
165 | #include <Graphic3d_ShaderVariable.lxx> |
166 | |
167 | #endif // _Graphic3d_ShaderVariable_HeaderFile |