aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/shader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/shader.cpp')
-rw-r--r--src/lua/modules/graphics/shader.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/lua/modules/graphics/shader.cpp b/src/lua/modules/graphics/shader.cpp
new file mode 100644
index 0000000..c2808ca
--- /dev/null
+++ b/src/lua/modules/graphics/shader.cpp
@@ -0,0 +1,120 @@
+#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 Ref<JSLProgram>& JSLRef;
+
+ static inline JSLRef checkJSLProgram(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
+ return proxy->getRef<JSLProgram>();
+ }
+
+ /**
+ * jsl:sendNumber("variable", 0.1)
+ */
+ static int l_sendNumber (lua_State* L)
+ {
+ JSLRef ref = checkJSLProgram(L);
+ const char* variable = luax_checkstring(L, 2);
+ float number = luax_checknumber(L, 3);
+ ref->sendFloat(variable, number);
+ return 0;
+ }
+
+ static int l_sendTexture (lua_State* L)
+ {
+ JSLRef ref = checkJSLProgram(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE);
+ Ref<Texture>& tex = proxy->getRef<Texture>();
+ ref->sendTexture(variable, tex.getObject());
+ return 0;
+ }
+
+ static int l_sendCanvas (lua_State* L)
+ {
+ JSLRef ref = checkJSLProgram(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS);
+ Ref<Canvas>& canvas = proxy->getRef<Canvas>();
+ ref->sendCanvas(variable, canvas.getObject());
+ return 0;
+ }
+
+ static int l_sendVec2 (lua_State* L)
+ {
+ JSLRef ref = checkJSLProgram(L);
+ const char* variable = luax_checkstring(L, 2);
+ float x = luax_checknumber(L, 3);
+ float y = luax_checknumber(L, 4);
+ ref->sendVec2(variable, x, y);
+ return 0;
+ }
+
+ static int l_sendVec3 (lua_State* L)
+ {
+ JSLRef ref = checkJSLProgram(L);
+ const char* variable = luax_checkstring(L, 2);
+ float x = luax_checknumber(L, 3);
+ float y = luax_checknumber(L, 4);
+ float z = luax_checknumber(L, 5);
+ ref->sendVec3(variable, x, y, z);
+ return 0;
+ }
+
+ static int l_sendVec4 (lua_State* L)
+ {
+ JSLRef ref = checkJSLProgram(L);
+ const char* variable = luax_checkstring(L, 2);
+ float x = luax_checknumber(L, 3);
+ float y = luax_checknumber(L, 4);
+ float z = luax_checknumber(L, 5);
+ float w = luax_checknumber(L, 6);
+ ref->sendVec4(variable, x, y, z, w);
+ return 0;
+ }
+
+ static int l_sendColor (lua_State* L)
+ {
+ return l_sendVec4(L);
+ }
+
+ 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 },
+ { "sendNumber", l_sendNumber },
+ { "sendTexture", l_sendTexture },
+ { "sendCanvas", l_sendCanvas },
+ { "sendVec2", l_sendVec2 },
+ { "sendVec3", l_sendVec3 },
+ { "sendVec4", l_sendVec4 },
+ { "sendColor", l_sendColor },
+ { 0, 0 }
+ };
+
+ /**
+ * JSL program
+ */
+ int luaopen_JSL(lua_State* L)
+ {
+ luax_newtype(L, JIN_GRAPHICS_SHADER, f);
+ return 0;
+ }
+
+} // lua
+} // jin \ No newline at end of file