Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glrenderer.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_GLRENDERER_H_)
21 #define __MITSUBA_HW_GLRENDERER_H_
22 
23 #include <mitsuba/hw/renderer.h>
24 
25 struct GLEWContextStruct;
26 
27 /// Get the per-thread context for GLEW-MX
28 extern MTS_EXPORT_HW GLEWContextStruct *glewGetContext();
29 
31 
32 /**
33  * \brief Specifies the maximum number of triangles that can
34  * be sent to the GPU in one batch. This is useful to
35  * avoid freezing the OS when dealing with huge inputs.
36  */
37 #define MTS_GL_MAX_QUEUED_TRIS 250000
38 
39 /**
40  * \brief OpenGL implementation of the \ref Renderer interface
41  * \ingroup libhw
42  */
44 public:
45  /// Construct a new OpenGL rendering interface
46  GLRenderer(Session *session);
47 
48  /// Initialize the renderer
49  virtual void init(Device *device, Renderer *other = NULL);
50 
51  /**
52  * \brief Reconfigure the renderer for a certain device
53  * (e.g. after a resize event)
54  */
55  void reconfigure(const Device *device);
56 
57  /// Shut the renderer down
58  virtual void shutdown();
59 
60  /// Create a new GPU texture object
61  GPUTexture *createGPUTexture(const std::string &name,
62  Bitmap *bitmap = NULL);
63 
64  /// Create a new GPU geometry object
65  GPUGeometry *createGPUGeometry(const Shape *shape);
66 
67  /// Create a new GPU program object
68  GPUProgram *createGPUProgram(const std::string &name);
69 
70  /// Create a new synchronization object
72 
73  /// Clear the viewport
74  void clear();
75 
76  /// Configure the camera
77  void setCamera(const ProjectiveCamera *pCamera,
78  const Point2 &apertureSample = Point2(0.5f),
79  const Point2 &aaSample = Point2(0.5f),
80  Float timeSample = 0.5f);
81 
82  /// Configure the camera (manual)
83  void setCamera(const Matrix4x4 &proj, const Matrix4x4 &view);
84 
85  /// Directly set the modelview or projection matrix
86  void setMatrix(EMatrixType type, const Matrix4x4 &value);
87 
88  /// Fetch the currently set modelview or projection matrix
89  Matrix4x4 getMatrix(EMatrixType type) const;
90 
91  /// Set up the renderer for drawing triangle geometry
92  void beginDrawingMeshes(bool transmitOnlyPositions = false);
93 
94  /// Send a triangle mesh to the renderer
95  void drawMesh(const TriMesh *geo);
96 
97  /// Send a triangle mesh to the renderer
98  void drawMesh(const GPUGeometry *geo);
99 
100  /// Clean up the renderer after drawing triangle geometry
101  void endDrawingMeshes();
102 
103  /**
104  * \brief Quickly draw all geometry that has been registered
105  * with the renderer.
106  *
107  * Only transmits positions, hence this is mainly useful for
108  * shadow mapping.
109  */
110  void drawAll(const std::vector<TransformedGPUGeometry> &allGeometry);
111 
112  /// Draw a quad using the given texture
113  void blitTexture(const GPUTexture *texture,
114  bool flipVertically = false,
115  bool centerHoriz = true, bool centerVert = true,
116  const Vector2i &offset = Vector2i(0, 0));
117 
118  /// Blit a screen-sized quad
119  void blitQuad(bool flipVertically);
120 
121  /**
122  * Draw a line of text on the screen. The coordinates are specified
123  * in pixel coordinates, where the upper left corner is the origin
124  */
125  void drawText(const Point2i &pos,
126  const Font *font, const std::string &text);
127 
128  /// Set the size of point primitives
129  void setPointSize(Float size);
130 
131  /// Draw a point
132  void drawPoint(const Point &p);
133 
134  /// Draw a line between two specified points
135  void drawLine(const Point &a, const Point &b);
136 
137  /// Draw a point (2D)
138  void drawPoint(const Point2 &p);
139 
140  /// Draw a point (2D, integer coordinates)
141  void drawPoint(const Point2i &p);
142 
143  /// Draw a line between two specified points (2D)
144  void drawLine(const Point2 &a, const Point2 &b);
145 
146  /// Draw a line between two specified points (2D, integer coordinates)
147  void drawLine(const Point2i &a, const Point2i &b);
148 
149  /// Draw a rectangle between two specified points (2D)
150  void drawRectangle(const Point2 &a, const Point2 &b);
151 
152  /// Draw a rectangle between two specified points (2D, integer coordinates)
153  void drawRectangle(const Point2i &a, const Point2i &b);
154 
155  /// Draw a filled rectangle between two specified points (2D)
156  void drawFilledRectangle(const Point2 &a, const Point2 &b);
157 
158  /// Draw a filled rectangle between two specified points (2D, integer coordinates)
159  void drawFilledRectangle(const Point2i &a, const Point2i &b);
160 
161  /// Draw an ellipse with the specified center and axes
162  void drawEllipse(const Point &center,
163  const Vector &axis1, const Vector &axis2);
164 
165  /// Draw a wire-frame axis-aligned box
166  void drawAABB(const AABB &aabb);
167 
168  /// Set the currently active blending mode
169  void setBlendMode(EBlendMode mode);
170 
171  /// Set the currently active culling mode
172  void setCullMode(ECullMode mode);
173 
174  /// Activate or deactivate the writing of depth information
175  void setDepthMask(bool value);
176 
177  /// Activate or deactivate depth testing
178  void setDepthTest(bool value);
179 
180  /// Set the current fixed-function pipeline color
181  void setColor(const Color3 &color, Float alpha = 1.0f);
182 
183  /// Set the current fixed-function pipeline color
184  void setColor(const Spectrum &spec, Float alpha = 1.0f);
185 
186  /// Set the depth value that is written by \ref clear()
187  void setClearDepth(Float depth);
188 
189  /// Set the color value that is written by \ref clear()
190  void setClearColor(const Color3 &color);
191 
192  /// Clear the view and projection transformations
193  void clearTransforms();
194 
195  /// Flush outstanding rendering commands
196  void flush();
197 
198  /// Completely finish outstanding rendering commands
199  void finish();
200 
201  /// Check for any error indications
202  void checkError(bool onlyWarn = true);
203 
204  /**
205  * \brief Send a debug string to the rendering backend
206  *
207  * This is mainly useful when an OpenGL trace is captured
208  * by a tool such as 'apitrace'.
209  */
210  void debugString(const std::string &text);
211 
213 protected:
214  /// Virtual destructor
215  virtual ~GLRenderer();
216 protected:
217  bool m_transmitOnlyPositions;
218  bool m_normalsEnabled;
219  bool m_texcoordsEnabled;
220  bool m_tangentsEnabled;
221  bool m_colorsEnabled;
222  size_t m_queuedTriangles;
223  int m_stride;
224 };
225 
227 
228 #endif /* __MITSUBA_HW_GLRENDERER_H_ */
TVector2< int > Vector2i
Definition: fwd.h:108
EBlendMode
Definition: renderer.h:84
virtual void setCamera(const ProjectiveCamera *pCamera, const Point2 &apertureSample=Point2(0.5f), const Point2 &aaSample=Point2(0.5f), Float timeSample=0.5f)=0
Configure the camera.
virtual void shutdown()
Shut the renderer down.
virtual void flush()=0
Flush outstanding rendering commands.
Abstract triangle mesh base class.
Definition: trimesh.h:68
General-purpose bitmap class with read and write support for several common file formats.
Definition: bitmap.h:50
virtual void beginDrawingMeshes(bool transmitOnlyPositions=false)=0
Set up the renderer for drawing triangle geometry.
virtual void drawEllipse(const Point &center, const Vector &axis1, const Vector &axis2)=0
Draw an ellipse with the specified center and axes.
virtual void setBlendMode(EBlendMode mode)=0
Set the currently active blending mode.
Utility class used to render text inside OpenGL programs using pre-rasterized TrueType fonts stored a...
Definition: font.h:34
virtual void drawLine(const Point &a, const Point &b)=0
Draw a line between two specified points.
virtual void clearTransforms()=0
Clear the view and projection transformations.
#define MTS_EXPORT_HW
Definition: platform.h:114
virtual void drawMesh(const TriMesh *shape)=0
Send a triangle mesh to the renderer.
virtual void checkError(bool onlyWarn=true)=0
Check for any error indications.
virtual void clear()=0
Clear the viewport.
Abstract GPU synchronization object implementing a memory fence operation.
Definition: gpusync.h:31
virtual void setClearColor(const Color3 &color)=0
Set the color value that is written by clear()
virtual void setCullMode(ECullMode mode)=0
Set the currently active culling mode.
virtual void drawText(const Point2i &pos, const Font *font, const std::string &text)=0
virtual GPUProgram * createGPUProgram(const std::string &name)=0
Create a new GPU program object.
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
virtual GPUTexture * createGPUTexture(const std::string &name, Bitmap *bitmap=NULL)=0
Create a new GPU texture object.
Abstract shader program (for fragment/vertex shading)
Definition: gpuprogram.h:30
Abstract base class of all shapes.
Definition: shape.h:178
RGB color data type.
Definition: spectrum.h:612
virtual void debugString(const std::string &text)=0
Send a debug string to the rendering backend.
virtual void setMatrix(EMatrixType type, const Matrix4x4 &value)=0
Directly set the modelview or projection matrix.
TPoint2< Float > Point2
Definition: fwd.h:129
Projective camera interface.
Definition: sensor.h:393
virtual void blitQuad(bool flipVertically)=0
Blit a screen-sized quad.
An abstract drawing device.
Definition: device.h:136
Axis-aligned bounding box data structure in three dimensions.
Definition: aabb.h:437
GLEWContextStruct * glewGetContext()
Get the per-thread context for GLEW-MX.
virtual Matrix4x4 getMatrix(EMatrixType type) const =0
Fetch the currently set modelview or projection matrix.
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
virtual void finish()=0
Completely finish outstanding rendering commands.
Definition: fwd.h:99
ECullMode
Possible culling modes.
Definition: renderer.h:91
Abstract renderer implementation.
Definition: renderer.h:79
A data structure for 1/2/3D and cube texture mapping. Also has optional render-to-texture functionali...
Definition: gputexture.h:32
Abstract windowing environment session.
Definition: session.h:32
Definition: fwd.h:96
virtual void drawRectangle(const Point2 &a, const Point2 &b)=0
Draw a rectangle between two specified points (2D)
Abstract geometry storage on a graphics card.
Definition: gpugeometry.h:32
Basic 4x4 matrix data type.
Definition: matrix.h:656
virtual GPUGeometry * createGPUGeometry(const Shape *mesh)=0
Create a new GPU geometry object.
virtual void setColor(const Color3 &color, Float alpha=1.0f)=0
Set the current fixed-function pipeline color.
virtual void setDepthMask(bool value)=0
Activate or deactivate the writing of depth information.
virtual GPUSync * createGPUSync()=0
Create a new synchronization object.
virtual void reconfigure(const Device *device)=0
Reconfigure the renderer for a certain device (e.g. after a resize event)
EMatrixType
Matrices of the fixed function pipeline.
Definition: renderer.h:98
virtual void endDrawingMeshes()=0
Clean up the renderer after drawing triangle geometry.
virtual void setDepthTest(bool value)=0
Activate or deactivate depth testing.
virtual void blitTexture(const GPUTexture *texture, bool flipVertically=false, bool centerHoriz=true, bool centerVert=true, const Vector2i &offset=Vector2i(0, 0))=0
Draw a quad using the given texture.
Definition: fwd.h:100
OpenGL implementation of the Renderer interface.
Definition: glrenderer.h:43
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
virtual void setPointSize(Float size)=0
Set the size of point primitives.
virtual void drawPoint(const Point &p)=0
Draw a point.
virtual void drawAABB(const AABB &aabb)=0
Draw a wire-frame axis-aligned box.
Definition: fwd.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138
virtual void drawAll(const std::vector< TransformedGPUGeometry > &geo)=0
Quickly draw all geometry that has been registered with the renderer.
virtual void drawFilledRectangle(const Point2 &a, const Point2 &b)=0
Draw a filled rectangle between two specified points (2D)
virtual void setClearDepth(Float depth)=0
Set the depth value that is written by clear()
virtual void init(Device *device, Renderer *other=NULL)