Browse Source

Add love.graphics.isSupported
Replaces love.graphics.hasPixelEffects and also does framebuffer support.

Also fixed 4 compiler warnings.

Bart van Strien 14 years ago
parent
commit
bd2b190a19

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

@@ -88,6 +88,16 @@ namespace graphics
 		return pointStyles.find(in, out);
 		return pointStyles.find(in, out);
 	}
 	}
 
 
+	bool Graphics::getConstant(const char * in, Support & out)
+	{
+		return support.find(in, out);
+	}
+
+	bool Graphics::getConstant(Support in, const char *& out)
+	{
+		return support.find(in, out);
+	}
+
 	StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
 	StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
 	{
 	{
 		{ "line", Graphics::DRAW_LINE },
 		{ "line", Graphics::DRAW_LINE },
@@ -139,5 +149,13 @@ namespace graphics
 
 
 	StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM> Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries));
 	StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM> Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries));
 
 
+	StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM>::Entry Graphics::supportEntries[] =
+	{
+		{ "framebuffers", Graphics::SUPPORT_FRAMEBUFFERS },
+		{ "pixeleffects", Graphics::SUPPORT_PIXELEFFECTS }
+	};
+
+	StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM> Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries));
+
 } // graphics
 } // graphics
 } // love
 } // love

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

@@ -78,6 +78,13 @@ namespace graphics
 			POINT_MAX_ENUM
 			POINT_MAX_ENUM
 		};
 		};
 
 
+		enum Support
+		{
+			SUPPORT_FRAMEBUFFERS = 1,
+			SUPPORT_PIXELEFFECTS,
+			SUPPORT_MAX_ENUM
+		};
+
 		virtual ~Graphics();
 		virtual ~Graphics();
 
 
 		static bool getConstant(const char * in, DrawMode & out);
 		static bool getConstant(const char * in, DrawMode & out);
@@ -98,6 +105,9 @@ namespace graphics
 		static bool getConstant(const char * in, PointStyle & out);
 		static bool getConstant(const char * in, PointStyle & out);
 		static bool getConstant(PointStyle in, const char *& out);
 		static bool getConstant(PointStyle in, const char *& out);
 
 
+		static bool getConstant(const char * in, Support & out);
+		static bool getConstant(Support in, const char *& out);
+
 	private:
 	private:
 
 
 		static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
 		static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
@@ -118,6 +128,9 @@ namespace graphics
 		static StringMap<PointStyle, POINT_MAX_ENUM>::Entry pointStyleEntries[];
 		static StringMap<PointStyle, POINT_MAX_ENUM>::Entry pointStyleEntries[];
 		static StringMap<PointStyle, POINT_MAX_ENUM> pointStyles;
 		static StringMap<PointStyle, POINT_MAX_ENUM> pointStyles;
 
 
+		static StringMap<Support, SUPPORT_MAX_ENUM>::Entry supportEntries[];
+		static StringMap<Support, SUPPORT_MAX_ENUM> support;
+
 	}; // Graphics
 	}; // Graphics
 
 
 } // graphics
 } // graphics

+ 13 - 0
src/modules/graphics/opengl/Framebuffer.cpp

@@ -183,6 +183,19 @@ namespace opengl
 		unloadVolatile();
 		unloadVolatile();
 	}
 	}
 
 
+	bool Framebuffer::isSupported()
+	{
+		if (!strategy) {
+			if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
+				strategy = &strategyGL3;
+			else if (GLEE_EXT_framebuffer_object)
+				strategy = &strategyEXT;
+			else
+				strategy = &strategyNone;
+		}
+		return (strategy != &strategyNone);
+	}
+
 	void Framebuffer::bindDefaultBuffer()
 	void Framebuffer::bindDefaultBuffer()
 	{
 	{
 		if (current != NULL)
 		if (current != NULL)

+ 2 - 0
src/modules/graphics/opengl/Framebuffer.h

@@ -22,6 +22,8 @@ namespace opengl
 		Framebuffer(int width, int height);
 		Framebuffer(int width, int height);
 		virtual ~Framebuffer();
 		virtual ~Framebuffer();
 
 
+		static bool isSupported();
+
 		unsigned int getStatus() const { return status; }
 		unsigned int getStatus() const { return status; }
 
 
 		static Framebuffer* current;
 		static Framebuffer* current;

+ 28 - 3
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -741,9 +741,33 @@ namespace opengl
 		return 0;
 		return 0;
 	}
 	}
 
 
