diff options
author | chai <chaifix@163.com> | 2021-10-27 01:06:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-27 01:06:48 +0800 |
commit | 0035e0d47bbce8311d3a4e559e74b8cdc5209d47 (patch) | |
tree | 51429abc6f8e50af1fc6ecfac0301a5667f6564b | |
parent | 12f3ac102d3aea08af540dd7f2cf0e08e939a70d (diff) |
*load image
-rw-r--r-- | Data/DefaultContent/Libraries/GameLab/Engine/Resource/init.lua | 23 | ||||
-rw-r--r-- | Data/Scripts/EditorApplication.lua | 6 | ||||
-rw-r--r-- | Data/boot.lua | 4 | ||||
-rw-r--r-- | Editor/EditorApplication.cpp | 2 | ||||
-rw-r--r-- | Editor/Utils/EditorUtils.cpp | 0 | ||||
-rw-r--r-- | Editor/Utils/EditorUtils.h | 0 | ||||
-rw-r--r-- | Projects/VisualStudio/Editor/Editor.vcxproj | 2 | ||||
-rw-r--r-- | Projects/VisualStudio/Editor/Editor.vcxproj.filters | 6 | ||||
-rw-r--r-- | Runtime/Scripting/Rendering/Rendering.bind.cpp | 22 | ||||
-rw-r--r-- | Runtime/Scripting/Resource/Resource.bind.cpp | 25 |
10 files changed, 57 insertions, 33 deletions
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Resource/init.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Resource/init.lua index a407869..4942131 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Resource/init.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Resource/init.lua @@ -2,19 +2,36 @@ local m = GameLab.Engine.Resource or {} GameLab.Engine.Resource = m local import = GameLab.import(...) --- classes +---------------------------------------------------------------------------------- +-- native classes +---------------------------------------------------------------------------------- + +---------------------------------------------------------------------------------- +-- native methods +---------------------------------------------------------------------------------- +-- LoadImageDataJob(path, callback) +---------------------------------------------------------------------------------- +-- classes +---------------------------------------------------------------------------------- m.ImageDataRequest = import("ImageDataRequest") +---------------------------------------------------------------------------------- -- methods - +---------------------------------------------------------------------------------- m.LoadImageDataAsync = function(path) local request = GameLab.Engine.Resource.ImageDataRequest.New() - m.ReadImageDataAsync(path, function(imgData) + m.LoadImageDataJob(path, function(imgData) request.isDone = true request.imageData = imgData end) return request end +m.LoadTexture = function(path, keepImgData, type, format, wrapMode, filterMode) + local imgData = GameLab.Engine.Resource.LoadImageData(path) + local tex = GameLab.Engine.Rendering.Texture.New(imgData, keepImgData, type, format, wrapMode, filterMode) + return tex +end + return m
\ No newline at end of file diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua index 6b42175..36c701a 100644 --- a/Data/Scripts/EditorApplication.lua +++ b/Data/Scripts/EditorApplication.lua @@ -64,13 +64,13 @@ GameLab.IO.ReadFilesAsync(files, function() Debug.Log("finished") end) -local imgData = Rendering.LoadImage("./Resources/Images/brickwall.jpg") +local imgData = Resource.LoadImageData("./Resources/Images/brickwall.jpg") Debug.Log(tostring(imgData:GetWidth())) Debug.Log(tostring(imgData:GetHeight())) -local tex = Rendering.Texture.New(imgData, false) +local tex = Resource.LoadTexture("./Resources/Images/brickwall.jpg") -local requets = Resource.LoadImageDataAsync("./Resources/Images/brickwall.jpg") +local request = Resource.LoadImageDataAsync("./Resources/Images/brickwall.jpg") while true do diff --git a/Data/boot.lua b/Data/boot.lua index ad8f4da..62b5d96 100644 --- a/Data/boot.lua +++ b/Data/boot.lua @@ -14,7 +14,7 @@ package.cpath=package.cpath .. ";" .. engineCLibs .. ";" .. editorCLibs -- debugging
-- 在这里会报一个异常, 不知道为什么
---require("LuaPanda").start("127.0.0.1",8818)
+require("LuaPanda").start("127.0.0.1",8818)
-- redirect
if GAMELAB_DEBUG then
@@ -32,7 +32,7 @@ require "GameLab.Editor" require "GameLab.Editor.GUI"
-- debugging
-require("LuaPanda").start("127.0.0.1",8818)
+--require("LuaPanda").start("127.0.0.1",8818)
-- launch editor
dofile("./Scripts/EditorApplication.lua")
diff --git a/Editor/EditorApplication.cpp b/Editor/EditorApplication.cpp index f45a2fc..5089d0b 100644 --- a/Editor/EditorApplication.cpp +++ b/Editor/EditorApplication.cpp @@ -11,7 +11,7 @@ EditorApplication::EditorApplication(LuaBind::VM* vm) Assert(!s_Created);
// ʼjobsystem
- JobSystem::Instance()->Initilize(4);
+ JobSystem::Instance()->Initilize(2);
}
EditorApplication::~EditorApplication()
diff --git a/Editor/Utils/EditorUtils.cpp b/Editor/Utils/EditorUtils.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Editor/Utils/EditorUtils.cpp diff --git a/Editor/Utils/EditorUtils.h b/Editor/Utils/EditorUtils.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Editor/Utils/EditorUtils.h diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index bc3ce5b..024d9d9 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -167,6 +167,7 @@ <ClCompile Include="..\..\..\Editor\Scripting\Editor\EditorApplication.bind.cpp" />
<ClCompile Include="..\..\..\Editor\Scripting\IMGUI\GUIButton.bind.cpp" />
<ClCompile Include="..\..\..\Editor\Shaders\BuiltinShaders.cpp" />
+ <ClCompile Include="..\..\..\Editor\Utils\EditorUtils.cpp" />
<ClCompile Include="..\..\..\Editor\Utils\HelperFuncs.cpp" />
<ClCompile Include="..\..\..\Editor\Win\Win.cpp" />
<ClCompile Include="..\..\..\Runtime\Common\DataBuffer.cpp" />
@@ -236,6 +237,7 @@ <ClInclude Include="..\..\..\Editor\Resource\ResourceManager.h" />
<ClInclude Include="..\..\..\Editor\Scripting\EditorScripting.h" />
<ClInclude Include="..\..\..\Editor\Shaders\BuiltinShaders.h" />
+ <ClInclude Include="..\..\..\Editor\Utils\EditorUtils.h" />
<ClInclude Include="..\..\..\Editor\Utils\HelperFuncs.h" />
<ClInclude Include="..\..\..\Editor\Win\Win.h" />
<ClInclude Include="..\..\..\Runtime\Common\DataBuffer.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index 8dc6c1f..81e2dd9 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -351,6 +351,9 @@ <ClCompile Include="..\..\..\Runtime\Scripting\Resource\Resource.bind.cpp">
<Filter>Runtime\Scripting\Resource</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\Editor\Utils\EditorUtils.cpp">
+ <Filter>Editor\Utils</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\Editor\GUI\Dock.h">
@@ -581,6 +584,9 @@ <ClInclude Include="..\..\..\Runtime\FileSystem\ImageJobs.h">
<Filter>Runtime\FileSystem</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Editor\Utils\EditorUtils.h">
+ <Filter>Editor\Utils</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/Scripting/Rendering/Rendering.bind.cpp b/Runtime/Scripting/Rendering/Rendering.bind.cpp index 40b3ac5..9bb6242 100644 --- a/Runtime/Scripting/Rendering/Rendering.bind.cpp +++ b/Runtime/Scripting/Rendering/Rendering.bind.cpp @@ -2,29 +2,7 @@ #include "Runtime/Graphics/Texture.h" #include "Runtime/Graphics/ImageData.h" -#define STB_IMAGE_IMPLEMENTATION -#include "ThirdParty/stb/stb_image.h" - -// imgData = Rendering.LoadImage(path) -int LoadImage(lua_State* L) -{ - LUA_BIND_STATE(L); - - const char* path = state.GetValue<const char*>(1, ""); - - stbi_set_flip_vertically_on_load(true); - ImageData* data = new ImageData(state.GetVM()); - int channels; - data->pixels = stbi_load(path, &data->width, &data->height, &channels, 0);
- data->format = ImageData::EPixelFormat::RGB; - data->type = ImageData::EPixelElementType::UNSIGNED_BYTE; - - data->PushUserdata(state); - return 1; -} - static luaL_Reg funcs[] = { - {"LoadImage", LoadImage}, {0, 0} }; diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp index 785115a..6f9c0bb 100644 --- a/Runtime/Scripting/Resource/Resource.bind.cpp +++ b/Runtime/Scripting/Resource/Resource.bind.cpp @@ -1,11 +1,14 @@ #include "Runtime/Lua/LuaHelper.h" #include "Runtime/Debug/Log.h" #include "Runtime/FileSystem/ImageJobs.h" +#include "Runtime/Graphics/ImageData.h" +#define STB_IMAGE_IMPLEMENTATION +#include "ThirdParty/stb/stb_image.h" using namespace LuaBind; // Resource.LoadImageDataAsync(path, callback) -int ReadImageDataAsync(lua_State* L) +int LoadImageDataJob(lua_State* L) { LUA_BIND_STATE(L); LUA_BIND_CHECK(L, "SF"); @@ -19,8 +22,26 @@ int ReadImageDataAsync(lua_State* L) return 0; } +int LoadImageData(lua_State* L) +{ + LUA_BIND_STATE(L); + + const char* path = state.GetValue<const char*>(1, ""); + + stbi_set_flip_vertically_on_load(true); + ImageData* data = new ImageData(state.GetVM()); + int channels; + data->pixels = stbi_load(path, &data->width, &data->height, &channels, 0); + data->format = ImageData::EPixelFormat::RGB; + data->type = ImageData::EPixelElementType::UNSIGNED_BYTE; + + data->PushUserdata(state); + return 1; +} + static luaL_Reg funcs[] = { - {"ReadImageDataAsync", ReadImageDataAsync}, + { "LoadImageData", LoadImageData }, + { "LoadImageDataJob", LoadImageDataJob }, {0, 0} }; |