diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 19bc6d3e9..a7a3b3ab0 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1693,6 +1693,17 @@ void Graphics::initCapabilities() pixelFormatUsage[i][0] = computePixelFormatUsage(format, false); pixelFormatUsage[i][1] = computePixelFormatUsage(format, true); } + +#ifdef LOVE_ANDROID + // This can't be done in initContext with the rest of the bug checks because + // isPixelFormatSupported relies on state initialized here / after init. + if (GLAD_ES_VERSION_3_0 && !isPixelFormatSupported(PIXELFORMAT_R8_UNORM, PIXELFORMATUSAGEFLAGS_SAMPLE | PIXELFORMATUSAGEFLAGS_RENDERTARGET)) + { + gl.bugs.brokenR8PixelFormat = true; + pixelFormatUsage[PIXELFORMAT_R8_UNORM][0] = computePixelFormatUsage(PIXELFORMAT_R8_UNORM, false); + pixelFormatUsage[PIXELFORMAT_R8_UNORM][1] = computePixelFormatUsage(PIXELFORMAT_R8_UNORM, true); + } +#endif } uint32 Graphics::computePixelFormatUsage(PixelFormat format, bool readable) diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 845030f8d..9d3a486d4 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -324,14 +324,6 @@ void OpenGL::setupContext() setColorWriteMask(state.colorWriteMask); contextInitialized = true; - -#ifdef LOVE_ANDROID - // This can't be done in initContext with the rest of the bug checks because - // isPixelFormatSupported relies on state initialized here / after init. - auto gfx = Module::getInstance(Module::M_GRAPHICS); - if (GLAD_ES_VERSION_3_0 && gfx != nullptr && !gfx->isPixelFormatSupported(PIXELFORMAT_R8_UNORM, PIXELFORMATUSAGEFLAGS_SAMPLE | PIXELFORMATUSAGEFLAGS_RENDERTARGET)) - bugs.brokenR8PixelFormat = true; -#endif } void OpenGL::deInitContext() @@ -1344,7 +1336,17 @@ bool OpenGL::rawTexStorage(TextureType target, int levels, PixelFormat pixelform glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_A, fmt.swizzle[3]); } - if (isTexStorageSupported()) + bool usetexstorage = isTexStorageSupported(); + + // The fallback for bugs.brokenR8PixelFormat is GL_LUMINANCE, which doesn't have a sized + // version in ES3 so it can't be used with glTexStorage. + if (pixelformat == PIXELFORMAT_R8_UNORM && bugs.brokenR8PixelFormat && GLAD_ES_VERSION_3_0) + { + usetexstorage = false; + fmt.internalformat = fmt.externalformat; + } + + if (usetexstorage) { if (target == TEXTURE_2D || target == TEXTURE_CUBE) glTexStorage2D(gltarget, levels, fmt.internalformat, width, height);