changed PixelEffect name to ShaderEffect, added lua-side support for vert/frag shader combinations with love.graphics.newShaderEffect, added tentative support for single-file vertex+fragment shaders

This commit is contained in:
Alexander Szpakowski
2012-12-20 21:51:31 -04:00
parent 28e3b105e9
commit 0611234067
18 changed files with 434 additions and 233 deletions
+31 -22
View File
@@ -433,29 +433,38 @@ int w_newCanvas(lua_State *L)
return 1;
}
int w_newPixelEffect(lua_State *L)
int w_newShaderEffect(lua_State *L)
{
if (!PixelEffect::isSupported())
if (!ShaderEffect::isSupported())
return luaL_error(L, "Sorry, your graphics card does not support pixel effects.");
try
{
luaL_checkstring(L, 1);
// clamp stack to 2 elements
lua_settop(L, 2);
luax_getfunction(L, "graphics", "_effectCodeToGLSL");
// push vertcode and fragcode strings to the top of the stack so they become arguments for the function
lua_pushvalue(L, 1);
lua_pcall(L, 1, 1, 0);
const char *code = lua_tostring(L, -1);
PixelEffect *effect = instance->newPixelEffect(code);
luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void *)effect);
lua_pushvalue(L, 2);
// call effectCodeToGLSL
lua_pcall(L, 2, 2, 0);
// get returned values from the top of the stack
const char *vertcode = luaL_optstring(L, -2, "");
const char *fragcode = luaL_optstring(L, -1, "");
ShaderEffect *effect = instance->newShaderEffect(vertcode, fragcode);
luax_newtype(L, "ShaderEffect", GRAPHICS_SHADEREFFECT_T, (void *)effect);
}
catch(const love::Exception &e)
{
// memory is freed in Graphics::newPixelEffect
// memory is freed in Graphics::newShaderEffect
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
lua_pushstring(L, e.what());
lua_pcall(L, 1,1, 0);
lua_pcall(L, 1, 1, 0);
const char *err = lua_tostring(L, -1);
return luaL_error(L, "%s", err);
}
@@ -794,26 +803,26 @@ int w_getCanvas(lua_State *L)
return 1;
}
int w_setPixelEffect(lua_State *L)
int w_setShaderEffect(lua_State *L)
{
if (lua_isnoneornil(L,1))
{
PixelEffect::detach();
ShaderEffect::detach();
return 0;
}
PixelEffect *effect = luax_checkpixeleffect(L, 1);
ShaderEffect *effect = luax_checkshadereffect(L, 1);
effect->attach();
return 0;
}
int w_getPixelEffect(lua_State *L)
int w_getShaderEffect(lua_State *L)
{
PixelEffect *effect = PixelEffect::current;
ShaderEffect *effect = ShaderEffect::current;
if (effect)
{
effect->retain();
luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void *) effect);
luax_newtype(L, "ShaderEffect", GRAPHICS_SHADEREFFECT_T, (void *) effect);
}
else
lua_pushnil(L);
@@ -841,8 +850,8 @@ int w_isSupported(lua_State *L)
if (!Canvas::isHdrSupported())
supported = false;
break;
case Graphics::SUPPORT_PIXELEFFECT:
if (!PixelEffect::isSupported())
case Graphics::SUPPORT_SHADEREFFECT:
if (!ShaderEffect::isSupported())
supported = false;
break;
case Graphics::SUPPORT_NPOT:
@@ -1256,7 +1265,7 @@ static const luaL_Reg functions[] =
{ "newSpriteBatch", w_newSpriteBatch },
{ "newParticleSystem", w_newParticleSystem },
{ "newCanvas", w_newCanvas },
{ "newPixelEffect", w_newPixelEffect },
{ "newShaderEffect", w_newShaderEffect },
{ "setColor", w_setColor },
{ "getColor", w_getColor },
@@ -1287,8 +1296,8 @@ static const luaL_Reg functions[] =
{ "setCanvas", w_setCanvas },
{ "getCanvas", w_getCanvas },
{ "setPixelEffect", w_setPixelEffect },
{ "getPixelEffect", w_getPixelEffect },
{ "setShaderEffect", w_setShaderEffect },
{ "getShaderEffect", w_getShaderEffect },
{ "isSupported", w_isSupported },
@@ -1349,7 +1358,7 @@ static const lua_CFunction types[] =
luaopen_spritebatch,
luaopen_particlesystem,
luaopen_canvas,
luaopen_pixeleffect,
luaopen_shadereffect,
0
};