summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-24 13:24:13 +0800
committerchai <chaifix@163.com>2021-10-24 13:24:13 +0800
commit3239ba18797b1aa098056aa0c2a70e250a27a06c (patch)
treecb42710213cd188dd5f7c7841693c9ebe1b1915a
parent7bf672fd0c6211909d94078b448032b1bd0916ef (diff)
* port shader
-rw-r--r--Editor/EditorMain.cpp6
-rw-r--r--Editor/GUI/ContainerWindow.cpp4
-rw-r--r--Editor/GUI/EditorWindows.h8
-rw-r--r--Editor/GUI/GUIWindow.cpp4
-rw-r--r--Editor/GUI/WindowManager.cpp6
-rw-r--r--Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp6
-rw-r--r--Editor/Scripting/EditorGUI/GUIWindow.bind.cpp20
-rw-r--r--Editor/Scripting/EditorScripting.cpp2
-rw-r--r--Editor/Utils/HelperFuncs.h4
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj29
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj.filters93
-rw-r--r--Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua8
-rw-r--r--Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua4
-rw-r--r--Resources/Libraries/GameLab/Editor/GUI/Functions.lua (renamed from Runtime/Graphics/Scripting/wrap_Device.cpp)0
-rw-r--r--Resources/Libraries/GameLab/Editor/GUI/init.lua2
-rw-r--r--Resources/Libraries/GameLab/Editor/Resource/ResourceManager3
-rw-r--r--Resources/Scripts/Editor/AssetBrowser.lua7
-rw-r--r--Resources/Scripts/EditorApplication.lua90
-rw-r--r--Runtime/Graphics/Device.cpp7
-rw-r--r--Runtime/Graphics/Device.h5
-rw-r--r--Runtime/Graphics/FrameBuffer.cpp4
-rw-r--r--Runtime/Graphics/GpuDataBuffer.cpp2
-rw-r--r--Runtime/Graphics/ImageData.cpp2
-rw-r--r--Runtime/Graphics/ImageData.h1
-rw-r--r--Runtime/Graphics/Scripting/wrap_GL.cpp0
-rw-r--r--Runtime/Graphics/Scripting/wrap_RenderTexture.cpp0
-rw-r--r--Runtime/Graphics/Shader.cpp146
-rw-r--r--Runtime/Graphics/Shader.h56
-rw-r--r--Runtime/Graphics/Texture.h4
-rw-r--r--Runtime/Graphics/VertexBuffer.cpp2
-rw-r--r--Runtime/Graphics/VertexBuffer.h3
-rw-r--r--Runtime/Lua/LuaBind/LuaBindRef.cpp16
-rw-r--r--Runtime/Lua/LuaBind/LuaBindRef.h10
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.h6
-rw-r--r--Runtime/Lua/LuaBind/LuaBindUtility.h8
-rw-r--r--Runtime/Lua/LuaBind/LuaBindVM.cpp5
-rw-r--r--Runtime/Lua/LuaHelper.cpp8
-rw-r--r--Runtime/Lua/LuaHelper.h2
-rw-r--r--Runtime/Math/FloatConversion.h697
-rw-r--r--Runtime/Math/Rect.h152
-rw-r--r--Runtime/Math/Vector2.cpp11
-rw-r--r--Runtime/Math/Vector2.h138
-rw-r--r--Runtime/Math/Vector3.h3
-rw-r--r--Runtime/Profiling/FrameStats.cpp12
-rw-r--r--Runtime/Profiling/FrameStats.h (renamed from Runtime/Profiler/FrameStats.h)0
-rw-r--r--Runtime/Profiling/Profiler.h (renamed from Runtime/Profiler/Profiler.h)0
-rw-r--r--Runtime/Scripting/Rendering/Rendering.bind.cpp17
-rw-r--r--Runtime/Scripting/Rendering/Shader.bind.cpp92
48 files changed, 672 insertions, 1033 deletions
diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp
index 7ca90ad..7686fa5 100644
--- a/Editor/EditorMain.cpp
+++ b/Editor/EditorMain.cpp
@@ -29,9 +29,8 @@ void OnRegisterNativeClass(LuaBind::State& state, int cls, std::string clsName,
lua_setfield(state, cls, "_type");
}
-void InitLuaState()
+void InitLuaState(LuaBind::VM& vm)
{
- LuaBind::VM vm;
vm.Setup();
vm.OpenLibs();
@@ -59,7 +58,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
WindowUtil::RegisterClasses();
- InitLuaState();
+ LuaBind::VM vm;
+ InitLuaState(vm);
return 0;
} \ No newline at end of file
diff --git a/Editor/GUI/ContainerWindow.cpp b/Editor/GUI/ContainerWindow.cpp
index 2aca239..5f3e6f8 100644
--- a/Editor/GUI/ContainerWindow.cpp
+++ b/Editor/GUI/ContainerWindow.cpp
@@ -274,7 +274,7 @@ bool ContainerWindow::SetRenderContext()
}
// 初始化,创建窗口
-void ContainerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize, std::string name)
+void ContainerWindow::Init(Rect pixelRect, int showMode, const Vector2& minSize, const Vector2& maxSize, std::string name)
{
// Aux windows are mac only. on windows they look just like normal utility windows.
if (showMode == kShowAuxWindow)
@@ -343,7 +343,7 @@ void ContainerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSiz
// parentWindow = GetMainEditorWindow();
}
- bool notSizeable = (minSize == maxSize) && (minSize != Vector2f::zero);
+ bool notSizeable = (minSize == maxSize) && (minSize != Vector2::zero);
if (notSizeable)
windowStyle &= ~(WS_THICKFRAME);
diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h
index 3b84b13..a7091dd 100644
--- a/Editor/GUI/EditorWindows.h
+++ b/Editor/GUI/EditorWindows.h
@@ -29,7 +29,7 @@ public :
class WindowManager : Singleton<WindowManager>
{
public:
- static Vector2f GetMousePosition();
+ static Vector2 GetMousePosition();
static GUIWindow* GetMouseOverWindow();
private:
@@ -56,7 +56,7 @@ public:
ContainerWindow(LuaBind::VM* vm);
~ContainerWindow();
- void Init(Rectf size, int showMode, const Vector2f& minSize, const Vector2f& maxSize, std::string name = "");
+ void Init(Rect size, int showMode, const Vector2& minSize, const Vector2& maxSize, std::string name = "");
void SetTitle(const char* title);
void SetIcon(LPCSTR iconName);
void SetAsRenderContext();
@@ -85,7 +85,7 @@ private:
bool m_IsClosing;
bool m_InMenuLoop;
bool m_CloseFromScriptDontShutdown;
- Rectf m_InternalRect;
+ Rect m_InternalRect;
POINT m_MinSize;
POINT m_MaxSize;
@@ -140,7 +140,7 @@ public:
void DoPaint();
void SetContainerWindow(ContainerWindow* wnd);
void Focus();
- void SetPosition(Rectf position);
+ void SetPosition(Rect position);
void SetAsRenderContext();
void OnFocus();
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp
index fb23a59..df28785 100644
--- a/Editor/GUI/GUIWindow.cpp
+++ b/Editor/GUI/GUIWindow.cpp
@@ -196,7 +196,7 @@ void GUIWindow::Init(std::string name)
//DWORD windowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
DWORD extendedStyle = WS_EX_TOOLWINDOW;
- Rectf pixelRect;
+ Rect pixelRect;
pixelRect.x = 0;
pixelRect.y = 0;
pixelRect.width = 32;
@@ -326,7 +326,7 @@ void GUIWindow::OnPaint()
InvokeLuaCallback(m_Script, "OnPaint");
}
-void GUIWindow::SetPosition(Rectf position)
+void GUIWindow::SetPosition(Rect position)
{
log_info("GUIWindow::SetPosition()");
RECT rc;
diff --git a/Editor/GUI/WindowManager.cpp b/Editor/GUI/WindowManager.cpp
index 533435f..d8a4135 100644
--- a/Editor/GUI/WindowManager.cpp
+++ b/Editor/GUI/WindowManager.cpp
@@ -8,12 +8,12 @@ GUIWindow* WindowManager::GetMouseOverWindow()
return NULL;
}
-Vector2f WindowManager::GetMousePosition()
+Vector2 WindowManager::GetMousePosition()
{
POINT pt;
if (!GetCursorPos(&pt))
- return Vector2f(0, 0);
+ return Vector2(0, 0);
- return Vector2f(pt.x, pt.y);
+ return Vector2(pt.x, pt.y);
}
diff --git a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp
index ce0efc8..02b29df 100644
--- a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp
+++ b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp
@@ -56,10 +56,10 @@ LUA_BIND_IMPL_METHOD(ContainerWindow, ContainerWindow::_New)
ContainerWindow* wnd = new ContainerWindow(state.GetVM());
- Rectf rect = state.GetValue<Rectf>(state, Rectf());
+ Rect rect = state.GetValue<Rect>(state, Rect());
int showMode = state.GetValue<int>(2, 0);
- Vector2f min = state.GetValue<Vector2f>(state, Vector2f());
- Vector2f max = state.GetValue<Vector2f>(state, Vector2f());
+ Vector2 min = state.GetValue<Vector2>(state, Vector2());
+ Vector2 max = state.GetValue<Vector2>(state, Vector2());
wnd->Init(rect, showMode, min, max);
diff --git a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp
index 9ecc209..e991398 100644
--- a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp
+++ b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp
@@ -16,6 +16,15 @@ LUA_BIND_POSTPROCESS(GUIWindow)
{
}
+LUA_BIND_IMPL_METHOD(GUIWindow, _New)
+{
+ LUA_BIND_STATE(L, GUIWindow);
+ GUIWindow* wnd = new GUIWindow(state.GetVM());
+ wnd->Init();
+ wnd->PushUserdata(state);
+ return 1;
+}
+
LUA_BIND_IMPL_METHOD(GUIWindow, _DoPaint)
{
LUA_BIND_PREPARE(L, GUIWindow);
@@ -53,7 +62,7 @@ LUA_BIND_IMPL_METHOD(GUIWindow, _SetPosition)
if (!state.CheckParams(1, "UT"))
return 0;
- Rectf rect;
+ Rect rect;
rect.x = state.GetField<float>(2, 1, 0);
rect.y = state.GetField<float>(2, 2, 0);
rect.width = state.GetField<float>(2, 3, 0);
@@ -61,12 +70,3 @@ LUA_BIND_IMPL_METHOD(GUIWindow, _SetPosition)
self->SetPosition(rect);
return 0;
}
-
-LUA_BIND_IMPL_METHOD(GUIWindow, _New)
-{
- LUA_BIND_PREPARE(L, GUIWindow);
- GUIWindow* wnd = new GUIWindow(state.GetVM());
- wnd->Init();
- wnd->PushUserdata(state);
- return 1;
-} \ No newline at end of file
diff --git a/Editor/Scripting/EditorScripting.cpp b/Editor/Scripting/EditorScripting.cpp
index 26509e0..75014f3 100644
--- a/Editor/Scripting/EditorScripting.cpp
+++ b/Editor/Scripting/EditorScripting.cpp
@@ -35,6 +35,8 @@ bool SetupGameLabEditorScripting(lua_State* L)
openlib(luaopen_GameLab_Debug);
openlib(luaopen_GameLab_Path);
+ openlib(luaopen_GameLab_Engine_Rendering);
+
openlib(luaopen_GameLab_Editor);
openlib(luaopen_GameLab_Editor_GUI);
diff --git a/Editor/Utils/HelperFuncs.h b/Editor/Utils/HelperFuncs.h
index 626e48f..def1e23 100644
--- a/Editor/Utils/HelperFuncs.h
+++ b/Editor/Utils/HelperFuncs.h
@@ -9,3 +9,7 @@ extern void PrintCallStack();
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
+
+#ifndef Assert
+#define Assert assert
+#endif
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj
index 7304a6a..4182808 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj
@@ -171,8 +171,19 @@
<ClCompile Include="..\..\..\Editor\Win\Win.cpp" />
<ClCompile Include="..\..\..\Runtime\Debug\Log.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\Path.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Device.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\FrameBuffer.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\GlyphAtlas.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\GpuDataBuffer.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\ImageData.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\OpenGL.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Point.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\PolyLine.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Quad.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\RenderTexture.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\Shader.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Texture.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\VertexBuffer.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindCFunctions.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindEnum.cpp" />
@@ -186,10 +197,13 @@
<ClCompile Include="..\..\..\Runtime\Lua\LuaHelper.cpp" />
<ClCompile Include="..\..\..\Runtime\Math\Vector2.cpp" />
<ClCompile Include="..\..\..\Runtime\Math\Vector3.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Profiling\FrameStats.cpp" />
<ClCompile Include="..\..\..\Runtime\Scripting\Debug\Debug.bind.cpp" />
<ClCompile Include="..\..\..\Runtime\Scripting\FileSystem\FileSystem.bind.cpp" />
<ClCompile Include="..\..\..\Runtime\Scripting\GL\GL.bind.cpp" />
<ClCompile Include="..\..\..\Runtime\Scripting\Path.bind.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\Rendering\Rendering.bind.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\Rendering\Shader.bind.cpp" />
<ClCompile Include="..\..\..\Runtime\Utilities\Base64.cpp" />
<ClCompile Include="..\..\..\Runtime\Utilities\Utf8.cpp" />
</ItemGroup>
@@ -209,8 +223,21 @@
<ClInclude Include="..\..\..\Editor\Win\Win.h" />
<ClInclude Include="..\..\..\Runtime\Debug\Log.h" />
<ClInclude Include="..\..\..\Runtime\FileSystem\Path.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Color.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Device.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\DeviceDefine.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\FrameBuffer.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\GlyphAtlas.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\GpuDataBuffer.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\ImageData.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\OpenGL.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Point.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\PolyLine.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Quad.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\RenderTexture.h" />
<ClInclude Include="..\..\..\Runtime\Graphics\Shader.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Texture.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\VertexBuffer.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBind.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindCFunctions.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.hpp" />
@@ -236,6 +263,8 @@
<ClInclude Include="..\..\..\Runtime\Math\Rect.h" />
<ClInclude Include="..\..\..\Runtime\Math\Vector2.h" />
<ClInclude Include="..\..\..\Runtime\Math\Vector3.h" />
+ <ClInclude Include="..\..\..\Runtime\Profiling\FrameStats.h" />
+ <ClInclude Include="..\..\..\Runtime\Profiling\Profiler.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\Assert.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\Base64.h" />
<ClInclude Include="..\..\..\Runtime\Utilities\Exception.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
index 9ae1dba..a23c44b 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
@@ -88,6 +88,12 @@
<Filter Include="Runtime\Lua\LuaBind\signal">
<UniqueIdentifier>{86d0c80c-7c35-425d-87c8-0529ef352650}</UniqueIdentifier>
</Filter>
+ <Filter Include="Runtime\Profiling">
+ <UniqueIdentifier>{dbc5b9a8-4107-4324-aa71-e6a9a7b6d23d}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Runtime\Scripting\Rendering">
+ <UniqueIdentifier>{6f4bc8ff-dc74-4866-938a-febc29400151}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\Editor\GUI\Dock.cpp">
@@ -237,6 +243,48 @@
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindHelper.cpp">
<Filter>Runtime\Lua\LuaBind</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\Device.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\FrameBuffer.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\GlyphAtlas.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\GpuDataBuffer.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\ImageData.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\Point.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\PolyLine.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\Quad.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\RenderTexture.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\Texture.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Graphics\VertexBuffer.cpp">
+ <Filter>Runtime\Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Profiling\FrameStats.cpp">
+ <Filter>Runtime\Profiling</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Scripting\Rendering\Shader.bind.cpp">
+ <Filter>Runtime\Scripting\Rendering</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Scripting\Rendering\Rendering.bind.cpp">
+ <Filter>Runtime\Scripting\Rendering</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\Editor\GUI\Dock.h">
@@ -392,6 +440,51 @@
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindHelper.h">
<Filter>Runtime\Lua\LuaBind</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\Color.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\Device.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\DeviceDefine.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\FrameBuffer.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\GlyphAtlas.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\GpuDataBuffer.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\ImageData.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\Point.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\PolyLine.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\Quad.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\RenderTexture.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\Texture.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Graphics\VertexBuffer.h">
+ <Filter>Runtime\Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Profiling\FrameStats.h">
+ <Filter>Runtime\Profiling</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Profiling\Profiler.h">
+ <Filter>Runtime\Profiling</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua
new file mode 100644
index 0000000..75e6f18
--- /dev/null
+++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua
@@ -0,0 +1,8 @@
+local m = GameLab.Engine.Rendering or {}
+GameLab.Engine.Rendering = m
+
+m.LoadTexture = function(path)
+
+end
+
+return m \ No newline at end of file
diff --git a/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua b/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua
index 5b1b140..22869e5 100644
--- a/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua
+++ b/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua
@@ -1,8 +1,8 @@
local EditorWindow = GameLab.Class("EditorWindow", "GameLab.Editor.GUI")
EditorWindow.Ctor = function(self, title)
- self.title = title
- self.guiWindow = nil
+ self.title = title -- 缂栬緫鍣ㄥ悕绉
+ self.guiWindow = nil -- 缁戝畾鐨凣UIWindow
end
EditorWindow.OnGUI = function(self)
diff --git a/Runtime/Graphics/Scripting/wrap_Device.cpp b/Resources/Libraries/GameLab/Editor/GUI/Functions.lua
index e69de29..e69de29 100644
--- a/Runtime/Graphics/Scripting/wrap_Device.cpp
+++ b/Resources/Libraries/GameLab/Editor/GUI/Functions.lua
diff --git a/Resources/Libraries/GameLab/Editor/GUI/init.lua b/Resources/Libraries/GameLab/Editor/GUI/init.lua
index a9c6ac9..e1b4576 100644
--- a/Resources/Libraries/GameLab/Editor/GUI/init.lua
+++ b/Resources/Libraries/GameLab/Editor/GUI/init.lua
@@ -5,6 +5,6 @@ local require = GameLab.require(...)
m.EditorWindow = require("EditorWindow")
-
+require("Functions")
return m \ No newline at end of file
diff --git a/Resources/Libraries/GameLab/Editor/Resource/ResourceManager b/Resources/Libraries/GameLab/Editor/Resource/ResourceManager
new file mode 100644
index 0000000..b28b04f
--- /dev/null
+++ b/Resources/Libraries/GameLab/Editor/Resource/ResourceManager
@@ -0,0 +1,3 @@
+
+
+
diff --git a/Resources/Scripts/Editor/AssetBrowser.lua b/Resources/Scripts/Editor/AssetBrowser.lua
index 07cead4..ee6de6a 100644
--- a/Resources/Scripts/Editor/AssetBrowser.lua
+++ b/Resources/Scripts/Editor/AssetBrowser.lua
@@ -3,14 +3,17 @@ local AssetBrowser = GameLab.Editor.GUI.EditorWindow.Extend("AssetBrowser", "Gam
AssetBrowser.Ctor = function(self)
self.base.Ctor(self, "AssetBrowser")
+
end
AssetBrowser.OnGUI = function(self)
- Debug.Log("AssetBrowser.OnGUI()" .. self.title)
+
+
end
AssetBrowser.OnFocus = function(self)
- Debug.Log("AssetBrowser.OnFocus()" .. self.title)
+
+
end
return AssetBrowser \ No newline at end of file
diff --git a/Resources/Scripts/EditorApplication.lua b/Resources/Scripts/EditorApplication.lua
index 8a175db..92bc5b9 100644
--- a/Resources/Scripts/EditorApplication.lua
+++ b/Resources/Scripts/EditorApplication.lua
@@ -39,6 +39,96 @@ local V4 = GameLab.Engine.Math.Vector4.Extend("V4", "GameLab.Engine.Math")
Debug.Log(EditorWindowManager.name)
+local vert = [[
+ #version 330 core
+ layout (location = 0) in vec3 aPos;
+ layout (location = 1) in vec3 aNormal;
+ layout (location = 2) in vec2 aTexCoords;
+ layout (location = 3) in vec3 aTangent;
+ layout (location = 4) in vec3 aBitangent;
+
+ out VS_OUT {
+ vec3 FragPos;
+ vec2 TexCoords;
+ vec3 TangentLightPos;
+ vec3 TangentViewPos;
+ vec3 TangentFragPos;
+ } vs_out;
+
+ uniform mat4 projection;
+ uniform mat4 view;
+ uniform mat4 model;
+
+ uniform vec3 lightPos;
+ uniform vec3 viewPos;
+
+ void main()
+ {
+ vs_out.FragPos = vec3(model * vec4(aPos, 1.0));
+ vs_out.TexCoords = aTexCoords;
+
+ mat3 normalMatrix = transpose(inverse(mat3(model)));
+ vec3 T = normalize(normalMatrix * aTangent);
+ vec3 N = normalize(normalMatrix * aNormal);
+ T = normalize(T - dot(T, N) * N);
+ vec3 B = cross(N, T);
+
+ mat3 TBN = transpose(mat3(T, B, N));
+ vs_out.TangentLightPos = TBN * lightPos;
+ vs_out.TangentViewPos = TBN * viewPos;
+ vs_out.TangentFragPos = TBN * vs_out.FragPos;
+
+ gl_Position = projection * view * model * vec4(aPos, 1.0);
+ }
+]]
+
+local frag = [[
+ #version 330 core
+ out vec4 FragColor;
+
+ in VS_OUT {
+ vec3 FragPos;
+ vec2 TexCoords;
+ vec3 TangentLightPos;
+ vec3 TangentViewPos;
+ vec3 TangentFragPos;
+ } fs_in;
+
+ uniform sampler2D diffuseMap;
+ uniform sampler2D normalMap;
+
+ uniform vec3 lightPos;
+ uniform vec3 viewPos;
+
+ void main()
+ {
+ // obtain normal from normal map in range [0,1]
+ vec3 normal = texture(normalMap, fs_in.TexCoords).rgb;
+ // transform normal vector to range [-1,1]
+ normal = normalize(normal * 2.0 - 1.0); // this normal is in tangent space
+
+ // get diffuse color
+ vec3 color = texture(diffuseMap, fs_in.TexCoords).rgb;
+ // ambient
+ vec3 ambient = 0.1 * color;
+ // diffuse
+ vec3 lightDir = normalize(fs_in.TangentLightPos - fs_in.TangentFragPos);
+ float diff = max(dot(lightDir, normal), 0.0);
+ vec3 diffuse = diff * color;
+ // specular
+ vec3 viewDir = normalize(fs_in.TangentViewPos - fs_in.TangentFragPos);
+ vec3 reflectDir = reflect(-lightDir, normal);
+ vec3 halfwayDir = normalize(lightDir + viewDir);
+ float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0);
+
+ vec3 specular = vec3(0.2) * spec;
+ FragColor = vec4(ambient + diffuse + specular, 1.0);
+ }
+]]
+
+local shader = GameLab.Engine.Rendering.Shader.New(vert, frag)
+Debug.Log("shader is " .. inspect(shader:IsValid()))
+
while true do
app:PullMessage()
diff --git a/Runtime/Graphics/Device.cpp b/Runtime/Graphics/Device.cpp
index d729a37..8136a54 100644
--- a/Runtime/Graphics/Device.cpp
+++ b/Runtime/Graphics/Device.cpp
@@ -5,10 +5,15 @@ Device g_Device;
Device::Device()
{
- Assert(deviceInited);
+ //Assert(deviceInited);
deviceInited = true;
}
+Device::~Device()
+{
+
+}
+
void Device::Initialize(DeviceSetting& setting)
{
GPU::BufferPool::Instance()->Initialize();
diff --git a/Runtime/Graphics/Device.h b/Runtime/Graphics/Device.h
index 4e02b72..e445efa 100644
--- a/Runtime/Graphics/Device.h
+++ b/Runtime/Graphics/Device.h
@@ -18,7 +18,7 @@ struct DeviceSetting
class Device : public NonCopyable
{
-public:
+public:
Device();
~Device();
@@ -41,7 +41,8 @@ public:
void EndFrame();
void PresentFrame();
- GET(SharedVertexBuffer*, SharedVBO, m_SharedVBO);
+ //GET(SharedVertexBuffer*, SharedVBO, m_SharedVBO);
+ SharedVertexBuffer* GetSharedVBO() { return &m_SharedVBO; }
GET_SET(Color, ClearColor, m_ClearColor);
diff --git a/Runtime/Graphics/FrameBuffer.cpp b/Runtime/Graphics/FrameBuffer.cpp
index e675aab..af4d831 100644
--- a/Runtime/Graphics/FrameBuffer.cpp
+++ b/Runtime/Graphics/FrameBuffer.cpp
@@ -3,10 +3,10 @@
// 有些版本的OpenGL不支持绑定多个RT
bool FrameBuffer::BindRenderTexture(RenderTexture* rt, int location /* = 0 */)
{
-
+ return false;
}
bool FrameBuffer::Blit(FrameBuffer* target)
{
-
+ return false;
}
diff --git a/Runtime/Graphics/GpuDataBuffer.cpp b/Runtime/Graphics/GpuDataBuffer.cpp
index 0b3e4ee..d20be65 100644
--- a/Runtime/Graphics/GpuDataBuffer.cpp
+++ b/Runtime/Graphics/GpuDataBuffer.cpp
@@ -193,7 +193,7 @@ namespace GPU
return 0;
}
- DataBuffer* ClaimBuffer(int size = 0, GLenum usage = GL_ARRAY_BUFFER)
+ DataBuffer* ClaimBuffer(int size, GLenum usage )
{
return BufferPool::Instance()->ClaimBuffer(size, usage);
}
diff --git a/Runtime/Graphics/ImageData.cpp b/Runtime/Graphics/ImageData.cpp
index e69de29..8e2e4bf 100644
--- a/Runtime/Graphics/ImageData.cpp
+++ b/Runtime/Graphics/ImageData.cpp
@@ -0,0 +1,2 @@
+#include "ImageData.h"
+
diff --git a/Runtime/Graphics/ImageData.h b/Runtime/Graphics/ImageData.h
index cd56e83..a3162bc 100644
--- a/Runtime/Graphics/ImageData.h
+++ b/Runtime/Graphics/ImageData.h
@@ -3,6 +3,7 @@
#include <vector>
+// 图片像素数据
class ImageData
{
public:
diff --git a/Runtime/Graphics/Scripting/wrap_GL.cpp b/Runtime/Graphics/Scripting/wrap_GL.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Runtime/Graphics/Scripting/wrap_GL.cpp
+++ /dev/null
diff --git a/Runtime/Graphics/Scripting/wrap_RenderTexture.cpp b/Runtime/Graphics/Scripting/wrap_RenderTexture.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Runtime/Graphics/Scripting/wrap_RenderTexture.cpp
+++ /dev/null
diff --git a/Runtime/Graphics/Shader.cpp b/Runtime/Graphics/Shader.cpp
index e69de29..b8b9e33 100644
--- a/Runtime/Graphics/Shader.cpp
+++ b/Runtime/Graphics/Shader.cpp
@@ -0,0 +1,146 @@
+#include <exception>
+#include "Runtime/Debug/log.h"
+#include "Shader.h"
+#include "OpenGL.h"
+
+void checkCompileshaderErrorors(GLuint shader, std::string type)
+{
+ GLint success;
+ GLchar infoLog[1024];
+ std::string shaderError = "";
+ if (type != "PROGRAM")
+ {
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
+ if (!success)
+ {
+ glGetShaderInfoLog(shader, 1024, NULL, infoLog);
+ shaderError = "ERROR::SHADER_COMPILATION_ERROR of type: " + type + "\n" + infoLog;
+ }
+ }
+ else
+ {
+ glGetProgramiv(shader, GL_LINK_STATUS, &success);
+ if (!success)
+ {
+ glGetProgramInfoLog(shader, 1024, NULL, infoLog);
+ shaderError = "ERROR::SHADER_COMPILATION_ERROR of type: " + type + "\n" + infoLog;
+ }
+ }
+ if (!success)
+ {
+ throw ShaderCompileExecption(shaderError);
+ }
+}
+
+Shader::Shader(LuaBind::VM*vm, bool keepSrc)
+ : NativeClass<Shader>(vm)
+ , m_KeepSrc(keepSrc)
+{
+}
+
+Shader::Shader(LuaBind::VM* vm, std::string& vert, std::string& frag, bool keepSrc)
+ : NativeClass<Shader>(vm)
+ , m_KeepSrc(keepSrc)
+{
+ const char* vertCode = vert.c_str();
+ const char* fragCode = frag.c_str();
+ // vertex shader
+ m_VertID = glCreateShader(GL_VERTEX_SHADER);
+ glShaderSource(m_VertID, 1, &vertCode, NULL);
+ glCompileShader(m_VertID);
+ checkCompileshaderErrorors(m_VertID, "VERTEX");
+ // fragment Shader
+ m_FragID = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(m_FragID, 1, &fragCode, NULL);
+ glCompileShader(m_FragID);
+ checkCompileshaderErrorors(m_FragID, "FRAGMENT");
+ // create program
+ m_ProgramID = glCreateProgram();
+ glAttachShader(m_ProgramID, m_VertID);
+ glAttachShader(m_ProgramID, m_FragID);
+ glLinkProgram(m_ProgramID);
+ checkCompileshaderErrorors(m_FragID, "PROGRAM");
+ // keep src
+ if (keepSrc)
+ {
+ m_VertSrc = vert;
+ m_FragSrc = frag;
+ }
+}
+
+Shader::~Shader()
+{
+ glDeleteProgram(m_ProgramID);
+ glDeleteShader(m_VertID);
+ glDeleteShader(m_FragID);
+}
+
+void Shader::ReCompile(std::string& vert, std::string frag)
+{
+ const char* vertCode = vert.c_str();
+ const char* fragCode = frag.c_str();
+ // vertex shader
+ glShaderSource(m_VertID, 1, &vertCode, NULL);
+ glCompileShader(m_VertID);
+ checkCompileshaderErrorors(m_VertID, "VERTEX");
+ // fragment Shader
+ glShaderSource(m_FragID, 1, &fragCode, NULL);
+ glCompileShader(m_FragID);
+ checkCompileshaderErrorors(m_FragID, "FRAGMENT");
+ // create program
+ glAttachShader(m_ProgramID, m_VertID);
+ glAttachShader(m_ProgramID, m_FragID);
+ glLinkProgram(m_ProgramID);
+ checkCompileshaderErrorors(m_FragID, "PROGRAM");
+ //
+ if (m_KeepSrc)
+ {
+ m_VertSrc = vert;
+ m_FragSrc = frag;
+ }
+}
+
+void Shader::ReCompileVert(std::string& vert)
+{
+ glDeleteShader(m_VertID);
+ const char* vertCode = vert.c_str();
+ // vertex shader
+ glShaderSource(m_VertID, 1, &vertCode, NULL);
+ glCompileShader(m_VertID);
+ checkCompileshaderErrorors(m_VertID, "VERTEX");
+ // create program
+ glAttachShader(m_ProgramID, m_VertID);
+ glAttachShader(m_ProgramID, m_FragID);
+ glLinkProgram(m_ProgramID);
+ checkCompileshaderErrorors(m_FragID, "PROGRAM");
+ //
+ if (m_KeepSrc)
+ {
+ m_VertSrc = vert;
+ }
+}
+
+void Shader::ReCompileFrag(std::string frag)
+{
+ glDeleteShader(m_FragID);
+ const char* fragCode = frag.c_str();
+ // fragment Shader
+ glShaderSource(m_FragID, 1, &fragCode, NULL);
+ glCompileShader(m_FragID);
+ checkCompileshaderErrorors(m_FragID, "FRAGMENT");
+ // create program
+ glAttachShader(m_ProgramID, m_VertID);
+ glAttachShader(m_ProgramID, m_FragID);
+ glLinkProgram(m_ProgramID);
+ checkCompileshaderErrorors(m_FragID, "PROGRAM");
+ //
+ if (m_KeepSrc)
+ {
+ m_FragSrc = frag;
+ }
+}
+
+bool Shader::IsValid()
+{
+ return m_ProgramID != 0;
+} \ No newline at end of file
diff --git a/Runtime/Graphics/Shader.h b/Runtime/Graphics/Shader.h
index b22a05f..7cca768 100644
--- a/Runtime/Graphics/Shader.h
+++ b/Runtime/Graphics/Shader.h
@@ -1,6 +1,60 @@
#pragma once
+#include <string>
+#include <exception>
+#include "Runtime/Graphics/OpenGL.h"
+#include "Runtime/Lua/LuaHelper.h"
+#include "Runtime/Utilities/UtilMacros.h"
+#include "runtime/Debug/Log.h"
-class Shader
+// 着色器程序
+class Shader : public LuaBind::NativeClass<Shader>
{
+public:
+ Shader(LuaBind::VM*vm, bool keepSrc = false);
+ Shader(LuaBind::VM*vm, std::string& vert, std::string& frag, bool keepSrc = false)/*throw(ShaderCompileExecption)*/;
+ ~Shader();
+
+ void ReCompile(std::string& vert, std::string frag)/*throw(ShaderCompileExecption)*/;
+ void ReCompileVert(std::string& vert)/*throw(ShaderCompileExecption)*/;
+ void ReCompileFrag(std::string frag)/*throw(ShaderCompileExecption)*/;
+
+ bool IsValid();
+
+ GET(GLint, ID, m_ProgramID);
+
+private:
+ bool m_KeepSrc;
+
+ std::string m_VertSrc;
+ std::string m_FragSrc;
+
+ GLint m_ProgramID;
+ GLint m_FragID;
+ GLint m_VertID;
+
+ LUA_BIND_DECL_CLASS(Shader);
+
+ LUA_BIND_DECL_METHOD(_New);
+ LUA_BIND_DECL_METHOD(_ReCompile);
+ LUA_BIND_DECL_METHOD(_ReCompileVert);
+ LUA_BIND_DECL_METHOD(_ReCompileFrag);
+ LUA_BIND_DECL_METHOD(_IsValid);
+ LUA_BIND_DECL_METHOD(_GetVertCode);
+ LUA_BIND_DECL_METHOD(_GetFragCode);
};
+
+class ShaderCompileExecption : public std::exception
+{
+public:
+ ShaderCompileExecption(std::string& err)
+ {
+ m_Err = err;
+ }
+ char const* what() const override
+ {
+ return m_Err.c_str();
+ }
+private:
+ std::string m_Err;
+}; \ No newline at end of file
diff --git a/Runtime/Graphics/Texture.h b/Runtime/Graphics/Texture.h
index ce05ff7..d09429c 100644
--- a/Runtime/Graphics/Texture.h
+++ b/Runtime/Graphics/Texture.h
@@ -1,6 +1,8 @@
#ifndef TEXTURE_H
#define TEXTURE_H
+#include "Runtime/Lua/LuaHelper.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
#include "../Utilities/UtilMacros.h"
#include "OpenGL.h"
#include "ImageData.h"
@@ -32,9 +34,9 @@ enum TextureFilter
class Texture
{
public:
+ Texture();
Texture(ImageData* imgData, TextureFormat format);
Texture(ImageData* imgData, TextureFormat format, TextureWrap wrap, TextureFilter filter);
- Texture();
~Texture();
GET(int, Width, m_Width);
diff --git a/Runtime/Graphics/VertexBuffer.cpp b/Runtime/Graphics/VertexBuffer.cpp
index c9f5164..7861d6f 100644
--- a/Runtime/Graphics/VertexBuffer.cpp
+++ b/Runtime/Graphics/VertexBuffer.cpp
@@ -1,5 +1,5 @@
#include "VertexBuffer.h"
-#include "../Profiler/FrameStats.h"
+#include "../Profiling/FrameStats.h"
void SetupDefaultVertexArray(const VertexArrayInfo& info);
void InvalidateVertexInputCache();
diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h
index 33c0783..9179e0d 100644
--- a/Runtime/Graphics/VertexBuffer.h
+++ b/Runtime/Graphics/VertexBuffer.h
@@ -69,6 +69,9 @@ private:
class SharedVertexBuffer
{
public:
+ SharedVertexBuffer();
+ ~SharedVertexBuffer();
+
void GetChunk(uint attrs, int maxVerts, int maxIndices, RenderMode mode, void **out_vb, void **out_ib);
void ReleaseChunk(int actualVerts, int actualIndices);
diff --git a/Runtime/Lua/LuaBind/LuaBindRef.cpp b/Runtime/Lua/LuaBind/LuaBindRef.cpp
index b2f8e1c..d0f2766 100644
--- a/Runtime/Lua/LuaBind/LuaBindRef.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindRef.cpp
@@ -4,24 +4,24 @@
namespace LuaBind
{
- Ref::Ref(LuaBind::VM* vm, RefMode mode)
+ UniversalRef::UniversalRef(LuaBind::VM* vm, RefMode mode)
: mRefID(LUA_NOREF)
, mMode(mode)
, mOwner(vm)
{
}
- Ref::~Ref()
+ UniversalRef::~UniversalRef()
{
// 自动释放引用
}
- Ref::operator bool()
+ UniversalRef::operator bool()
{
return (mRefID != LUA_NOREF);
}
- void Ref::UnRef()
+ void UniversalRef::UnRef()
{
if (mRefID == LUA_NOREF)
return;
@@ -41,7 +41,7 @@ namespace LuaBind
}
}
- void Ref::SetRef(LuaBind::State& state, int idx)
+ void UniversalRef::SetRef(LuaBind::State& state, int idx)
{
assert(state.GetVM() == mOwner);
@@ -59,7 +59,7 @@ namespace LuaBind
}
}
- bool Ref::PushRef(LuaBind::State& state)
+ bool UniversalRef::PushRef(LuaBind::State& state)
{
assert(mRefID != LUA_NOREF);
@@ -84,12 +84,12 @@ namespace LuaBind
}
StrongRef::StrongRef(LuaBind::VM* vm)
- : Ref(vm, STRONG_REF)
+ : UniversalRef(vm, STRONG_REF)
{
}
WeakRef::WeakRef(LuaBind::VM* vm)
- : Ref(vm, WEAK_REF)
+ : UniversalRef(vm, WEAK_REF)
{
}
diff --git a/Runtime/Lua/LuaBind/LuaBindRef.h b/Runtime/Lua/LuaBind/LuaBindRef.h
index c7b7ab3..793559e 100644
--- a/Runtime/Lua/LuaBind/LuaBindRef.h
+++ b/Runtime/Lua/LuaBind/LuaBindRef.h
@@ -9,7 +9,7 @@ namespace LuaBind
// 全局引用,保存在LUA_REGISTRYINDEX下面的两个表里,生命周期手动控制
// 如果要用局部引用,用MemberRef,会保存在UserData的RefTable里,生命周期和UserData一致
- class Ref
+ class UniversalRef
{
public:
enum RefMode
@@ -18,8 +18,8 @@ namespace LuaBind
WEAK_REF
};
- Ref(LuaBind::VM* vm, RefMode mode = STRONG_REF);
- virtual ~Ref();
+ UniversalRef(LuaBind::VM* vm, RefMode mode = STRONG_REF);
+ virtual ~UniversalRef();
operator bool();
@@ -43,7 +43,7 @@ namespace LuaBind
};
// 强引用,在LUA_REGISTRYINDEX["GAMELAB_UNIVERSAL_STRONG_REFERENCE_TABLE"]里,保证lua object不会被回收
- class StrongRef: public Ref
+ class StrongRef: public UniversalRef
{
public:
StrongRef(LuaBind::VM* vm);
@@ -51,7 +51,7 @@ namespace LuaBind
};
// 弱引用,在LUA_REGISTRYINDEX["GAMELAB_UNIVERSAL_WEAK_REFERENCE_TABLE"]里,不影响lua object的回收,只是作为一个方便取lua object的映射
- class WeakRef : public Ref
+ class WeakRef : public UniversalRef
{
public:
WeakRef(LuaBind::VM* vm);
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h
index 60e05be..c81ba8c 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.h
+++ b/Runtime/Lua/LuaBind/LuaBindState.h
@@ -227,9 +227,8 @@ namespace LuaBind
//--------------------------------------------------------------------------------//
- // 确保不安全的lua调用能够在调用之后返回到最初stack状态。
- class ScopedState
- : public State
+ // RAII, 确保不安全的lua调用能够在调用之后返回到最初stack状态。
+ class ScopedState : public State
{
public:
ScopedState(lua_State* state)
@@ -253,7 +252,6 @@ namespace LuaBind
private:
void* operator new(size_t);
int mRestoreTop;
-
};
// 注册工厂,注册class table,以type name为键设置在名称空间上。在注册阶段不会设置元表,等到New方法调用的时候才会。
diff --git a/Runtime/Lua/LuaBind/LuaBindUtility.h b/Runtime/Lua/LuaBind/LuaBindUtility.h
index 94f2e9c..7e6eb77 100644
--- a/Runtime/Lua/LuaBind/LuaBindUtility.h
+++ b/Runtime/Lua/LuaBind/LuaBindUtility.h
@@ -6,10 +6,10 @@
// RegisterClass 注册类的方法和成员,比如枚举、常量等到class table GetNativeClassName 获得工厂的类名,
// 同时用来避免注册时错误注册为了singleton,通过编译时报错避免
#define LUA_BIND_DECL_CLASS(type, ...) \
- friend class ::State; \
- friend class ::NativeClass<type,##__VA_ARGS__>; \
- static void RegisterClass(::State&); \
- static void RegisterPostprocess(::State&); \
+ friend class LuaBind::State; \
+ friend class LuaBind::NativeClass<type,##__VA_ARGS__>; \
+ static void RegisterClass(LuaBind::State&); \
+ static void RegisterPostprocess(LuaBind::State&); \
static const char* GetNativeClassName() { return #type; };\
static const char* GetClassName() { return #type; };
diff --git a/Runtime/Lua/LuaBind/LuaBindVM.cpp b/Runtime/Lua/LuaBind/LuaBindVM.cpp
index e454929..7a56013 100644
--- a/Runtime/Lua/LuaBind/LuaBindVM.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindVM.cpp
@@ -62,7 +62,10 @@ namespace LuaBind
void VM::SetCurThread(lua_State* cur)
{
- mCurThread = cur;
+ if (this)
+ {
+ mCurThread = cur;
+ }
}
lua_State* VM::GetCurThread()
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp
index 53bea3f..e458e28 100644
--- a/Runtime/Lua/LuaHelper.cpp
+++ b/Runtime/Lua/LuaHelper.cpp
@@ -3,9 +3,9 @@
using namespace LuaBind;
template <>
-Rectf State::GetValue < Rectf >(int idx, const Rectf value)
+Rect State::GetValue < Rect >(int idx, const Rect value)
{
- Rectf rect;
+ Rect rect;
rect.x = GetField<float>(idx, 1, 0);
rect.y = GetField<float>(idx, 2, 0);
rect.width = GetField<float>(idx, 3, 0);
@@ -14,9 +14,9 @@ Rectf State::GetValue < Rectf >(int idx, const Rectf value)
}
template <>
-Vector2f State::GetValue < Vector2f >(int idx, const Vector2f value)
+Vector2 State::GetValue < Vector2 >(int idx, const Vector2 value)
{
- Vector2f v2;
+ Vector2 v2;
v2.x = GetField<float>(idx, 1, 0);
v2.y = GetField<float>(idx, 2, 0);
return v2;
diff --git a/Runtime/Lua/LuaHelper.h b/Runtime/Lua/LuaHelper.h
index 4ab0d6a..10d9421 100644
--- a/Runtime/Lua/LuaHelper.h
+++ b/Runtime/Lua/LuaHelper.h
@@ -3,6 +3,8 @@
#include "Runtime/Math/Vector2.h"
#include "./LuaBind/LuaBind.h"
+// lua 5.1 doc: https://www.lua.org/manual/5.1/
+
class LuaHelper
{
public:
diff --git a/Runtime/Math/FloatConversion.h b/Runtime/Math/FloatConversion.h
index 96a4d1d..e69de29 100644
--- a/Runtime/Math/FloatConversion.h
+++ b/Runtime/Math/FloatConversion.h
@@ -1,697 +0,0 @@
-#ifndef FLOATCONVERSION_H
-#define FLOATCONVERSION_H
-
-#include <algorithm>
-#include <cmath>
-#include <limits>
-#include <math.h>
-
-#include "Runtime/Utilities/Type.h"
-#include "Runtime/Utilities/Assert.h"
-
-#if defined(SN_TARGET_PS3)
-# include <ppu_intrinsics.h>
-#elif defined(__GNUC__) && defined(__ppc__)
-# include <ppc_intrinsics.h>
-#endif
-
-#ifndef kPI
-#define kPI 3.14159265358979323846264338327950288419716939937510F
-#endif
-
-const float kBiggestFloatSmallerThanOne = 0.99999994f;
-const double kBiggestDoubleSmallerThanOne = 0.99999999999999989;
-
-#if defined(_XBOX)
-#define __FSELF __fself
-#elif defined(SN_TARGET_PS3)
-#define __FSELF __fsels
-#endif
-
-inline float FloatMin(float a, float b)
-{
-#if defined(_XBOX) || defined(SN_TARGET_PS3)
- return __FSELF((a)-(b), b, a);
-#else
- // return std::min(a, b);
- return a < b ? a : b;
-#endif
-}
-
-inline float FloatMax(float a, float b)
-{
-#if defined(_XBOX) || defined(SN_TARGET_PS3)
- return __FSELF((a)-(b), a, b);
-#else
- //return std::max(a, b);
- return a > b ? a : b;
-#endif
-}
-
-inline float Abs(float v)
-{
-#if defined(__ppc__) && (defined(__MWERKS__) || defined(SN_TARGET_PS3))
- return __fabsf(v);
-#elif defined(_XBOX)
- return __fabs(v);
-#else
- return v < 0.0F ? -v : v;
-#endif
-}
-
-inline double Abs(double v)
-{
- return v < 0.0 ? -v : v;
-}
-
-inline int Abs(int v)
-{
- return v < 0 ? -v : v;
-}
-
-// Floor, ceil and round functions.
-//
-// When changing or implementing these functions, make sure the tests in MathTest.cpp
-// still pass.
-//
-// Floor: rounds to the largest integer smaller than or equal to the input parameter.
-// Ceil: rounds to the smallest integer larger than or equal to the input parameter.
-// Round: rounds to the nearest integer. Ties (0.5) are rounded up to the smallest integer
-// larger than or equal to the input parameter.
-// Chop/truncate: use a normal integer cast.
-//
-// Windows:
-// Casts are as fast as a straight fistp on an SSE equipped CPU. This is by far the most common
-// scenario and will result in the best code for most users. fistp will use the rounding mode set
-// in the control register (round to nearest by default), and needs fiddling to work properly.
-// This actually makes code that attempt to use fistp slower than a cast.
-// Unless we want round to nearest, in which case fistp should be the best choice, right? But
-// it is not. The default rounding mode is round to nearest, but in case of a tie (0.5), round to
-// nearest even is used. Thus 0.5 is rounded down to 0, 1.5 is rounded up to 2.
-// Conclusion - fistp is useless without stupid fiddling around that actually makes is slower than
-// an SSE cast.
-//
-// OS X Intel:
-// Needs investigating
-//
-// OS X PowerPC:
-// Needs investigating
-//
-// Xbox 360:
-// Needs investigating
-//
-// PS3:
-// Needs investigating
-//
-// iPhone:
-// Needs investigating
-//
-// Android:
-// Needs investigating
-
-
-inline int FloorfToInt(float f)
-{
- DebugAssertIf(f < INT_MIN || f > INT_MAX);
- return f >= 0 ? (int)f : (int)(f - kBiggestFloatSmallerThanOne);
-}
-
-inline UInt32 FloorfToIntPos(float f)
-{
- DebugAssertIf(f < 0 || f > UINT_MAX);
- return (UInt32)f;
-}
-
-inline float Floorf(float f)
-{
- // Use std::floor().
- // We are interested in reliable functions that do not lose precision.
- // Casting to int and back to float would not be helpful.
- return floor(f);
-}
-
-inline double Floord(double f)
-{
- // Use std::floor().
- // We are interested in reliable functions that do not lose precision.
- // Casting to int and back to float would not be helpful.
- return floor(f);
-}
-
-
-inline int CeilfToInt(float f)
-{
- DebugAssertIf(f < INT_MIN || f > INT_MAX);
- return f >= 0 ? (int)(f + kBiggestFloatSmallerThanOne) : (int)(f);
-}
-
-inline UInt32 CeilfToIntPos(float f)
-{
- DebugAssertIf(f < 0 || f > UINT_MAX);
- return (UInt32)(f + kBiggestFloatSmallerThanOne);
-}
-
-inline float Ceilf(float f)
-{
- // Use std::ceil().
- // We are interested in reliable functions that do not lose precision.
- // Casting to int and back to float would not be helpful.
- return ceil(f);
-}
-
-inline double Ceild(double f)
-{
- // Use std::ceil().
- // We are interested in reliable functions that do not lose precision.
- // Casting to int and back to float would not be helpful.
- return ceil(f);
-}
-
-
-inline int RoundfToInt(float f)
-{
- return FloorfToInt(f + 0.5F);
-}
-
-inline UInt32 RoundfToIntPos(float f)
-{
- return FloorfToIntPos(f + 0.5F);
-}
-
-inline float Roundf(float f)
-{
- return Floorf(f + 0.5F);
-}
-
-inline double Roundf(double f)
-{
- return Floord(f + 0.5);
-}
-
-
-// Fast conversion of float [0...1] to 0 ... 65535
-inline int NormalizedToWord(float f)
-{
- f = FloatMax(f, 0.0F);
- f = FloatMin(f, 1.0F);
- return RoundfToIntPos(f * 65535.0f);
-}
-
-// Fast conversion of float [0...1] to 0 ... 65535
-inline float WordToNormalized(int p)
-{
- AssertIf(p < 0 || p > 65535);
- return (float)p / 65535.0F;
-}
-
-// Fast conversion of float [0...1] to 0 ... 255
-inline int NormalizedToByte(float f)
-{
- f = FloatMax(f, 0.0F);
- f = FloatMin(f, 1.0F);
- return RoundfToIntPos(f * 255.0f);
-}
-
-// Fast conversion of float [0...1] to 0 ... 255
-inline float ByteToNormalized(int p)
-{
- AssertIf(p < 0 || p > 255);
- return (float)p / 255.0F;
-}
-
-
-// Returns float remainder for t / length
-inline float Repeat(float t, float length)
-{
- return t - Floorf(t / length) * length;
-}
-
-// Returns double remainder for t / length
-inline double RepeatD(double t, double length)
-{
- return t - floor(t / length) * length;
-}
-
-// Returns relative angle on the interval (-pi, pi]
-inline float DeltaAngleRad(float current, float target)
-{
- float delta = Repeat((target - current), 2 * kPI);
- if (delta > kPI)
- delta -= 2 * kPI;
- return delta;
-}
-
-// Returns true if the distance between f0 and f1 is smaller than epsilon
-inline bool CompareApproximately(float f0, float f1, float epsilon = 0.000001F)
-{
- float dist = (f0 - f1);
- dist = Abs(dist);
- return dist < epsilon;
-}
-
-// CopySignf () returns x with its sign changed to y's.
-inline float CopySignf(float x, float y)
-{
- union
- {
- float f;
- UInt32 i;
- } u, u0, u1;
- u0.f = x; u1.f = y;
- UInt32 a = u0.i;
- UInt32 b = u1.i;
- SInt32 mask = 1 << 31;
- UInt32 sign = b & mask;
- a &= ~mask;
- a |= sign;
-
- u.i = a;
- return u.f;
-}
-
-inline int CompareFloatRobustSignUtility(float A)
-{
- // The sign bit of a number is the high bit.
- union
- {
- float f;
- int i;
- } u;
- u.f = A;
- return (u.i) & 0x80000000;
-}
-
-inline bool CompareFloatRobust(float f0, float f1, int maxUlps = 10)
-{
- // After adjusting floats so their representations are lexicographically
- // ordered as twos-complement integers a very small positive number
- // will compare as 'close' to a very small negative number. If this is
- // not desireable, and if you are on a platform that supports
- // subnormals (which is the only place the problem can show up) then
- // you need this check.
- // The check for A == B is because zero and negative zero have different
- // signs but are equal to each other.
- if (CompareFloatRobustSignUtility(f0) != CompareFloatRobustSignUtility(f1))
- return f0 == f1;
-
- union
- {
- float f;
- int i;
- } u0, u1;
- u0.f = f0;
- u1.f = f1;
- int aInt = u0.i;
- // Make aInt lexicographically ordered as a twos-complement int
- if (aInt < 0)
- aInt = 0x80000000 - aInt;
- // Make bInt lexicographically ordered as a twos-complement int
- int bInt = u1.i;
- if (bInt < 0)
- bInt = 0x80000000 - bInt;
-
- // Now we can compare aInt and bInt to find out how far apart A and B
- // are.
- int intDiff = Abs(aInt - bInt);
- if (intDiff <= maxUlps)
- return true;
- return false;
-}
-
-// Returns the t^2
-template<class T>
-T Sqr(const T& t)
-{
- return t * t;
-}
-
-#define kDeg2Rad (2.0F * kPI / 360.0F)
-#define kRad2Deg (1.F / kDeg2Rad)
-
-inline float Deg2Rad(float deg)
-{
- // TODO : should be deg * kDeg2Rad, but can't be changed,
- // because it changes the order of operations and that affects a replay in some RegressionTests
- return deg / 360.0F * 2.0F * kPI;
-}
-
-inline float Rad2Deg(float rad)
-{
- // TODO : should be rad * kRad2Deg, but can't be changed,
- // because it changes the order of operations and that affects a replay in some RegressionTests
- return rad / 2.0F / kPI * 360.0F;
-}
-
-inline float Lerp(float from, float to, float t)
-{
- return to * t + from * (1.0F - t);
-}
-
-inline bool IsNAN(float value)
-{
-#if defined __APPLE_CC__
- return value != value;
-#elif _MSC_VER
- return _isnan(value) != 0;
-#else
- return isnan(value);
-#endif
-}
-
-inline bool IsNAN(double value)
-{
-#if defined __APPLE_CC__
- return value != value;
-#elif _MSC_VER
- return _isnan(value) != 0;
-#else
- return isnan(value);
-#endif
-}
-
-inline bool IsPlusInf(float value) { return value == std::numeric_limits<float>::infinity(); }
-inline bool IsMinusInf(float value) { return value == -std::numeric_limits<float>::infinity(); }
-
-inline bool IsFinite(const float& value)
-{
- // Returns false if value is NaN or +/- infinity
- UInt32 intval = *reinterpret_cast<const UInt32*>(&value);
- return (intval & 0x7f800000) != 0x7f800000;
-}
-
-inline bool IsFinite(const double& value)
-{
- // Returns false if value is NaN or +/- infinity
- UInt64 intval = *reinterpret_cast<const UInt64*>(&value);
- return (intval & 0x7ff0000000000000LL) != 0x7ff0000000000000LL;
-}
-
-inline float InvSqrt(float p) { return 1.0F / sqrt(p); }
-inline float Sqrt(float p) { return sqrt(p); }
-
-// - Almost highest precision sqrt
-// - Returns 0 if value is 0 or -1
-// inline float FastSqrt (float value)
-
-// - Almost highest precision inv sqrt
-// - if value == 0 or -0 it returns 0.
-// inline float FastInvSqrt (float value)
-
-// - Low precision inv sqrt approximately
-// - if value == 0 or -0 it returns nan or undefined
-// inline float FastestInvSqrt (float value)
-
-#if defined(__ppc__) || defined(SN_TARGET_PS3)
-
-#if UNITY_WII
-// Copied from <CodeWarrior>\PowerPC_EABI_Support\MSL\MSL_C\PPC_EABI\Include\math_ppc_inlines.h
-// Requires hardware floating to be enabled
-// P.S I've also profiled with function below which uses fabs(x) == 0.0F, it's two times slower than this one
-inline float FastSqrt(float x)
-{
- static const double _half = .5f;
- static const double _three = 3.0f;
-
- if (x > 0.0f)
- {
- double xd = (double)x;
- double guess = __frsqrte(xd); /* returns an approximation to */
- guess = _half * guess*(_three - guess * guess*xd); /* now have 12 sig bits */
- guess = _half * guess*(_three - guess * guess*xd); /* now have 24 sig bits */
- return (float)(xd * guess);
- }
- else if (x < 0.0)
- return NAN;
- else
- return x;
-}
-#else
-// - Accurate to 1 bit precision
-// - returns zero if x is zero
-inline float FastSqrt(float x)
-{
- const float half = 0.5;
- const float one = 1.0;
- float B, y0, y1;
-
- // This'll NaN if it hits frsqrte. Handle both +0.0 and -0.0
- if (fabs(x) == 0.0F)
- return x;
-
- B = x;
-
-#if defined(__GNUC__) && !defined(SN_TARGET_PS3)
- y0 = __frsqrtes(B);
-#else
- y0 = __frsqrte(B);
-#endif
- // First refinement step
-
- y1 = y0 + half * y0*(one - B * y0*y0);
-
- // Second refinement step -- copy the output of the last step to the input of this step
-
- y0 = y1;
- y1 = y0 + half * y0*(one - B * y0*y0);
-
- // Get sqrt(x) from x * 1/sqrt(x)
- return x * y1;
-}
-#endif
-
-// - Accurate to 1 bit precision
-// - returns zero if f is zero
-inline float FastInvSqrt(float f)
-{
- float result;
- float estimate, estimate2;
- float oneHalf = 0.5f;
- float one = oneHalf + oneHalf;
- //Calculate a 5 bit starting estimate for the reciprocal sqrt
-#if defined(__GNUC__) && !defined(SN_TARGET_PS3)
- estimate = estimate2 = __frsqrtes(f);
-#else
- estimate = estimate2 = __frsqrte(f);
-#endif
-
- //if you require less precision, you may reduce the number of loop iterations
- estimate = estimate + oneHalf * estimate * (one - f * estimate * estimate);
- estimate = estimate + oneHalf * estimate * (one - f * estimate * estimate);
-
-#if defined(__GNUC__) && !defined(SN_TARGET_PS3)
- result = __fsels(-f, estimate2, estimate);
-#else
- result = __fsel(-f, estimate2, estimate);
-#endif
- return result;
-}
-
-// Fast inverse sqrt function
-inline float FastestInvSqrt(float value)
-{
-#if defined (__ppc__) && (defined (__MWERKS__) || defined(SN_TARGET_PS3))
- return (float)__frsqrte(value);
-#elif defined (__ppc__)
- return (float)__frsqrtes(value);
-#else
- return 1.0F / sqrtf(value);
-#endif
-}
-
-#else
-
-inline float FastSqrt(float value)
-{
- return sqrtf(value);
-}
-
-inline float FastInvSqrt(float f)
-{
- // The Newton iteration trick used in FastestInvSqrt is a bit faster on
- // Pentium4 / Windows, but lower precision. Doing two iterations is precise enough,
- // but actually a bit slower.
- if (fabs(f) == 0.0F)
- return f;
- return 1.0F / sqrtf(f);
-}
-
-inline float FastestInvSqrt(float f)
-{
- union
- {
- float f;
- int i;
- } u;
- float fhalf = 0.5f*f;
- u.f = f;
- int i = u.i;
- i = 0x5f3759df - (i >> 1);
- u.i = i;
- f = u.f;
- f = f * (1.5f - fhalf * f*f);
- // f = f*(1.5f - fhalf*f*f); // uncommenting this would be two iterations
- return f;
-}
-
-#endif
-
-inline float SqrtImpl(float f)
-{
-#if UNITY_WII || UNITY_FLASH
- return FastSqrt(f);
-#else
- return sqrt(f);
-#endif
-}
-inline float Sin(float f)
-{
- return sinf(f);
-}
-
-inline float Pow(float f, float f2)
-{
- return powf(f, f2);
-}
-
-inline float Cos(float f)
-{
- return cosf(f);
-}
-
-inline float Sign(float f)
-{
-#if defined(_XBOX)
- return __fsel(f, 1.0f, -1.0f);
-#else
- if (f < 0.0F)
- return -1.0F;
- else
- return 1.0;
-#endif
-}
-
-#if UNITY_EDITOR
-
-class FloatToHalfConverter
-{
-public:
- FloatToHalfConverter();
-
- void Convert(const float& src, UInt16& dest)
- {
- UInt32 bits = *reinterpret_cast<const UInt32*>(&src);
- UInt8 index = UInt8(bits >> 23);
- UInt32 sign = bits & 0x80000000;
- UInt32 mantissa = bits & 0x007fffff;
- dest = (sign >> 16) | m_ExponentTable[index] | (mantissa >> m_MantissaShift[index]);
- }
-
-private:
- UInt16 m_ExponentTable[256];
- UInt8 m_MantissaShift[256];
-};
-
-extern FloatToHalfConverter g_FloatToHalf;
-
-#endif // UNITY_EDITOR
-
-#if UNITY_SUPPORTS_SSE
-#include "Runtime/Math/Simd/SimdMath.h"
-
-#define SSE_CONST4(name, val) static const ALIGN16 UInt32 name[4] = { (val), (val), (val), (val) }
-#define CONST_M128I(name) *(const __m128i *)&name
-
-static ALIGN16 UInt16 source[] = { 0,0,0,0,0,0,0,0 };
-static ALIGN16 float destination[] = { 0.0,0.0,0.0,0.0 };
-
-static void HalfToFloat(UInt16 src, float& dest)
-{
- SSE_CONST4(mask_nosign, 0x7fff);
- SSE_CONST4(smallest_normal, 0x0400);
- SSE_CONST4(infinity, 0x7c00);
- SSE_CONST4(expadjust_normal, (127 - 15) << 23);
- SSE_CONST4(magic_denorm, 113 << 23);
-
- source[0] = src;
- __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i*>(source));
- __m128i mnosign = CONST_M128I(mask_nosign);
- __m128i eadjust = CONST_M128I(expadjust_normal);
- __m128i smallest = CONST_M128I(smallest_normal);
- __m128i infty = CONST_M128I(infinity);
- __m128i expmant = _mm_and_si128(mnosign, in);
- __m128i justsign = _mm_xor_si128(in, expmant);
- __m128i b_notinfnan = _mm_cmpgt_epi32(infty, expmant);
- __m128i b_isdenorm = _mm_cmpgt_epi32(smallest, expmant);
- __m128i shifted = _mm_slli_epi32(expmant, 13);
- __m128i adj_infnan = _mm_andnot_si128(b_notinfnan, eadjust);
- __m128i adjusted = _mm_add_epi32(eadjust, shifted);
- __m128i den1 = _mm_add_epi32(shifted, CONST_M128I(magic_denorm));
- __m128i adjusted2 = _mm_add_epi32(adjusted, adj_infnan);
- __m128 den2 = _mm_sub_ps(_mm_castsi128_ps(den1), *(const __m128 *)&magic_denorm);
- __m128 adjusted3 = _mm_and_ps(den2, _mm_castsi128_ps(b_isdenorm));
- __m128 adjusted4 = _mm_andnot_ps(_mm_castsi128_ps(b_isdenorm), _mm_castsi128_ps(adjusted2));
- __m128 adjusted5 = _mm_or_ps(adjusted3, adjusted4);
- __m128i sign = _mm_slli_epi32(justsign, 16);
- __m128 out = _mm_or_ps(adjusted5, _mm_castsi128_ps(sign));
- _mm_storeu_ps(destination, out);
- dest = destination[0];
-#undef SSE_CONST4
-#undef CONST_M128I
-}
-
-#else
-
-static void HalfToFloat(UInt16 src, float& dest)
-{
- // Integer alias
- UInt32& bits = *reinterpret_cast<UInt32*>(&dest);
-
- // Based on Fabian Giesen's public domain half_to_float_fast3
- static const UInt32 magic = { 113 << 23 };
- const float& magicFloat = *reinterpret_cast<const float*>(&magic);
- static const UInt32 shiftedExp = 0x7c00 << 13; // exponent mask after shift
-
- // Mask out sign bit
- bits = src & 0x7fff;
- if (bits)
- {
- // Move exponent + mantissa to correct bits
- bits <<= 13;
- UInt32 exponent = bits & shiftedExp;
- if (exponent == 0)
- {
- // Handle denormal
- bits += magic;
- dest -= magicFloat;
- }
- else if (exponent == shiftedExp) // Inf/NaN
- bits += (255 - 31) << 23;
- else
- bits += (127 - 15) << 23;
- }
-
- // Copy sign bit
- bits |= (src & 0x8000) << 16;
-}
-
-#endif
-
-using std::cos;
-using std::pow;
-using std::atan2;
-using std::acos;
-using std::sin;
-using std::sqrt;
-using std::log;
-using std::exp;
-
-// On non-C99 platforms log2 is not available, so approximate it.
-#if UNITY_WIN || UNITY_XENON || UNITY_ANDROID || UNITY_FLASH || UNITY_WEBGL
-#define kNaturalLogarithm2 0.693147180559945309417
-#define Log2(x) (logf(x) / kNaturalLogarithm2)
-#else
-#define Log2(x) log2f(x)
-#endif
-
-
-#endif
diff --git a/Runtime/Math/Rect.h b/Runtime/Math/Rect.h
index dbd147c..4725375 100644
--- a/Runtime/Math/Rect.h
+++ b/Runtime/Math/Rect.h
@@ -1,150 +1,6 @@
-#ifndef RECT_H
-#define RECT_H
+#pragma once
-#include "Vector2.h"
-
-// A rectangle.
-template <typename T>
-class RectT
-{
-public:
- typedef RectT<T> RectType;
- typedef float BaseType;
-
- T x; //< Rectangle x coordinate.
- T y; //< Rectangle y coordinate.
- T width; //< Rectangle width.
- T height; //< Rectangle height.
-
- inline static const char* GetTypeString();
- inline static bool IsAnimationChannel() { return false; }
- inline static bool MightContainPPtr() { return false; }
- // Create a empty rectangle.
- RectT()
- {
- Reset();
- }
-
- // Create a new rectangle.
- RectT(T inX, T inY, T iWidth, T iHeight)
- {
- x = inX; width = iWidth;
- y = inY; height = iHeight;
- }
-
- T GetRight() const { return x + width; }
- T GetBottom() const { return y + height; }
- void SetLeft(T l) { T oldXMax = GetXMax(); x = l; width = oldXMax - x; }
- void SetTop(T t) { T oldYMax = GetYMax(); y = t; height = oldYMax - y; }
- void SetRight(T r) { width = r - x; }
- void SetBottom(T b) { height = b - y; }
-
-
- T GetXMax() const { return x + width; }
- T GetYMax() const { return y + height; }
-
- // Return true if rectangle is empty.
- inline bool IsEmpty() const { return width <= 0 || height <= 0; }
-
- inline void SetPosition(const Vector2f& position) { x = position.x; y = position.y; }
- inline Vector2f GetPosition() const { return Vector2f(x, y); }
-
- inline void SetSize(const Vector2f& size) { width = size.x; height = size.y; }
- inline Vector2f GetSize() const { return Vector2f(width, height); }
- // Resets the rectangle
- inline void Reset() { x = y = width = height = 0; }
-
- // Sets the rectangle
- inline void Set(T inX, T inY, T iWidth, T iHeight)
- {
- x = inX; width = iWidth;
- y = inY; height = iHeight;
- }
-
- inline void Scale(T dx, T dy) { x *= dx; width *= dx; y *= dy; height *= dy; }
-
- // Set Center position of rectangle (size stays the same)
- void SetCenterPos(T cx, T cy) { x = cx - width / 2; y = cy - height / 2; }
- Vector2f GetCenterPos() const { return Vector2f(x + (BaseType)width / 2, y + (BaseType)height / 2); }
-
- // Ensure this is inside the rect r.
- void Clamp(const RectType &r)
- {
- T x2 = x + width;
- T y2 = y + height;
- T rx2 = r.x + r.width;
- T ry2 = r.y + r.height;
-
- if (x < r.x) x = r.x;
- if (x2 > rx2) x2 = rx2;
- if (y < r.y) y = r.y;
- if (y2 > ry2) y2 = ry2;
-
- width = x2 - x;
- if (width < 0) width = 0;
-
- height = y2 - y;
- if (height < 0) height = 0;
- }
-
- // Move rectangle by deltaX, deltaY.
- inline void Move(T dX, T dY) { x += dX; y += dY; }
-
- // Return the width of rectangle.
- inline T Width() const { return width; }
-
- // Return the height of rectangle.
- inline T Height() const { return height; }
-
- // Return true if a point lies within rectangle bounds.
- inline bool Contains(T px, T py) const { return (px >= x) && (px < x + width) && (py >= y) && (py < y + height); }
- inline bool Contains(const Vector2f& p) const { return Contains(p.x, p.y); }
- // Return true if a relative point lies within rectangle bounds.
- inline bool ContainsRel(T x, T y) const
- {
- return (x >= 0) && (x < Width()) && (y >= 0) && (y < Height());
- }
-
- inline bool Intersects(const RectType& r) const
- {
- // Rects are disjoint if there's at least one separating axis
- bool disjoint = x + width < r.x;
- disjoint |= r.x + r.width < x;
- disjoint |= y + height < r.y;
- disjoint |= r.y + r.height < y;
- return !disjoint;
- }
-
- // Normalize a rectangle such that xmin <= xmax and ymin <= ymax.
- inline void Normalize()
- {
- width = std::max<T>(width, 0);
- height = std::max<T>(height, 0);
- }
-
- bool operator == (const RectType& r)const { return x == r.x && y == r.y && width == r.width && height == r.height; }
- bool operator != (const RectType& r)const { return x != r.x || y != r.y || width != r.width || height != r.height; }
-};
-
-typedef RectT<float> Rectf;
-typedef RectT<int> RectInt;
-
-template<> inline const char* Rectf::GetTypeString() { return "Rectf"; }
-template<> inline const char* RectInt::GetTypeString() { return "RectInt"; }
-
-inline bool CompareApproximately(const Rectf& lhs, const Rectf& rhs)
+struct Rect
{
- return CompareApproximately(lhs.x, rhs.x) && CompareApproximately(lhs.y, rhs.y) &&
- CompareApproximately(lhs.width, rhs.width) && CompareApproximately(lhs.height, rhs.height);
-}
-
-// Make a rect with width & height
-template<typename T>
-inline RectT<T> MinMaxRect(T minx, T miny, T maxx, T maxy) { return RectT<T>(minx, miny, maxx - minx, maxy - miny); }
-
-// RectT<float> specialization
-template<>
-inline bool Rectf::IsEmpty() const { return width <= 0.00001F || height <= 0.00001F; }
-
-
-#endif
+ int x, y, width, height;
+}; \ No newline at end of file
diff --git a/Runtime/Math/Vector2.cpp b/Runtime/Math/Vector2.cpp
index e636362..2b70b24 100644
--- a/Runtime/Math/Vector2.cpp
+++ b/Runtime/Math/Vector2.cpp
@@ -1,11 +1,4 @@
#include "Vector2.h"
-using namespace std;
-
-const float Vector2f::epsilon = 0.00001F;
-const float Vector2f::infinity = numeric_limits<float>::infinity();
-const Vector2f Vector2f::infinityVec = Vector2f(numeric_limits<float>::infinity(), numeric_limits<float>::infinity());
-
-const Vector2f Vector2f::zero = Vector2f(0, 0);
-const Vector2f Vector2f::xAxis = Vector2f(1, 0);
-const Vector2f Vector2f::yAxis = Vector2f(0, 1);
+Vector2 Vector2::one = Vector2(1, 1);
+Vector2 Vector2::zero = Vector2(0, 0);
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h
index 62f4659..5fb230c 100644
--- a/Runtime/Math/Vector2.h
+++ b/Runtime/Math/Vector2.h
@@ -1,112 +1,30 @@
-#ifndef VECTOR2_H
-#define VECTOR2_H
+#pragma once
-#include "FloatConversion.h"
-
-class Vector2f
+struct Vector2
{
-public:
- float x, y;
-
-
- Vector2f() : x(0.f), y(0.f) {}
- Vector2f(float inX, float inY) { x = inX; y = inY; }
- explicit Vector2f(const float* p) { x = p[0]; y = p[1]; }
-
- void Set(float inX, float inY) { x = inX; y = inY; }
-
- float* GetPtr() { return &x; }
- const float* GetPtr()const { return &x; }
- float& operator[] (int i) { DebugAssertIf(i < 0 || i > 1); return (&x)[i]; }
- const float& operator[] (int i)const { DebugAssertIf(i < 0 || i > 1); return (&x)[i]; }
-
- Vector2f& operator += (const Vector2f& inV) { x += inV.x; y += inV.y; return *this; }
- Vector2f& operator -= (const Vector2f& inV) { x -= inV.x; y -= inV.y; return *this; }
- Vector2f& operator *= (const float s) { x *= s; y *= s; return *this; }
- Vector2f& operator /= (const float s) { DebugAssertIf(CompareApproximately(s, 0.0F)); x /= s; y /= s; return *this; }
- bool operator == (const Vector2f& v)const { return x == v.x && y == v.y; }
- bool operator != (const Vector2f& v)const { return x != v.x || y != v.y; }
-
-
- Vector2f operator - () const { return Vector2f(-x, -y); }
-
- Vector2f& Scale(const Vector2f& inV) { x *= inV.x; y *= inV.y; return *this; }
-
- static const float epsilon;
- static const float infinity;
- static const Vector2f infinityVec;
- static const Vector2f zero;
- static const Vector2f xAxis;
- static const Vector2f yAxis;
-};
-//inline Vector2f Scale(const Vector2f& lhs, const Vector2f& rhs) { return Vector2f(lhs.x * rhs.x, lhs.y * rhs.y); }
-//
-//inline Vector2f operator + (const Vector2f& lhs, const Vector2f& rhs) { return Vector2f(lhs.x + rhs.x, lhs.y + rhs.y); }
-//inline Vector2f operator - (const Vector2f& lhs, const Vector2f& rhs) { return Vector2f(lhs.x - rhs.x, lhs.y - rhs.y); }
-//inline float Dot(const Vector2f& lhs, const Vector2f& rhs) { return lhs.x * rhs.x + lhs.y * rhs.y; }
-//
-//inline float SqrMagnitude(const Vector2f& inV) { return Dot(inV, inV); }
-//inline float Magnitude(const Vector2f& inV) { return SqrtImpl(Dot(inV, inV)); }
-//
-//inline float Angle(const Vector2f& lhs, const Vector2f& rhs) { return acos(std::min(1.0f, std::max(-1.0f, Dot(lhs, rhs) / (Magnitude(lhs) * Magnitude(rhs))))); }
-//
-//inline Vector2f operator * (const Vector2f& inV, float s) { return Vector2f(inV.x * s, inV.y * s); }
-//inline Vector2f operator * (const float s, const Vector2f& inV) { return Vector2f(inV.x * s, inV.y * s); }
-//inline Vector2f operator / (const Vector2f& inV, float s) { Vector2f temp(inV); temp /= s; return temp; }
-//inline Vector2f Inverse(const Vector2f& inVec) { return Vector2f(1.0F / inVec.x, 1.0F / inVec.y); }
-//
-/// Normalizes a vector, asserts if the vector can be normalized
-//inline Vector2f Normalize(const Vector2f& inV) { return inV / Magnitude(inV); }
-/// Normalizes a vector, returns default vector if it can't be normalized
-//inline Vector2f NormalizeSafe(const Vector2f& inV, const Vector2f& defaultV = Vector2f::zero);
-//
-//inline Vector2f Lerp(const Vector2f& from, const Vector2f& to, float t) { return to * t + from * (1.0f - t); }
-//
-/// Returns a vector with the smaller of every component from v0 and v1
-//inline Vector2f min(const Vector2f& lhs, const Vector2f& rhs) { return Vector2f(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y)); }
-/// Returns a vector with the larger of every component from v0 and v1
-//inline Vector2f max(const Vector2f& lhs, const Vector2f& rhs) { return Vector2f(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y)); }
-//
-//bool CompareApproximately(const Vector2f& inV0, const Vector2f& inV1, float inMaxDist = Vector2f::epsilon);
-//
-//inline bool CompareApproximately(const Vector2f& inV0, const Vector2f& inV1, float inMaxDist)
-//{
-// return SqrMagnitude(inV1 - inV0) < inMaxDist * inMaxDist;
-//}
-//
-//inline bool IsNormalized(const Vector2f& vec, float epsilon = Vector2f::epsilon)
-//{
-// return CompareApproximately(SqrMagnitude(vec), 1.0F, epsilon);
-//}
-//
-//// Returns the abs of every component of the vector
-//inline Vector2f Abs(const Vector2f& v) { return Vector2f(Abs(v.x), Abs(v.y)); }
-//
-//inline bool IsFinite(const Vector2f& f)
-//{
-// return IsFinite(f.x) & IsFinite(f.y);
-//}
-//
-//inline Vector2f NormalizeFast(const Vector2f& inV)
-//{
-// float m = SqrMagnitude(inV);
-// // GCC version of __frsqrte:
-// // static inline double __frsqrte (double x) {
-// // double y;
-// // asm ( "frsqrte %0, %1" : /*OUT*/ "=f" (y) : /*IN*/ "f" (x) );
-// // return y;
-// // }
-// return inV * FastInvSqrt(m);
-//}
-//
-//inline Vector2f NormalizeSafe(const Vector2f& inV, const Vector2f& defaultV)
-//{
-// float mag = Magnitude(inV);
-// if (mag > Vector2f::epsilon)
-// return inV / Magnitude(inV);
-// else
-// return defaultV;
-//}
-
-
-#endif \ No newline at end of file
+ Vector2(float x=0, float y = 0)
+ {
+ this->x = x;
+ this->y = y;
+ }
+ inline void Set(float x, float y)
+ {
+ this->x = x;
+ this->y = y;
+ }
+
+ bool operator == (const Vector2& v) const
+ {
+ return v.x == x && v.y == y;
+ }
+
+ bool operator != (const Vector2& v) const
+ {
+ return v.x != x || v.y != y;
+ }
+
+ float x, y;
+
+ static Vector2 zero;
+ static Vector2 one;
+}; \ No newline at end of file
diff --git a/Runtime/Math/Vector3.h b/Runtime/Math/Vector3.h
index 041ffef..08e2592 100644
--- a/Runtime/Math/Vector3.h
+++ b/Runtime/Math/Vector3.h
@@ -1,9 +1,8 @@
#ifndef VECTOR3_H
#define VECTOR3_H
-class Vector3
+struct Vector3
{
-public:
float x, y, z;
inline void Set(float x, float y, float z)
diff --git a/Runtime/Profiling/FrameStats.cpp b/Runtime/Profiling/FrameStats.cpp
new file mode 100644
index 0000000..a89ef4a
--- /dev/null
+++ b/Runtime/Profiling/FrameStats.cpp
@@ -0,0 +1,12 @@
+#pragma once
+#include "FrameStats.h"
+
+void FrameStats::AddDrawCall(uint n)
+{
+
+}
+
+void FrameStats::AddTrianglesCount(uint n)
+{
+
+} \ No newline at end of file
diff --git a/Runtime/Profiler/FrameStats.h b/Runtime/Profiling/FrameStats.h
index b3073d5..b3073d5 100644
--- a/Runtime/Profiler/FrameStats.h
+++ b/Runtime/Profiling/FrameStats.h
diff --git a/Runtime/Profiler/Profiler.h b/Runtime/Profiling/Profiler.h
index e69de29..e69de29 100644
--- a/Runtime/Profiler/Profiler.h
+++ b/Runtime/Profiling/Profiler.h
diff --git a/Runtime/Scripting/Rendering/Rendering.bind.cpp b/Runtime/Scripting/Rendering/Rendering.bind.cpp
new file mode 100644
index 0000000..29fa421
--- /dev/null
+++ b/Runtime/Scripting/Rendering/Rendering.bind.cpp
@@ -0,0 +1,17 @@
+#include "Runtime/Graphics/Shader.h"
+
+int luaopen_GameLab_Engine_Rendering(lua_State* L)
+{
+ log_info("Scripting", "luaopen_GameLab_Engine_Rendering()");
+
+ LUA_BIND_STATE(L);
+
+ state.PushGlobalNamespace();
+ state.PushNamespace("GameLab");
+ state.PushNamespace("Engine");
+ state.PushNamespace("Rendering");
+
+ state.RegisterNativeClass<Shader>();
+
+ return 1;
+} \ No newline at end of file
diff --git a/Runtime/Scripting/Rendering/Shader.bind.cpp b/Runtime/Scripting/Rendering/Shader.bind.cpp
new file mode 100644
index 0000000..6646407
--- /dev/null
+++ b/Runtime/Scripting/Rendering/Shader.bind.cpp
@@ -0,0 +1,92 @@
+#include "Runtime/Graphics/Shader.h"
+#include "Runtime/Debug/Log.h"
+
+using namespace LuaBind;
+
+LUA_BIND_REGISTRY(Shader)
+{
+ LUA_BIND_REGISTER_METHODS(state,
+ { "New", _New },
+ { "ReCompile", _ReCompile },
+ { "ReCompileVert", _ReCompileVert },
+ { "ReCompileFrag", _ReCompileFrag },
+ { "IsValid", _IsValid },
+ { "GetVertCode", _GetVertCode },
+ { "GetFragCode", _GetFragCode }
+ );
+}
+
+LUA_BIND_POSTPROCESS(Shader)
+{
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _New)
+{
+ LUA_BIND_STATE(L, Shader);
+ LUA_BIND_CHECK(L, "SS*");
+ try {
+ std::string vert, frag;
+ bool keepCode = false;
+ if (state.GetTop() == 2)
+ {
+ vert = state.GetValue<cc8*>(-2, "");
+ frag = state.GetValue<cc8*>(-1, "");
+ }
+ else
+ {
+ vert = state.GetValue<cc8*>(-3, "");
+ frag = state.GetValue<cc8*>(-2, "");
+ keepCode = state.GetValue<bool>(-1, false);
+ }
+ Shader* shader = new Shader(state.GetVM(), vert, frag, keepCode);
+ shader->PushUserdata(state);
+ return 1;
+ }
+ catch (ShaderCompileExecption e)
+ {
+ log_error(e.what());
+ }
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _ReCompile)
+{
+ LUA_BIND_PREPARE(L, Shader);
+
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _ReCompileVert)
+{
+ LUA_BIND_PREPARE(L, Shader);
+
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _ReCompileFrag)
+{
+ LUA_BIND_PREPARE(L, Shader);
+
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _IsValid)
+{
+ LUA_BIND_PREPARE(L, Shader);
+ state.Push(self->IsValid());
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _GetVertCode)
+{
+ LUA_BIND_PREPARE(L, Shader);
+ state.Push(self->m_VertSrc.c_str());
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(Shader, _GetFragCode)
+{
+ LUA_BIND_PREPARE(L, Shader);
+ state.Push(self->m_FragSrc.c_str());
+ return 1;
+} \ No newline at end of file