mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
Renderer GL: Don't leak shader/UBO handles
This commit is contained in:
parent
5c40fb0cbf
commit
f219432c6a
2 changed files with 15 additions and 9 deletions
|
@ -117,6 +117,7 @@ class RendererGL final : public Renderer {
|
||||||
// Note: The caller is responsible for deleting the currently bound FBO before calling this
|
// Note: The caller is responsible for deleting the currently bound FBO before calling this
|
||||||
void setFBO(uint handle) { screenFramebuffer.m_handle = handle; }
|
void setFBO(uint handle) { screenFramebuffer.m_handle = handle; }
|
||||||
void resetStateManager() { gl.reset(); }
|
void resetStateManager() { gl.reset(); }
|
||||||
|
void clearShaderCache();
|
||||||
void initUbershader(OpenGL::Program& program);
|
void initUbershader(OpenGL::Program& program);
|
||||||
|
|
||||||
#ifdef PANDA3DS_FRONTEND_QT
|
#ifdef PANDA3DS_FRONTEND_QT
|
||||||
|
|
|
@ -24,10 +24,7 @@ void RendererGL::reset() {
|
||||||
colourBufferCache.reset();
|
colourBufferCache.reset();
|
||||||
textureCache.reset();
|
textureCache.reset();
|
||||||
|
|
||||||
for (auto& shader : shaderCache) {
|
clearShaderCache();
|
||||||
shader.second.program.free();
|
|
||||||
}
|
|
||||||
shaderCache.clear();
|
|
||||||
|
|
||||||
// Init the colour/depth buffer settings to some random defaults on reset
|
// Init the colour/depth buffer settings to some random defaults on reset
|
||||||
colourBufferLoc = 0;
|
colourBufferLoc = 0;
|
||||||
|
@ -808,6 +805,8 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
program.create({defaultShadergenVs, fragShader});
|
program.create({defaultShadergenVs, fragShader});
|
||||||
gl.useProgram(program);
|
gl.useProgram(program);
|
||||||
|
|
||||||
|
fragShader.free();
|
||||||
|
|
||||||
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
|
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
|
||||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex0"), 0);
|
glUniform1i(OpenGL::uniformLocation(program, "u_tex0"), 0);
|
||||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex1"), 1);
|
glUniform1i(OpenGL::uniformLocation(program, "u_tex1"), 1);
|
||||||
|
@ -937,16 +936,22 @@ void RendererGL::screenshot(const std::string& name) {
|
||||||
stbi_write_png(name.c_str(), width, height, 4, flippedPixels.data(), 0);
|
stbi_write_png(name.c_str(), width, height, 4, flippedPixels.data(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RendererGL::clearShaderCache() {
|
||||||
|
for (auto& shader : shaderCache) {
|
||||||
|
CachedProgram& cachedProgram = shader.second;
|
||||||
|
cachedProgram.program.free();
|
||||||
|
glDeleteBuffers(1, &cachedProgram.uboBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
shaderCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void RendererGL::deinitGraphicsContext() {
|
void RendererGL::deinitGraphicsContext() {
|
||||||
// Invalidate all surface caches since they'll no longer be valid
|
// Invalidate all surface caches since they'll no longer be valid
|
||||||
textureCache.reset();
|
textureCache.reset();
|
||||||
depthBufferCache.reset();
|
depthBufferCache.reset();
|
||||||
colourBufferCache.reset();
|
colourBufferCache.reset();
|
||||||
|
clearShaderCache();
|
||||||
for (auto& shader : shaderCache) {
|
|
||||||
shader.second.program.free();
|
|
||||||
}
|
|
||||||
shaderCache.clear();
|
|
||||||
|
|
||||||
// All other GL objects should be invalidated automatically and be recreated by the next call to initGraphicsContext
|
// All other GL objects should be invalidated automatically and be recreated by the next call to initGraphicsContext
|
||||||
// TODO: Make it so that depth and colour buffers get written back to 3DS memory
|
// TODO: Make it so that depth and colour buffers get written back to 3DS memory
|
||||||
|
|
Loading…
Add table
Reference in a new issue