LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Material.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 MATERIAL_H_6014714286
16#define MATERIAL_H_6014714286
17
18#include <LibCarna/LibCarna.hpp>
23#include <string>
24
30namespace LibCarna
31{
32
33namespace base
34{
35
36
37
38// ----------------------------------------------------------------------------------
39// Material
40// ----------------------------------------------------------------------------------
41
175class LIBCARNA Material : public GeometryFeature
176{
177
179
180 struct Details;
181 const std::unique_ptr< Details > pimpl;
182
183 const ShaderProgram* shader;
184
185protected:
186
187 friend class GeometryFeature;
188
192 Material( const std::string& shaderName );
193
197 virtual ~Material();
198
199public:
200
204 const std::string shaderName;
205
214
217 template< typename ParameterType >
218 void setParameter( const std::string& name, const ParameterType& value );
219
224
228 void removeParameter( const std::string& name );
229
233 bool hasParameter( const std::string& name ) const;
234
239 const ShaderUniformBase& parameter( const std::string& name ) const;
240
241 float lineWidth() const;
242
243 void setLineWidth( float lineWidth );
244
248 static Material& create( const std::string& shaderName );
249
255 virtual bool controlsSameVideoResource( const GeometryFeature& other ) const override;
256
257 // ------------------------------------------------------------------------------
258 // Material :: ManagedInterface
259 // ------------------------------------------------------------------------------
260
268 {
269
270 public:
271
278
282
289
293 const ShaderProgram& shader() const;
294
299
300 }; // Material :: ManagedInterface
301
302 // ------------------------------------------------------------------------------
303
305
306}; // Material
307
308
309template< typename ParameterType >
310void Material::setParameter( const std::string& name, const ParameterType& value )
311{
312 addParameter( new ShaderUniform< ParameterType >( name, value ) );
313}
314
315
316
317} // namespace LibCarna :: base
318
319} // namespace LibCarna
320
321#endif // MATERIAL_H_6014714286
Defines LibCarna::base::GeometryFeature.
Contains forward-declarations.
Defines LibCarna::base::ShaderManager.
Defines LibCarna::base::ShaderUniformType, LibCarna::base::ShaderUniformBase, and LibCarna::base::Sha...
Represents an association.
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.hpp:268
const ShaderProgram & shader() const
References the shader of this material.
ManagedInterface(Material &material)
Acquires the video resources from material.
virtual ~ManagedInterface()
Releases the video resources previously acquired from the managing geometryFeature.
Material & material
References the material.
Definition Material.hpp:298
void activate(RenderState &renderState) const
Activates this material by setting the proper shader on the current context, configuring it and tweak...
Specifies the shader and it's configuration that are to be used for rendering a Geometry node with a ...
Definition Material.hpp:176
virtual ManagedInterface * acquireVideoResource() override
Acquires the video resources from this GeometryFeature by returning new instance of a class derived f...
void clearParameters()
Removes all previously set parameters.
virtual ~Material()
Deletes.
const std::string shaderName
Identifies this material's shader.
Definition Material.hpp:204
void removeParameter(const std::string &name)
Removes the parameter named name if it exists.
void addParameter(ShaderUniformBase *uniform)
Records uniform as shader parameter. This will be uploaded to the shader when the material is activat...
const ShaderUniformBase & parameter(const std::string &name) const
References the paramter named name.
virtual bool controlsSameVideoResource(const GeometryFeature &other) const override
Tells whether this instance maintains the same video resources like other.
bool hasParameter(const std::string &name) const
Tells whether a paramter named name exists.
Material(const std::string &shaderName)
Instantiates.
static Material & create(const std::string &shaderName)
Instantiates. Call release when you do not need the object any longer.
void setParameter(const std::string &name, const ParameterType &value)
Definition Material.hpp:310
Manages the OpenGL render state.
Maintains an OpenGL shader program. Realizes the RAII-idiom.
Type-independent abstract ShaderUniform base class.
Defines LibCarna::base::noncopyable and NON_COPYABLE.
#define NON_COPYABLE
Marks the class that it is placed in as non-copyable.