Skip to content

Commit

Permalink
GL context needed in Image when deleting GL texture. This may not alw…
Browse files Browse the repository at this point in the history
…ays be the case. Added some checks, and allowed renderer to delete it instead.
  • Loading branch information
smistad committed Aug 15, 2023
1 parent 26dc411 commit 829e385
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion source/FAST/Data/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,12 @@ void Image::freeAll() {
this->free(Host::getInstance());
}
if(m_GLtextureID > 0) {
glDeleteTextures(1, &m_GLtextureID);
// We have to have current GL context to delete it
if(QGLContext::currentContext() == nullptr) {
reportWarning() << "Unable to delete texture because no OpenGL context was current" << reportEnd();
} else {
glDeleteTextures(1, &m_GLtextureID);
}
m_GLtextureID = 0;
m_GLtextureUpToDate = false;
}
Expand Down
4 changes: 2 additions & 2 deletions source/FAST/Visualization/ImageRenderer/ImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ImageRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, flo
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
//if(w != input->getWidth() && h != input->getHeight()) {
// Remove old texture
//glDeleteTextures(1, &mTexturesToRender[inputNr]); // We cannot delete the texture, because it belongs to the Image object.
glDeleteTextures(1, &mTexturesToRender[inputNr]);
mTexturesToRender.erase(inputNr);
glDeleteVertexArrays(1, &mVAO[inputNr]);
mVAO.erase(inputNr);
Expand All @@ -117,7 +117,7 @@ void ImageRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, flo
//}
}

auto access = input->getOpenGLTextureAccess(ACCESS_READ, device);
auto access = input->getOpenGLTextureAccess(ACCESS_READ, device, false, true);
auto textureID = access->get();

mTexturesToRender[inputNr] = textureID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void SegmentationRenderer::drawNormal(std::unordered_map<uint, std::shared_ptr<S
// If texture exists, delete the old one
if(mTexturesToRender.count(inputNr) > 0) {
// Delete old texture
//glDeleteTextures(1, &mTexturesToRender[inputNr]); // We cannot delete the texture, because it belongs to the Image object.
glDeleteTextures(1, &mTexturesToRender[inputNr]);
mTexturesToRender.erase(inputNr);
glDeleteVertexArrays(1, &mVAO[inputNr]);
mVAO.erase(inputNr);
Expand All @@ -105,7 +105,7 @@ void SegmentationRenderer::drawNormal(std::unordered_map<uint, std::shared_ptr<S
mEBO.erase(inputNr);
}

auto access = input->getOpenGLTextureAccess(ACCESS_READ, device);
auto access = input->getOpenGLTextureAccess(ACCESS_READ, device, false, true);
auto textureID = access->get();
mTexturesToRender[inputNr] = textureID;
mImageUsed[inputNr] = input;
Expand Down

0 comments on commit 829e385

Please sign in to comment.