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"
This commit is contained in:
Alex Szpakowski
2013-05-05 16:47:42 -03:00
parent 08d6e658c1
commit 63404f7097
11 changed files with 112 additions and 32 deletions
+27 -1
View File
@@ -234,7 +234,6 @@ bool Graphics::toggleFullscreen()
return setMode(width, height, &flags);
}
void Graphics::reset()
{
DisplayState s;
@@ -1306,6 +1305,33 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
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)
+9 -4
View File
@@ -88,10 +88,7 @@ struct DisplayState
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;
@@ -527,6 +524,14 @@ public:
**/
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);
+1 -4
View File
@@ -171,10 +171,7 @@ int w_Canvas_clear(lua_State *L)
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))
{
@@ -1241,6 +1241,26 @@ int w_isSupported(lua_State *L)
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.
@@ -1645,6 +1665,7 @@ static const luaL_Reg functions[] =
{ "getShader", w_getShader },
{ "isSupported", w_isSupported },
{ "getRendererInfo", w_getRendererInfo },
{ "draw", w_draw },
{ "drawq", w_drawg }, // legacy
@@ -98,6 +98,7 @@ 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_getRendererInfo(lua_State *L);
int w_draw(lua_State *L);
int w_drawg(lua_State *L);
int w_print(lua_State *L);