SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLTextureIBL.cpp
Go to the documentation of this file.
1 /**
2  * \file SLGLTextureIBL.cpp
3  * \date April 2018
4  * \authors Carlos Arauz, Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #include <SLAssetManager.h>
11 #include <SLScene.h>
12 #include <SLGLTextureIBL.h>
13 
14 //-----------------------------------------------------------------------------
15 const SLint ROUGHNESS_NUM_MIP_LEVELS = 5; //! Number of mip levels for roughness cubemaps
16 //-----------------------------------------------------------------------------
17 //! ctor for generated textures from hdr textures
19  SLstring shaderPath,
20  SLGLTexture* sourceTexture,
21  SLVec2i size,
22  SLTextureType texType,
23  SLenum target,
24  SLbool readBackPixels,
25  SLint min_filter,
26  SLint mag_filter)
27 {
28  if (sourceTexture != nullptr)
29  {
30  assert(sourceTexture->texType() >= TT_hdr);
31  assert(texType > TT_hdr);
32  }
33 
34  _sourceTexture = sourceTexture;
35  _texType = texType;
36  _min_filter = min_filter;
37  _mag_filter = mag_filter;
38  _wrap_s = GL_CLAMP_TO_EDGE;
39  _wrap_t = GL_CLAMP_TO_EDGE;
40  _target = target;
41  _texID = 0;
42  _bumpScale = 1.0f;
43  _resizeToPow2 = false;
44  _autoCalcTM3D = false;
45  _needsUpdate = false;
46  _bytesOnGPU = 0;
47  _width = size.x;
48  _height = size.y;
49  _bytesPerPixel = 0;
50  _deleteImageAfterBuild = false;
51  _readBackPixels = readBackPixels;
52 
53  name("Generated " + typeName());
54 
57  shaderPath + "PBR_CubeMap.vert",
58  shaderPath + "PBR_CylinderToCubeMap.frag");
59  else if (texType == TT_irradianceCubemap)
61  shaderPath + "PBR_CubeMap.vert",
62  shaderPath + "PBR_IrradianceConvolution.frag");
63  else if (texType == TT_roughnessCubemap)
65  shaderPath + "PBR_CubeMap.vert",
66  shaderPath + "PBR_PrefilterRoughness.frag");
67  else if (texType == TT_brdfLUT)
69  shaderPath + "PBR_BRDFIntegration.vert",
70  shaderPath + "PBR_BRDFIntegration.frag");
71 
72  // perspective projection with field of view of 90 degrees
73  _captureProjection.perspective(90.0f, 1.0f, 0.1f, 10.0f);
74 
75  // initialize capture views: 6 views each at all 6 directions of the faces of a cube map
76  // clang-format off
77  SLMat4f mat;
78  mat.lookAt(0, 0, 0, 1, 0, 0, 0,-1, 0); _captureViews.push_back(mat);
79  mat.lookAt(0, 0, 0,-1, 0, 0, 0,-1, 0); _captureViews.push_back(mat);
80  mat.lookAt(0, 0, 0, 0, 1, 0, 0, 0, 1); _captureViews.push_back(mat);
81  mat.lookAt(0, 0, 0, 0,-1, 0, 0, 0,-1); _captureViews.push_back(mat);
82  mat.lookAt(0, 0, 0, 0, 0, 1, 0,-1, 0); _captureViews.push_back(mat);
83  mat.lookAt(0, 0, 0, 0, 0,-1, 0,-1, 0); _captureViews.push_back(mat);
84  // clang-format on
85 
86  // Add pointer to the global resource vectors for deallocation
87  if (am)
88  am->textures().push_back(this);
89 }
90 //-----------------------------------------------------------------------------
92 {
93  deleteData(true);
94 
95  glDeleteVertexArrays(1, &_cubeVAO);
96  _cubeVAO = 0;
97  glDeleteBuffers(1, &_cubeVBO);
98  _cubeVBO = 0;
99  glDeleteVertexArrays(1, &_quadVAO);
100  _quadVAO = 0;
101  glDeleteBuffers(1, &_quadVBO);
102  _quadVBO = 0;
103  GET_GL_ERROR;
104 }
105 //-----------------------------------------------------------------------------
106 /*!
107  Build the texture into a cube map, rendering the texture 6 times and capturing
108  each time one side of the cube (except for the BRDF LUT texture, which is
109  completely generated by calculations directly with the shader).
110  This is probably the most difficult OpenGL code in the project.
111 */
113 {
114  // Assure to delete all images if we read the pixels back
115  if (_readBackPixels)
116  deleteImages();
117  bool saveReadbackTextures = false;
118 
119  glGenTextures(1, &_texID);
120  glBindTexture(_target, _texID);
121 
122  GLuint fboID;
123  glGenFramebuffers(1, &fboID);
124 
125  GLuint rboID;
126  glGenRenderbuffers(1, &rboID);
127 
130  {
133 
134  // Build the textures for the 6 faces of a cubemap with no data
135  for (SLuint i = 0; i < 6; i++)
136  {
137  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
138  0,
140  _width,
141  _height,
142  0,
145  nullptr);
146  }
147 
148  glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrap_s);
149  glTexParameteri(_target, GL_TEXTURE_WRAP_T, _wrap_t);
150  glTexParameteri(_target, GL_TEXTURE_WRAP_R, _wrap_t);
151  glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _min_filter);
152  glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _mag_filter);
153 
155 
156  if (_sourceTexture != nullptr)
158 
159  _shaderProgram->uniform1i("u_environmentMap", texUnit);
160 
161  glActiveTexture(GL_TEXTURE0 + texUnit);
162  glBindTexture(_sourceTexture->target(),
163  _sourceTexture->texID());
164  glViewport(0, 0, _width, _height);
165  glBindFramebuffer(GL_FRAMEBUFFER, fboID);
166  glBindRenderbuffer(GL_RENDERBUFFER, rboID);
167  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, _width, _height);
168  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
169 
171 
172  // Set the list of draw buffers.
173  GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
174  glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
175 
176  for (SLuint i = 0; i < 6; i++)
177  {
179  _shaderProgram->uniformMatrix4fv("u_mvpMatrix", 1, mvp.m());
180 
181  glFramebufferTexture2D(GL_FRAMEBUFFER,
182  GL_COLOR_ATTACHMENT0,
183  GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
184  _texID,
185  0);
186 
187  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
188  renderCube();
189 
190  if (_readBackPixels)
191  {
192  string name = (_texType == TT_environmentCubemap)
193  ? "environmentCubemap_side"
194  : "irradianceCubemap_side";
195  name += std::to_string(i) + ".png";
197  _height,
198  name,
199  saveReadbackTextures);
200  }
201  }
202 
203  glBindFramebuffer(GL_FRAMEBUFFER, 0);
204  glBindRenderbuffer(GL_RENDERBUFFER, 0);
205 
207  {
208  glBindTexture(GL_TEXTURE_CUBE_MAP, _texID);
209  glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
210  }
211  }
212  else if (_texType == TT_roughnessCubemap)
213  {
215  "the source texture is not an environment map");
216 
219 
220  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
221  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
222  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
223  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
224  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
225  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0);
226  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, ROUGHNESS_NUM_MIP_LEVELS - 1);
227 
228  // Define textures for all mip levels of all six sides of the cube map
229  for (SLint mipLevel = 0; mipLevel < ROUGHNESS_NUM_MIP_LEVELS; mipLevel++)
230  {
231  // Calculate the size of this mip level
232  SLint mipWidth = _width / (1 << mipLevel);
233  SLint mipHeight = _height / (1 << mipLevel);
234 
235  for (SLint i = 0; i < 6; i++)
236  {
237  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
238  mipLevel,
240  mipWidth,
241  mipHeight,
242  0,
245  nullptr);
246  }
247  }
248 
250 
251  if (_sourceTexture != nullptr)
253 
254  _shaderProgram->uniform1i("u_environmentMap", texUnit);
255  _shaderProgram->uniform1f("u_environmentMapSize", (float)_sourceTexture->width());
256 
257  glActiveTexture(GL_TEXTURE0 + texUnit);
258  glBindTexture(_sourceTexture->target(), _sourceTexture->texID());
259 
260  for (SLint mipLevel = 0; mipLevel < ROUGHNESS_NUM_MIP_LEVELS; ++mipLevel)
261  {
262  // Resize framebuffer according to mip level size
263  SLint mipWidth = _width / (1 << mipLevel);
264  SLint mipHeight = _height / (1 << mipLevel);
265  glViewport(0, 0, mipWidth, mipHeight);
266 
267  glBindFramebuffer(GL_FRAMEBUFFER, fboID);
268 
269  SLfloat roughness = (SLfloat)mipLevel / (SLfloat)(ROUGHNESS_NUM_MIP_LEVELS - 1);
270  _shaderProgram->uniform1f("u_roughness", roughness);
271 
272  for (SLuint i = 0; i < 6; ++i)
273  {
275  _shaderProgram->uniformMatrix4fv("u_mvpMatrix", 1, mvp.m());
276  glFramebufferTexture2D(GL_FRAMEBUFFER,
277  GL_COLOR_ATTACHMENT0,
278  GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
279  _texID,
280  mipLevel);
281 
282  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
283 
285 
286  renderCube();
287 
288  if (_readBackPixels)
289  {
290  string name = "roughnessCubemap_mip" +
291  std::to_string(mipLevel) + "_side" +
292  std::to_string(i) + ".png";
293  readPixels((SLint)mipWidth,
294  (SLint)mipHeight,
295  name,
296  saveReadbackTextures);
297  }
298  }
299 
300  glBindFramebuffer(GL_FRAMEBUFFER, 0);
301  }
302  }
303  else if (_texType == TT_brdfLUT)
304  {
307 
308  glTexImage2D(_target,
309  0,
311  _width,
312  _height,
313  0,
316  0);
317  glTexParameteri(_target, GL_TEXTURE_WRAP_S, _wrap_s);
318  glTexParameteri(_target, GL_TEXTURE_WRAP_T, _wrap_t);
319  glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, _min_filter);
320  glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _mag_filter);
321 
322  glBindFramebuffer(GL_FRAMEBUFFER, fboID);
323 
324  glFramebufferTexture2D(GL_FRAMEBUFFER,
325  GL_COLOR_ATTACHMENT0,
326  GL_TEXTURE_2D,
327  _texID,
328  0);
329 
330  glViewport(0, 0, _width, _height);
332 
333  if (_sourceTexture != nullptr)
335  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
336 
338 
339  renderQuad();
340 
341  if (_readBackPixels)
342  {
343  string name = "brdfLUT.png";
345  _height,
346  name,
347  saveReadbackTextures);
348  }
349 
350  glBindFramebuffer(GL_FRAMEBUFFER, 0);
351  }
352 
353  glDeleteFramebuffers(1, &fboID);
354  glDeleteRenderbuffers(1, &rboID);
355 
356  // Reset the viewport
357  SLGLState* state = SLGLState::instance();
358  auto vp = state->viewport();
359  glViewport(vp.x, vp.y, vp.z, vp.w);
360  glFinish();
361  GET_GL_ERROR;
362 }
363 //-----------------------------------------------------------------------------
364 //! Renders 2x2 cube, used to project a texture to a cube texture with 6 sides
366 {
367  // initialize (if necessary)
368  if (_cubeVAO == 0)
369  {
370  // clang-format off
371  // Define vertex positions of an inward facing cube
372  // The original code from learnopengl.com used an outwards facing cube
373  // with disabled face culling. With our default enabled face culling this
374  // lead to a horrible error that cost us about 10kFr. of debugging.
375  // Thanks to the tip of Michael Goettlicher we finally got it correct.
376  float vertices[] = {
377  // back face
378  -1.0f, -1.0f, -1.0f, // bottom-left
379  1.0f, -1.0f, -1.0f, // bottom-right
380  1.0f, 1.0f, -1.0f, // top-right
381  1.0f, 1.0f, -1.0f, // top-right
382  -1.0f, 1.0f, -1.0f, // top-left
383  -1.0f, -1.0f, -1.0f, // bottom-left
384  // front face
385  -1.0f, -1.0f, 1.0f, // bottom-left
386  1.0f, 1.0f, 1.0f, // top-right
387  1.0f, -1.0f, 1.0f, // bottom-right
388  1.0f, 1.0f, 1.0f, // top-right
389  -1.0f, -1.0f, 1.0f, // bottom-left
390  -1.0f, 1.0f, 1.0f, // top-left
391  // left face
392  -1.0f, 1.0f, 1.0f, // top-right
393  -1.0f, -1.0f, -1.0f, // bottom-left
394  -1.0f, 1.0f, -1.0f, // top-left
395  -1.0f, -1.0f, -1.0f, // bottom-left
396  -1.0f, 1.0f, 1.0f, // top-right
397  -1.0f, -1.0f, 1.0f, // bottom-right
398  // right face
399  1.0f, 1.0f, 1.0f, // top-left
400  1.0f, 1.0f, -1.0f, // top-right
401  1.0f, -1.0f, -1.0f, // bottom-right
402  1.0f, -1.0f, -1.0f, // bottom-right
403  1.0f, -1.0f, 1.0f, // bottom-left
404  1.0f, 1.0f, 1.0f, // top-left
405  // bottom face
406  -1.0f, -1.0f, -1.0f, // top-right
407  1.0f, -1.0f, 1.0f, // bottom-left
408  1.0f, -1.0f, -1.0f, // top-left
409  1.0f, -1.0f, 1.0f, // bottom-left
410  -1.0f, -1.0f, -1.0f, // top-right
411  -1.0f, -1.0f, 1.0f, // bottom-right
412  // top face
413  1.0f, 1.0f, 1.0f, // right-top-front
414  -1.0f, 1.0f, 1.0f, // left-top-front
415  -1.0f, 1.0f, -1.0f, // left-top-back
416  -1.0f, 1.0f, -1.0f, // left-top-back
417  1.0f, 1.0f, -1.0f, // right-top-back
418  1.0f, 1.0f , 1.0f // right-top-front
419  };
420 
421  // clang-format on
422  glGenVertexArrays(1, &_cubeVAO);
423  glGenBuffers(1, &_cubeVBO);
424 
425  // fill buffer
426  glBindBuffer(GL_ARRAY_BUFFER, _cubeVBO);
427  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
428 
429  // link vertex attributes
430  glBindVertexArray(_cubeVAO);
431  glEnableVertexAttribArray(0);
432  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
433  glBindBuffer(GL_ARRAY_BUFFER, 0);
434  glBindVertexArray(0);
435  }
436 
437  // render inwards facing cube with face culling enabled
438  glBindVertexArray(_cubeVAO);
439  glDrawArrays(GL_TRIANGLES, 0, 36);
440  glBindVertexArray(0);
441 }
442 //-----------------------------------------------------------------------------
443 //! Renders a 2x2 XY quad, used for rendering and capturing the BRDF integral
445 {
446  if (_quadVAO == 0)
447  {
448  // clang-format off
449  // Define a front (+Z) facing quad with texture coordinates
450  float quadVertices[] = {
451  // positions // texture Coords
452  -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
453  -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
454  1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
455  1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
456  };
457  // clang-format on
458 
459  // setup plane VAO
460  glGenVertexArrays(1, &_quadVAO);
461  glGenBuffers(1, &_quadVBO);
462  glBindVertexArray(_quadVAO);
463  glBindBuffer(GL_ARRAY_BUFFER, _quadVBO);
464  glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
465  glEnableVertexAttribArray(0);
466  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
467  glEnableVertexAttribArray(1);
468  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
469  }
470 
471  // Render quad
472  glBindVertexArray(_quadVAO);
473  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
474  glBindVertexArray(0);
475 }
476 //-----------------------------------------------------------------------------
477 //! Reads back the pixels into an image
478 /*
479  * The image based lighting textures are only generated on the GPU. For
480  * debugging or ray tracing we need to read back the pixels into main memory.
481  */
482 void SLGLTextureIBL::readPixels(int width, int height, string name, bool savePNG)
483 {
484  CVImage* image = new CVImage(width,
485  height,
487  name);
488  glReadPixels(0,
489  0,
490  width,
491  height,
493  GL_UNSIGNED_BYTE,
494  image->data());
495  GET_GL_ERROR;
496 
497  if (savePNG)
498  image->savePNG(name, 9, false);
499 
500  _images.push_back(image);
501 }
502 //-----------------------------------------------------------------------------
504 {
505 #if defined(DEBUG) || defined(_DEBUG)
506  GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
507  switch (fbStatus)
508  {
509  case GL_FRAMEBUFFER_COMPLETE: break;
510  case GL_FRAMEBUFFER_UNDEFINED: SL_LOG("**** GL_FRAMEBUFFER_UNDEFINED ****"); break;
511  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: SL_LOG("**** GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ****"); break;
512  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: SL_LOG("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT ****"); break;
513  case GL_FRAMEBUFFER_UNSUPPORTED: SL_LOG("**** GL_FRAMEBUFFER_UNSUPPORTED ****"); break;
514  case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: SL_LOG("**** GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE ****"); break;
515  // case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: SL_LOG("**** GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER ****"); break;
516  // case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: SL_LOG("**** GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER ****"); break;
517  // case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: SL_LOG("**** GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS ****"); break;
518  default: SL_LOG("Unknown framebuffer status!!!");
519  }
520 #endif
521 }
522 //-----------------------------------------------------------------------------
float SLfloat
Definition: SL.h:173
unsigned int SLenum
Definition: SL.h:176
#define SL_LOG(...)
Definition: SL.h:233
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
#define GET_GL_ERROR
Definition: SLGLState.h:56
#define SL_BRDF_LUT_GL_INTERNAL_FORMAT
Definition: SLGLTexture.h:55
#define SL_HDR_PIXEL_BYTES
Definition: SLGLTexture.h:54
SLTextureType
Texture type enumeration & their filename appendix for auto type detection.
Definition: SLGLTexture.h:76
@ TT_brdfLUT
Definition: SLGLTexture.h:93
@ TT_irradianceCubemap
Definition: SLGLTexture.h:91
@ TT_environmentCubemap
Definition: SLGLTexture.h:90
@ TT_roughnessCubemap
Definition: SLGLTexture.h:92
@ TT_hdr
Definition: SLGLTexture.h:89
#define SL_READ_PIXELS_CV_FORMAT
Definition: SLGLTexture.h:60
#define SL_BRDF_LUT_GL_FORMAT
Definition: SLGLTexture.h:56
#define SL_HDR_GL_INTERNAL_FORMAT
Definition: SLGLTexture.h:51
#define SL_BRDF_LUT_GL_TYPE
Definition: SLGLTexture.h:57
#define SL_HDR_GL_FORMAT
Definition: SLGLTexture.h:52
#define SL_READ_PIXELS_GL_FORMAT
Definition: SLGLTexture.h:59
#define SL_HDR_GL_TYPE
Definition: SLGLTexture.h:53
#define SL_BRDF_LUT_PIXEL_BYTES
Definition: SLGLTexture.h:58
const SLint ROUGHNESS_NUM_MIP_LEVELS
OpenCV image class with the same interface as the former SLImage class.
Definition: CVImage.h:64
uchar * data()
Definition: CVImage.h:123
void savePNG(const string &filename, int compressionLevel=6, bool flipY=true, bool convertBGR2RGB=true)
Save as PNG at a certain compression level (0-9)
Definition: CVImage.cpp:637
Toplevel holder of the assets meshes, materials, textures and shaders.
SLVGLTexture & textures()
Generic Shader Program class inherited from SLGLProgram.
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
void useProgram()
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Singleton class holding all OpenGL states.
Definition: SLGLState.h:71
void viewport(SLint x, SLint y, SLsizei width, SLsizei height)
Definition: SLGLState.cpp:378
static SLGLState * instance()
Public static instance getter for singleton pattern.
Definition: SLGLState.h:74
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
SLbool _resizeToPow2
Flag if image should be resized to n^2.
Definition: SLGLTexture.h:321
void deleteImages()
Deletes the CVImages in _images. No more texture mapping in ray tracing.
SLint _bytesPerPixel
Bytes per texture image pixel (images exist either in _images or on the GPU or on both)
Definition: SLGLTexture.h:310
SLTextureType texType()
Definition: SLGLTexture.h:228
SLint _width
Texture image width in pixels (images exist either in _images or on the GPU or on both)
Definition: SLGLTexture.h:305
SLfloat _bumpScale
Bump mapping scale factor.
Definition: SLGLTexture.h:320
SLuint height()
Definition: SLGLTexture.h:219
SLuint _bytesOnGPU
NO. of bytes on GPU.
Definition: SLGLTexture.h:317
SLenum target() const
Definition: SLGLTexture.h:226
SLuint width()
Definition: SLGLTexture.h:218
SLint _wrap_t
Wrapping in t direction.
Definition: SLGLTexture.h:314
SLint _min_filter
Minification filter.
Definition: SLGLTexture.h:311
SLint _wrap_s
Wrapping in s direction.
Definition: SLGLTexture.h:313
SLbool _deleteImageAfterBuild
Flag if images should be deleted after build on GPU.
Definition: SLGLTexture.h:326
SLint _height
Texture image height in pixels (images exist either in _images or on the GPU or on both)
Definition: SLGLTexture.h:306
SLTextureType _texType
See SLTextureType.
Definition: SLGLTexture.h:304
void deleteData(SLbool deleteAlsoOnGPU)
Delete all data (CVImages and GPU textures)
CVVImage _images
Vector of CVImage pointers.
Definition: SLGLTexture.h:302
SLenum _target
texture target
Definition: SLGLTexture.h:315
SLstring typeName()
Returns the texture type as string.
std::atomic< bool > _needsUpdate
Flag if image needs an single update.
Definition: SLGLTexture.h:323
SLint _internalFormat
Internal OpenGL format.
Definition: SLGLTexture.h:309
void texType(SLTextureType bt)
Definition: SLGLTexture.h:200
SLuint texID() const
Definition: SLGLTexture.h:227
SLint _mag_filter
Magnification filter.
Definition: SLGLTexture.h:312
void bindActive(SLuint texUnit=0)
SLbool _autoCalcTM3D
Flag if texture matrix should be calculated from AABB for 3D mapping.
Definition: SLGLTexture.h:319
SLuint _texID
OpenGL texture ID.
Definition: SLGLTexture.h:303
SLGLProgram * _shaderProgram
Shader program to render the texture.
SLVMat4f _captureViews
All 6 positions of the views that represent the 6 sides of the cube map.
virtual ~SLGLTextureIBL()
SLGLTexture * _sourceTexture
2D Texture from the HDR Image
virtual void build(SLint texID=0)
void renderQuad()
Renders a 2x2 XY quad, used for rendering and capturing the BRDF integral.
SLMat4f _captureProjection
Projection matrix for capturing the textures.
SLGLTextureIBL()
Default constructor.
void logFramebufferStatus()
void renderCube()
Renders 2x2 cube, used to project a texture to a cube texture with 6 sides.
void readPixels(int width, int height, string name, bool savePNG)
Reads back the pixels into an image.
SLbool _readBackPixels
Flag if generated texture should be read back from GPU into cvMat.
void lookAt(T EyeX, T EyeY, T EyeZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
Defines the a view matrix as the corresponding gluLookAt function.
Definition: SLMat4.h:708
void m(int i, T val)
Definition: SLMat4.h:93
void perspective(T fov, T aspect, T n, T f)
Defines a perspective projection matrix with a field of view angle.
Definition: SLMat4.h:874
const SLstring & name() const
Definition: SLObject.h:38
T y
Definition: SLVec2.h:30
T x
Definition: SLVec2.h:30