0027860: Visualization - clean up Transformation Persistence API
[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
30f0ad28 23//! Interface for generic variable value.
24struct 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.
40template<class T>
41struct Graphic3d_UniformValueTypeID {
42 /* Not implemented */
43};
44
45template<>
c4a8a6bb 46struct Graphic3d_UniformValueTypeID<Standard_Integer> {
30f0ad28 47 static const Standard_Size ID = __LINE__;
48};
49
50template<>
c4a8a6bb 51struct Graphic3d_UniformValueTypeID<Standard_ShortReal> {
30f0ad28 52 static const Standard_Size ID = __LINE__;
53};
54
55template<>
c4a8a6bb 56struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2> {
30f0ad28 57 static const Standard_Size ID = __LINE__;
58};
59
60template<>
c4a8a6bb 61struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3> {
30f0ad28 62 static const Standard_Size ID = __LINE__;
63};
64
65template<>
c4a8a6bb 66struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4> {
30f0ad28 67 static const Standard_Size ID = __LINE__;
68};
69
70template<>
c4a8a6bb 71struct Graphic3d_UniformValueTypeID<Graphic3d_Vec2i> {
30f0ad28 72 static const Standard_Size ID = __LINE__;
73};
74
75template<>
c4a8a6bb 76struct Graphic3d_UniformValueTypeID<Graphic3d_Vec3i> {
30f0ad28 77 static const Standard_Size ID = __LINE__;
78};
79
80template<>
c4a8a6bb 81struct Graphic3d_UniformValueTypeID<Graphic3d_Vec4i> {
30f0ad28 82 static const Standard_Size ID = __LINE__;
83};
84
85//! Describes specific value of custom uniform variable.
86template <class T>
87struct 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 100typedef Graphic3d_UniformValue<Standard_Integer> Graphic3d_UniformInt;
30f0ad28 101
102//! Integer uniform 2D vector.
c4a8a6bb 103typedef Graphic3d_UniformValue<Graphic3d_Vec2i> Graphic3d_UniformVec2i;
30f0ad28 104
105//! Integer uniform 3D vector.
c4a8a6bb 106typedef Graphic3d_UniformValue<Graphic3d_Vec3i> Graphic3d_UniformVec3i;
30f0ad28 107
108//! Integer uniform 4D vector.
c4a8a6bb 109typedef Graphic3d_UniformValue<Graphic3d_Vec4i> Graphic3d_UniformVec4i;
30f0ad28 110
111//! Floating-point uniform value.
c4a8a6bb 112typedef Graphic3d_UniformValue<Standard_ShortReal> Graphic3d_UniformFloat;
30f0ad28 113
114//! Floating-point uniform 2D vector.
c4a8a6bb 115typedef Graphic3d_UniformValue<Graphic3d_Vec2> Graphic3d_UniformVec2;
30f0ad28 116
117//! Floating-point uniform 3D vector.
c4a8a6bb 118typedef Graphic3d_UniformValue<Graphic3d_Vec3> Graphic3d_UniformVec3;
30f0ad28 119
120//! Floating-point uniform 4D vector.
c4a8a6bb 121typedef Graphic3d_UniformValue<Graphic3d_Vec4> Graphic3d_UniformVec4;
30f0ad28 122
123//! Describes custom uniform shader variable.
124class Graphic3d_ShaderVariable : public Standard_Transient
125{
126public:
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
145public:
146
92efcf78 147 DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderVariable,Standard_Transient)
30f0ad28 148
149protected:
150
151 //! Creates new uninitialized shader variable.
152 Standard_EXPORT Graphic3d_ShaderVariable (const TCollection_AsciiString& theName);
153
154protected:
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 163DEFINE_STANDARD_HANDLE (Graphic3d_ShaderVariable, Standard_Transient)
164
30f0ad28 165#include <Graphic3d_ShaderVariable.lxx>
166
167#endif // _Graphic3d_ShaderVariable_HeaderFile