From 5c4384b589ce146828a8c83a64b16c720338f21b Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 22 Sep 2022 20:53:03 +0800 Subject: [PATCH] Fixed SHVkBuffer initial copy data for mapped buffers and made the cube spin --- .../src/Application/SBApplication.cpp | 6 +++-- SHADE_Application/src/Scenes/SBTestScene.cpp | 21 +++++++++--------- SHADE_Application/src/Scenes/SBTestScene.h | 2 +- .../src/Graphics/Buffers/SHVkBuffer.cpp | 14 ++++++++---- .../MiddleEnd/Interface/SHRenderable.cpp | 1 - TempShaderFolder/TestCubeVs.glsl | 2 +- TempShaderFolder/TestCubeVs.spv | Bin 1768 -> 1804 bytes 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 53cc1e40..93d1cdff 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -22,8 +22,8 @@ #include "ECS_Base/Managers/SHEntityManager.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Scene/SHSceneManager.h" - #include "Scenes/SBTestScene.h" +#include "Math/Transform/SHTransformComponent.h" using namespace SHADE; @@ -58,8 +58,10 @@ namespace Sandbox SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHComponentManager::CreateComponentSparseSet(); + SHADE::SHComponentManager::CreateComponentSparseSet(); + SHADE::SHComponentManager::CreateComponentSparseSet(); + // Set up graphics system and windows graphicsSystem->SetWindow(&window); sdlWindow = SDL_CreateWindowFrom(window.GetHWND()); diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index 93d4e19b..e6082d3f 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -30,8 +30,6 @@ namespace Sandbox } void SBTestScene::Init() { - SHComponentManager::CreateComponentSparseSet(); - SHADE::SHGraphicsSystem* graphicsSystem = static_cast(SHADE::SHSystemManager::GetSystem()); // Create temp meshes const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem); @@ -41,27 +39,28 @@ namespace Sandbox auto matInst = graphicsSystem->AddMaterialInstance(); // Create entity and add mesh - testEntity = SHADE::SHEntityManager::CreateEntity(); - SHComponentManager::AddComponent(testEntity); - auto& renderable = *SHADE::SHComponentManager::GetComponent_s(testEntity); - auto& transform = *SHADE::SHComponentManager::GetComponent_s(testEntity); + testObj = SHADE::SHEntityManager::CreateEntity(); + //SHComponentManager::AddComponent(testObj); + auto& renderable = *SHADE::SHComponentManager::GetComponent_s(testObj); + auto& transform = *SHADE::SHComponentManager::GetComponent_s(testObj); renderable.Mesh = CUBE_MESH; renderable.SetMaterial(matInst); renderable.TransformMatrix.Translate(0.0f, 0.0f, 2.0f); - - transform.SetWorldPosition (SHVec3 (0.0f, 0.0f, 2.0f)); // Add script SHADE::SHScriptEngine* scriptEngine = static_cast(SHADE::SHSystemManager::GetSystem()); - scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testEntity), "TestScript"); + scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript"); } + void SBTestScene::Update(float dt) { static float rotation = 0.0f; - auto& transform = *SHADE::SHComponentManager::GetComponent_s(testEntity); - transform.SetWorldRotation (rotation, 0.0f, 0.0f); + auto& renderable = *SHADE::SHComponentManager::GetComponent_s(testObj); + SHTransform tf; + tf.rotation = SHVec3(rotation, 0.0f, 0.0f); + renderable.TransformMatrix = tf.ComputeTRS(); rotation += dt * 10.0f; diff --git a/SHADE_Application/src/Scenes/SBTestScene.h b/SHADE_Application/src/Scenes/SBTestScene.h index bb382477..81ee3e7b 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.h +++ b/SHADE_Application/src/Scenes/SBTestScene.h @@ -9,7 +9,7 @@ namespace Sandbox { private: EntityID camera; - unsigned int testEntity; + EntityID testObj; public: virtual void Load(); diff --git a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.cpp b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.cpp index 59916731..da4bc292 100644 --- a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.cpp +++ b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.cpp @@ -419,14 +419,20 @@ namespace SHADE // mainly host visible. Can be cached (need to flush/invalidate), uncached (always coherent) and coherent (virtual). if(memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { - if (allocFlags | VMA_ALLOCATION_CREATE_MAPPED_BIT) - mappedPtr = allocInfo.pMappedData; + const bool CREATE_MAPPED = allocFlags & VMA_ALLOCATION_CREATE_MAPPED_BIT; + + if (CREATE_MAPPED) + mappedPtr = allocInfo.pMappedData; else mappedPtr = nullptr; - if (data) - MapWriteUnmap(data, srcSize, 0, 0); + { + if (CREATE_MAPPED) + WriteToMemory(data, srcSize, 0, 0); + else + MapWriteUnmap(data, srcSize, 0, 0); + } } else { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index 984e753b..32a6a99a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -27,7 +27,6 @@ namespace SHADE sharedMaterial = {}; material = {}; oldMaterial = {}; - } void SHRenderable::OnDestroy() diff --git a/TempShaderFolder/TestCubeVs.glsl b/TempShaderFolder/TestCubeVs.glsl index 1e3a11d7..b2d52104 100644 --- a/TempShaderFolder/TestCubeVs.glsl +++ b/TempShaderFolder/TestCubeVs.glsl @@ -57,6 +57,6 @@ void main() // render NDC first //gl_Position = vec4(aVertexPos, 1.0f); - gl_Position = cameraData.vpMat * vec4 (aVertexPos, 1.0f); + gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); Out.vertColor = vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeVs.spv b/TempShaderFolder/TestCubeVs.spv index f0b31ea23f835273164024fc22e42f8e3c4cc918..eb9a1209e697acf798dc5ab441bdbdfed631bc9c 100644 GIT binary patch literal 1804 zcmZ9LYflqF6o$uM06{=RE-KcRdPflzh>1~S3Mn6|U_ib$lXfMWY`4vJTQ8sd3;L7% zRemw?eRg-qhH1{udEfKSnKNgm#X^13m`i5b%$i-3js;T?W6X@1NakkixV1TqyPMlP zTPWsCF%hDfH&+tBq;JpqAz)T^LspSJmc5j1%XVZ%{R*1@XmLrqHe2oH;bF72-|h?s z?P2^q@Y;bNdhMF$S&>`4gFzTE>G9HrCAgMa`Yudd^6XzxJb`dlK1j_@y89QZ0SA z>9KW2xT1L|jzJHcKUQZN{h%L-N5fqmj^f1U&g|z?`K9FU>_?@yfp9swM|)z!GcTk( zb0Cg>Gu-Sr&H=~lIC=?3-yDYz$2~R`!AD2j^{Fn*IFJgCoaF?k8Zerx7dSoegd;EO z$lFv7db)lA*Mu3w-5XA8Dkblk-ZF^OuRNw_VCo>wn+Lo7c>iF|x+oUDCIrS`mN%if zDqGQd>ISp_lD<=#t1`w$hA+!!zct}$&FJAO^5~(*N`nDt=p0zG|M z)66-k7yWI`#Ng3`-950M>!~q6-=V*+IBTi7B9H$AKCwrdiNTQz%ss=g_jAqU<1FZ3 zXl8GC^kCiroU4U*kjK0O@UC7jdFUg9J^qT}O~2QdzAVe=9sPPEB|TY@!8?3YKK=Qv zHNaiFLz}0FNNZ K|EH|4Wd8wmlZ7(? literal 1768 zcmZ9LYflqF6ovA)6cQnt1#>m=i~9Dg9|GoNw`AM0r!p4p%3jC{`b}#7qs2w-+Gw^LtyZIX*zODl z?P2^Q@Y;bNdhMp&^2?c)S}q13ZLFE~OPV{m^>FmqrpMD+&=t&MughQqHC z8*`)x{bsn?ahwB=*>Us|j=nh#AC7x$D1wiUxa(6*m~kW(963t~PBmaO*Di5-;0Z@w z){(cN9Q1Va65bGI5U0PD1f`h1Vcsen`^;;u z%E-$;-~}0DO_=_Ym%1wY(o@%C@?RI`Jn-ZP(`z`F?}mKxqhHQqt!GM$e`xGVtCUZ^rbH=GI~e9-b$JFDCNQQ