LibCarna Version 3.4.0
Loading...
Searching...
No Matches
ShaderUniform.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef SHADERUNIFORM_H_6014714286
16#define SHADERUNIFORM_H_6014714286
17
24#include <LibCarna/LibCarna.hpp>
26
27namespace LibCarna
28{
29
30namespace base
31{
32
33
34
35// ----------------------------------------------------------------------------------
36// ShaderUniformType
37// ----------------------------------------------------------------------------------
38
43template< typename ValueType >
51
52
57template< >
66
67
68
69// ----------------------------------------------------------------------------------
70// ShaderUniformBase
71// ----------------------------------------------------------------------------------
72
78class LIBCARNA ShaderUniformBase
79{
80
81public:
82
86 ShaderUniformBase( const std::string& name );
87
92
96 std::string name;
97
102 bool upload() const;
103
104protected:
105
109 virtual void uploadTo( int location ) const = 0;
110
111private:
112
113 const static int NULL_UNIFORM_LOCATION = -1;
114
115 int location( const ShaderProgram& ) const;
116
117}; // ShaderUniformBase
118
119
120
121// ----------------------------------------------------------------------------------
122// uploadUniform
123// ----------------------------------------------------------------------------------
124
129void LIBCARNA uploadUniform( int location, const int value );
130
131void LIBCARNA uploadUniform( int location, const unsigned int value );
132
133void LIBCARNA uploadUniform( int location, const float value );
134
135void LIBCARNA uploadUniform( int location, const math::Vector2f& value );
136
137void LIBCARNA uploadUniform( int location, const math::Vector3f& value );
138
139void LIBCARNA uploadUniform( int location, const math::Vector4f& value );
140
141void LIBCARNA uploadUniform( int location, const math::Matrix3f& value );
142
143void LIBCARNA uploadUniform( int location, const math::Matrix4f& value );
144
151// ----------------------------------------------------------------------------------
152// ShaderUniform
153// ----------------------------------------------------------------------------------
154
166template< typename ValueType >
168{
169
170public:
171
173
178
181 ShaderUniform( const std::string& name, const ValueType& value );
182
186
187protected:
188
189 virtual void uploadTo( int location ) const override;
190
191}; // ShaderUniform
192
193
194template< typename ValueType >
195ShaderUniform< ValueType >::ShaderUniform( const std::string& name, const ValueType& value )
196 : ShaderUniformBase( name )
197 , value( value )
198{
199}
200
201
202template< typename ValueType >
203void ShaderUniform< ValueType >::uploadTo( int location ) const
204{
205 typedef typename ShaderUniformType< ValueType >::UniformType UniformType;
206 uploadUniform( location, static_cast< const UniformType& >( value ) );
207}
208
209
210
211} // namespace LibCarna :: base
212
213} // namespace LibCarna
214
215#endif // SHADERUNIFORM_H_6014714286
Contains forward-declarations.
Represents an association.
Represents a color. Objects from this class are copyable and assignable.
Definition Color.hpp:45
Maintains an OpenGL shader program. Realizes the RAII-idiom.
Type-independent abstract ShaderUniform base class.
ShaderUniformBase(const std::string &name)
Instantiates.
virtual void uploadTo(int location) const =0
Uploads this uniform to location.
virtual ~ShaderUniformBase()
Does nothing.
bool upload() const
Uploads this uniform to the current shader. Returns true if the current shader has a matching uniform...
std::string name
Holds the name of this uniform.
Implements ShaderUniformBase class for particular ValueType.
virtual void uploadTo(int location) const override
Uploads this uniform to location.
ShaderUniform(const std::string &name, const ValueType &value)
ValueType Value
Holds the accepted value type.
Defines LibCarna::base::math namespace and LIBCARNA_FOR_VECTOR3UI.
Eigen::Matrix< float, 3, 3, Eigen::ColMajor > Matrix3f
Defines matrix.
Definition math.hpp:198
Eigen::Matrix< float, 2, 1 > Vector2f
Defines vector.
Definition math.hpp:201
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
Definition math.hpp:200
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Matrix4f
Defines matrix.
Definition math.hpp:197
Eigen::Matrix< float, 4, 1 > Vector4f
Defines vector.
Definition math.hpp:199
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.