diff options
author | chai <chaifix@163.com> | 2019-01-04 22:54:59 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-01-04 22:54:59 +0800 |
commit | c446e8186afa31c8d346383c0db8b8070fa563cd (patch) | |
tree | a2a0e088c51f1ba251756aa5ab50b27dc8eeef39 /src | |
parent | c42eb2529eead4b17c0c7f9da7ac9c41563a13fa (diff) |
*编译jsl shader失败时使用error shader
Diffstat (limited to 'src')
-rw-r--r-- | src/3rdparty/luax/luax.h | 14 | ||||
-rw-r--r-- | src/libjin-lua/common/je_lua_common.h | 1 | ||||
-rw-r--r-- | src/libjin-lua/common/je_lua_error.h | 30 | ||||
-rw-r--r-- | src/libjin-lua/je_lua_jin.cpp | 2 | ||||
-rw-r--r-- | src/libjin-lua/modules/audio/je_lua_audio.cpp | 4 | ||||
-rw-r--r-- | src/libjin-lua/modules/graphics/je_lua_graphics.cpp | 30 | ||||
-rw-r--r-- | src/libjin-lua/scripts/audio/audio.lua | 5 | ||||
-rw-r--r-- | src/libjin-lua/scripts/audio/audio.lua.h | 6 | ||||
-rw-r--r-- | src/libjin-lua/scripts/graphics/graphics.lua | 48 | ||||
-rw-r--r-- | src/libjin-lua/scripts/graphics/graphics.lua.h | 104 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_shader.cpp | 4 |
11 files changed, 167 insertions, 81 deletions
diff --git a/src/3rdparty/luax/luax.h b/src/3rdparty/luax/luax.h index aac9ee4..08411f9 100644 --- a/src/3rdparty/luax/luax.h +++ b/src/3rdparty/luax/luax.h @@ -106,12 +106,24 @@ inline float luax_rawgetnumberthenpop(lua_State* L, int i, int k) */ #define luax_typerror luaL_typerror - /** * Error checking */ #define luax_error luaL_error +inline void luax_errorf(lua_State* L, const char* fmt, ...) +{ + const int FORMAT_MSG_BUFFER_SIZE = 2048; + char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 }; + va_list args; + va_start(args, fmt); + vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args); + va_end(args); + //luax_getglobal(L, "jin"); + //luax_setfieldstring(L, "error", err); + luax_error(L, err); +} + /** * Push value on the top of stack. */ diff --git a/src/libjin-lua/common/je_lua_common.h b/src/libjin-lua/common/je_lua_common.h index cdd4f36..dbda9a0 100644 --- a/src/libjin-lua/common/je_lua_common.h +++ b/src/libjin-lua/common/je_lua_common.h @@ -3,7 +3,6 @@ #include "je_lua.h" #include "je_lua_port.h" -#include "je_lua_error.h" #include "je_lua_reference.h" #endif
\ No newline at end of file diff --git a/src/libjin-lua/common/je_lua_error.h b/src/libjin-lua/common/je_lua_error.h deleted file mode 100644 index bd5695d..0000000 --- a/src/libjin-lua/common/je_lua_error.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __JIN_ERROR_H -#define __JIN_ERROR_H - -#include <string.h> - -#include "common/je_lua.h" - -namespace JinEngine -{ - namespace Lua - { - - static const int FORMAT_MSG_BUFFER_SIZE = 2048; - - inline void error(lua_State* L, const char* fmt, ...) - { - char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 }; - va_list args; - va_start(args, fmt); - vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args); - va_end(args); - //luax_getglobal(L, "jin"); - //luax_setfieldstring(L, "error", err); - luax_error(L, err); - } - - } // namespace Lua -} // namespace JinEngine - -#endif
\ No newline at end of file diff --git a/src/libjin-lua/je_lua_jin.cpp b/src/libjin-lua/je_lua_jin.cpp index debd79e..256e081 100644 --- a/src/libjin-lua/je_lua_jin.cpp +++ b/src/libjin-lua/je_lua_jin.cpp @@ -111,6 +111,7 @@ namespace JinEngine #include "scripts/log.lua.h" #include "scripts/tiledmap/tiledmap.lua.h" #include "scripts/physics/physics.lua.h" + #include "scripts/audio/audio.lua.h" #include "scripts/app.lua.h" @@ -128,6 +129,7 @@ namespace JinEngine { "xml.lua", xml_lua }, { "tiledmap.lua", tiledmap_lua }, { "physics.lua", physics_lua }, + { "audio.lua", audio_lua }, // { "log.lua", log_lua }, { 0, 0 } diff --git a/src/libjin-lua/modules/audio/je_lua_audio.cpp b/src/libjin-lua/modules/audio/je_lua_audio.cpp index f5ef31f..d5cfb43 100644 --- a/src/libjin-lua/modules/audio/je_lua_audio.cpp +++ b/src/libjin-lua/modules/audio/je_lua_audio.cpp @@ -87,14 +87,14 @@ namespace JinEngine } catch (Exception& e) { - error(L, "Failed to read source file %s", f); + luax_errorf(L, "Failed to read source file %s", f); luax_pushnil(L); return 1; } Source* src = new SDLSource((void*)&b, b.size()); if (src == nullptr) { - error(L, "Failed to decode source file %s", f); + luax_errorf(L, "Failed to decode source file %s", f); luax_pushnil(L); return 1; } diff --git a/src/libjin-lua/modules/graphics/je_lua_graphics.cpp b/src/libjin-lua/modules/graphics/je_lua_graphics.cpp index a77f1ad..96577f5 100644 --- a/src/libjin-lua/modules/graphics/je_lua_graphics.cpp +++ b/src/libjin-lua/modules/graphics/je_lua_graphics.cpp @@ -197,14 +197,14 @@ namespace JinEngine } catch (Exception& e) { - error(L, "Failed to read image %s", f); + luax_errorf(L, "Failed to read image %s", f); luax_pushnil(L); return 1; } bitmap = new Bitmap(&b, b.size()); if (bitmap == nullptr) { - error(L, "Failed to decode image file %s", f); + luax_errorf(L, "Failed to decode image file %s", f); luax_pushnil(L); return 1; } @@ -232,13 +232,18 @@ namespace JinEngine return 1; } + // See embed graphics.lua. LUA_IMPLEMENT int l_newShader(lua_State* L) { const char* program = luax_checkstring(L, 1); - Shader* jsl = new Shader(program); - if (jsl == nullptr) + Shader* jsl = nullptr; + try { - error(L, "Failed to compile shader"); + jsl = new Shader(program); + } + catch (JinEngine::Exception& e) + { + //luax_errorf(L, "Failed to compile shader"); luax_pushnil(L); return 1; } @@ -246,22 +251,27 @@ namespace JinEngine return 1; } + // See embed graphics.lua LUA_IMPLEMENT int l_newShaderf(lua_State* L) { const char* path = luax_checkstring(L, 1); AssetDatabase* fs = AssetDatabase::get(); if (!fs->exists(path)) { - error(L, "No such shader file \"%s\"", path); + //luax_errorf(L, "No such shader file \"%s\"", path); luax_pushnil(L); return 1; } Buffer b; fs->read(path, b); - Shader* jsl = new Shader((char*)&b); - if (jsl == nullptr) + Shader* jsl = nullptr; + try + { + jsl = new Shader((char*)&b); + } + catch (JinEngine::Exception& e) { - error(L, "Failed to compile shader"); + //luax_errorf(L, "Failed to compile shader"); luax_pushnil(L); return 1; } @@ -705,7 +715,7 @@ namespace JinEngine AssetDatabase* fs = AssetDatabase::get(); if (!fs->exists(path)) { - error(L, "No such font \"%s\"", path); + luax_errorf(L, "No such font \"%s\"", path); luax_pushnil(L); return 1; } diff --git a/src/libjin-lua/scripts/audio/audio.lua b/src/libjin-lua/scripts/audio/audio.lua new file mode 100644 index 0000000..e462652 --- /dev/null +++ b/src/libjin-lua/scripts/audio/audio.lua @@ -0,0 +1,5 @@ + +jin.audio = jin.audio or {} + + + diff --git a/src/libjin-lua/scripts/audio/audio.lua.h b/src/libjin-lua/scripts/audio/audio.lua.h new file mode 100644 index 0000000..2ea6d41 --- /dev/null +++ b/src/libjin-lua/scripts/audio/audio.lua.h @@ -0,0 +1,6 @@ +/*Auto generated, don't modify by hand.*/ +static char audio_lua[] = { +13,10,106,105,110,46,97,117,100,105,111,32,61,32,106,105,110,46,97,117, +100,105,111,32,111,114,32,123,125,32,13,10,13,10,13,10,13,10,0 +}; + diff --git a/src/libjin-lua/scripts/graphics/graphics.lua b/src/libjin-lua/scripts/graphics/graphics.lua index ae896d0..3abb64d 100644 --- a/src/libjin-lua/scripts/graphics/graphics.lua +++ b/src/libjin-lua/scripts/graphics/graphics.lua @@ -138,7 +138,21 @@ local function compileBuiltInShaders() return col * texel(tex, v.uv); } #END_FRAGMENT_SHADER - ]] + ]] + jg.Shaders.Error = jg.newShader[[ + #VERTEX_SHADER + Vertex vert(Vertex v) + { + return v; + } + #END_VERTEX_SHADER + #FRAGMENT_SHADER + Color frag(Color col, Texture tex, Vertex v) + { + return Color(1, 0, 1, 1); + } + #END_FRAGMENT_SHADER + ]] end local _init = jg.init @@ -155,10 +169,6 @@ jg.init = function(setting) return initialized end -jg.unuseShader = function() - jg.useShader(jg.Shaders.Default) -end - -- Reset all attributes to default value. jg.reset = function() jg.setColor(255, 255, 255, 255) @@ -167,3 +177,31 @@ jg.reset = function() jg.unsetFont() jg.unuseShader() end + +jg.unuseShader = function() + jg.useShader(jg.Shaders.Default) +end + +local _newShader = jg.newShader + +jg.newShader = function(program) + local shader = _newShader(program) + if shader == nil then + jin.log.error("Compile shader failed:\n" .. debug.traceback()) + return jg.Shaders.Error + else + return shader + end +end + +local _newShaderf = jg.newShaderf + +jg.newShaderf = function(file) + local shader = _newShaderf(file) + if shader == nil then + jin.log.error("Compile shader failed:\n" .. debug.traceback()) + return jg.Shaders.Error + else + return shader + end +end diff --git a/src/libjin-lua/scripts/graphics/graphics.lua.h b/src/libjin-lua/scripts/graphics/graphics.lua.h index eb686c9..cb6cf56 100644 --- a/src/libjin-lua/scripts/graphics/graphics.lua.h +++ b/src/libjin-lua/scripts/graphics/graphics.lua.h @@ -131,37 +131,79 @@ static char graphics_lua[] = { 120,32,118,41,13,10,9,9,123,13,10,9,9,9,114,101,116,117,114,110, 32,99,111,108,32,42,32,116,101,120,101,108,40,116,101,120,44,32,118,46, 117,118,41,59,13,10,9,9,125,13,10,9,9,35,69,78,68,95,70,82, -65,71,77,69,78,84,95,83,72,65,68,69,82,13,10,9,93,93,32,13, -10,101,110,100,13,10,13,10,108,111,99,97,108,32,95,105,110,105,116,32, -61,32,106,103,46,105,110,105,116,13,10,108,111,99,97,108,32,105,110,105, -116,105,97,108,105,122,101,100,32,61,32,102,97,108,115,101,13,10,106,103, -46,105,110,105,116,32,61,32,102,117,110,99,116,105,111,110,40,115,101,116, -116,105,110,103,41,32,13,10,32,32,32,32,105,102,32,105,110,105,116,105, -97,108,105,122,101,100,32,116,104,101,110,32,13,10,32,32,32,32,32,32, -32,32,114,101,116,117,114,110,32,105,110,105,116,105,97,108,105,122,101,100, -13,10,32,32,32,32,101,110,100,13,10,32,32,32,32,105,110,105,116,105, -97,108,105,122,101,100,32,61,32,95,105,110,105,116,40,115,101,116,116,105, -110,103,41,13,10,32,32,32,32,105,102,32,105,110,105,116,105,97,108,105, -122,101,100,32,116,104,101,110,32,13,10,32,32,32,32,32,32,32,32,99, -111,109,112,105,108,101,66,117,105,108,116,73,110,83,104,97,100,101,114,115, -40,41,13,10,32,32,32,32,32,32,32,32,106,103,46,117,115,101,83,104, +65,71,77,69,78,84,95,83,72,65,68,69,82,13,10,9,93,93,13,10, +32,32,32,32,106,103,46,83,104,97,100,101,114,115,46,69,114,114,111,114, +32,61,32,106,103,46,110,101,119,83,104,97,100,101,114,91,91,13,10,32, +32,32,32,9,35,86,69,82,84,69,88,95,83,72,65,68,69,82,13,10, +9,9,86,101,114,116,101,120,32,118,101,114,116,40,86,101,114,116,101,120, +32,118,41,13,10,9,9,123,13,10,9,9,9,114,101,116,117,114,110,32, +118,59,13,10,9,9,125,13,10,9,9,35,69,78,68,95,86,69,82,84, +69,88,95,83,72,65,68,69,82,13,10,9,9,35,70,82,65,71,77,69, +78,84,95,83,72,65,68,69,82,13,10,9,9,67,111,108,111,114,32,102, +114,97,103,40,67,111,108,111,114,32,99,111,108,44,32,84,101,120,116,117, +114,101,32,116,101,120,44,32,86,101,114,116,101,120,32,118,41,13,10,9, +9,123,13,10,9,9,9,114,101,116,117,114,110,32,67,111,108,111,114,40, +49,44,32,48,44,32,49,44,32,49,41,59,13,10,9,9,125,13,10,9, +9,35,69,78,68,95,70,82,65,71,77,69,78,84,95,83,72,65,68,69, +82,13,10,32,32,32,32,93,93,13,10,101,110,100,13,10,13,10,108,111, +99,97,108,32,95,105,110,105,116,32,61,32,106,103,46,105,110,105,116,13, +10,108,111,99,97,108,32,105,110,105,116,105,97,108,105,122,101,100,32,61, +32,102,97,108,115,101,13,10,106,103,46,105,110,105,116,32,61,32,102,117, +110,99,116,105,111,110,40,115,101,116,116,105,110,103,41,32,13,10,32,32, +32,32,105,102,32,105,110,105,116,105,97,108,105,122,101,100,32,116,104,101, +110,32,13,10,32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,105, +110,105,116,105,97,108,105,122,101,100,13,10,32,32,32,32,101,110,100,13, +10,32,32,32,32,105,110,105,116,105,97,108,105,122,101,100,32,61,32,95, +105,110,105,116,40,115,101,116,116,105,110,103,41,13,10,32,32,32,32,105, +102,32,105,110,105,116,105,97,108,105,122,101,100,32,116,104,101,110,32,13, +10,32,32,32,32,32,32,32,32,99,111,109,112,105,108,101,66,117,105,108, +116,73,110,83,104,97,100,101,114,115,40,41,13,10,32,32,32,32,32,32, +32,32,106,103,46,117,115,101,83,104,97,100,101,114,40,106,103,46,83,104, +97,100,101,114,115,46,68,101,102,97,117,108,116,41,13,10,32,32,32,32, +101,110,100,13,10,32,32,32,32,114,101,116,117,114,110,32,105,110,105,116, +105,97,108,105,122,101,100,32,13,10,101,110,100,13,10,13,10,45,45,32, +82,101,115,101,116,32,97,108,108,32,97,116,116,114,105,98,117,116,101,115, +32,116,111,32,100,101,102,97,117,108,116,32,118,97,108,117,101,46,13,10, +106,103,46,114,101,115,101,116,32,61,32,102,117,110,99,116,105,111,110,40, +41,13,10,32,32,32,32,106,103,46,115,101,116,67,111,108,111,114,40,50, +53,53,44,32,50,53,53,44,32,50,53,53,44,32,50,53,53,41,13,10, +32,32,32,32,106,103,46,115,101,116,67,108,101,97,114,67,111,108,111,114, +40,48,44,32,48,44,32,48,44,32,48,41,13,10,32,32,32,32,106,103, +46,99,108,101,97,114,40,41,13,10,32,32,32,32,106,103,46,117,110,115, +101,116,70,111,110,116,40,41,13,10,32,32,32,32,106,103,46,117,110,117, +115,101,83,104,97,100,101,114,40,41,13,10,101,110,100,13,10,13,10,106, +103,46,117,110,117,115,101,83,104,97,100,101,114,32,61,32,102,117,110,99, +116,105,111,110,40,41,13,10,32,32,32,32,106,103,46,117,115,101,83,104, 97,100,101,114,40,106,103,46,83,104,97,100,101,114,115,46,68,101,102,97, -117,108,116,41,13,10,32,32,32,32,101,110,100,13,10,32,32,32,32,114, -101,116,117,114,110,32,105,110,105,116,105,97,108,105,122,101,100,32,13,10, -101,110,100,13,10,13,10,106,103,46,117,110,117,115,101,83,104,97,100,101, -114,32,61,32,102,117,110,99,116,105,111,110,40,41,13,10,32,32,32,32, -106,103,46,117,115,101,83,104,97,100,101,114,40,106,103,46,83,104,97,100, -101,114,115,46,68,101,102,97,117,108,116,41,13,10,101,110,100,13,10,13, -10,45,45,32,82,101,115,101,116,32,97,108,108,32,97,116,116,114,105,98, -117,116,101,115,32,116,111,32,100,101,102,97,117,108,116,32,118,97,108,117, -101,46,13,10,106,103,46,114,101,115,101,116,32,61,32,102,117,110,99,116, -105,111,110,40,41,13,10,32,32,32,32,106,103,46,115,101,116,67,111,108, -111,114,40,50,53,53,44,32,50,53,53,44,32,50,53,53,44,32,50,53, -53,41,13,10,32,32,32,32,106,103,46,115,101,116,67,108,101,97,114,67, -111,108,111,114,40,48,44,32,48,44,32,48,44,32,48,41,13,10,32,32, -32,32,106,103,46,99,108,101,97,114,40,41,13,10,32,32,32,32,106,103, -46,117,110,115,101,116,70,111,110,116,40,41,13,10,32,32,32,32,106,103, -46,117,110,117,115,101,83,104,97,100,101,114,40,41,13,10,101,110,100,13, -10,0 +117,108,116,41,13,10,101,110,100,13,10,13,10,108,111,99,97,108,32,95, +110,101,119,83,104,97,100,101,114,32,61,32,106,103,46,110,101,119,83,104, +97,100,101,114,13,10,13,10,106,103,46,110,101,119,83,104,97,100,101,114, +32,61,32,102,117,110,99,116,105,111,110,40,112,114,111,103,114,97,109,41, +32,13,10,32,32,32,32,108,111,99,97,108,32,115,104,97,100,101,114,32, +61,32,95,110,101,119,83,104,97,100,101,114,40,112,114,111,103,114,97,109, +41,13,10,32,32,32,32,105,102,32,115,104,97,100,101,114,32,61,61,32, +110,105,108,32,116,104,101,110,32,13,10,32,32,32,32,32,32,32,32,106, +105,110,46,108,111,103,46,101,114,114,111,114,40,34,67,111,109,112,105,108, +101,32,115,104,97,100,101,114,32,102,97,105,108,101,100,58,92,110,34,32, +46,46,32,100,101,98,117,103,46,116,114,97,99,101,98,97,99,107,40,41, +41,13,10,32,32,32,32,32,32,32,32,114,101,116,117,114,110,32,106,103, +46,83,104,97,100,101,114,115,46,69,114,114,111,114,13,10,32,32,32,32, +101,108,115,101,13,10,32,32,32,32,32,32,32,32,114,101,116,117,114,110, +32,115,104,97,100,101,114,13,10,32,32,32,32,101,110,100,13,10,101,110, +100,13,10,13,10,108,111,99,97,108,32,95,110,101,119,83,104,97,100,101, +114,102,32,61,32,106,103,46,110,101,119,83,104,97,100,101,114,102,13,10, +13,10,106,103,46,110,101,119,83,104,97,100,101,114,102,32,61,32,102,117, +110,99,116,105,111,110,40,102,105,108,101,41,13,10,32,32,32,32,108,111, +99,97,108,32,115,104,97,100,101,114,32,61,32,95,110,101,119,83,104,97, +100,101,114,102,40,102,105,108,101,41,13,10,32,32,32,32,105,102,32,115, +104,97,100,101,114,32,61,61,32,110,105,108,32,116,104,101,110,32,13,10, +32,32,32,32,32,32,32,32,106,105,110,46,108,111,103,46,101,114,114,111, +114,40,34,67,111,109,112,105,108,101,32,115,104,97,100,101,114,32,102,97, +105,108,101,100,58,92,110,34,32,46,46,32,100,101,98,117,103,46,116,114, +97,99,101,98,97,99,107,40,41,41,13,10,32,32,32,32,32,32,32,32, +114,101,116,117,114,110,32,106,103,46,83,104,97,100,101,114,115,46,69,114, +114,111,114,13,10,32,32,32,32,101,108,115,101,13,10,32,32,32,32,32, +32,32,32,114,101,116,117,114,110,32,115,104,97,100,101,114,13,10,32,32, +32,32,101,110,100,13,10,101,110,100,13,10,0 }; diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp index 0eb3631..059c411 100644 --- a/src/libjin/graphics/shaders/je_shader.cpp +++ b/src/libjin/graphics/shaders/je_shader.cpp @@ -5,6 +5,7 @@ #include "../../time/je_timer.h" #include "../../filesystem/je_buffer.h" +#include "../../utils/je_log.h" #include "../../utils/je_macros.h" #include "../je_gl.h" @@ -65,7 +66,8 @@ namespace JinEngine { if (!compile(program)) { - throw 0; + jin_log_error("Compile jsl shader failed."); + throw Exception("Compile jsl shader failed"); } } |