-	int w_hasPixelEffects(lua_State * L)
+	int w_isSupported(lua_State * L)
 	{
 	{
-		lua_pushboolean(L, PixelEffect::isSupported());
+		bool supported = true;
+		size_t len = lua_gettop(L);
+		Graphics::Support support;
+		for (unsigned int i = 1; i <= len; i++)
+		{
+			const char * str = luaL_checkstring(L, i);
+			if(!Graphics::getConstant(str, support))
+				supported = false;
+			switch(support)
+			{
+				case Graphics::SUPPORT_FRAMEBUFFERS:
+					if (!Framebuffer::isSupported())
+						supported = false;
+					break;
+				case Graphics::SUPPORT_PIXELEFFECTS:
+					if (!PixelEffect::isSupported())
+						supported = false;
+					break;
+				default:
+					supported = false;
+			}
+			if (!supported)
+				break;
+		}
+		lua_pushboolean(L, supported);
 		return 1;
 		return 1;
 	}
 	}
 
 
@@ -1149,7 +1173,8 @@ namespace opengl
 		{ "setRenderTarget", w_setRenderTarget },
 		{ "setRenderTarget", w_setRenderTarget },
 
 
 		{ "setPixelEffect", w_setPixelEffect },
 		{ "setPixelEffect", w_setPixelEffect },
-		{ "hasPixelEffects", w_hasPixelEffects },
+
+		{ "isSupported", w_isSupported },
 
 
 		{ "draw", w_draw },
 		{ "draw", w_draw },
 		{ "drawq", w_drawq },
 		{ "drawq", w_drawq },

+ 1 - 1
src/modules/graphics/opengl/wrap_Graphics.h

@@ -89,7 +89,7 @@ namespace opengl
 	int w_newScreenshot(lua_State * L);
 	int w_newScreenshot(lua_State * L);
 	int w_setRenderTarget(lua_State * L);
 	int w_setRenderTarget(lua_State * L);
 	int w_setPixelEffect(lua_State * L);
 	int w_setPixelEffect(lua_State * L);
-	int w_hasPixelEffects(lua_State * L);
+	int w_isSupported(lua_State * L);
 	int w_getGLSLVersion(lua_State * L);
 	int w_getGLSLVersion(lua_State * L);
 	int w_draw(lua_State * L);
 	int w_draw(lua_State * L);
 	int w_drawq(lua_State * L);
 	int w_drawq(lua_State * L);

+ 4 - 4
src/modules/graphics/opengl/wrap_PixelEffect.cpp

@@ -31,8 +31,8 @@ namespace opengl
 			return luaL_error(L, "Invalid variable count (expected 1-4, got %d).", count);
 			return luaL_error(L, "Invalid variable count (expected 1-4, got %d).", count);
 
 
 		float values[4] = {0,0,0,0};
 		float values[4] = {0,0,0,0};
-		for (int i = 0; i < count; ++i)
-			values[i] = luaL_checknumber(L, i+1 + 2);
+		for (unsigned int i = 0; i < count; ++i)
+			values[i] = (float) luaL_checknumber(L, i+1 + 2);
 
 
 		try {
 		try {
 			effect->sendFloat(name, count, values);
 			effect->sendFloat(name, count, values);
@@ -54,8 +54,8 @@ namespace opengl
 			return luaL_error(L, "Invalid matrix size: %dx%d (only 2x2, 3x3 and 4x4 matrices are supported).", count, count);
 			return luaL_error(L, "Invalid matrix size: %dx%d (only 2x2, 3x3 and 4x4 matrices are supported).", count, count);
 
 
 		float values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 		float values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-		for (int i = 0; i < count; ++i)
-			values[i] = luaL_checknumber(L, i+1 + 3);
+		for (unsigned int i = 0; i < count; ++i)
+			values[i] = (float) luaL_checknumber(L, i+1 + 3);
 
 
 		try {
 		try {
 			effect->sendFloat(name, size, values);
 			effect->sendFloat(name, size, values);