Commits

Alex Szpakowski committed 9be52f4

Replaced love.graphics.isSupported, love.graphics.hasCanvasFormat, and love.graphics.getSystemLimit with love.graphics.getSupported, love.graphics.getCanvasFormats, and love.graphics.getSystemLimits.

getSupported and getCanvasFormats return a table with the possible features/formats as keys and a boolean indicating support as values. getSystemLimits returns a table with the system limit types as keys and their numbers as values.

Removed the 'hdrcanvas' graphics feature enum because the 'hdr' Canvas format enum supersedes it.

Comments (0)

Files changed (6)

src/modules/graphics/Graphics.cpp

 
 StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM>::Entry Graphics::supportEntries[] =
 {
-	{ "hdrcanvas", Graphics::SUPPORT_HDR_CANVAS },
 	{ "multicanvas", Graphics::SUPPORT_MULTI_CANVAS },
 	{ "dxt", Graphics::SUPPORT_DXT },
 	{ "bc5", Graphics::SUPPORT_BC5 },

src/modules/graphics/Graphics.h

 
 	enum Support
 	{
-		SUPPORT_HDR_CANVAS,
 		SUPPORT_MULTI_CANVAS,
 		SUPPORT_DXT,
 		SUPPORT_BC5,

src/modules/graphics/opengl/Graphics.cpp

 	return limit;
 }
 
+bool Graphics::isSupported(Support feature) const
+{
+	switch (feature)
+	{
+	case Graphics::SUPPORT_MULTI_CANVAS:
+		return Canvas::isMultiCanvasSupported();
+	case Graphics::SUPPORT_DXT:
+		return Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5);
+	case SUPPORT_BC5:
+		return Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5);
+	case Graphics::SUPPORT_INSTANCING:
+		return GLEE_ARB_draw_instanced;
+	case Graphics::SUPPORT_SRGB:
+		return Canvas::isFormatSupported(Canvas::FORMAT_SRGB);
+	default:
+		return false;
+	}
+}
+
 void Graphics::push()
 {
 	if (userMatrices == matrixLimit)

src/modules/graphics/opengl/Graphics.h

 	 **/
 	double getSystemLimit(SystemLimit limittype) const;
 
+	/**
+	 * Gets whether a graphics feature is supported on this system.
+	 **/
+	bool isSupported(Support feature) const;
+
 	void push();
 	void pop();
 	void rotate(float r);

src/modules/graphics/opengl/wrap_Graphics.cpp

 	return 1;
 }
 
-int w_isSupported(lua_State *L)
+int w_getSupported(lua_State *L)
 {
-	bool supported = true;
-	size_t len = lua_gettop(L);
-	Graphics::Support support;
-	for (unsigned int i = 1; i <= len; i++)
+	lua_createtable(L, 0, (int) Graphics::SUPPORT_MAX_ENUM);
+
+	for (int i = 0; i < (int) Graphics::SUPPORT_MAX_ENUM; i++)
 	{
-		const char *str = luaL_checkstring(L, i);
-		if (!Graphics::getConstant(str, support))
-			return luaL_error(L, "Invalid graphics feature: %s", str);
+		Graphics::Support feature = (Graphics::Support) i;
+		const char *name = nullptr;
 
-		switch (support)
-		{
-		case Graphics::SUPPORT_HDR_CANVAS:
-			if (!Canvas::isFormatSupported(Canvas::FORMAT_HDR))
-				supported = false;
-			break;
-		case Graphics::SUPPORT_MULTI_CANVAS:
-			if (!Canvas::isMultiCanvasSupported())
-				supported = false;
-			break;
-		case Graphics::SUPPORT_DXT:
-			if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5))
-				supported = false;
-			break;
-		case Graphics::SUPPORT_BC5:
-			if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5))
-				supported = false;
-			break;
-		case Graphics::SUPPORT_INSTANCING:
-			if (!GLEE_ARB_draw_instanced)
-				supported = false;
-			break;
-		case Graphics::SUPPORT_SRGB:
-			if (!Canvas::isFormatSupported(Canvas::FORMAT_SRGB))
-				supported = false;
-			break;
-		default:
-			supported = false;
-		}
-		if (!supported)
-			break;
+		if (!Graphics::getConstant(feature, name))
+			continue;
+
+		luax_pushboolean(L, instance->isSupported(feature));
+		lua_setfield(L, -2, name);
 	}
-	lua_pushboolean(L, supported);
+
 	return 1;
 }
 
-int w_hasCanvasFormat(lua_State *L)
+int w_getCanvasFormats(lua_State *L)
 {
-	const char *str = luaL_checkstring(L, 1);
-	Canvas::Format format;
+	lua_createtable(L, 0, (int) Canvas::FORMAT_MAX_ENUM);
 
-	if (!Canvas::getConstant(str, format))
-		return luaL_error(L, "Invalid canvas format: %s", str);
+	for (int i = 0; i < (int) Canvas::FORMAT_MAX_ENUM; i++)
+	{
+		Canvas::Format format = (Canvas::Format) i;
+		const char *name = nullptr;
 
-	luax_pushboolean(L, Canvas::isFormatSupported(format));
+		if (!Canvas::getConstant(format, name))
+			continue;
+
+		luax_pushboolean(L, Canvas::isFormatSupported(format));
+		lua_setfield(L, -2, name);
+	}
+
 	return 1;
 }
 
 	return 4;
 }
 
-int w_getSystemLimit(lua_State *L)
+int w_getSystemLimits(lua_State *L)
 {
-	const char *limitstr = luaL_checkstring(L, 1);
-	Graphics::SystemLimit limittype;
+	lua_createtable(L, 0, Graphics::LIMIT_MAX_ENUM);
 
-	if (!Graphics::getConstant(limitstr, limittype))
-		return luaL_error(L, "Invalid system limit type: %s", limitstr);
+	for (int i = 0; i < (int) Graphics::LIMIT_MAX_ENUM; i++)
+	{
+		Graphics::SystemLimit limittype = (Graphics::SystemLimit) i;
+		const char *name = nullptr;
 
-	lua_pushnumber(L, instance->getSystemLimit(limittype));
+		if (!Graphics::getConstant(limittype, name))
+			continue;
+
+		lua_pushnumber(L, instance->getSystemLimit(limittype));
+		lua_setfield(L, -2, name);
+	}
+
 	return 1;
 }
 
 	{ "setShader", w_setShader },
 	{ "getShader", w_getShader },
 
-	{ "isSupported", w_isSupported },
-	{ "hasCanvasFormat", w_hasCanvasFormat },
+	{ "getSupported", w_getSupported },
+	{ "getCanvasFormats", w_getCanvasFormats },
+	{ "getSystemLimits", w_getSystemLimits },
 	{ "getRendererInfo", w_getRendererInfo },
-	{ "getSystemLimit", w_getSystemLimit },
 
 	{ "draw", w_draw },
 

src/modules/graphics/opengl/wrap_Graphics.h

 int w_getCanvas(lua_State *L);
 int w_setShader(lua_State *L);
 int w_getShader(lua_State *L);
-int w_isSupported(lua_State *L);
-int w_hasCanvasFormat(lua_State *L);
+int w_getSupported(lua_State *L);
+int w_getCanvasFormats(lua_State *L);
+int w_getSystemLimits(lua_State *L);
 int w_getRendererInfo(lua_State *L);
-int w_getSystemLimit(lua_State *L);
 int w_draw(lua_State *L);
 int w_print(lua_State *L);
 int w_printf(lua_State *L);