From 325b89e02366150d29bfa46d8c40a0f1ed2334ac Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Thu, 4 Apr 2019 11:47:55 +0000 Subject: [PATCH] Fix automatic mipmap generation for Canvas textures When using glTexStorage2D, OSG doesn't allocate storage for the levels of the mipmap above the base unless an image is assigned to the texture. --- simgear/canvas/ODGauge.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/simgear/canvas/ODGauge.cxx b/simgear/canvas/ODGauge.cxx index f7e95c4d..12bb52d2 100644 --- a/simgear/canvas/ODGauge.cxx +++ b/simgear/canvas/ODGauge.cxx @@ -250,10 +250,16 @@ namespace canvas if( !texture ) { + // It shouldn't be necessary to allocate an image for the + // texture that is the target of dynamic rendering, but + // otherwise OSG won't construct all the mipmaps for the texture + // and dynamic mipmap generation doesn't work. + osg::Image* image = new osg::Image; + image->allocateImage(_size_x, _size_y, 1, GL_RGBA, GL_UNSIGNED_BYTE); texture = new osg::Texture2D; texture->setResizeNonPowerOfTwoHint(false); - texture->setTextureSize(_size_x, _size_y); - texture->setInternalFormat(GL_RGBA); + texture->setImage(image); + texture->setUnRefImageDataAfterApply(true); } updateSampling();