0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / Graphic3d / Graphic3d_ShaderVariable.hxx
1 // Created on: 2013-09-25
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Graphic3d_ShaderVariable_HeaderFile
17 #define _Graphic3d_ShaderVariable_HeaderFile
18
19 #include <Graphic3d_Vec.hxx>
20 #include <Standard_Transient.hxx>
21 #include <TCollection_AsciiString.hxx>
22
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<>
46 struct Graphic3d_UniformValueTypeID<Standard_Integer> {
47   static const Standard_Size ID = __LINE__;
48 };
49
50 template<>
51 struct Graphic3d_UniformValueTypeID<Standard_ShortReal> {
52   static const Standard_Size ID = __LINE__;
53 };
54
55 template<>
56 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2> {
57   static const Standard_Size ID = __LINE__;
58 };
59
60 template<>
61 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3> {
62   static const Standard_Size ID = __LINE__;
63 };
64
65 template<>
66 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4> {
67   static const Standard_Size ID = __LINE__;
68 };
69
70 template<>
71 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2i> {
72   static const Standard_Size ID = __LINE__;
73 };
74
75 template<>
76 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3i> {
77   static const Standard_Size ID = __LINE__;
78 };
79
80 template<>
81 struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4i> {
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.
100 typedef Graphic3d_UniformValue<Standard_Integer> Graphic3d_UniformInt;
101
102 //! Integer uniform 2D vector.
103 typedef Graphic3d_UniformValue<Graphic3d_Vec2i> Graphic3d_UniformVec2i;
104
105 //! Integer uniform 3D vector.
106 typedef Graphic3d_UniformValue<Graphic3d_Vec3i> Graphic3d_UniformVec3i;
107
108 //! Integer uniform 4D vector.
109 typedef Graphic3d_UniformValue<Graphic3d_Vec4i> Graphic3d_UniformVec4i;
110
111 //! Floating-point uniform value.
112 typedef Graphic3d_UniformValue<Standard_ShortReal> Graphic3d_UniformFloat;
113
114 //! Floating-point uniform 2D vector.
115 typedef Graphic3d_UniformValue<Graphic3d_Vec2> Graphic3d_UniformVec2;
116
117 //! Floating-point uniform 3D vector.
118 typedef Graphic3d_UniformValue<Graphic3d_Vec3> Graphic3d_UniformVec3;
119
120 //! Floating-point uniform 4D vector.
121 typedef Graphic3d_UniformValue<Graphic3d_Vec4> Graphic3d_UniformVec4;
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
147   DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderVariable,Standard_Transient)
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
163 DEFINE_STANDARD_HANDLE (Graphic3d_ShaderVariable, Standard_Transient)
164
165 #include <Graphic3d_ShaderVariable.lxx>
166
167 #endif // _Graphic3d_ShaderVariable_HeaderFile