Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gltexture.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_GLTEXTURE_H_)
21 #define __MITSUBA_HW_GLTEXTURE_H_
22 
23 #include <mitsuba/hw/glrenderer.h>
24 #include <mitsuba/hw/gputexture.h>
25 
27 
28 /** \brief OpenGL-based GPUTexture implementation
29  * \ingroup libhw
30  */
32 public:
33  /// Create a new GLTexture with the given name and bitmap
34  GLTexture(const std::string &name, Bitmap *bitmap);
35 
36  /// Upload the texture
37  void init();
38 
39  /// Refresh (re-upload) the texture
40  void refresh();
41 
42  /**
43  * \brief Refresh (re-upload) a subregion of the texture
44  *
45  * Note: this is only implemented for 2D textures
46  */
47  void refresh(const Point2i &offset, const Vector2i &size);
48 
49  /// Free the texture from GPU memory
50  void cleanup();
51 
52  /**
53  * \brief Bind the texture and enable texturing
54  *
55  * \param textureUnit
56  * Specifies the unit to which this texture should be bound
57  * \param textureIndex
58  * When this texture has multiple sub-textures (e.g.
59  * a color and depth map in the case of a
60  * \ref EColorAndDepthBuffer texture), this parameter
61  * specifies the one to be bound
62  */
63  void bind(int textureUnit = 0, int textureIndex = 0) const;
64 
65  /// Download the texture (only for render target textures)
66  void download(Bitmap *bitmap = NULL);
67 
68  /// Unbind the texture and disable texturing
69  void unbind() const;
70 
71  /// Activate the render target
72  void activateTarget();
73 
74  /// Activate a certain face of a cube map as render target
75  void activateSide(int side);
76 
77  /// Restrict rendering to a sub-region of the texture
78  void setTargetRegion(const Point2i &offset, const Vector2i &size);
79 
80  /// Deactivate the render target
81  void releaseTarget();
82 
83  /**
84  * \brief Blit a render buffer into another render buffer
85  *
86  * \param target
87  * Specifies the target render buffer (or NULL for the framebuffer)
88  * \param what
89  * A bitwise-OR of the components in \ref EFrameBufferType to copy
90  */
91  void blit(GPUTexture *target, int what) const;
92 
93  /**
94  * \brief Blit a render buffer into another render buffer
95  *
96  * \param target
97  * Specifies the target render buffer (or NULL for the framebuffer)
98  * \param what
99  * A bitwise-OR of the components in \ref EFrameBufferType to copy
100  * \param sourceOffset
101  * Offset in the source render buffer
102  * \param sourceOffset
103  * Size of the region to be copied from the source render buffer
104  * \param destOffset
105  * Offset in the destination render buffer
106  * \param destOffset
107  * Size of the region to be copied into the dest destination buffer
108  */
109  void blit(GPUTexture *target, int what, const Point2i &sourceOffset,
110  const Vector2i &sourceSize, const Point2i &destOffset,
111  const Vector2i &destSize) const;
112 
113  /// Clear (assuming that this is a render buffer)
114  void clear();
115 
116  /// Assuming that this is a 2D RGB framebuffer, read a single pixel from the GPU
117  Color3 getPixel(int x, int y) const;
118 
120 protected:
121  /// Virtual destructor
122  virtual ~GLTexture();
123 protected:
124  /// Look up relevant constants
125  void lookupGLConstants();
126 
127  /// Configure texture filtering
128  void configureTexture();
129 
130  uint32_t m_id;
131  uint32_t m_glType;
132  uint32_t m_format;
133  uint32_t m_internalFormat;
134  uint32_t m_dataFormat;
135  uint32_t m_fboId, m_depthId;
136  mutable bool m_needsUpdate;
137 };
138 
140 
141 #endif /* __MITSUBA_HW_GLTEXTURE_H_ */
virtual void refresh()=0
Refresh (re-upload) the texture.
General-purpose bitmap class with read and write support for several common file formats.
Definition: bitmap.h:50
#define MTS_EXPORT_HW
Definition: platform.h:114
virtual void cleanup()=0
Free the texture from GPU memory.
virtual void bind(int textureUnit=0, int textureIndex=0) const =0
Bind the texture and enable texturing.
virtual Color3 getPixel(int x, int y) const =0
Assuming that this is a 2D RGB framebuffer, read a single pixel from the GPU.
virtual void releaseTarget()=0
Deactivate the render target.
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
RGB color data type.
Definition: spectrum.h:612
virtual void download(Bitmap *bitmap=NULL)=0
OpenGL-based GPUTexture implementation.
Definition: gltexture.h:31
#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 activateSide(int side)=0
Activate a certain face of a cube map as render target.
Definition: fwd.h:99
virtual void clear()=0
Clear (assuming that this is a render buffer)
virtual void setTargetRegion(const Point2i &offset, const Vector2i &size)=0
Restrict rendering to a sub-region of the texture.
A data structure for 1/2/3D and cube texture mapping. Also has optional render-to-texture functionali...
Definition: gputexture.h:32
virtual void init()=0
Upload the texture.
virtual void blit(GPUTexture *target, int what) const =0
Blit a render buffer into another render buffer.
virtual void unbind() const =0
Unbind the texture and disable texturing.
Definition: fwd.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138
virtual void activateTarget()=0
Activate the render target.