Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shader.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_RENDER_SHADER_H_)
21 #define __MITSUBA_RENDER_SHADER_H_
22 
23 #include <mitsuba/mitsuba.h>
24 
26 
27 class Shader;
28 class Renderer;
29 class GPUProgram;
30 
31 /**
32  * \brief Abstract hardware resource.
33  *
34  * Implementations provides support for functionality that are also able to
35  * live on the GPU. By default, the method 'createShader' just returns \c NULL,
36  * which means that the BSDF/Light source/Texture/.. has not yet been ported
37  * to the GPU-based renderer.
38  */
40 public:
41  virtual Shader *createShader(Renderer *renderer) const;
42 
43  virtual ~HWResource() { }
44 };
45 
46 /**
47  * \brief %Shader base class for use with a VPL-style renderer.
48  *
49  * Subclasses can implement one of various things, such as a BSDF,
50  * a light source, or a texture.
51  *
52  * \ingroup librender
53  */
55 public:
56  enum EShaderType {
57  EBSDFShader = 0,
59  EEmitterShader
60  };
61 
62  enum EFlags {
63  ETransparent = 0x01
64  };
65 
66  // Return the type of shader represented by this instance
67  inline EShaderType getType() const { return m_type; }
68 
69  /// Return a list of flags
70  inline uint32_t getFlags() const { return m_flags; }
71 
72  /**
73  * \brief For transparent objects, this function returns
74  * the alpha blending weight
75  */
76  virtual Float getAlpha() const;
77 
78  // List other shaders, on which this instance depends
79  virtual void putDependencies(std::vector<Shader *> &deps);
80 
81  /**
82  * \brief Is this shader complete?
83  *
84  * This is mainly useful to check whether all dependencies
85  * could be constructed successfully. The default
86  * implementation returns \c true.
87  */
88  virtual bool isComplete() const;
89 
90  /**
91  * \brief Generate a string version of this shader's evaluation
92  * routine.
93  *
94  * The appended string should assign the name \c evalName to this
95  * function. The function names of depedencies (as specified by
96  * \ref putDependencies), are supplied in the parameter \c depNames
97  * in identical order.
98  */
99  virtual void generateCode(std::ostringstream &oss,
100  const std::string &evalName,
101  const std::vector<std::string> &depNames) const = 0;
102 
103  /**
104  * \brief This function can optionally be implemented to resolve named
105  * program parameters to numerical IDs for increased performance.
106  *
107  * The int array returned here will later be passed to \ref bind().
108  * The default implementation does nothing.
109  */
110  virtual void resolve(const GPUProgram *program, const std::string &evalName,
111  std::vector<int> &parameterIDs) const;
112 
113  /**
114  * \brief Configure the the associated GPU program.
115  *
116  * This function is typically used to bind textures and
117  * to set program pararameters.
118  */
119  virtual void bind(GPUProgram *program, const std::vector<int> &parameterIDs,
120  int &textureUnitOffset) const;
121 
122  /// Release any bound resources.
123  virtual void unbind() const;
124 
125  /// Release all resources
126  virtual void cleanup(Renderer *renderer);
127 
129 protected:
130  Shader(Renderer *renderer, EShaderType type);
131 
132  /// Virtual destructor
133  virtual ~Shader();
134 protected:
135  EShaderType m_type;
136  uint32_t m_flags;
137 };
138 
140 
141 #endif /* __MITSUBA_RENDER_SHADER_H_ */
EShaderType getType() const
Definition: shader.h:67
Shader base class for use with a VPL-style renderer.
Definition: shader.h:54
EShaderType
Definition: shader.h:56
Abstract hardware resource.
Definition: shader.h:39
virtual ~HWResource()
Definition: shader.h:43
uint32_t getFlags() const
Return a list of flags.
Definition: shader.h:70
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Abstract shader program (for fragment/vertex shading)
Definition: gpuprogram.h:30
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Abstract renderer implementation.
Definition: renderer.h:79
Parent of all Mitsuba classes.
Definition: object.h:38
#define MTS_EXPORT_RENDER
Definition: platform.h:109
Definition: shader.h:58
#define MTS_NAMESPACE_END
Definition: platform.h:138
EFlags
Definition: shader.h:62