Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glprogram.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_HW_GLPROGRAM_H_)
21 #define __MITSUBA_HW_GLPROGRAM_H_
22 
23 #include <mitsuba/hw/gpuprogram.h>
24 #include <mitsuba/hw/glrenderer.h>
25 
27 
28 /** \brief OpenGL shader class -- responsible from compiling
29  * and linking GLSL fragments
30  * \ingroup libhw
31  */
33 public:
34  /// Construct a new (empty) shader
35  GLProgram(const std::string &name = "default");
36 
37  /// Initialize the shader
38  void init();
39 
40  /// Bind the shader
41  void bind();
42 
43  /// Set the default shader program
44  void unbind();
45 
46  /// Remove all related OpenGL handles
47  void cleanup();
48 
49  /// Determine the ID number of a named parameter
50  int getParameterID(const std::string &name, bool failIfMissing = true) const;
51 
52  /// Set a boolean parameter
53  void setParameter(int id, bool value);
54 
55  /// Set a float parameter
56  void setParameter(int id, Float value);
57 
58  /// Set a integer parameter
59  void setParameter(int id, int value);
60 
61  /// Set a unsigned integer parameter
62  void setParameter(int id, uint32_t value);
63 
64  /// Set a Vector parameter
65  void setParameter(int id, const Vector &value);
66 
67  /// Set a Vector3i parameter
68  void setParameter(int id, const Vector3i &value);
69 
70  /// Set a Vector2 parameter
71  void setParameter(int id, const Vector2 &value);
72 
73  /// Set a Vector2i parameter
74  void setParameter(int id, const Vector2i &value);
75 
76  /// Set a Vector4 parameter
77  void setParameter(int id, const Vector4 &value);
78 
79  /// Set a Point parameter
80  void setParameter(int id, const Point &value);
81 
82  /// Set a Point3i parameter
83  void setParameter(int id, const Point3i &value);
84 
85  /// Set a Point2 parameter
86  void setParameter(int id, const Point2 &value);
87 
88  /// Set a Point2i parameter
89  void setParameter(int id, const Point2i &value);
90 
91  /// Set a Point4 parameter
92  void setParameter(int id, const Point4 &value);
93 
94  /// Set a Matrix2x2 parameter
95  void setParameter(int id, const Matrix2x2 &value);
96 
97  /// Set a Matrix3x3 parameter
98  void setParameter(int id, const Matrix3x3 &value);
99 
100  /// Set a Matrix4x4 parameter
101  void setParameter(int id, const Matrix4x4 &value);
102 
103  /// Set a Spectrum parameter (will be converted to linear RGB)
104  void setParameter(int id, const Spectrum &value);
105 
106  /// Set a Color3 parameter
107  void setParameter(int id, const Color3 &value);
108 
109  /** Set a GPUTexture parameter. Must be executed after
110  binding the texture to a texture unit */
111  void setParameter(int id, const GPUTexture *value);
112 
114 protected:
115  /// Create a shader from source code
116  int createShader(int type, const std::string &source);
117 
118  /// Return the info log (shader)
119  std::string getInfoLogShader(int id);
120 
121  /// Return the info log (program)
122  std::string getInfoLogProgram();
123 
124  /// Virtual destructor
125  virtual ~GLProgram();
126 private:
127  GLuint m_id[3];
128  GLuint m_program;
129 };
130 
132 
133 #endif /* __MITSUBA_HW_GLPROGRAM_H_ */
Definition: fwd.h:101
#define MTS_EXPORT_HW
Definition: platform.h:114
Basic 2x2 matrix data type.
Definition: matrix.h:455
virtual int getParameterID(const std::string &name, bool failIfMissing=true) const =0
Determine the ID number of a named parameter.
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Abstract shader program (for fragment/vertex shading)
Definition: gpuprogram.h:30
RGB color data type.
Definition: spectrum.h:612
virtual void cleanup()=0
Remove all allocated handles.
virtual void bind()=0
Bind the shader.
OpenGL shader class – responsible from compiling and linking GLSL fragments.
Definition: glprogram.h:32
virtual void init()=0
Upload to the GPU.
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Definition: fwd.h:99
A data structure for 1/2/3D and cube texture mapping. Also has optional render-to-texture functionali...
Definition: gputexture.h:32
Definition: fwd.h:96
void setParameter(const std::string &name, bool value, bool failIfMissing=true)
Set a boolean parameter by name.
Definition: gpuprogram.h:83
Basic 4x4 matrix data type.
Definition: matrix.h:656
Definition: fwd.h:100
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
virtual void unbind()=0
Set the default shader program.
Definition: fwd.h:97
Definition: fwd.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138
Basic 3x3 matrix data type.
Definition: matrix.h:560