mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Add love.graphics.isSupported
Replaces love.graphics.hasPixelEffects and also does framebuffer support. Also fixed 4 compiler warnings.
This commit is contained in:
@@ -88,6 +88,16 @@ namespace graphics
|
||||
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[] =
|
||||
{
|
||||
{ "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::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
|
||||
} // love
|
||||
|
||||
@@ -78,6 +78,13 @@ namespace graphics
|
||||
POINT_MAX_ENUM
|
||||
};
|
||||
|
||||
enum Support
|
||||
{
|
||||
SUPPORT_FRAMEBUFFERS = 1,
|
||||
SUPPORT_PIXELEFFECTS,
|
||||
SUPPORT_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Graphics();
|
||||
|
||||
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(PointStyle in, const char *& out);
|
||||
|
||||
static bool getConstant(const char * in, Support & out);
|
||||
static bool getConstant(Support in, const char *& out);
|
||||
|
||||
private:
|
||||
|
||||
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> pointStyles;
|
||||
|
||||
static StringMap<Support, SUPPORT_MAX_ENUM>::Entry supportEntries[];
|
||||
static StringMap<Support, SUPPORT_MAX_ENUM> support;
|
||||
|
||||
}; // Graphics
|
||||
|
||||
} // graphics
|
||||
|
||||
@@ -183,6 +183,19 @@ namespace opengl
|
||||
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()
|
||||
{
|
||||
if (current != NULL)
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace opengl
|
||||
Framebuffer(int width, int height);
|
||||
virtual ~Framebuffer();
|
||||
|
||||
static bool isSupported();
|
||||
|
||||
unsigned int getStatus() const { return status; }
|
||||
|
||||
static Framebuffer* current;
|
||||
|
||||
@@ -741,9 +741,33 @@ namespace opengl
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1149,7 +1173,8 @@ namespace opengl
|
||||
{ "setRenderTarget", w_setRenderTarget },
|
||||
|
||||
{ "setPixelEffect", w_setPixelEffect },
|
||||
{ "hasPixelEffects", w_hasPixelEffects },
|
||||
|
||||
{ "isSupported", w_isSupported },
|
||||
|
||||
{ "draw", w_draw },
|
||||
{ "drawq", w_drawq },
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace opengl
|
||||
int w_newScreenshot(lua_State * L);
|
||||
int w_setRenderTarget(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_draw(lua_State * L);
|
||||
int w_drawq(lua_State * L);
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace opengl
|
||||
return luaL_error(L, "Invalid variable count (expected 1-4, got %d).", count);
|
||||
|
||||
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 {
|
||||
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);
|
||||
|
||||
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 {
|
||||
effect->sendFloat(name, size, values);
|
||||
|
||||
Reference in New Issue
Block a user