From 1056301981ee30f1a72882c395a78e5204bc5e78 Mon Sep 17 00:00:00 2001 From: Patedam Date: Sun, 22 Feb 2026 17:47:46 -0500 Subject: [PATCH] Fix some errors with meshrenderer moving to engine that gemini didnt have time to fix Will have to resync how to load more meshes. Probably need a command to do it but for now not needed. --- .../Core/Application/ApplicationManager.h | 1 + .../include/Core/Application/IApplication.h | 23 +++--- Juliet/include/Engine/Engine.h | 2 +- Juliet/include/Graphics/MeshRenderer.h | 13 ++-- Juliet/src/Engine/Engine.cpp | 32 ++++++--- Juliet/src/Graphics/MeshRenderer.cpp | 29 +++++--- JulietApp/main.cpp | 72 ++----------------- JulietApp/main.h | 9 ++- 8 files changed, 74 insertions(+), 107 deletions(-) diff --git a/Juliet/include/Core/Application/ApplicationManager.h b/Juliet/include/Core/Application/ApplicationManager.h index 3672694..3666f35 100644 --- a/Juliet/include/Core/Application/ApplicationManager.h +++ b/Juliet/include/Core/Application/ApplicationManager.h @@ -8,5 +8,6 @@ namespace Juliet { enum class JulietInit_Flags : uint8; + struct Arena; extern JULIET_API void StartApplication(IApplication& app, JulietInit_Flags flags); } // namespace Juliet diff --git a/Juliet/include/Core/Application/IApplication.h b/Juliet/include/Core/Application/IApplication.h index f8e9d03..1101bb7 100644 --- a/Juliet/include/Core/Application/IApplication.h +++ b/Juliet/include/Core/Application/IApplication.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace Juliet { struct RenderPass; @@ -7,25 +9,26 @@ namespace Juliet struct Texture; struct ColorTargetInfo; struct DepthStencilTargetInfo; + struct Arena; class IApplication { public: - virtual ~IApplication() = default; - virtual void Init() = 0; - virtual void Shutdown() = 0; - virtual void Update() = 0; - virtual bool IsRunning() = 0; + virtual ~IApplication() = default; + virtual void Init(NonNullPtr arena) = 0; + virtual void Shutdown() = 0; + virtual void Update() = 0; + virtual bool IsRunning() = 0; // Accessors for Engine Systems virtual struct Window* GetPlatformWindow() = 0; virtual struct GraphicsDevice* GetGraphicsDevice() = 0; // Render Lifecycle (Engine-Managed Render Loop) - virtual void OnPreRender(CommandList* cmd) = 0; - virtual void OnRender(RenderPass* pass, CommandList* cmd) = 0; - virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0; - virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0; - virtual struct Camera GetDebugCamera() = 0; + virtual void OnPreRender(CommandList* cmd) = 0; + virtual void OnRender(RenderPass* pass, CommandList* cmd) = 0; + virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0; + virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0; + virtual struct Camera GetDebugCamera() = 0; }; } // namespace Juliet diff --git a/Juliet/include/Engine/Engine.h b/Juliet/include/Engine/Engine.h index ea7dfb0..466fa4d 100644 --- a/Juliet/include/Engine/Engine.h +++ b/Juliet/include/Engine/Engine.h @@ -15,7 +15,7 @@ namespace Juliet void InitializeEngine(JulietInit_Flags flags); void ShutdownEngine(); - void LoadApplication(IApplication& app, Arena* arena); + void LoadApplication(IApplication& app); void UnloadApplication(); void RunEngine(); diff --git a/Juliet/include/Graphics/MeshRenderer.h b/Juliet/include/Graphics/MeshRenderer.h index a8df0b6..81b5683 100644 --- a/Juliet/include/Graphics/MeshRenderer.h +++ b/Juliet/include/Graphics/MeshRenderer.h @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include namespace Juliet @@ -41,16 +41,17 @@ namespace Juliet GraphicsPipeline* Pipeline; }; - [[nodiscard]] JULIET_API bool InitializeMeshRenderer(NonNullPtr arena, NonNullPtr device, - NonNullPtr window); - JULIET_API void ShutdownMeshRenderer(); - JULIET_API void LoadMeshesOnGPU(NonNullPtr cmdList); + JULIET_API void InitializeMeshRenderer(NonNullPtr arena); + [[nodiscard]] JULIET_API bool InitializeMeshRendererGraphics(NonNullPtr device, NonNullPtr window); + JULIET_API void ShutdownMeshRendererGraphics(); + JULIET_API void ShutdownMeshRenderer(); + JULIET_API void LoadMeshesOnGPU(NonNullPtr cmdList); JULIET_API void RenderMeshes(NonNullPtr pass, NonNullPtr cmdList, PushData& pushData); // Utils [[nodiscard]] JULIET_API MeshID AddCube(); [[nodiscard]] JULIET_API MeshID AddQuad(); - JULIET_API void SetMeshTransform(MeshID id, const Matrix& transform); + JULIET_API void SetMeshTransform(MeshID id, const Matrix& transform); #if ALLOW_SHADER_HOT_RELOAD JULIET_API void ReloadMeshRendererShaders(); diff --git a/Juliet/src/Engine/Engine.cpp b/Juliet/src/Engine/Engine.cpp index 60b0476..95a991a 100644 --- a/Juliet/src/Engine/Engine.cpp +++ b/Juliet/src/Engine/Engine.cpp @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include #include #include @@ -41,8 +41,13 @@ namespace Juliet DebugDisplay_Initialize(device); if (Window* window = EngineInstance.Application->GetPlatformWindow()) { - InitializeMeshRenderer(EngineInstance.PlatformArena, device, window); - InitializeSkyboxRenderer(device, window); + bool success = InitializeMeshRendererGraphics(device, window); + Assert(success); + (void)(success); + + success = InitializeSkyboxRenderer(device, window); + Assert(success); + (void)(success); } } @@ -81,7 +86,7 @@ namespace Juliet { DebugDisplay_Shutdown(device); ShutdownSkyboxRenderer(); - ShutdownMeshRenderer(); + ShutdownMeshRendererGraphics(); } } @@ -130,7 +135,7 @@ namespace Juliet // Debug display flush (inside render pass) Camera debugCamera = EngineInstance.Application->GetDebugCamera(); DebugDisplay_Flush(cmdList, pass, debugCamera); - + // Note: The MeshRenderer and SkyboxRenderer draw calls are still inside Application->OnRender // They shouldn't be moved here directly without an interface since they require PushData. @@ -148,6 +153,8 @@ namespace Juliet void InitializeEngine(JulietInit_Flags flags) { + EngineInstance.PlatformArena = ArenaAllocate({ .AllowRealloc = true } JULIET_DEBUG_PARAM("Platform Arena")); + InitializeLogManager(); #if JULIET_DEBUG @@ -165,13 +172,17 @@ namespace Juliet ShutdownFilesystem(); ShutdownLogManager(); + + ArenaRelease(EngineInstance.PlatformArena); } - void LoadApplication(IApplication& app, Arena* platformArena) + void LoadApplication(IApplication& app) { - EngineInstance.Application = &app; - EngineInstance.PlatformArena = platformArena; - EngineInstance.Application->Init(); + EngineInstance.Application = &app; + + InitializeMeshRenderer(EngineInstance.PlatformArena); + + EngineInstance.Application->Init(EngineInstance.PlatformArena); // Systems depending on Window/GraphicsDevice InitializeDependentSystems(); @@ -183,6 +194,9 @@ namespace Juliet ShutdownDependentSystems(); EngineInstance.Application->Shutdown(); + + ShutdownMeshRenderer(); + EngineInstance.Application = nullptr; } diff --git a/Juliet/src/Graphics/MeshRenderer.cpp b/Juliet/src/Graphics/MeshRenderer.cpp index 383c90e..965ec56 100644 --- a/Juliet/src/Graphics/MeshRenderer.cpp +++ b/Juliet/src/Graphics/MeshRenderer.cpp @@ -15,13 +15,16 @@ namespace Juliet MeshRenderer g_MeshRenderer; } // namespace - bool InitializeMeshRenderer(NonNullPtr arena, NonNullPtr device, NonNullPtr window) + void InitializeMeshRenderer(NonNullPtr arena) { - bool result = true; - g_MeshRenderer.Meshes.Create(arena JULIET_DEBUG_PARAM("Meshes")); g_MeshRenderer.Vertices.Create(arena JULIET_DEBUG_PARAM("Vertices")); g_MeshRenderer.Indices.Create(arena JULIET_DEBUG_PARAM("Indices")); + } + + bool InitializeMeshRendererGraphics(NonNullPtr device, NonNullPtr window) + { + bool result = true; GraphicsDevice* graphicsDevice = g_MeshRenderer.Device = device.Get(); @@ -81,10 +84,15 @@ namespace Juliet DestroyShader(graphicsDevice, fragmentShader); } + // Load evereything that is already in the vectors + CommandList* loadCmd = AcquireCommandList(device); + LoadMeshesOnGPU(loadCmd); + SubmitCommandLists(loadCmd); + return result; } - void ShutdownMeshRenderer() + void ShutdownMeshRendererGraphics() { if (g_MeshRenderer.LoadCopyBuffer) { @@ -95,7 +103,10 @@ namespace Juliet DestroyGraphicsBuffer(g_MeshRenderer.Device, g_MeshRenderer.IndexBuffer); DestroyGraphicsBuffer(g_MeshRenderer.Device, g_MeshRenderer.VertexBuffer); + } + void ShutdownMeshRenderer() + { g_MeshRenderer.Indices.Destroy(); g_MeshRenderer.Vertices.Destroy(); g_MeshRenderer.Meshes.Destroy(); @@ -177,12 +188,14 @@ namespace Juliet for (Mesh& mesh : g_MeshRenderer.Meshes) { - pushData.Model = mesh.Transform; + pushData.Model = mesh.Transform; pushData.TextureIndex = 0; pushData.VertexOffset = static_cast(mesh.VertexOffset); - pushData.Padding = 0; - pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f; - pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f; + pushData.Padding = 0; + pushData.Scale[0] = 1.0f; + pushData.Scale[1] = 1.0f; + pushData.Translate[0] = 0.0f; + pushData.Translate[1] = 0.0f; SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData); DrawIndexedPrimitives(pass, static_cast(mesh.IndexCount), 1, static_cast(mesh.IndexOffset), static_cast(mesh.VertexOffset), 0); diff --git a/JulietApp/main.cpp b/JulietApp/main.cpp index dfe7df0..5b63356 100644 --- a/JulietApp/main.cpp +++ b/JulietApp/main.cpp @@ -23,8 +23,8 @@ #include #include #include -#include #include +#include #ifdef JULIET_ENABLE_IMGUI #include @@ -64,18 +64,13 @@ namespace } Game; const char* GameFunctionTable[] = { "GameInit", "GameShutdown", "GameUpdate" }; - - Arena* PlatformArena = nullptr; } // namespace -void JulietApplication::Init() +void JulietApplication::Init(NonNullPtr) { Log(LogLevel::Message, LogCategory::Tool, "Initializing Juliet Application..."); - Log(LogLevel::Message, LogCategory::Tool, "%s", CStr(GetBasePath())); - PlatformArena = ArenaAllocate({ .AllowRealloc = true } JULIET_DEBUG_PARAM("Platform Arena")); - GraphicsConfig config; #if JULIET_DEBUG config.EnableDebug = true; @@ -90,8 +85,6 @@ void JulietApplication::Init() { AttachToWindow(GraphicsDevice, MainWindow); { - Running = InitializeMeshRenderer(PlatformArena, GraphicsDevice, MainWindow); - // Create Depth Buffer TextureCreateInfo depthCI = {}; depthCI.Type = TextureType::Texture_2D; @@ -121,64 +114,11 @@ void JulietApplication::Init() float x = static_cast(col) * kSpacing - kOffset; float y = static_cast(row) * kSpacing - kOffset; - float seed = static_cast(row * kGridSize + col); + float seed = static_cast(row * kGridSize + col); Matrix rotation = MatrixRotation(seed * 0.73f, seed * 1.17f, seed * 0.53f); SetMeshTransform(cube, MatrixTranslation(x, y, 0.0f) * rotation); } } - - CommandList* loadCmd = AcquireCommandList(GraphicsDevice); - LoadMeshesOnGPU(loadCmd); - SubmitCommandLists(loadCmd); - - if (Running == false) - { - return; - } - - // Create Skybox Pipeline - String skyboxVSEntry = WrapString("main"); - ShaderCreateInfo skyboxVSCI = {}; - skyboxVSCI.EntryPoint = skyboxVSEntry; - skyboxVSCI.Stage = ShaderStage::Vertex; - String vsPath = GetAssetPath(WrapString("Skybox.vert.dxil")); - Shader* skyboxVS = CreateShader(GraphicsDevice, vsPath, skyboxVSCI); - - String skyboxFSEntry = WrapString("main"); - ShaderCreateInfo skyboxFSCI = {}; - skyboxFSCI.EntryPoint = skyboxFSEntry; - skyboxFSCI.Stage = ShaderStage::Fragment; - String fsPath = GetAssetPath(WrapString("Skybox.frag.dxil")); - Shader* skyboxFS = CreateShader(GraphicsDevice, fsPath, skyboxFSCI); - - ColorTargetDescription colorTargetDesc = {}; - colorTargetDesc.Format = GetSwapChainTextureFormat(GraphicsDevice, MainWindow); - - GraphicsPipelineCreateInfo skyboxPipelineCI = {}; - skyboxPipelineCI.VertexShader = skyboxVS; - skyboxPipelineCI.FragmentShader = skyboxFS; - skyboxPipelineCI.PrimitiveType = PrimitiveType::TriangleList; - skyboxPipelineCI.TargetInfo.ColorTargetDescriptions = &colorTargetDesc; - skyboxPipelineCI.TargetInfo.NumColorTargets = 1; - skyboxPipelineCI.TargetInfo.DepthStencilFormat = TextureFormat::D32_FLOAT; - skyboxPipelineCI.TargetInfo.HasDepthStencilTarget = true; - skyboxPipelineCI.RasterizerState.FillMode = FillMode::Solid; - skyboxPipelineCI.RasterizerState.CullMode = CullMode::None; - skyboxPipelineCI.RasterizerState.FrontFace = FrontFace::Clockwise; - skyboxPipelineCI.DepthStencilState.EnableDepthTest = true; - skyboxPipelineCI.DepthStencilState.EnableDepthWrite = false; - skyboxPipelineCI.DepthStencilState.CompareOperation = CompareOperation::LessOrEqual; - - SkyboxPipeline = CreateGraphicsPipeline(GraphicsDevice, skyboxPipelineCI); - if (SkyboxPipeline == nullptr) - { - LogError(LogCategory::Graphics, "Failed to create skybox pipeline!"); - Running = false; - } - - if (skyboxVS) DestroyShader(GraphicsDevice, skyboxVS); - if (skyboxFS) DestroyShader(GraphicsDevice, skyboxFS); - } GameCode.Functions = reinterpret_cast(&Game); @@ -215,8 +155,6 @@ void JulietApplication::Shutdown() DestroyTexture(GraphicsDevice, DepthBuffer); } - ShutdownMeshRenderer(); - if (MainWindow && GraphicsDevice) { DetachFromWindow(GraphicsDevice, MainWindow); @@ -232,8 +170,6 @@ void JulietApplication::Shutdown() DestroyGraphicsDevice(GraphicsDevice); } - ArenaRelease(PlatformArena); - Log(LogLevel::Message, LogCategory::Tool, "Juliet App shutdown Completed"); } @@ -262,7 +198,7 @@ void JulietApplication::Update() { float fps = static_cast(fpsFrames) / fpsTimer; float ms = (fpsTimer / static_cast(fpsFrames)) * 1000.0f; - char title[64]; + char title[64]; snprintf(title, sizeof(title), "Juliet | %.1f FPS | %.2f ms", static_cast(fps), static_cast(ms)); SetWindowTitle(MainWindow, WrapString(title)); fpsTimer = 0.0f; diff --git a/JulietApp/main.h b/JulietApp/main.h index 6ca4c52..8e418aa 100644 --- a/JulietApp/main.h +++ b/JulietApp/main.h @@ -18,7 +18,7 @@ namespace Juliet class JulietApplication : public Juliet::IApplication { protected: - void Init() override; + void Init(Juliet::NonNullPtr arena) override; void Shutdown() override; void Update() override; bool IsRunning() override; @@ -43,13 +43,12 @@ class JulietApplication : public Juliet::IApplication Juliet::HotReloadCode GameCode = {}; Juliet::GraphicsPipeline* GraphicsPipeline = {}; Juliet::Texture* DepthBuffer = {}; - Juliet::GraphicsPipeline* SkyboxPipeline = {}; Juliet::Arena* GameArena = nullptr; Juliet::Arena* GameScratchArena = nullptr; - int AutoCloseFrameCount = -1; - bool Running = false; - float CameraTime = 0.0f; + int AutoCloseFrameCount = -1; + bool Running = false; + float CameraTime = 0.0f; }; JulietApplication& GetEditorApplication();