diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 3b060dc7f..72b932e7b 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -1044,6 +1044,7 @@ bool Canvas::isMultiCanvasSupported() } bool Canvas::supportedFormats[] = {false}; +bool Canvas::checkedFormats[] = {false}; bool Canvas::isFormatSupported(Canvas::Format format) { @@ -1065,12 +1066,11 @@ bool Canvas::isFormatSupported(Canvas::Format format) supported = GLEE_VERSION_4_2 || GLEE_ARB_ES2_compatibility; break; case FORMAT_RG11B10F: - supported = GLEE_VERSION_3_0 || (GLEE_ARB_texture_float && GLEE_ARB_color_buffer_float - && GLEE_EXT_packed_float); + supported = GLEE_VERSION_3_0 || (GLEE_ARB_texture_float && GLEE_EXT_packed_float); break; case FORMAT_RGBA16F: case FORMAT_RGBA32F: - supported = GLEE_VERSION_3_0 || (GLEE_ARB_texture_float && GLEE_ARB_color_buffer_float); + supported = GLEE_VERSION_3_0 || GLEE_ARB_texture_float; break; case FORMAT_SRGB: supported = GLEE_VERSION_3_0 || ((GLEE_ARB_framebuffer_sRGB || GLEE_EXT_framebuffer_sRGB) @@ -1084,8 +1084,8 @@ bool Canvas::isFormatSupported(Canvas::Format format) if (!supported) return false; - if (supportedFormats[format]) - return true; + if (checkedFormats[format]) + return supportedFormats[format]; // Even though we might have the necessary OpenGL version or extension, // drivers are still allowed to throw FRAMEBUFFER_UNSUPPORTED when attaching @@ -1111,16 +1111,16 @@ bool Canvas::isFormatSupported(Canvas::Format format) glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 2, 2, 0, externalformat, textype, nullptr); GLuint fbo = 0; - GLenum status = strategy->createFBO(fbo, texture); + supported = (strategy->createFBO(fbo, texture) == GL_FRAMEBUFFER_COMPLETE); strategy->deleteFBO(fbo, 0, 0); gl.deleteTexture(texture); // Cache the result so we don't do this for every isFormatSupported call. - if (status == GL_FRAMEBUFFER_COMPLETE) - supportedFormats[format] = true; + checkedFormats[format] = true; + supportedFormats[format] = supported; - return status == GL_FRAMEBUFFER_COMPLETE; + return supported; } void Canvas::bindDefaultCanvas() diff --git a/src/modules/graphics/opengl/Canvas.h b/src/modules/graphics/opengl/Canvas.h index 41cf0ad40..3e2a623d2 100644 --- a/src/modules/graphics/opengl/Canvas.h +++ b/src/modules/graphics/opengl/Canvas.h @@ -43,17 +43,17 @@ public: // Different Canvas render target formats. enum Format { - FORMAT_NORMAL, - FORMAT_HDR, - FORMAT_RGBA8, - FORMAT_RGBA4, - FORMAT_RGB5A1, - FORMAT_RGB565, - FORMAT_RGB10A2, - FORMAT_RG11B10F, - FORMAT_RGBA16F, - FORMAT_RGBA32F, - FORMAT_SRGB, + FORMAT_NORMAL, // Usually RGBA8 or a similar fallback. Always supported. + FORMAT_HDR, // Usually RGBA16F. Not always supported. + FORMAT_RGBA8, // RGBA with 8 bits per component. + FORMAT_RGBA4, // RGBA with 4 bits per component. + FORMAT_RGB5A1, // RGB with 5 bits per component, and A with 1 bit. + FORMAT_RGB565, // RGB with 5, 6, and 5 bits each, respectively. + FORMAT_RGB10A2, // RGB with 10 bits each, and A with 2 bits. + FORMAT_RG11B10F, // Floating point [0, +inf]. RG with 11 FP bits each, and B with 10 FP bits. + FORMAT_RGBA16F, // Floating point [-inf, +inf]. RGBA with 16 FP bits per component. + FORMAT_RGBA32F, // Floating point [-inf, +inf]. RGBA with 32 FP bits per component. + FORMAT_SRGB, // sRGB with 8 bits per component, plus 8 bit linear A. FORMAT_MAX_ENUM }; @@ -158,6 +158,7 @@ private: void drawv(const Matrix &t, const Vertex *v); static bool supportedFormats[FORMAT_MAX_ENUM]; + static bool checkedFormats[FORMAT_MAX_ENUM]; static StringMap::Entry formatEntries[]; static StringMap formats;