Add pixel effects (love-glsl)

This commit is contained in:
vrld
2011-07-24 14:03:46 +02:00
parent 9c11bfa236
commit 24a52f056b
11 changed files with 7724 additions and 6125 deletions
@@ -24,6 +24,7 @@
#include <font/Rasterizer.h>
#include <scripts/graphics.lua.h>
#include "GLInfo.h"
namespace love
{
@@ -383,6 +384,33 @@ namespace opengl
return 1;
}
int w_newPixelEffect(lua_State * L)
{
if (!PixelEffect::isSupported())
return luaL_error(L, "Sorry, your graphics card does not support pixel effects.");
try {
luaL_checkstring(L, 1);
luax_getfunction(L, "graphics", "_effectCodeToGLSL");
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);
} catch (love::Exception& e) {
// memory is freed in Graphics::newPixelEffect
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
lua_pushstring(L, e.what());
lua_pcall(L, 1,1, 0);
const char* err = lua_tostring(L, -1);
return luaL_error(L, err);
}
return 1;
}
int w_setColor(lua_State * L)
{
Color c;
@@ -702,6 +730,24 @@ namespace opengl
return 0;
}
int w_setPixelEffect(lua_State * L)
{
if (lua_isnoneornil(L,1)) {
PixelEffect::detach();
return 0;
}
PixelEffect * effect = luax_checkpixeleffect(L, 1);
effect->attach();
return 0;
}
int w_hasPixelEffects(lua_State * L)
{
lua_pushboolean(L, PixelEffect::isSupported());
return 1;
}
/**
* Draws an Image at the specified coordinates, with rotation and
* scaling along both axes.
@@ -1075,6 +1121,7 @@ namespace opengl
{ "newSpriteBatch", w_newSpriteBatch },
{ "newParticleSystem", w_newParticleSystem },
{ "newFramebuffer", w_newFramebuffer },
{ "newPixelEffect", w_newPixelEffect },
{ "setColor", w_setColor },
{ "getColor", w_getColor },
@@ -1102,6 +1149,9 @@ namespace opengl
{ "newScreenshot", w_newScreenshot },
{ "setRenderTarget", w_setRenderTarget },
{ "setPixelEffect", w_setPixelEffect },
{ "hasPixelEffects", w_hasPixelEffects },
{ "draw", w_draw },
{ "drawq", w_drawq },
{ "drawTest", w_drawTest },
@@ -1158,6 +1208,7 @@ namespace opengl
luaopen_spritebatch,
luaopen_particlesystem,
luaopen_framebuffer,
luaopen_pixeleffect,
0
};