diff options
author | chai <chaifix@163.com> | 2021-10-29 15:02:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-29 15:02:46 +0800 |
commit | 796b4b05ec62eb5d58a634854998f485072e8a2b (patch) | |
tree | 30f188382f14b3b9c69fe5846262a39a8b4664cc /Runtime/Scripting | |
parent | 91c32cb173201ac8803a1e4452e8342969b8e484 (diff) |
*passing texture to glsl
Diffstat (limited to 'Runtime/Scripting')
-rw-r--r-- | Runtime/Scripting/GL/GL.bind.cpp | 16 | ||||
-rw-r--r-- | Runtime/Scripting/Rendering/Rendering.bind.cpp | 8 | ||||
-rw-r--r-- | Runtime/Scripting/Rendering/Shader.bind.cpp | 19 |
3 files changed, 33 insertions, 10 deletions
diff --git a/Runtime/Scripting/GL/GL.bind.cpp b/Runtime/Scripting/GL/GL.bind.cpp index 903e706..40093e9 100644 --- a/Runtime/Scripting/GL/GL.bind.cpp +++ b/Runtime/Scripting/GL/GL.bind.cpp @@ -54,10 +54,10 @@ int ClearColor(lua_State* L) LUA_BIND_STATE(L); if (LuaHelper::IsType(state, "GameLab.Engine.Rendering.Color", -1)) { - float r = state.GetField(-1, "r", 0); - float g = state.GetField(-1, "g", 0); - float b = state.GetField(-1, "b", 0); - float a = state.GetField(-1, "a", 0); + float r = state.GetField<float>(-1, "r", 0); + float g = state.GetField<float>(-1, "g", 0); + float b = state.GetField<float>(-1, "b", 0); + float a = state.GetField<float>(-1, "a", 0); glClearColor(r, g, b, a); } else if (LuaHelper::IsType(state, "GameLab.Engine.Rendering.Color32", -1)) @@ -70,10 +70,10 @@ int ClearColor(lua_State* L) } else if (LuaHelper::IsType(state, "table", -1)) { - float r = state.GetField(-1, 1, 0); - float g = state.GetField(-1, 2, 0); - float b = state.GetField(-1, 3, 0); - float a = state.GetField(-1, 4, 0); + float r = state.GetField<float>(-1, 1, 0); + float g = state.GetField<float>(-1, 2, 0); + float b = state.GetField<float>(-1, 3, 0); + float a = state.GetField<float>(-1, 4, 0); glClearColor(r, g, b, a); } else diff --git a/Runtime/Scripting/Rendering/Rendering.bind.cpp b/Runtime/Scripting/Rendering/Rendering.bind.cpp index 197ff0a..cb294a3 100644 --- a/Runtime/Scripting/Rendering/Rendering.bind.cpp +++ b/Runtime/Scripting/Rendering/Rendering.bind.cpp @@ -2,6 +2,7 @@ #include "Runtime/Graphics/Texture.h" #include "Runtime/Graphics/ImageData.h" #include "Runtime/Graphics/UIQuad.h" +#include "Runtime/Graphics/GfxDevice.h" // Rendering.DrawUIQuad({}) static int DrawUIQuad(lua_State* L) @@ -13,8 +14,15 @@ static int DrawUIQuad(lua_State* L) return 0; } +static int ResetUniformState(lua_State* L) +{ + g_GfxDevice.ResetUniformsState(); + return 0; +} + static luaL_Reg funcs[] = { {"DrawUIQuad", DrawUIQuad}, + {"ResetUniformState", ResetUniformState}, {0, 0} }; diff --git a/Runtime/Scripting/Rendering/Shader.bind.cpp b/Runtime/Scripting/Rendering/Shader.bind.cpp index 89f1ebb..83f8477 100644 --- a/Runtime/Scripting/Rendering/Shader.bind.cpp +++ b/Runtime/Scripting/Rendering/Shader.bind.cpp @@ -15,12 +15,13 @@ LUA_BIND_REGISTRY(Shader) { "Use", _Use }, { "Unuse", _UnUse }, //{ "SetColor", _SetColor }, + { "SetTexture", _SetTexture }, { "SetVector2", _SetVector2 }, { "SetVector3", _SetVector3 }, { "SetVector4", _SetVector4 }, //{ "SetMatrix3", _SetMatrix3 }, { "SetMatrix44", _SetMatrix4 } - ); + ); } LUA_BIND_POSTPROCESS(Shader) @@ -160,4 +161,18 @@ LUA_BIND_IMPL_METHOD(Shader, _SetMatrix4) g_GfxDevice.SetUniformMat4(name, m4); return 1; -}
\ No newline at end of file +} + +// shader:SetTexture(name,texture) +LUA_BIND_IMPL_METHOD(Shader, _SetTexture) +{ + LUA_BIND_PREPARE(L, Shader); + LUA_BIND_CHECK(L, "USU"); + + cc8* name = state.GetValue(2, ""); + Texture* tex = state.GetUserdata<Texture>(); + + g_GfxDevice.SetUniformTexture(name, tex); + + return 1; +} |