aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/luaopen_JSL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/luaopen_JSL.cpp')
-rw-r--r--src/lua/modules/graphics/luaopen_JSL.cpp146
1 files changed, 0 insertions, 146 deletions
diff --git a/src/lua/modules/graphics/luaopen_JSL.cpp b/src/lua/modules/graphics/luaopen_JSL.cpp
deleted file mode 100644
index ccd9ebd..0000000
--- a/src/lua/modules/graphics/luaopen_JSL.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace jin
-{
-namespace lua
-{
-
- using namespace jin::graphics;
-
- typedef Texture Image;
-
- static inline Ref<JSLProgram>& checkJSLProgram(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- return proxy->getRef<JSLProgram>();
- }
-
- static enum VARIABLE_TYPE
- {
- INVALID = 0,
-
- NUMBER,
- IMAGE,
- CANVAS,
- VEC2,
- VEC3,
- VEC4,
- COLOR,
- };
-
- static VARIABLE_TYPE strToType(const char* str)
- {
- std::string s = std::string(str);
- if (s == "number") return NUMBER;
- else if (s == "Image") return IMAGE;
- else if (s == "Canvas") return CANVAS;
- else if (s == "vec2") return VEC2;
- else if (s == "vec3") return VEC3;
- else if (s == "vec4") return VEC4;
- else if (s == "Color") return COLOR;
- else return INVALID;
- }
-
- /**
- * Use send function send variables to JSL program.
- */
- static int l_send(lua_State* L)
- {
- Ref<JSLProgram>& ref = checkJSLProgram(L);
- // number Image Texel
- const char* typestr = luax_checkstring(L, 2);
- // variable name
- const char* variable = luax_checkstring(L, 3);
- if (typestr != nullptr)
- {
- int type = strToType(typestr);
- switch (type)
- {
- case NUMBER:
- {
- float number = luax_checknumber(L, 4);
- ref->sendFloat(variable, number);
- break;
- }
- case IMAGE:
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 4, JIN_GRAPHICS_IMAGE);
- Ref<Image>& tex = proxy->getRef<Image>();
- ref->sendTexture(variable, tex.getObject());
- break;
- }
- case CANVAS:
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 4, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& canvas = proxy->getRef<Canvas>();
- ref->sendCanvas(variable, canvas.getObject());
- break;
- }
- case VEC2:
- {
- float x = luax_checknumber(L, 4);
- float y = luax_checknumber(L, 5);
- ref->sendVec2(variable, x, y);
- break;
- }
- case VEC3:
- {
- float x = luax_checknumber(L, 4);
- float y = luax_checknumber(L, 5);
- float z = luax_checknumber(L, 6);
- ref->sendVec3(variable, x, y, z);
- break;
- }
- case VEC4:
- {
- float x = luax_checknumber(L, 4);
- float y = luax_checknumber(L, 5);
- float z = luax_checknumber(L, 6);
- float w = luax_checknumber(L, 7);
- ref->sendVec4(variable, x, y, z, w);
- break;
- }
- case COLOR:
- {
- color col;
- col.rgba.r = luax_checkinteger(L, 4);
- col.rgba.g = luax_checkinteger(L, 5);
- col.rgba.b = luax_checkinteger(L, 6);
- col.rgba.a = luax_checkinteger(L, 7);
- ref->sendColor(variable, &col);
- break;
- }
- default:
- return 0;
- }
- }
- return 1;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "send", l_send },
- { 0, 0 }
- };
-
- /**
- * JSL program
- */
- int luaopen_JSL(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_SHADER, f);
- return 0;
- }
-
-}
-} \ No newline at end of file