diff options
author | chai <chaifix@163.com> | 2019-01-07 09:54:08 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-01-07 09:54:08 +0800 |
commit | 2af7f2f5e3da8f6c236e7996781950e1bc6c1f9c (patch) | |
tree | f6a8a9618e146c93e4d4d964a6e13cd16f528693 | |
parent | 909e544ed322b28a6f59febf3213e05068e9e93c (diff) | |
parent | da056982e50bdd9cb9f944691cc88ca98b053b77 (diff) |
Merge branch 'master' of warmcat.org:/home/git-repo/Jin
22 files changed, 226 insertions, 108 deletions
diff --git a/bin/jin.exe b/bin/jin.exe Binary files differindex dd2f048..92e0cbc 100644 --- a/bin/jin.exe +++ b/bin/jin.exe diff --git a/build/vc++/libjin-lua/libjin-lua.vcxproj b/build/vc++/libjin-lua/libjin-lua.vcxproj index d19961d..c680269 100644 --- a/build/vc++/libjin-lua/libjin-lua.vcxproj +++ b/build/vc++/libjin-lua/libjin-lua.vcxproj @@ -209,7 +209,6 @@ <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua.h" /> <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_common.h" /> <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_constant.h" /> - <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_error.h" /> <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_callback.h" /> <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_function.h" /> <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_object.h" /> @@ -268,6 +267,7 @@ <ItemGroup> <None Include="..\..\..\src\libjin-lua\scripts\ai\ai.lua" /> <None Include="..\..\..\src\libjin-lua\scripts\ai\state_machine.lua" /> + <None Include="..\..\..\src\libjin-lua\scripts\audio\audio.lua" /> <None Include="..\..\..\src\libjin-lua\scripts\log.lua" /> <None Include="..\..\..\src\libjin-lua\scripts\physics\physics.lua" /> <None Include="..\..\..\src\libjin-lua\scripts\tiledmap\tiledmap.lua" /> diff --git a/build/vc++/libjin-lua/libjin-lua.vcxproj.filters b/build/vc++/libjin-lua/libjin-lua.vcxproj.filters index eccf119..dd4b486 100644 --- a/build/vc++/libjin-lua/libjin-lua.vcxproj.filters +++ b/build/vc++/libjin-lua/libjin-lua.vcxproj.filters @@ -91,6 +91,9 @@ <Filter Include="source\scripts\physics"> <UniqueIdentifier>{1a9ea013-c770-410a-a2ec-a9b51d1c4112}</UniqueIdentifier> </Filter> + <Filter Include="source\scripts\audio"> + <UniqueIdentifier>{76da0223-0e72-44da-8abe-8dd97c1cec35}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\src\libjin-lua\modules\graphics\je_lua_sprite.cpp"> @@ -239,9 +242,6 @@ <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_constant.h"> <Filter>source\common</Filter> </ClInclude> - <ClInclude Include="..\..\..\src\libjin-lua\common\je_lua_error.h"> - <Filter>source\common</Filter> - </ClInclude> <ClInclude Include="..\..\..\src\libjin-lua\modules\time\je_lua_timer.h"> <Filter>source\modules\time</Filter> </ClInclude> @@ -403,6 +403,9 @@ <None Include="..\..\..\src\libjin-lua\scripts\physics\physics.lua"> <Filter>source\scripts\physics</Filter> </None> + <None Include="..\..\..\src\libjin-lua\scripts\audio\audio.lua"> + <Filter>source\scripts\audio</Filter> + </None> </ItemGroup> <ItemGroup> <Text Include="..\..\..\src\libjin-lua\scripts\app.lua"> diff --git a/samples/post-processing/config.lua b/samples/post-processing/config.lua index 095ee28..3c6ff07 100644 --- a/samples/post-processing/config.lua +++ b/samples/post-processing/config.lua @@ -1,6 +1,6 @@ return { - title = "window form", + title = "post-processing", icon = "splash.png", vsync = true }
\ No newline at end of file diff --git a/samples/post-processing/shaders/rgb-split.jsl b/samples/post-processing/shaders/rgb-split.jsl index e3b8abc..aba401b 100644 --- a/samples/post-processing/shaders/rgb-split.jsl +++ b/samples/post-processing/shaders/rgb-split.jsl @@ -9,7 +9,7 @@ Vertex vert(Vertex v) Color frag(Color col, Texture tex, Vertex v) { float t = jin_Time.x; - t = 0.02; + //t = 0.02; float a = abs(sin(t)) * 3.14; vec2 p = vec2(0.5*cos(a) + 0.5, 0.5*sin(a) + 0.5); vec2 dir = v.uv - p; @@ -22,4 +22,4 @@ Color frag(Color col, Texture tex, Vertex v) vec4 c3 = texel(tex, v.uv + value / jin_RenderTargetSize.y); return vec4(c1.r, c2.g, c3.b, c1.a + c2.a + c3.b); } -#END_FRAGMENT_SHADER
\ No newline at end of file +#END_FRAGMENT_SHADER 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/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp index 016367c..49ac797 100644 --- a/src/libjin/graphics/fonts/je_texture_font.cpp +++ b/src/libjin/graphics/fonts/je_texture_font.cpp @@ -276,7 +276,7 @@ namespace JinEngine const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; const vector<GlyphVertex>& glyphvertices = page->glyphvertices; Matrix modelMatrix = gl.getModelViewMatrix(x, y, 1, 1, 0, 0, 0); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); for (int i = 0; i < glyphinfolist.size(); ++i) @@ -288,6 +288,7 @@ namespace JinEngine gl.drawArrays(GL_QUADS, 0, info.count); gl.bindTexture(0); } + shader->end(); } void TextureFont::render(const Content& text, int x, int y, int lineheight, int spacing) diff --git a/src/libjin/graphics/fonts/je_ttf.cpp b/src/libjin/graphics/fonts/je_ttf.cpp index 1df7fa7..89aa096 100644 --- a/src/libjin/graphics/fonts/je_ttf.cpp +++ b/src/libjin/graphics/fonts/je_ttf.cpp @@ -295,7 +295,7 @@ namespace JinEngine const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; const vector<GlyphVertex>& glyphvertices = page->glyphvertices; Matrix modelMatrix = gl.getModelViewMatrix(x, y, 1, 1, 0, 0, 0); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); for (int i = 0; i < glyphinfolist.size(); ++i) @@ -307,6 +307,7 @@ namespace JinEngine gl.drawArrays(GL_QUADS, 0, info.count); gl.bindTexture(0); } + shader->end(); } void TTF::render(const Text& text, int x, int y, int lineheight, int spacing /* = 0 */) diff --git a/src/libjin/graphics/je_graphic.cpp b/src/libjin/graphics/je_graphic.cpp index 18dbf42..e2c22d1 100644 --- a/src/libjin/graphics/je_graphic.cpp +++ b/src/libjin/graphics/je_graphic.cpp @@ -71,7 +71,7 @@ namespace JinEngine textureCoords[6] = 1; textureCoords[7] = 0; // Set shader. Shader* shader = gl.getShader(); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()) .uploadVertices(2, GL_FLOAT, 0, vertexCoords) @@ -80,6 +80,8 @@ namespace JinEngine gl.bindTexture(getGLTexture()); gl.drawArrays(GL_QUADS, 0, 4); gl.bindTexture(0); + + shader->end(); } void Graphic::render(const Math::Quad& slice, float x, float y, float sx, float sy, float r, float ax, float ay) const @@ -105,7 +107,7 @@ namespace JinEngine Math::Matrix modelViewMatrix = gl.getModelViewMatrix(x, y, sx, sy, r, ax, ay); Shader* shader = gl.getShader(); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()) .uploadVertices(2, GL_FLOAT, 0, vertexCoords) @@ -114,6 +116,8 @@ namespace JinEngine gl.bindTexture(getGLTexture()); gl.drawArrays(GL_QUADS, 0, 4); gl.bindTexture(0); + + shader->end(); } void Graphic::render(const Math::Transform& transform) const diff --git a/src/libjin/graphics/je_mesh.cpp b/src/libjin/graphics/je_mesh.cpp index 2d453b0..e3bebe6 100644 --- a/src/libjin/graphics/je_mesh.cpp +++ b/src/libjin/graphics/je_mesh.cpp @@ -60,7 +60,7 @@ namespace JinEngine Math::Matrix modelViewMatrix = gl.getModelViewMatrix(x, y, sx, sy, r, ox, oy); Shader* shader = gl.getShader(); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()) .uploadVertices(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].xy)) @@ -70,6 +70,8 @@ namespace JinEngine gl.bindTexture(mGraphic->getGLTexture()); gl.drawArrays(GL_POLYGON, 0, mVertices.size()); gl.bindTexture(0); + + shader->end(); }; } // namespace Graphics diff --git a/src/libjin/graphics/je_shapes.cpp b/src/libjin/graphics/je_shapes.cpp index ce5c7e7..493e173 100644 --- a/src/libjin/graphics/je_shapes.cpp +++ b/src/libjin/graphics/je_shapes.cpp @@ -25,12 +25,14 @@ namespace JinEngine Matrix modelMatrix = gl.getModelViewMatrix(); Shader* shader = gl.getShader(); - shader->prepare() + shader->begin() .uploadVertices(2, GL_FLOAT, 0, verts) .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); gl.drawArrays(GL_POINTS, 0, 1); + + shader->end(); } void points(int n, GLshort* p) @@ -38,12 +40,14 @@ namespace JinEngine Matrix modelMatrix = gl.getModelViewMatrix(); Shader* shader = gl.getShader(); - shader->prepare() + shader->begin() .uploadVertices(2, GL_SHORT, 0, p) .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); gl.drawArrays(GL_POINTS, 0, n); + + shader->end(); } void line(int x1, int y1, int x2, int y2) @@ -56,12 +60,14 @@ namespace JinEngine Matrix modelMatrix = gl.getModelViewMatrix(); Shader* shader = gl.getShader(); - shader->prepare() + shader->begin() .uploadVertices(2, GL_FLOAT, 0, verts) .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); gl.drawArrays(GL_LINES, 0, 2); + + shader->end(); } void circle(RenderMode mode, int x, int y, int r) @@ -105,12 +111,14 @@ namespace JinEngine { Shader* shader = gl.getShader(); Matrix modelMatrix = gl.getModelViewMatrix(); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()) .uploadVertices(2, GL_FLOAT, 0, p); gl.drawArrays(GL_LINE_LOOP, 0, count); + + shader->end(); } void polygon(RenderMode mode, float* p, int count) @@ -123,12 +131,14 @@ namespace JinEngine { Shader* shader = gl.getShader(); Matrix modelMatrix = gl.getModelViewMatrix(); - shader->prepare() + shader->begin() .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix) .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()) .uploadVertices(2, GL_FLOAT, 0, p); gl.drawArrays(GL_POLYGON, 0, count); + + shader->end(); } } diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp index 0eb3631..0803e65 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" @@ -57,7 +58,8 @@ namespace JinEngine // const int DEFAULT_TEXTURE_UNIT = 0; - GLint Shader::mTextureUnit = DEFAULT_TEXTURE_UNIT; + static GLint textureUnit = 0; + GLint Shader::mAttributeIndex = 0; Shader::Shader(const string& program) @@ -65,7 +67,8 @@ namespace JinEngine { if (!compile(program)) { - throw 0; + jin_log_error("Compile jsl shader failed."); + throw Exception("Compile jsl shader failed"); } } @@ -77,8 +80,11 @@ namespace JinEngine glDeleteShader(mPID); } - Shader& Shader::prepare() + Shader& Shader::begin() { + + textureUnit = DEFAULT_TEXTURE_UNIT; + // Send uniforms. sendInt(SHADER_MAIN_TEXTURE, DEFAULT_TEXTURE_UNIT); sendVec2(SHADER_TIME, Time::getSecond(), Time::getDeltaTime()); @@ -91,15 +97,17 @@ namespace JinEngine { sendVec2(SHADER_RENDERTARGET_SIZE, rt->getWidth(), rt->getHeight()); } - // Reset attribute index. - for(; mAttributeIndex > 0; --mAttributeIndex) - glDisableVertexAttribArray(mAttributeIndex); - - mTextureUnit = DEFAULT_TEXTURE_UNIT; return *this; } + void Shader::end() + { + // Reset attribute index. + for (; mAttributeIndex > 0; --mAttributeIndex) + glDisableVertexAttribArray(mAttributeIndex); + } + bool Shader::compile(const string& program) { string vertex_shader, fragment_shader; @@ -157,7 +165,7 @@ namespace JinEngine // return 0; //mTextureUnits[name] = mCurrentTextureUnit; //return mCurrentTextureUnit; - return mTextureUnit++; + return textureUnit++; } GLint Shader::getUniformLocation(const char* uniform) diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h index c3ca721..402805a 100644 --- a/src/libjin/graphics/shaders/je_shader.h +++ b/src/libjin/graphics/shaders/je_shader.h @@ -47,7 +47,12 @@ namespace JinEngine /// /// Prepare shader and set default uniforms. /// - Shader& prepare(); + Shader& begin(); + + /// + /// End use shader. + /// + void end(); /// /// Send float value to shader. @@ -181,7 +186,7 @@ namespace JinEngine /// bool compile(const std::string& program); - static GLint mTextureUnit; + //static GLint mTextureUnit; static GLint mAttributeIndex; GLuint mPID; |