summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-04 10:00:00 +0800
committerchai <chaifix@163.com>2021-11-04 10:00:00 +0800
commitb215d811a1981e20f35bb31df4e6cd2a74146193 (patch)
treee95655e6d97d0979678e56988287a030c2074ed1
parentcc68bba3a4e1a78bc8b62a5902230a4ae5043ccb (diff)
*misc
-rw-r--r--Data/DefaultContent/Libraries/GameLab/Debug.lua6
-rw-r--r--Data/Libraries/GameLab/Editor/EditorWindow.lua (renamed from Data/Libraries/GameLab/Editor/GUI/EditorWindow.lua)44
-rw-r--r--Data/Libraries/GameLab/Editor/GUI/init.lua2
-rw-r--r--Data/Libraries/GameLab/Editor/init.lua1
-rw-r--r--Data/Resources/Shaders/BaseColor.glsl (renamed from Data/Resources/Shaders/BaseColor.gls)0
-rw-r--r--Data/Resources/Shaders/Editor-Shape.glsl (renamed from Data/Resources/Shaders/Editor-Text.gls)0
-rw-r--r--Data/Resources/Shaders/Editor-Text.glsl45
-rw-r--r--Data/Resources/Shaders/Editor-UI.glsl (renamed from Data/Resources/Shaders/Editor-UI.gls)0
-rw-r--r--Data/Scripts/Editor/AssetBrowser.lua9
-rw-r--r--Data/Scripts/EditorGUI/EditorWindowManager.lua2
-rw-r--r--Runtime/Graphics/Shader.cpp6
-rw-r--r--Runtime/Graphics/Shader.h2
-rw-r--r--Runtime/Graphics/ShaderCompiler.cpp46
-rw-r--r--Runtime/Graphics/ShaderCompiler.h14
14 files changed, 113 insertions, 64 deletions
diff --git a/Data/DefaultContent/Libraries/GameLab/Debug.lua b/Data/DefaultContent/Libraries/GameLab/Debug.lua
new file mode 100644
index 0000000..9f68160
--- /dev/null
+++ b/Data/DefaultContent/Libraries/GameLab/Debug.lua
@@ -0,0 +1,6 @@
+
+local c_log = GameLab.Debug.Log
+local c_log_editor = GameLab.Debug.LogEditor
+local c_log_warning = GameLab.Debug.LogWarning
+local c_log_error = GameLab.Debug.LogError
+
diff --git a/Data/Libraries/GameLab/Editor/GUI/EditorWindow.lua b/Data/Libraries/GameLab/Editor/EditorWindow.lua
index 4f0525f..af79771 100644
--- a/Data/Libraries/GameLab/Editor/GUI/EditorWindow.lua
+++ b/Data/Libraries/GameLab/Editor/EditorWindow.lua
@@ -1,23 +1,23 @@
-local EditorWindow = GameLab.Class("GameLab.Editor.GUI.EditorWindow")
-
-EditorWindow.Ctor = function(self, title)
- self.title = title -- 编辑器名称
- self.guiWindow = nil -- 绑定的GUIWindow
-end
-
-EditorWindow.OnGUI = function(self)
-end
-
-EditorWindow.OnUpdate = function(self)
-end
-
-EditorWindow.OnStart = function(self)
-end
-
-EditorWindow.OnStop = function(self)
-end
-
-EditorWindow.OnFocus = function(self)
-end
-
+local EditorWindow = GameLab.Class("GameLab.Editor.EditorWindow")
+
+EditorWindow.Ctor = function(self, title)
+ self.title = title -- 编辑器名称
+ self.guiWindow = nil -- 绑定的GUIWindow
+end
+
+EditorWindow.OnGUI = function(self)
+end
+
+EditorWindow.OnUpdate = function(self)
+end
+
+EditorWindow.OnStart = function(self)
+end
+
+EditorWindow.OnStop = function(self)
+end
+
+EditorWindow.OnFocus = function(self)
+end
+
return EditorWindow \ No newline at end of file
diff --git a/Data/Libraries/GameLab/Editor/GUI/init.lua b/Data/Libraries/GameLab/Editor/GUI/init.lua
index def4237..a1ccb7c 100644
--- a/Data/Libraries/GameLab/Editor/GUI/init.lua
+++ b/Data/Libraries/GameLab/Editor/GUI/init.lua
@@ -3,8 +3,6 @@ local m = GameLab.Editor.GUI
local import = GameLab.import(...)
-m.EditorWindow = import("EditorWindow")
-
import("Functions")
return m \ No newline at end of file
diff --git a/Data/Libraries/GameLab/Editor/init.lua b/Data/Libraries/GameLab/Editor/init.lua
index 97b4b2e..c151aab 100644
--- a/Data/Libraries/GameLab/Editor/init.lua
+++ b/Data/Libraries/GameLab/Editor/init.lua
@@ -4,5 +4,6 @@ GameLab.Editor = m
local import = GameLab.import(...)
m.AssetManager = import("AssetManager")
+m.EditorWindow = import("EditorWindow")
return m \ No newline at end of file
diff --git a/Data/Resources/Shaders/BaseColor.gls b/Data/Resources/Shaders/BaseColor.glsl
index b1aed17..b1aed17 100644
--- a/Data/Resources/Shaders/BaseColor.gls
+++ b/Data/Resources/Shaders/BaseColor.glsl
diff --git a/Data/Resources/Shaders/Editor-Text.gls b/Data/Resources/Shaders/Editor-Shape.glsl
index 7548507..7548507 100644
--- a/Data/Resources/Shaders/Editor-Text.gls
+++ b/Data/Resources/Shaders/Editor-Shape.glsl
diff --git a/Data/Resources/Shaders/Editor-Text.glsl b/Data/Resources/Shaders/Editor-Text.glsl
new file mode 100644
index 0000000..03ec5a7
--- /dev/null
+++ b/Data/Resources/Shaders/Editor-Text.glsl
@@ -0,0 +1,45 @@
+#version 330 core
+
+CMD_BEGIN
+Cull Off
+Blend SrcAlpha OneMinusSrcAlpha
+DepthTest Off
+CMD_END
+
+uniform mat4 gamelab_mat_mvp;
+uniform sampler2D gamelab_main_tex;
+uniform vec2 gamelab_ui_position;
+
+VSH_BEGIN
+layout (location = 0) in vec2 vPos;
+layout (location = 1) in vec2 vUV;
+layout (location = 2) in vec4 vColor;
+
+out vec2 uv;
+out vec4 color;
+
+void main()
+{
+ vec2 pos = vPos + gamelab_ui_position;
+ vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0);
+ gl_Position = clip;
+ uv = vUV;
+ color = vColor;
+}
+VSH_END
+
+FSH_BEGIN
+in vec2 uv;
+in vec4 color;
+
+out vec4 FragColor;
+
+void main()
+{
+ //vec2 uv = vec2(uv.x, 1 - uv.y);
+ vec4 sampled = vec4(0.8,0.8,0.8,texture(gamelab_main_tex, uv).r);
+ sampled *= color;
+ //sampled = vec4(1,1,1,1);
+ FragColor = sampled;
+}
+FSH_END
diff --git a/Data/Resources/Shaders/Editor-UI.gls b/Data/Resources/Shaders/Editor-UI.glsl
index b2b348b..b2b348b 100644
--- a/Data/Resources/Shaders/Editor-UI.gls
+++ b/Data/Resources/Shaders/Editor-UI.glsl
diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua
index a0cb295..89d4eba 100644
--- a/Data/Scripts/Editor/AssetBrowser.lua
+++ b/Data/Scripts/Editor/AssetBrowser.lua
@@ -1,5 +1,5 @@
local Debug = GameLab.Debug
-local AssetBrowser = GameLab.Editor.GUI.EditorWindow.Extend("GameLab.Editor.AssetBrowser")
+local AssetBrowser = GameLab.Editor.EditorWindow.Extend("GameLab.Editor.AssetBrowser")
local GL = GameLab.Engine.GL
local Matrix44 = GameLab.Engine.Math.Matrix44
local Engine = GameLab.Engine
@@ -15,7 +15,6 @@ local shader = nil
local tex
AssetBrowser.OnGUI = function(self)
-
if tex == nil then
tex = Engine.Resource.LoadTexture("./Resources/Images/tile.png")
--tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall_small.jpg")
@@ -24,7 +23,7 @@ AssetBrowser.OnGUI = function(self)
if shader == nil then
-- local glsl = IO.ReadFile("./Resources/Shaders/Editor-Text.glsl", IO.EFileMode.Text)
-- shader = Engine.Rendering.Shader.New(glsl)
- shader = Engine.Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.gls")
+ shader = Engine.Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.glsl")
end
local ortho = Matrix44.New()
@@ -36,11 +35,11 @@ AssetBrowser.OnGUI = function(self)
Engine.Rendering.UseShader(shader)
Engine.Rendering.SetMatrix44("gamelab_mat_mvp", ortho)
- Engine.Rendering.SetVector2("gamelab_ui_position", {0, 0})
+ Engine.Rendering.SetVector2("gamelab_ui_position", {0, 30})
--Engine.Rendering.SetTexture("gamelab_main_tex", tex)
--Engine.Rendering.DrawUIQuad({0, 0, 200, 200})
_G["default_font"]:GetCharacters("你好世界!Hello,World! Project Window Properties", 12)
- --Engine.Rendering.DrawUI9Slicing(1, {25, 25}, {25, 25}, {80, 80}, {200, 200} )
+ --Engine.Rendering.DrawUI9Slicing(1, {25, 25}, {25, 25}, {80, 80}, {400, 50} )
Engine.Rendering.ResetUniformState()
end
diff --git a/Data/Scripts/EditorGUI/EditorWindowManager.lua b/Data/Scripts/EditorGUI/EditorWindowManager.lua
index 707038b..e3595ae 100644
--- a/Data/Scripts/EditorGUI/EditorWindowManager.lua
+++ b/Data/Scripts/EditorGUI/EditorWindowManager.lua
@@ -2,4 +2,4 @@ local EditorWindowManager = {}
EditorWindowManager.name = "asd"
-return EditorWindowManager \ No newline at end of file
+return EditorWindowManager \ No newline at end of file
diff --git a/Runtime/Graphics/Shader.cpp b/Runtime/Graphics/Shader.cpp
index 8df3624..d1fe78e 100644
--- a/Runtime/Graphics/Shader.cpp
+++ b/Runtime/Graphics/Shader.cpp
@@ -45,7 +45,7 @@ Shader::Shader(LuaBind::VM*vm)
{
}
-Shader::Shader(LuaBind::VM*vm, std::string& glslShader)
+Shader::Shader(LuaBind::VM*vm, std::string& glsllShader)
: NativeClass<Shader>(vm)
{
// stlstringڴСֵջ䣬RAII֤ͷ
@@ -53,9 +53,9 @@ Shader::Shader(LuaBind::VM*vm, std::string& glslShader)
std::string fsh ;
try
{
- GLSCompiler::Compile(glslShader, vsh, fsh, m_Commands);
+ GLSLCompiler::Compile(glsllShader, vsh, fsh, m_Commands);
}
- catch (GLSCompileException& e)
+ catch (GLSLCompileException& e)
{
ReleaseRenderCommandGroup(m_Commands);
throw ShaderCompileExecption(e.what());
diff --git a/Runtime/Graphics/Shader.h b/Runtime/Graphics/Shader.h
index 6b2b1bc..14d022b 100644
--- a/Runtime/Graphics/Shader.h
+++ b/Runtime/Graphics/Shader.h
@@ -14,7 +14,7 @@ class Shader : public LuaBind::NativeClass<Shader>
public:
Shader()/*throw(ShaderCompileExecption)*/;
Shader(LuaBind::VM*vm)/*throw(ShaderCompileExecption)*/;
- Shader(LuaBind::VM*vm, std::string& glslShader)/*throw(ShaderCompileExecption)*/;
+ Shader(LuaBind::VM*vm, std::string& glsllShader)/*throw(ShaderCompileExecption)*/;
Shader(LuaBind::VM*vm, const char* vert, const char* frag)/*throw(ShaderCompileExecption)*/;
~Shader();
diff --git a/Runtime/Graphics/ShaderCompiler.cpp b/Runtime/Graphics/ShaderCompiler.cpp
index ddd21a6..20b19f5 100644
--- a/Runtime/Graphics/ShaderCompiler.cpp
+++ b/Runtime/Graphics/ShaderCompiler.cpp
@@ -13,18 +13,18 @@ static const char* CMD_END = "CMD_END";
std::string s_CompileError = "";
-// GLSΪIJ
+// GLSLΪIJ
// * CMD_BEGIN CMD_END ֮
// * VERTEX_SHADER_BEGIN VERTEX_SHADER_END֮Ķɫ
// * FRAGMENT_SHADER_BEGIN FRAGMENT_SHADER_END֮Ƭɫ
// * ֮Ĺ
-void GLSCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& group)/*throw GLSCompileException*/
+void GLSLCompiler::Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& group)/*throw GLSLCompileException*/
{
#define CheckLabel(label) {\
int pos = src.find(label);\
if(pos == string::npos || !IsLabelActive(src, label)) {\
s_CompileError = std::string("Compile Shader Error: No ") + #label + " label";\
- throw GLSCompileException(s_CompileError.c_str());\
+ throw GLSLCompileException(s_CompileError.c_str());\
}}
CheckLabel(VSH_BEGIN);
@@ -59,7 +59,7 @@ if(pos == string::npos || !IsLabelActive(src, label)) {\
fsh = common + fsh;
}
-std::string GLSCompiler::GetContent(std::string& src, const char* from, const char* to)
+std::string GLSLCompiler::GetContent(std::string& src, const char* from, const char* to)
{
int begin = src.find(from);
int end = src.find(to);
@@ -71,7 +71,7 @@ std::string GLSCompiler::GetContent(std::string& src, const char* from, const ch
return content;
}
-std::string GLSCompiler::TrimContent(std::string& src, const char* from, const char* to)
+std::string GLSLCompiler::TrimContent(std::string& src, const char* from, const char* to)
{
int begin = src.find(from);
int end = src.find(to);
@@ -79,7 +79,7 @@ std::string GLSCompiler::TrimContent(std::string& src, const char* from, const c
return result;
}
-bool GLSCompiler::IsLabelActive(std::string& src, const char* label)
+bool GLSLCompiler::IsLabelActive(std::string& src, const char* label)
{
int pos = src.find(label);
if (pos == string::npos)
@@ -98,7 +98,7 @@ bool GLSCompiler::IsLabelActive(std::string& src, const char* label)
return true;
}
-bool GLSCompiler::IsCommandActive(std::string& src, const char* label)
+bool GLSLCompiler::IsCommandActive(std::string& src, const char* label)
{
int pos = src.find(label);
if (pos == string::npos)
@@ -117,7 +117,7 @@ bool GLSCompiler::IsCommandActive(std::string& src, const char* label)
return true;
}
-void GLSCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group)
+void GLSLCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group)
{
istringstream ss = istringstream(cmds);
string line;
@@ -139,7 +139,7 @@ void GLSCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group)
else
{
s_CompileError = string("Unknown command " + cmdName);
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
}
}
@@ -147,7 +147,7 @@ void GLSCompiler::ParseCmd(std::string& cmds, RenderCommandGroup& group)
#define IsSeperator(c) (c == ' ' || c == '\r' || c == '\n' || c == /*tab*/9)
// ҵڵĵһʣΪ
-bool GLSCompiler::FindCmdPos(std::string& line, int* start, int* end)
+bool GLSLCompiler::FindCmdPos(std::string& line, int* start, int* end)
{
for (int i = 0; i < line.size(); ++i)
{
@@ -166,7 +166,7 @@ bool GLSCompiler::FindCmdPos(std::string& line, int* start, int* end)
return false;
}
-bool GLSCompiler::IsLineCommentd(std::string& line)
+bool GLSLCompiler::IsLineCommentd(std::string& line)
{
for (int i = 0; i < line.size(); ++i)
{
@@ -185,7 +185,7 @@ bool GLSCompiler::IsLineCommentd(std::string& line)
#define MAX_PARAM 2
-void GLSCompiler::CommandCull(std::string& p, RenderCommandGroup& group)
+void GLSLCompiler::CommandCull(std::string& p, RenderCommandGroup& group)
{
std::string params[1];
GetParams("Cull", p, params, 1);
@@ -200,12 +200,12 @@ void GLSCompiler::CommandCull(std::string& p, RenderCommandGroup& group)
{
delete pCull;
s_CompileError = string("Compile Shader Error: Invalid parameter of Cull: " + params[0]);
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
group.push_back(pCull);
}
-void GLSCompiler::CommandBlend(std::string& p, RenderCommandGroup& group)
+void GLSLCompiler::CommandBlend(std::string& p, RenderCommandGroup& group)
{
std::string params[2];
GetParams("Blend", p, params, 2);
@@ -239,7 +239,7 @@ void GLSCompiler::CommandBlend(std::string& p, RenderCommandGroup& group)
{
delete pblend;
s_CompileError = string("Compile Shader Error: Invalid parameter of Blend: " + params[0]);
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
if (params[1] == "Zero") blend.dstFac = Cmd_Blend::Blend_Zero;
@@ -260,13 +260,13 @@ void GLSCompiler::CommandBlend(std::string& p, RenderCommandGroup& group)
{
delete pblend;
s_CompileError = string("Compile Shader Error: Invalid parameter of Blend: " + params[1]);
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
group.push_back(pblend);
}
-void GLSCompiler::CommandDepthTest(std::string& p, RenderCommandGroup& group)
+void GLSLCompiler::CommandDepthTest(std::string& p, RenderCommandGroup& group)
{
std::string params[1];
GetParams("DepthTest", p, params, 1);
@@ -286,12 +286,12 @@ void GLSCompiler::CommandDepthTest(std::string& p, RenderCommandGroup& group)
{
delete pTest;
s_CompileError = string("Compile Shader Error: Invalid parameter of DepthTest: " + params[0]);
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
group.push_back(pTest);
}
-void GLSCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group)
+void GLSLCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group)
{
std::string params[1];
GetParams("DepthWrite", p, params, 1);
@@ -304,12 +304,12 @@ void GLSCompiler::CommandDepthWrite(std::string& p, RenderCommandGroup& group)
{
delete pwrite;
s_CompileError = string("Compile Shader Error: Invalid parameter of DepthWrite: " + params[0]);
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
group.push_back(pwrite);
}
-void GLSCompiler::GetParams(const char* cmdName, std::string& params, std::string* out, int n)
+void GLSLCompiler::GetParams(const char* cmdName, std::string& params, std::string* out, int n)
{
int index = 0;
for (int i = 0; i < params.size(); ++i)
@@ -324,7 +324,7 @@ void GLSCompiler::GetParams(const char* cmdName, std::string& params, std::strin
if (index >= n)
{
s_CompileError = string("Compile Shader Error: Invalid parameter count of ") + cmdName +" : " + params;
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
if(!IsSeperator(params[j]))
out[index++] = params.substr(i, j - i + 1);
@@ -337,7 +337,7 @@ void GLSCompiler::GetParams(const char* cmdName, std::string& params, std::strin
if (index >= n)
{
s_CompileError = string("Compile Shader Error: Invalid parameter count of ") + cmdName + " : " + params;
- throw GLSCompileException(s_CompileError.c_str());
+ throw GLSLCompileException(s_CompileError.c_str());
}
out[index++] = params.substr(i, j - i);
break;
diff --git a/Runtime/Graphics/ShaderCompiler.h b/Runtime/Graphics/ShaderCompiler.h
index 2d48bb0..a9d174b 100644
--- a/Runtime/Graphics/ShaderCompiler.h
+++ b/Runtime/Graphics/ShaderCompiler.h
@@ -6,36 +6,36 @@
#include "Runtime/Threading/Job.h"
#include "Runtime/Graphics/RenderCommands.h"
-// GLS(GameLab Shader)
+// GLSL(GameLab Shader)
// in: .glsl path
// out: vsh & fsh
-class CompileGLSJob : public Job
+class CompileGLSLJob : public Job
{
};
// in: glsl shader
// out: vsh & fsh
-class CompileGLSShaderJob : public Job
+class CompileGLSLShaderJob : public Job
{
};
-class GLSCompileException : public std::exception
+class GLSLCompileException : public std::exception
{
public:
- GLSCompileException(const char* what)
+ GLSLCompileException(const char* what)
: std::exception(what)
{
}
};
-class GLSCompiler
+class GLSLCompiler
{
public:
- static void Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& cmd)/*throw GLSCompileException*/;
+ static void Compile(std::string& src, std::string& vsh, std::string& fsh, RenderCommandGroup& cmd)/*throw GLSLCompileException*/;
private:
static std::string GetContent(std::string& src, const char* from, const char* to);