From 91c32cb173201ac8803a1e4452e8342969b8e484 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 29 Oct 2021 13:36:49 +0800 Subject: *GLSL test --- .../Libraries/GameLab/Engine/Math/Rect.lua | 10 ++++ Data/Resources/Shaders/Editor-UI.glsl | 30 ++++------- Data/Scripts/Editor/AssetBrowser.lua | 60 ++++++++++++++++++--- Data/Scripts/EditorApplication.lua | 61 +++------------------- 4 files changed, 79 insertions(+), 82 deletions(-) create mode 100644 Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua (limited to 'Data') diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua new file mode 100644 index 0000000..2aeb0f7 --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua @@ -0,0 +1,10 @@ +local Rect = GameLab.Class("GameLab.Engine.Math.Rect") + +Rect.Ctor = function(self, x, y, width, height) + self.x = x or 0 + self.y = y or 0 + self.width = width or 0 + self.height = height or 0 +end + +return Rect \ No newline at end of file diff --git a/Data/Resources/Shaders/Editor-UI.glsl b/Data/Resources/Shaders/Editor-UI.glsl index 4edfe73..493ed9b 100644 --- a/Data/Resources/Shaders/Editor-UI.glsl +++ b/Data/Resources/Shaders/Editor-UI.glsl @@ -1,42 +1,30 @@ #version 330 core -uniform vec2 screenSize; + +uniform vec4 screenSize; +uniform vec4 windowSize; VSH_BEGIN -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aColor; -layout (location = 2) in vec2 aTexCoord; +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; -out vec3 ourColor; -out vec2 TexCoord; +uniform mat4 mvp; void main() { - gl_Position = vec4(aPos, 1.0); - ourColor = aColor; - TexCoord = vec2(aTexCoord.x, aTexCoord.y); + vec4 clip = mvp * vec4(vPos, -1, 1.0); + gl_Position = clip; } VSH_END - FSH_BEGIN out vec4 FragColor; -in vec3 ourColor; -in vec2 TexCoord; - -uniform float mixValue; - -// texture samplers -uniform sampler2D texture1; -uniform sampler2D texture2; - void main() { - // linearly interpolate between both textures - FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), mixValue); + FragColor = vec4(1,1,1,1); } FSH_END diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua index e6e4a4a..b936702 100644 --- a/Data/Scripts/Editor/AssetBrowser.lua +++ b/Data/Scripts/Editor/AssetBrowser.lua @@ -8,17 +8,63 @@ AssetBrowser.Ctor = function(self) self.base.Ctor(self, "AssetBrowser") end +local shader = nil + +local glsl = [[ + +#version 330 core + +VSH_BEGIN + +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; + +uniform mat4 mvp; + +void main() +{ + vec4 clip = mvp * vec4(vPos, -1, 1.0); + gl_Position = clip; +} + +VSH_END + +FSH_BEGIN + +out vec4 FragColor; + +void main() +{ + FragColor = vec4(1,1,1,1); +} +FSH_END + +]] + AssetBrowser.OnGUI = function(self) + + if shader == nil then + shader = GameLab.Engine.Rendering.Shader.New(glsl) + end + + local ortho = Matrix44.New() + ortho:SetOrtho(-200, 200, -200, 200, 0.1, 10) + Debug.Log("AssetBrowser.OnGUI()") GL.ClearColor({0,0,0,1}) GL.Clear(GL.EBufferType.ColorBuffer) - GL.Color({1,1,0,1}) - GL.LoadPixelMatrix(-250, 250, -300, 300) - GL.Begin(GL.EPrimitiveType.Triangles) - GL.Vertex({0,0,-1}) - GL.Vertex({0,300,-1}) - GL.Vertex({250,0,-1}) - GL.End() + -- GL.Color({1,1,0,1}) + -- GL.LoadPixelMatrix(-250, 250, -300, 300) + -- GL.Begin(GL.EPrimitiveType.Triangles) + -- GL.Vertex({0,0,-1}) + -- GL.Vertex({0,300,-1}) + -- GL.Vertex({250,0,-1}) + -- GL.End() + + shader:Use() + shader:SetMatrix44("mvp", ortho) + GameLab.Engine.Rendering.DrawUIQuad({0, 0, 100, 100}) + end AssetBrowser.OnFocus = function(self) diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua index a233d88..75749df 100644 --- a/Data/Scripts/EditorApplication.lua +++ b/Data/Scripts/EditorApplication.lua @@ -3,6 +3,8 @@ local inspect = require "inspect" local AssetBrowser = require "./Scripts/Editor/AssetBrowser" local EditorWindowManager = require "./Scripts/EditorGUI/EditorWindowManager" +local Editor = GameLab.Editor +local Engine = GameLab.Engine local Resource = GameLab.Engine.Resource local Rendering = GameLab.Engine.Rendering local Debug = GameLab.Debug @@ -23,7 +25,7 @@ app:SetMainWindow(mainWindow) local guiWindow = GUI.GUIWindow.New() guiWindow:SetContainerWindow(mainWindow) -guiWindow:SetPosition({0,0, 500, 400}) +guiWindow:SetPosition({0,0, 400, 400}) collectgarbage() @@ -40,7 +42,7 @@ Debug.Log(inspect(v)) Debug.Log(EditorWindowManager.name) -local c = Rendering.Color.New(1,1,1,1) +local c = Engine.Rendering.Color.New(1,1,1,1) Debug.Log(inspect(c)) Debug.Log(inspect(GL.EBufferType)) @@ -64,13 +66,13 @@ GameLab.IO.ReadFilesAsync(files, function() Debug.Log("finished") end) -local imgData = Resource.LoadImageData("./Resources/Images/brickwall.jpg") +local imgData = Engine.Resource.LoadImageData("./Resources/Images/brickwall.jpg") Debug.Log(tostring(imgData:GetWidth())) Debug.Log(tostring(imgData:GetHeight())) -local tex = Resource.LoadTexture("./Resources/Images/brickwall.jpg") +local tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall.jpg") -local request = Resource.LoadImageDataAsync("./Resources/Images/brickwall.jpg") +local request = Engine.Resource.LoadImageDataAsync("./Resources/Images/brickwall.jpg") local vsh = [[ #version 330 core @@ -109,55 +111,6 @@ local fsh = [[ } ]] -local glsl = [[ - -#version 330 core -uniform vec2 screenSize; - -VSH_BEGIN - -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aColor; -layout (location = 2) in vec2 aTexCoord; - -out vec3 ourColor; -out vec2 TexCoord; - -void main() -{ - gl_Position = vec4(aPos, 1.0); - ourColor = aColor; - TexCoord = vec2(aTexCoord.x, aTexCoord.y); -} - -VSH_END - - -FSH_BEGIN - -out vec4 FragColor; - -in vec3 ourColor; -in vec2 TexCoord; - -uniform float mixValue; - -// texture samplers -uniform sampler2D texture1; -uniform sampler2D texture2; - -void main() -{ - // linearly interpolate between both textures - FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), mixValue); -} - -FSH_END - -]] - -local shader = Rendering.Shader.New(glsl) - while true do app:OnStep() -- cgit v1.1-26-g67d0