mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-12-25 22:25:46 +00:00
Add shader interface API to Lua API
This commit is contained in:
parent
2ac3ad9fb1
commit
8c80cf6318
3 changed files with 102 additions and 1 deletions
|
@ -361,7 +361,7 @@ static void scriptError(lua_State *L, const std::string& msg)
|
|||
// - The C++ standard allows offsetof() only on POD-types. Oh well, it probably works anyways.
|
||||
// If it does not compile for some reason, comment it out, hope for the best, and go ahead.
|
||||
#if !(defined(__GNUC__) && __GNUC__ <= 2)
|
||||
void compile_time_assertions()
|
||||
static void compile_time_assertions()
|
||||
{
|
||||
#define oo(cls) offsetof(cls, _objtype)
|
||||
compile_assert(oo(Path) == oo(RenderObject));
|
||||
|
@ -378,6 +378,7 @@ void compile_time_assertions()
|
|||
compile_assert(oo(Path) == oo(Avatar));
|
||||
compile_assert(oo(Path) == oo(BaseText));
|
||||
compile_assert(oo(Path) == oo(PauseQuad));
|
||||
compile_assert(oo(Path) == oo(Shader));
|
||||
#undef oo
|
||||
}
|
||||
#endif
|
||||
|
@ -458,6 +459,12 @@ std::string getString(lua_State *L, int slot = 1)
|
|||
return sr;
|
||||
}
|
||||
|
||||
static inline
|
||||
const char *getCString(lua_State *L, int slot = 1)
|
||||
{
|
||||
return lua_isstring(L, slot) ? lua_tostring(L, slot) : NULL;
|
||||
}
|
||||
|
||||
static inline
|
||||
Shot *getShot(lua_State *L, int slot = 1)
|
||||
{
|
||||
|
@ -579,6 +586,16 @@ BaseText *getText(lua_State *L, int slot = 1)
|
|||
return q;
|
||||
}
|
||||
|
||||
static inline
|
||||
Shader *getShader(lua_State *L, int slot = 1)
|
||||
{
|
||||
Shader *q = (Shader*)lua_touserdata(L, slot);
|
||||
ENSURE_TYPE(q, SCO_SHADER);
|
||||
if (!q)
|
||||
scriptDebug(L, "Invalid Shader");
|
||||
return q;
|
||||
}
|
||||
|
||||
static SkeletalSprite *getSkeletalSprite(Entity *e)
|
||||
{
|
||||
return e ? &e->skeletalSprite : NULL;
|
||||
|
@ -7680,6 +7697,70 @@ luaFunc(text_setWidth)
|
|||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(loadShader)
|
||||
{
|
||||
const char *vertRaw = getCString(L, 1);
|
||||
const char *fragRaw = getCString(L, 2);
|
||||
std::string vert, frag;
|
||||
if(vertRaw)
|
||||
findFile_helper(vertRaw, vert);
|
||||
if(fragRaw)
|
||||
findFile_helper(fragRaw, frag);
|
||||
Shader *sh = new Shader();
|
||||
sh->load(vert, frag);
|
||||
if(!sh->isLoaded())
|
||||
{
|
||||
delete sh;
|
||||
sh = NULL;
|
||||
}
|
||||
luaReturnPtr(sh);
|
||||
}
|
||||
|
||||
luaFunc(createShader)
|
||||
{
|
||||
Shader *sh = new Shader();
|
||||
sh->loadSrc(getCString(L, 1), getCString(L, 2));
|
||||
if(!sh->isLoaded())
|
||||
{
|
||||
delete sh;
|
||||
sh = NULL;
|
||||
}
|
||||
luaReturnPtr(sh);
|
||||
}
|
||||
|
||||
luaFunc(shader_setAsAfterEffect)
|
||||
{
|
||||
core->afterEffectManager->scriptShader = lua_isuserdata(L, 1) ? getShader(L, 1) : NULL;
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(shader_setInt)
|
||||
{
|
||||
Shader *sh = getShader(L, 1);
|
||||
const char *name = getCString(L, 2);
|
||||
if(sh && name)
|
||||
sh->setInt(name, lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6));
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(shader_setFloat)
|
||||
{
|
||||
Shader *sh = getShader(L, 1);
|
||||
const char *name = getCString(L, 2);
|
||||
if(sh && name)
|
||||
sh->setFloat(name, lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6));
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(shader_delete)
|
||||
{
|
||||
Shader *sh = getShader(L);
|
||||
delete sh;
|
||||
if(core->afterEffectManager->scriptShader == sh)
|
||||
core->afterEffectManager->scriptShader = NULL;
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -8550,6 +8631,13 @@ static const struct {
|
|||
luaRegister(text_setFontSize),
|
||||
luaRegister(text_setWidth),
|
||||
|
||||
luaRegister(loadShader),
|
||||
luaRegister(createShader),
|
||||
luaRegister(shader_setAsAfterEffect),
|
||||
luaRegister(shader_setFloat),
|
||||
luaRegister(shader_setInt),
|
||||
luaRegister(shader_delete),
|
||||
|
||||
luaRegister(isQuad),
|
||||
luaRegister(isNode),
|
||||
luaRegister(isObject),
|
||||
|
|
|
@ -35,6 +35,7 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs)
|
|||
activeShader = AS_NONE;
|
||||
numEffects = 0;
|
||||
bRenderGridPoints = true;
|
||||
scriptShader = 0;
|
||||
|
||||
screenWidth = core->getWindowWidth();
|
||||
screenHeight = core->getWindowHeight();
|
||||
|
@ -245,6 +246,7 @@ void AfterEffectManager::setActiveShader(ActiveShader as)
|
|||
activeShader = as;
|
||||
}
|
||||
|
||||
|
||||
void AfterEffectManager::renderGrid()
|
||||
{
|
||||
#ifdef BBGE_BUILD_OPENGL
|
||||
|
@ -278,11 +280,21 @@ void AfterEffectManager::renderGrid()
|
|||
activeShader = &glowShader;
|
||||
break;
|
||||
}
|
||||
|
||||
if(scriptShader)
|
||||
activeShader = scriptShader;
|
||||
|
||||
}
|
||||
|
||||
if (activeShader)
|
||||
{
|
||||
//while(glGetError() != GL_NO_ERROR) {}
|
||||
|
||||
activeShader->bind();
|
||||
|
||||
activeShader->setInt("tex", 0);
|
||||
}
|
||||
|
||||
screenWidth = core->getWindowWidth();
|
||||
screenHeight = core->getWindowHeight();
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ public:
|
|||
int textureWidth, textureHeight;
|
||||
|
||||
Shader blurShader, bwShader, washoutShader, motionBlurShader, glowShader;
|
||||
Shader *scriptShader;
|
||||
|
||||
Vector ** drawGrid;
|
||||
|
||||
|
|
Loading…
Reference in a new issue