0027670: Visualization - avoid duplication of structures defining primitive array...
[occt.git] / src / Graphic3d / Graphic3d_ShaderVariable.lxx
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 // =======================================================================
17 // function : As
18 // purpose  : Returns variable value casted to specified type
19 // =======================================================================
20 template <class T> inline
21 T& Graphic3d_ValueInterface::As()
22 {
23   Graphic3d_UniformValue<T>* aPtr = dynamic_cast<Graphic3d_UniformValue<T>*> (this);
24   return aPtr->Value;
25 }
26
27 // =======================================================================
28 // function : As
29 // purpose  : Returns variable value casted to specified type
30 // =======================================================================
31 template <class T> inline
32 const T& Graphic3d_ValueInterface::As() const
33 {
34   const Graphic3d_UniformValue<T>* aPtr = dynamic_cast<const Graphic3d_UniformValue<T>*> (this);
35   return aPtr->Value;
36 }
37
38 // =======================================================================
39 // function : TypeID
40 // purpose  : Returns unique identifier of value type
41 // =======================================================================
42 template <class T> inline
43 Standard_Size Graphic3d_UniformValue<T>::TypeID() const
44 {
45   return Graphic3d_UniformValueTypeID<T>::ID;
46 }
47
48 // =======================================================================
49 // function : Create
50 // purpose  : Creates initialized shader variable
51 // =======================================================================
52 template<class T> inline
53 Graphic3d_ShaderVariable* Graphic3d_ShaderVariable::Create (const TCollection_AsciiString& theName,
54                                                             const T&                       theValue)
55 {
56   Graphic3d_ShaderVariable* theVariable = new Graphic3d_ShaderVariable (theName);
57   theVariable->myValue = new Graphic3d_UniformValue<T> (theValue);
58   return theVariable;
59 }