0024855: Revision of parameters of standard materials
[occt.git] / src / Graphic3d / Graphic3d_ShaderVariable.hxx
CommitLineData
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
23#include <Graphic3d_ShaderVariable_Handle.hxx>
24
25//! Interface for generic variable value.
26struct Graphic3d_ValueInterface
27{
28 //! Releases memory resources of variable value.
29 Standard_EXPORT virtual ~Graphic3d_ValueInterface();
30
31 //! Returns unique identifier of value type.
32 virtual Standard_Size TypeID() const = 0;
33
34 //! Returns variable value casted to specified type.
35 template <class T> T& As();
36
37 //! Returns variable value casted to specified type.
38 template <class T> const T& As() const;
39};
40
41//! Generates unique type identifier for variable value.
42template<class T>
43struct Graphic3d_UniformValueTypeID {
44 /* Not implemented */
45};
46
47template<>
c4a8a6bb 48struct Graphic3d_UniformValueTypeID<Standard_Integer> {
30f0ad28 49 static const Standard_Size ID = __LINE__;
50};
51
52template<>
c4a8a6bb 53struct Graphic3d_UniformValueTypeID<Standard_ShortReal> {
30f0ad28 54 static const Standard_Size ID = __LINE__;
55};
56
57template<>
c4a8a6bb 58struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2> {
30f0ad28 59 static const Standard_Size ID = __LINE__;
60};
61
62template<>
c4a8a6bb 63struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3> {
30f0ad28 64 static const Standard_Size ID = __LINE__;
65};
66
67template<>
c4a8a6bb 68struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4> {
30f0ad28 69 static const Standard_Size ID = __LINE__;
70};
71
72template<>
c4a8a6bb 73struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2i> {
30f0ad28 74 static const Standard_Size ID = __LINE__;
75};
76
77template<>
c4a8a6bb 78struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3i> {
30f0ad28 79 static const Standard_Size ID = __LINE__;
80};
81
82template<>
c4a8a6bb 83struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4i> {
30f0ad28 84 static const Standard_Size ID = __LINE__;
85};
86
87//! Describes specific value of custom uniform variable.
88template <class T>
89struct Graphic3d_UniformValue : public Graphic3d_ValueInterface
90{
91 //! Creates new variable value.
92 Graphic3d_UniformValue (const T& theValue) : Value (theValue) { }
93
94 //! Returns unique identifier of value type.
95 virtual Standard_Size TypeID() const;
96
97 //! Value of custom uniform variable.
98 T Value;
99};
100
101//! Integer uniform value.
c4a8a6bb 102typedef Graphic3d_UniformValue<Standard_Integer> Graphic3d_UniformInt;
30f0ad28 103
104//! Integer uniform 2D vector.
c4a8a6bb 105typedef Graphic3d_UniformValue<Graphic3d_Vec2i> Graphic3d_UniformVec2i;
30f0ad28 106
107//! Integer uniform 3D vector.
c4a8a6bb 108typedef Graphic3d_UniformValue<Graphic3d_Vec3i> Graphic3d_UniformVec3i;
30f0ad28 109
110//! Integer uniform 4D vector.
c4a8a6bb 111typedef Graphic3d_UniformValue<Graphic3d_Vec4i> Graphic3d_UniformVec4i;
30f0ad28 112
113//! Floating-point uniform value.
c4a8a6bb 114typedef Graphic3d_UniformValue<Standard_ShortReal> Graphic3d_UniformFloat;
30f0ad28 115
116//! Floating-point uniform 2D vector.
c4a8a6bb 117typedef Graphic3d_UniformValue<Graphic3d_Vec2> Graphic3d_UniformVec2;
30f0ad28 118
119//! Floating-point uniform 3D vector.
c4a8a6bb 120typedef Graphic3d_UniformValue<Graphic3d_Vec3> Graphic3d_UniformVec3;
30f0ad28 121
122//! Floating-point uniform 4D vector.
c4a8a6bb 123typedef Graphic3d_UniformValue<Graphic3d_Vec4> Graphic3d_UniformVec4;
30f0ad28 124
125//! Describes custom uniform shader variable.
126class Graphic3d_ShaderVariable : public Standard_Transient
127{
128public:
129
130 //! Releases resources of shader variable.
131 Standard_EXPORT virtual ~Graphic3d_ShaderVariable();
132
133 //! Returns name of shader variable.
134 Standard_EXPORT const TCollection_AsciiString& Name() const;
135
136 //! Checks if the shader variable is valid or not.
137 Standard_EXPORT Standard_Boolean IsDone() const;
138
139 //! Returns interface of shader variable value.
140 Standard_EXPORT Graphic3d_ValueInterface* Value();
141
142 //! Creates new initialized shader variable.
143 template<class T>
144 static Graphic3d_ShaderVariable* Create (const TCollection_AsciiString& theName,
145 const T& theValue);
146
147public:
148
149 DEFINE_STANDARD_RTTI (Graphic3d_ShaderVariable)
150
151protected:
152
153 //! Creates new uninitialized shader variable.
154 Standard_EXPORT Graphic3d_ShaderVariable (const TCollection_AsciiString& theName);
155
156protected:
157
158 //! The name of uniform shader variable.
159 TCollection_AsciiString myName;
160
161 //! The generic value of shader variable.
162 Graphic3d_ValueInterface* myValue;
163};
164
165#include <Graphic3d_ShaderVariable.lxx>
166
167#endif // _Graphic3d_ShaderVariable_HeaderFile