Carna  Version 3.3.2
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>
19 #include <Carna/base/noncopyable.h>
20 #include <string>
21 
26 namespace Carna
27 {
28 
29 namespace base
30 {
31 
32 
33 
34 // ----------------------------------------------------------------------------------
35 // Material
36 // ----------------------------------------------------------------------------------
37 
174 class CARNA_LIB Material : public GeometryFeature
175 {
176 
178 
179  struct Details;
180  const std::unique_ptr< Details > pimpl;
181 
182  const ShaderProgram* shader;
183 
184 protected:
185 
186  friend class GeometryFeature;
187 
191  Material( const std::string& shaderName );
192 
196  virtual ~Material();
197 
198 public:
199 
203  const std::string shaderName;
204 
212  void addParameter( ShaderUniformBase* uniform );
213 
216  template< typename ParameterType >
217  void setParameter( const std::string& name, const ParameterType& value );
218 
222  void clearParameters();
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 
273  ManagedInterface( Material& material );
274 
277  virtual ~ManagedInterface();
278 
284  void activate( RenderState& renderState ) const;
285 
289  const ShaderProgram& shader() const;
290 
295 
296  }; // Material :: ManagedInterface
297 
298  // ------------------------------------------------------------------------------
299 
300  virtual ManagedInterface* acquireVideoResource() override;
301 
302 }; // Material
303 
304 
305 template< typename ParameterType >
306 void 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
Manages the OpenGL render state.
Definition: RenderState.h:85
Defines Carna::base::ShaderManager.
Defines Carna::base::GeometryFeature.
Represents an acquisition of video resources from a particular Material. This realizes the RAII idiom...
Definition: Material.h:263
Represents "components" that are aggregated by Geometry objects. Closer description is given here...
Type-independent abstract ShaderUniform base class.
Definition: ShaderUniform.h:76
Maintains an OpenGL shader program. Realizes the RAII-idiom.
Definition: ShaderProgram.h:47
Represents an acquisition of the video resources from a particular GeometryFeature. This acquisition realizes the RAII idiom.
Specifies the shader and it&#39;s configuration that are to be used for rendering a Geometry node with a ...
Definition: Material.h:174
void setParameter(const std::string &name, const ParameterType &value)
Definition: Material.h:306
const std::string shaderName
Identifies this material&#39;s shader.
Definition: Material.h:203
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Definition: noncopyable.h:109
Material & material
References the material.
Definition: Material.h:294
Implements ShaderUniformBase class for particular ValueType.