Skip to content

Commit

Permalink
VIDEO: reset more potential invalid gl states after deleting objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed May 17, 2020
1 parent 1a38c65 commit ad5805b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/modules/video/gl/GLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,13 @@ void deleteBuffers(uint8_t amount, Id* ids) {
if (amount == 0) {
return;
}
for (uint8_t i = 0u; i < amount; ++i) {
for (int j = 0; j < lengthof(_priv::s.bufferHandle); ++j) {
if (_priv::s.bufferHandle[j] == ids[i]) {
_priv::s.bufferHandle[j] = InvalidId;
}
}
}
static_assert(sizeof(Id) == sizeof(GLuint), "Unexpected sizes");
glDeleteBuffers((GLsizei)amount, (GLuint*)ids);
checkError();
Expand Down Expand Up @@ -815,6 +822,12 @@ void deleteTextures(uint8_t amount, Id* ids) {
glDeleteTextures((GLsizei)amount, (GLuint*)ids);
checkError();
for (int i = 0; i < amount; ++i) {
for (int j = 0; j < lengthof(_priv::s.textureHandle); ++j) {
if (_priv::s.textureHandle[j] == ids[i]) {
// the texture might still be bound...
_priv::s.textureHandle[j] = InvalidId;
}
}
ids[i] = InvalidId;
}
}
Expand Down Expand Up @@ -852,13 +865,16 @@ void deleteFramebuffers(uint8_t amount, Id* ids) {
if (amount == 0) {
return;
}
for (int i = 0; i < amount; ++i) {
if (ids[i] == _priv::s.framebufferHandle) {
bindFramebuffer(InvalidId);
}
ids[i] = InvalidId;
}
static_assert(sizeof(Id) == sizeof(GLuint), "Unexpected sizes");
glDeleteFramebuffers((GLsizei)amount, (const GLuint*)ids);
checkError();
for (int i = 0; i < amount; ++i) {
if (ids[i] == _priv::s.framebufferHandle) {
_priv::s.framebufferHandle = InvalidId;
}
ids[i] = InvalidId;
}
}
Expand All @@ -873,6 +889,11 @@ void deleteRenderbuffers(uint8_t amount, Id* ids) {
if (amount == 0) {
return;
}
for (uint8_t i = 0u; i < amount; ++i) {
if (_priv::s.renderBufferHandle == ids[i]) {
bindRenderbuffer(InvalidId);
}
}
static_assert(sizeof(Id) == sizeof(GLuint), "Unexpected sizes");
glDeleteRenderbuffers((GLsizei)amount, (GLuint*)ids);
checkError();
Expand Down
1 change: 1 addition & 0 deletions src/tools/voxedit/ui/editorscene/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void Viewport::onResized(int oldw, int oldh) {
const glm::ivec2 windowSize(int(frameBufferSize.x / scaleFactor + 0.5f), int(frameBufferSize.y / scaleFactor + 0.5f));
_controller.onResize(frameBufferSize, windowSize);
_frameBuffer.shutdown();
_frameBufferTexture.shutdown();
video::FrameBufferConfig cfg;
cfg.dimension(frameBufferSize).depthBuffer(true).colorTexture(true);
_frameBuffer.init(cfg);
Expand Down

0 comments on commit ad5805b

Please sign in to comment.