diff options
author | chai <chaifix@163.com> | 2018-09-02 00:48:21 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-09-02 00:48:21 +0800 |
commit | 862763a88f6b4a6cb6c034287c509a91776adf8b (patch) | |
tree | 78c1f391c1c5ed95acfda055e3bf806290df74d8 /src/lua/modules/graphics/jsl.cpp | |
parent | b05e2443533af8e3badb4a8469a634cb302c63f8 (diff) |
*update
Diffstat (limited to 'src/lua/modules/graphics/jsl.cpp')
-rw-r--r-- | src/lua/modules/graphics/jsl.cpp | 164 |
1 files changed, 75 insertions, 89 deletions
diff --git a/src/lua/modules/graphics/jsl.cpp b/src/lua/modules/graphics/jsl.cpp index 58de46a..9714695 100644 --- a/src/lua/modules/graphics/jsl.cpp +++ b/src/lua/modules/graphics/jsl.cpp @@ -10,7 +10,6 @@ namespace lua using namespace jin::graphics; - typedef Texture Image; typedef Ref<JSLProgram>& JSLRef; static inline JSLRef checkJSLProgram(lua_State* L) @@ -32,93 +31,74 @@ namespace lua COLOR, }; - static VARIABLE_TYPE strToType(const char* str) + /** + * jsl:sendNumber("variable", 0.1) + */ + static int l_sendNumber (lua_State* L) { - 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; + JSLRef ref = checkJSLProgram(L); + const char* variable = luax_checkstring(L, 2); + float number = luax_checknumber(L, 3); + ref->sendFloat(variable, number); + return 0; } - /** - * Use send function send variables to JSL program. - */ - static int l_send(lua_State* L) + 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) { - JSLRef 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; + return l_sendVec4(L); } static int l_gc(lua_State* L) @@ -129,9 +109,15 @@ namespace lua } static const luaL_Reg f[] = { - { "__gc", l_gc }, - { "send", l_send }, - { 0, 0 } + { "__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 } }; /** @@ -143,5 +129,5 @@ namespace lua return 0; } -} -}
\ No newline at end of file +} // lua +} // jin
\ No newline at end of file |