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
@@ -58,9 +58,6 @@ int w_close(lua_State *L);
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);
+20
View File
@@ -109,6 +109,16 @@ bool Graphics::getConstant(Support in, const char *&out)
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 },
@@ -192,5 +202,15 @@ StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM>::Entry Graphics::suppor
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
+15
View File
@@ -109,6 +109,15 @@ public:
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);
@@ -135,6 +144,9 @@ public:
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[];
@@ -161,6 +173,9 @@ private:
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
+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);
+3 -5
View File
@@ -182,8 +182,7 @@ float Joystick::getAxis(int index, int axis)
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;
@@ -197,9 +196,8 @@ int Joystick::getAxes(lua_State *L)
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;
+14 -14
View File
@@ -50,43 +50,43 @@ int w_getJoystickCount(lua_State *L)
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;
}
@@ -103,15 +103,15 @@ int w_getBall(lua_State *L)
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 (int i = 1; i < num; i++)
buttonlist[counter++] = luaL_checkint(L, i + 1) - 1;
for (unsigned int i = 1; i < num; i++)
{
buttonlist[counter++] = (int) luaL_checknumber(L, i+1)-1;
}
buttonlist[counter] = -1;
luax_pushboolean(L, instance->isDown(index, buttonlist));
+1 -1
View File
@@ -111,7 +111,7 @@ public:
/**
* 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;