Commits

Alex Szpakowski committed a6e8b92

Added love.graphics.getRendererInfo(infotype). Useful for creating more informative error reports and advanced debugging.
Returned string can be highly system-dependent, so don't rely on its output!

infotype can be "name", "version", "vendor", or "device"

  • Participants
  • Parent commits 8a9e57c

Comments (0)

Files changed (11)

src/modules/filesystem/physfs/wrap_Filesystem.h

 int w_read(lua_State *L);
 int w_write(lua_State *L);
 int w_append(lua_State *L);
-int w_eof(lua_State *L);
-int w_tell(lua_State *L);
-int w_seek(lua_State *L);
 int w_enumerate(lua_State *L);
 int w_lines(lua_State *L);
 int w_load(lua_State *L);

src/modules/graphics/Graphics.cpp

 	return support.find(in, out);
 }
 
+bool Graphics::getConstant(const char *in, RendererInfo &out)
+{
+	return rendererInfo.find(in, out);
+}
+
+bool Graphics::getConstant(RendererInfo in, const char *&out)
+{
+	return rendererInfo.find(in, out);
+}
+
 StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
 {
 	{ "line", Graphics::DRAW_LINE },
 
 StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM> Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries));
 
+StringMap<Graphics::RendererInfo, Graphics::RENDERER_INFO_MAX_ENUM>::Entry Graphics::rendererInfoEntries[] =
+{
+	{ "name", Graphics::RENDERER_INFO_NAME },
+	{ "version", Graphics::RENDERER_INFO_VERSION },
+	{ "vendor", Graphics::RENDERER_INFO_VENDOR },
+	{ "device", Graphics::RENDERER_INFO_DEVICE },
+};
+
+StringMap<Graphics::RendererInfo, Graphics::RENDERER_INFO_MAX_ENUM> Graphics::rendererInfo(Graphics::rendererInfoEntries, sizeof(Graphics::rendererInfoEntries));
+
 } // graphics
 } // love

src/modules/graphics/Graphics.h

 		SUPPORT_MAX_ENUM
 	};
 
+	enum RendererInfo
+	{
+		RENDERER_INFO_NAME = 1,
+		RENDERER_INFO_VERSION,
+		RENDERER_INFO_VENDOR,
+		RENDERER_INFO_DEVICE,
+		RENDERER_INFO_MAX_ENUM
+	};
+
 	virtual ~Graphics();
 
 	static bool getConstant(const char *in, DrawMode &out);
 	static bool getConstant(const char *in, Support &out);
 	static bool getConstant(Support in, const char  *&out);
 
+	static bool getConstant(const char *in, RendererInfo &out);
+	static bool getConstant(RendererInfo in, const char *&out);
+
 private:
 
 	static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
 	static StringMap<Support, SUPPORT_MAX_ENUM>::Entry supportEntries[];
 	static StringMap<Support, SUPPORT_MAX_ENUM> support;
 
+	static StringMap<RendererInfo, RENDERER_INFO_MAX_ENUM>::Entry rendererInfoEntries[];
+	static StringMap<RendererInfo, RENDERER_INFO_MAX_ENUM> rendererInfo;
+
 }; // Graphics
 
 } // graphics

src/modules/graphics/opengl/Graphics.cpp

 	return setMode(width, height, &flags);
 }
 
-
 void Graphics::reset()
 {
 	DisplayState s;
 	return img;
 }
 
