From 59ac6d3971dcec30fcbe5283fc3cdb45e5d27dcf Mon Sep 17 00:00:00 2001 From: Ruslan Kabatsayev Date: Fri, 7 Apr 2023 00:47:37 +0400 Subject: [PATCH] Generate mipmap pyramid manually for GL_RGB textures if glGenerateMipmap() fails This failure can happen in GLES2 mode when GL_SRGB8 is not color renderable. --- src/core/StelTexture.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/StelTexture.cpp b/src/core/StelTexture.cpp index 8a5085411b874..a7b940543f592 100644 --- a/src/core/StelTexture.cpp +++ b/src/core/StelTexture.cpp @@ -432,7 +432,25 @@ bool StelTexture::glLoad(const GLData& data) { glSize = glSize + glSize/3; //mipmaps require 1/3 more mem } + + StelOpenGL::checkGLErrors(__FILE__, __LINE__); gl->glGenerateMipmap(GL_TEXTURE_2D); + + const bool manualMipmapGeneration = gl->glGetError() != GL_NO_ERROR; + if(manualMipmapGeneration && data.format==GL_RGB) + { + // Formula from the glspec, "Mipmapping" subsection in section 3.8.11 Texture Minification + const int totalMipmapLevels = 1+std::floor(std::log2(std::max(width,height))); + qDebug().nospace() << "Making a mipmap pyramid for a " << width << "×" << height << " RGB texture"; + QImage img(reinterpret_cast(data.data.constData()), width, height, QImage::Format_RGB888); + for(int level=1; levelglTexImage2D(GL_TEXTURE_2D, level, internalFormat, img.width(), img.height(), 0, + static_cast(data.format), static_cast(data.type), img.bits()); + } + } } //register ID with textureMgr and increment size