Browse Source

Add support for falling back to glBlendEquationEXT if necessary.

This should help keep LÖVE from crashing on old cards with crappy drivers.
Bill Meltsner 13 years ago
parent
commit
57b4d2c5b9

+ 1 - 0
src/modules/graphics/Graphics.cpp

@@ -156,6 +156,7 @@ namespace graphics
 		{ "canvas", Graphics::SUPPORT_CANVAS },
 		{ "canvas", Graphics::SUPPORT_CANVAS },
 		{ "pixeleffect", Graphics::SUPPORT_PIXELEFFECT },
 		{ "pixeleffect", Graphics::SUPPORT_PIXELEFFECT },
 		{ "npot", Graphics::SUPPORT_NPOT },
 		{ "npot", Graphics::SUPPORT_NPOT },
+		{ "subtractive", Graphics::SUPPORT_SUBTRACTIVE },
 	};
 	};
 
 
 	StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM> Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries));
 	StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM> Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries));

+ 1 - 0
src/modules/graphics/Graphics.h

@@ -85,6 +85,7 @@ namespace graphics
 			SUPPORT_CANVAS = 1,
 			SUPPORT_CANVAS = 1,
 			SUPPORT_PIXELEFFECT,
 			SUPPORT_PIXELEFFECT,
 			SUPPORT_NPOT,
 			SUPPORT_NPOT,
+			SUPPORT_SUBTRACTIVE,
 			SUPPORT_MAX_ENUM
 			SUPPORT_MAX_ENUM
 		};
 		};
 
 

+ 18 - 4
src/modules/graphics/opengl/Graphics.cpp

@@ -511,10 +511,24 @@ namespace opengl
 	{
 	{
 		glAlphaFunc(GL_GEQUAL, 0);
 		glAlphaFunc(GL_GEQUAL, 0);
 
 
-		if (mode == BLEND_SUBTRACTIVE)
-			glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
-		else
-			glBlendEquation(GL_FUNC_ADD);
+		if (GLEE_VERSION_1_4 || GLEE_ARB_imaging) {
+			if (mode == BLEND_SUBTRACTIVE) {
+				glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
+			} else {
+				glBlendEquation(GL_FUNC_ADD);
+			}
+		} else if (GLEE_EXT_blend_minmax && GLEE_EXT_blend_subtract) {
+			if (mode == BLEND_SUBTRACTIVE) {
+				glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT);
+			} else {
+				glBlendEquationEXT(GL_FUNC_ADD_EXT);
+			}
+		} else {
+			if (mode == BLEND_SUBTRACTIVE) {
+				std::cerr << "This graphics card does not support the subtract blend mode!" << std::endl;
+			}
+			// GL_FUNC_ADD is the default even without access to glBlendEquation, so that'll still work.
+		}
 
 
 		if (mode == BLEND_ALPHA)
 		if (mode == BLEND_ALPHA)
 			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

+ 4 - 0
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -19,6 +19,7 @@
 **/
 **/
 
 
 #include "wrap_Graphics.h"
 #include "wrap_Graphics.h"
+#include "GLee.h"
 #include <graphics/DrawQable.h>
 #include <graphics/DrawQable.h>
 #include <image/ImageData.h>
 #include <image/ImageData.h>
 #include <font/Rasterizer.h>
 #include <font/Rasterizer.h>
@@ -793,6 +794,9 @@ namespace opengl
 					if (!Image::hasNpot())
 					if (!Image::hasNpot())
 						supported = false;
 						supported = false;
 					break;
 					break;
+				case Graphics::SUPPORT_SUBTRACTIVE:
+					supported = (GLEE_VERSION_1_4 || GLEE_ARB_imaging) || (GLEE_EXT_blend_minmax && GLEE_EXT_blend_subtract);
+					break;
 				default:
 				default:
 					supported = false;
 					supported = false;
 			}
 			}