+std::string Graphics::getRendererInfo(Graphics::RendererInfo infotype) const
+{
+	const char *infostr = 0;
+
+	switch (infotype)
+	{
+	case Graphics::RENDERER_INFO_NAME:
+	default:
+		infostr = "OpenGL";
+		break;
+	case Graphics::RENDERER_INFO_VERSION:
+		infostr = (const char *) glGetString(GL_VERSION);
+		break;
+	case Graphics::RENDERER_INFO_VENDOR:
+		infostr = (const char *) glGetString(GL_VENDOR);
+		break;
+	case Graphics::RENDERER_INFO_DEVICE:
+		infostr = (const char *) glGetString(GL_RENDERER);
+		break;
+	}
+
+	if (!infostr)
+		throw love::Exception("Cannot retrieve renderer information.");
+
+	return std::string(infostr);
+}
+
 void Graphics::push()
 {
 	if (userMatrices == matrixLimit)

src/modules/graphics/opengl/Graphics.h

 	DisplayState()
 	{
 		color.set(255,255,255,255);
-		backgroundColor.r = 0;
-		backgroundColor.g = 0;
-		backgroundColor.b = 0;
-		backgroundColor.a = 255;
+		backgroundColor.set(0, 0, 0, 255);
 		blendMode = Graphics::BLEND_ALPHA;
 		lineStyle = Graphics::LINE_SMOOTH;
 		pointSize = 1.0f;
 	 **/
 	love::image::ImageData *newScreenshot(love::image::Image *image, bool copyAlpha = true);
 
+	/**
+	 * Returns a string containing system-dependent renderer information.
+	 * Returned string can vary greatly between systems! Do not rely on it for
+	 * anything!
+	 * @param infotype The type of information to return.
+	 **/
+	std::string getRendererInfo(Graphics::RendererInfo infotype) const;
+
 	void push();
 	void pop();
 	void rotate(float r);

src/modules/graphics/opengl/wrap_Canvas.cpp

 	Color c;
 	if (lua_isnoneornil(L, 2))
 	{
-		c.r = 0;
-		c.g = 0;
-		c.b = 0;
-		c.a = 0;
+		c.set(0, 0, 0, 0);
 	}
 	else if (lua_istable(L, 2))
 	{

src/modules/graphics/opengl/wrap_Graphics.cpp

 	return 1;
 }
 
+int w_getRendererInfo(lua_State *L)
+{
+	const char *str = luaL_checkstring(L, 1);
+	Graphics::RendererInfo infotype;
+
+	if (!Graphics::getConstant(str, infotype))
+		return luaL_error(L, "Invalid renderer info type: %s", str);
+
+	try
+	{
+		luax_pushstring(L, instance->getRendererInfo(infotype));
+	}
+	catch (love::Exception &e)
+	{
+		return luaL_error(L, "%s", e.what());
+	}
+	
+	return 1;
+}
+
 /**
  * Draws an Image at the specified coordinates, with rotation and
  * scaling along both axes.
 	{ "getShader", w_getShader },
 
 	{ "isSupported", w_isSupported },
+	{ "getRendererInfo", w_getRendererInfo },
 
 	{ "draw", w_draw },
 	{ "drawq", w_drawg }, // legacy

src/modules/graphics/opengl/wrap_Graphics.h

 int w_setShader(lua_State *L);
 int w_getShader(lua_State *L);
 int w_isSupported(lua_State *L);
+int w_getRendererInfo(lua_State *L);
 int w_draw(lua_State *L);
 int w_drawg(lua_State *L);
 int w_print(lua_State *L);

src/modules/joystick/sdl/Joystick.cpp

 
 int Joystick::getAxes(lua_State *L)
 {
-	love::luax_assert_argc(L, 1, 1);
-	int index = (int)lua_tointeger(L, 1) - 1;
+	int index = luaL_checkint(L, 1) - 1;
 
 	if (!verifyJoystick(index))
 		return 0;
 
 int Joystick::getBall(lua_State *L)
 {
-	love::luax_assert_argc(L, 2, 2);
-	int index = (int)lua_tointeger(L, 1) - 1;
-	int ball = (int)lua_tointeger(L, 2) - 1;
+	int index = luaL_checkint(L, 1) - 1;
+	int ball = luaL_checkint(L, 2) - 1;
 
 	if (!verifyJoystick(index))
 		return 0;

src/modules/joystick/sdl/wrap_Joystick.cpp

 
 int w_getName(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
+	int index = luaL_checkint(L, 1) - 1;
 	lua_pushstring(L, instance->getName(index));
 	return 1;
 }
 
 int w_getAxisCount(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
+	int index = luaL_checkint(L, 1) - 1;
 	lua_pushinteger(L, instance->getAxisCount(index));
 	return 1;
 }
 
 int w_getBallCount(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
+	int index = luaL_checkint(L, 1) - 1;
 	lua_pushinteger(L, instance->getBallCount(index));
 	return 1;
 }
 
 int w_getButtonCount(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
+	int index = luaL_checkint(L, 1) - 1;
 	lua_pushinteger(L, instance->getButtonCount(index));
 	return 1;
 }
 
 int w_getHatCount(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
+	int index = luaL_checkint(L, 1) - 1;
 	lua_pushinteger(L, instance->getHatCount(index));
 	return 1;
 }
 
 int w_getAxis(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
-	int axis = luaL_checkint(L, 2)-1;
+	int index = luaL_checkint(L, 1) - 1;
+	int axis = luaL_checkint(L, 2) - 1;
 	lua_pushnumber(L, instance->getAxis(index, axis));
 	return 1;
 }
 
 int w_isDown(lua_State *L)
 {
-	int index = luaL_checkint(L, 1)-1;
-	unsigned int num = lua_gettop(L);
+	int index = luaL_checkint(L, 1) - 1;
+	int num = lua_gettop(L);
+	
 	int *buttonlist = new int[num];
-	unsigned int counter = 0;
+	int counter = 0;
 
-	for (unsigned int i = 1; i < num; i++)
-	{
-		buttonlist[counter++] = (int) luaL_checknumber(L, i+1)-1;
-	}
+	for (int i = 1; i < num; i++)
+		buttonlist[counter++] = luaL_checkint(L, i + 1) - 1;
+
 	buttonlist[counter] = -1;
 
 	luax_pushboolean(L, instance->isDown(index, buttonlist));

src/modules/math/MathModule.h

 	/**
 	 * Calculate Simplex noise for the specified coordinate(s).
 	 *
-	 * @return Noise value in the range of [0,1].
+	 * @return Noise value in the range of [-1,1].
 	 **/
 	float noise(float x) const;
 	float noise(float x, float y) const;