Carna Version 3.3.3
Loading...
Searching...
No Matches
Material.h
Go to the documentation of this file.
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 MATERIAL_H_6014714286
13#define MATERIAL_H_6014714286
14
15#include <Carna/Carna.h>
18#include <Carna/base/ShaderUniform.h>
20#include <string>
21
26namespace Carna
27{
28
29namespace base
30{
31
32
33
34// ----------------------------------------------------------------------------------
35// Material
36// ----------------------------------------------------------------------------------
37
174class CARNA_LIB Material : public GeometryFeature
175{
176
178
179 struct Details;
180 const std::unique_ptr< Details > pimpl;
181
182 const ShaderProgram* shader;
183
184protected:
185
186 friend class GeometryFeature;
187
191 Material( const std::string& shaderName );
192
196 virtual ~Material();
197
198public:
199
203 const std::string shaderName;
204
213
216 template< typename ParameterType >
217 void setParameter( const std::string& name, const ParameterType& value );
218
223
227 void removeParameter( const std::string& name );
228
232 bool hasParameter( const std::string& name ) const;
233
238 const ShaderUniformBase& parameter( const std::string& name ) const;
239
243 static Material& create( const std::string& shaderName );
244
250 virtual bool controlsSameVideoResource( const GeometryFeature& other ) const override;
251
252 // ------------------------------------------------------------------------------
253 // Material :: ManagedInterface
254 // ------------------------------------------------------------------------------
255
264 {
265
266 public:
267
274
278
285
289 const ShaderProgram& shader() const;
290
295
296 }; // Material :: ManagedInterface
297
298 // ------------------------------------------------------------------------------
299
301
302}; // Material
303
304
305template< typename ParameterType >
306void Material::setParameter( const std::string& name, const ParameterType& value )
307{
308 addParameter( new ShaderUniform< ParameterType >( name, value ) );
309}
310
311
312
313} // namespace Carna :: base
314
315} // namespace Carna
316
317#endif // MATERIAL_H_6014714286
Defines Carna::base::GeometryFeature.
Defines Carna::base::ShaderManager.
Represents an association.
Definition Association.h:45
Represents an acquisition of the video resources from a particular GeometryFeature....
Represents "components" that are aggregated by Geometry objects. Closer description is given here.
Represents an acquisition of video resources from a particular Material. This realizes the RAII idiom...
Definition Material.h:264
ManagedInterface(Material &material)
Acquires the video resources from material.
void activate(RenderState &renderState) const
Activates this material by setting the proper shader on the current context, configuring it and tweak...
const ShaderProgram & shader() const
References the shader of this material.
Material & material
References the material.
Definition Material.h:294
virtual ~ManagedInterface()
Releases the video resources previously acquired from the managing geometryFeature.
Specifies the shader and it's configuration that are to be used for rendering a Geometry node with a ...
Definition Material.h:175
Material(const std::string &shaderName)
Instantiates.
virtual ManagedInterface * acquireVideoResource() override
Acquires the video resources from this GeometryFeature by returning new instance of a class derived f...
bool hasParameter(const std::string &name) const
Tells whether a paramter named name exists.
void clearParameters()
Removes all previously set parameters.
const std::string shaderName
Identifies this material's shader.
Definition Material.h:203
void removeParameter(const std::string &name)
Removes the parameter named name if it exists.
virtual ~Material()
Deletes.
const ShaderUniformBase & parameter(const std::string &name) const
References the paramter named name.
void setParameter(const std::string &name, const ParameterType &value)
Definition Material.h:306
void addParameter(ShaderUniformBase *uniform)
Records uniform as shader parameter. This will be uploaded to the shader when the material is activat...
virtual bool controlsSameVideoResource(const GeometryFeature &other) const override
Tells whether this instance maintains the same video resources like other.
static Material & create(const std::string &shaderName)
Instantiates. Call release when you do not need the object any longer.
Manages the OpenGL render state.
Definition RenderState.h:86
Maintains an OpenGL shader program. Realizes the RAII-idiom.
Type-independent abstract ShaderUniform base class.
#define NON_COPYABLE
Features class it is placed in as non-copyable.