Apress / ray-tracing-gems

Source Code for "Ray Tracing Gems: High-Quality and Real-Time Rendering with DXR and Other APIs" by Eric Haines and Tomas Akenine-Möller

Home Page:https://www.apress.com/us/book/9781484244265

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GL Texture memory leak in Chapter 28: Ray Tracing Inhomogeneous Volumes

mmmovania opened this issue · comments

There is a potential GL texture memory leak in the code. It generates a new texture object each frame (line 459-462).

Solution:
Two additions in the code should do it :)

  1. Add the following code after line 431
kernel_params.iteration = 0;

//allocate texture once
glBindTexture(GL_TEXTURE_2D, display_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
  1. Replace glTexImage2D and parameter setting calls (lines 459-462) with the following glTexSubImage2D call,
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, NULL);

Thanks! I am checking with the author.

Reply from Matthias Raab:

... as far as I see the proposed fixes are definitely cleaner and should be applied.

(I don't think it's an actual memory leak, but there's a chance that drivers don't handle that too efficiently)


So, I've applied your solution - thanks for pointing it out.