Carna Version 3.3.3
Loading...
Searching...
No Matches
ShaderUniform.h
1/*
2 * Copyright (C) 2010 - 2015 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 */
11
12#ifndef SHADERUNIFORM_H_6014714286
13#define SHADERUNIFORM_H_6014714286
14
15#include <Carna/Carna.h>
16#include <Carna/base/math.h>
17
24namespace Carna
25{
26
27namespace base
28{
29
30
31
32// ----------------------------------------------------------------------------------
33// ShaderUniformType
34// ----------------------------------------------------------------------------------
35
40template< typename ValueType >
48
49
54template< >
63
64
65
66// ----------------------------------------------------------------------------------
67// ShaderUniformBase
68// ----------------------------------------------------------------------------------
69
76class CARNA_LIB ShaderUniformBase
77{
78
79public:
80
84 ShaderUniformBase( const std::string& name );
85
90
94 std::string name;
95
100 bool upload() const;
101
102protected:
103
107 virtual void uploadTo( int location ) const = 0;
108
109private:
110
111 const static int NULL_UNIFORM_LOCATION = -1;
112
113 int location( const ShaderProgram& ) const;
114
115}; // ShaderUniformBase
116
117
118
119// ----------------------------------------------------------------------------------
120// uploadUniform
121// ----------------------------------------------------------------------------------
122
127void CARNA_LIB uploadUniform( int location, const int value );
128
129void CARNA_LIB uploadUniform( int location, const unsigned int value );
130
131void CARNA_LIB uploadUniform( int location, const float value );
132
133void CARNA_LIB uploadUniform( int location, const math::Vector2f& value );
134
135void CARNA_LIB uploadUniform( int location, const math::Vector3f& value );
136
137void CARNA_LIB uploadUniform( int location, const math::Vector4f& value );
138
139void CARNA_LIB uploadUniform( int location, const math::Matrix3f& value );
140
141void CARNA_LIB uploadUniform( int location, const math::Matrix4f& value );
142
149// ----------------------------------------------------------------------------------
150// ShaderUniform
151// ----------------------------------------------------------------------------------
152
165template< typename ValueType >
167{
168
169public:
170
172
177
180 ShaderUniform( const std::string& name, const ValueType& value );
181
185
186protected:
187
188 virtual void uploadTo( int location ) const override;
189
190}; // ShaderUniform
191
192
193template< typename ValueType >
194ShaderUniform< ValueType >::ShaderUniform( const std::string& name, const ValueType& value )
195 : ShaderUniformBase( name )
196 , value( value )
197{
198}
199
200
201template< typename ValueType >
202void ShaderUniform< ValueType >::uploadTo( int location ) const
203{
204 typedef typename ShaderUniformType< ValueType >::UniformType UniformType;
205 uploadUniform( location, static_cast< const UniformType& >( value ) );
206}
207
208
209
210} // namespace Carna :: base
211
212} // namespace Carna
213
214#endif // SHADERUNIFORM_H_6014714286
Represents an association.
Definition Association.h:45
Represents a color. Objects from this class are copyable and assignable.
Definition Color.h:42
Maintains an OpenGL shader program. Realizes the RAII-idiom.
Type-independent abstract ShaderUniform base class.
virtual void uploadTo(int location) const =0
Uploads this uniform to location.
bool upload() const
Uploads this uniform to the current shader. Returns true if the current shader has a matching uniform...
ShaderUniformBase(const std::string &name)
Instantiates.
virtual ~ShaderUniformBase()
Does nothing.
std::string name
Holds the name of this uniform.
Implements ShaderUniformBase class for particular ValueType.
ValueType Value
Holds the accepted value type.
virtual void uploadTo(int location) const override
Uploads this uniform to location.
ShaderUniform(const std::string &name, const ValueType &value)
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
Eigen::Matrix< float, 2, 1 > Vector2f
Defines vector.
Definition math.h:197
Eigen::Matrix< float, 4, 1 > Vector4f
Defines vector.
Definition math.h:195
Eigen::Matrix< float, 3, 3, Eigen::ColMajor > Matrix3f
Defines matrix.
Definition math.h:194
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
Definition math.h:196
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Matrix4f
Defines matrix.
Definition math.h:193
math::Vector4f UniformType
Maps the ShaderUniform value type Color to uploaded type math::Vector4f.
Maps ShaderUniform value types to actually uploaded data types. This general case maps T to T.
ValueType UniformType
Maps ShaderUniform value types to itself.