diff options
| author | chai <chaifix@163.com> | 2019-01-14 16:40:14 +0800 | 
|---|---|---|
| committer | chai <chaifix@163.com> | 2019-01-14 16:40:14 +0800 | 
| commit | 98c9825c49a1674f59eafb3253829ca7d5cac3c1 (patch) | |
| tree | bdd2a6da72fc998ff884b011a2260dc72537c25f /src/libjin-lua/modules/graphics/l_shader.cpp | |
| parent | 8b00d67febf133e89f6a0bfabc41feed555dc4a9 (diff) | |
*rename source file
Diffstat (limited to 'src/libjin-lua/modules/graphics/l_shader.cpp')
| -rw-r--r-- | src/libjin-lua/modules/graphics/l_shader.cpp | 132 | 
1 files changed, 132 insertions, 0 deletions
diff --git a/src/libjin-lua/modules/graphics/l_shader.cpp b/src/libjin-lua/modules/graphics/l_shader.cpp new file mode 100644 index 0000000..bdf82b4 --- /dev/null +++ b/src/libjin-lua/modules/graphics/l_shader.cpp @@ -0,0 +1,132 @@ +#include "common/l_object.h" +#include "common/l_common.h" +#include "libjin/jin.h" + +#include "l_shader.h" +#include "l_canvas.h" +#include "l_texture.h" + +using namespace JinEngine::Graphics; +using namespace JinEngine::Graphics::Shaders; + +namespace JinEngine +{ +    namespace Lua +    { + +        const char* Jin_Lua_Shader = "Shader"; + +        static inline Shader* checkShader(lua_State* L) +        { +            LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader); +            return luaObj->getObject<Shader>(); +        } +     +        /** +        * jsl:sendNumber("variable", 0.1) +        */ +        LUA_IMPLEMENT int l_sendNumber(lua_State* L) +        { +            Shader* shader = checkShader(L); +            const char* variable = luax_checkstring(L, 2); +            float number = luax_checknumber(L, 3); +            shader->sendFloat(variable, number); +            return 0; +        } + +        LUA_IMPLEMENT int l_sendTexture(lua_State* L) +        { +            Shader* shader = checkShader(L); +            const char* variable = luax_checkstring(L, 2); +            LuaObject* luaObj = (LuaObject*)luax_checktype(L, 3, Jin_Lua_Texture); +            shader->sendTexture(variable, luaObj->getObject<Texture>()); +            return 0; +        } + +        LUA_IMPLEMENT int l_sendCanvas(lua_State* L) +        { +            Shader* shader = checkShader(L); +            const char* variable = luax_checkstring(L, 2); +            LuaObject* luaObj = (LuaObject*)luax_checktype(L, 3, Jin_Lua_Canvas); +            shader->sendCanvas(variable, luaObj->getObject<Canvas>()); +            return 0; +        } + +        LUA_IMPLEMENT int l_sendVec2(lua_State* L) +        { +            Shader* shader = checkShader(L); +            const char* variable = luax_checkstring(L, 2); +            if (!luax_istable(L, 3)) +            { +                luax_typerror(L, 3, "table"); +                return 1; +            } +            float x = luax_rawgetnumber(L, 3, 1); +            float y = luax_rawgetnumber(L, 3, 2); +            shader->sendVec2(variable, x, y); +            return 0; +        } + +        LUA_IMPLEMENT int l_sendVec3(lua_State* L) +        { +            Shader* shader = checkShader(L); +            const char* variable = luax_checkstring(L, 2); +            if (!luax_istable(L, 3)) +            { +                luax_typerror(L, 3, "table"); +                return 1; +            } +            float x = luax_rawgetnumber(L, 3, 1); +            float y = luax_rawgetnumber(L, 3, 2); +            float z = luax_rawgetnumber(L, 3, 3); +            shader->sendVec3(variable, x, y, z); +            return 0; +        } + +        LUA_IMPLEMENT int l_sendVec4(lua_State* L) +        { +            Shader* shader = checkShader(L); +            const char* variable = luax_checkstring(L, 2); +            if (!luax_istable(L, 3)) +            { +                luax_typerror(L, 3, "table"); +                return 1; +            } +            float x = luax_rawgetnumber(L, 3, 1); +            float y = luax_rawgetnumber(L, 3, 2); +            float z = luax_rawgetnumber(L, 3, 3); +            float w = luax_rawgetnumber(L, 3, 4); +            shader->sendVec4(variable, x, y, z, w); +            return 0; +        } + +        LUA_IMPLEMENT int l_sendColor(lua_State* L) +        { +            return l_sendVec4(L); +        } + +        LUA_IMPLEMENT int l_gc(lua_State* L) +        { +            LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader); +            luaObj->release(); +            return 0; +        } + +        LUA_EXPORT void luaopen_Shader(lua_State* L) +        { +            luaL_Reg methods[] = { +                { "__gc",        l_gc          }, +                { "sendNumber",  l_sendNumber  }, +                { "sendTexture", l_sendTexture }, +                { "sendCanvas",  l_sendCanvas  }, +                { "sendVec2",    l_sendVec2    }, +                { "sendVec3",    l_sendVec3    }, +                { "sendVec4",    l_sendVec4    }, +                { "sendColor",   l_sendColor   }, +                { 0,             0             } +            }; +            luax_newtype(L, Jin_Lua_Shader, methods); +        } + +    } // namespace Lua +} // namespace JinEngine
\ No newline at end of file  | 
