Commits

Alex Szpakowski committed f9f9e1a

Added some comments describing the formats in the Canvas::Format enum.

Comments (0)

Files changed (2)

src/modules/graphics/opengl/Canvas.cpp

 }
 
 bool Canvas::supportedFormats[] = {false};
+bool Canvas::checkedFormats[] = {false};
 
 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)
 	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
 	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()

src/modules/graphics/opengl/Canvas.h

 	// 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
 	};
 
 	void drawv(const Matrix &t, const Vertex *v);
 
 	static bool supportedFormats[FORMAT_MAX_ENUM];
+	static bool checkedFormats[FORMAT_MAX_ENUM];
 
 	static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
 	static StringMap<Format, FORMAT_MAX_ENUM> formats;