From bd3c1f268d959d351631b51d32d9912370144ddd Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 15 Oct 2018 13:51:56 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0=E6=96=87=E5=AD=97?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/modules/graphics/graphics.cpp | 63 ++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'src/lua/modules/graphics/graphics.cpp') diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 645ae4a..700c8a5 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -164,6 +164,30 @@ namespace lua return 1; } + static int l_newShaderf(lua_State* L) + { + const char* path = luax_checkstring(L, 1); + Filesystem* fs = Filesystem::get(); + if (!fs->exists(path)) + { + error(L, "No such shader file %s\n", path); + luax_pushnil(L); + return 1; + } + Buffer b; + fs->read(path, &b); + Shader* jsl = Shader::createShader((char*)b.data); + if (jsl == nullptr) + { + error(L, "Failed to compile shader"); + luax_pushnil(L); + return 1; + } + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy)); + proxy->bind(new Ref(jsl, JIN_GRAPHICS_SHADER)); + return 1; + } + static int l_newCanvas(lua_State* L) { int w = luax_checknumber(L, 1); @@ -277,24 +301,6 @@ namespace lua font->print(page, x, y); } - /* print(string, x, y, lineheight, spacing) */ - /* need set font */ - static int l_print(lua_State* L) - { - Font* font = context.curFont; - if (font == nullptr) - return 0; - unsigned length; - const char* str = luax_checklstring(L, 1, &length); - Text text(Encode::UTF8, str, length); - int x = luax_optnumber(L, 2, 0); - int y = luax_optnumber(L, 3, 0); - int lineheight = luax_optnumber(L, 4, font->getFontSize()); - int spacing = luax_optnumber(L, 5, 0); - font->print(text, x, y, lineheight, spacing); - return 0; - } - static int l_draw(lua_State* L) { if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE)) @@ -305,8 +311,6 @@ namespace lua l_draw_text(L); else if (luax_istype(L, 1, JIN_GRAPHICS_PAGE)) l_draw_page(L); - else if (luax_isstring(L, 1)) - l_print(L); else { luax_typerror(L, 1, "texture or canvas"); @@ -355,6 +359,24 @@ namespace lua } } + /* print(string, x, y, lineheight, spacing) */ + /* need set font */ + static int l_print(lua_State* L) + { + Font* font = context.curFont; + if (font == nullptr) + return 0; + unsigned length; + const char* str = luax_checklstring(L, 1, &length); + Text text(Encode::UTF8, str, length); + int x = luax_optnumber(L, 2, 0); + int y = luax_optnumber(L, 3, 0); + int lineheight = luax_optnumber(L, 4, font->getFontSize()); + int spacing = luax_optnumber(L, 5, 0); + font->print(text, x, y, lineheight, spacing); + return 0; + } + static int l_setColor(lua_State* L) { if (luax_gettop(L) == 0) @@ -670,6 +692,7 @@ namespace lua { "newBitmap", l_newBitmap }, { "newTexture", l_newTexture }, { "newShader", l_newShader }, + { "newShaderf", l_newShaderf }, { "newCanvas", l_newCanvas }, { "newTTFData", l_newTTFData }, { "newText", l_newText }, -- cgit v1.1-26-g67d0