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.
This commit is contained in:
2026-02-22 17:47:46 -05:00
parent 932c45d844
commit 1056301981
8 changed files with 74 additions and 107 deletions

View File

@@ -8,5 +8,6 @@ namespace Juliet
{ {
enum class JulietInit_Flags : uint8; enum class JulietInit_Flags : uint8;
struct Arena;
extern JULIET_API void StartApplication(IApplication& app, JulietInit_Flags flags); extern JULIET_API void StartApplication(IApplication& app, JulietInit_Flags flags);
} // namespace Juliet } // namespace Juliet

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h>
namespace Juliet namespace Juliet
{ {
struct RenderPass; struct RenderPass;
@@ -7,12 +9,13 @@ namespace Juliet
struct Texture; struct Texture;
struct ColorTargetInfo; struct ColorTargetInfo;
struct DepthStencilTargetInfo; struct DepthStencilTargetInfo;
struct Arena;
class IApplication class IApplication
{ {
public: public:
virtual ~IApplication() = default; virtual ~IApplication() = default;
virtual void Init() = 0; virtual void Init(NonNullPtr<Arena> arena) = 0;
virtual void Shutdown() = 0; virtual void Shutdown() = 0;
virtual void Update() = 0; virtual void Update() = 0;
virtual bool IsRunning() = 0; virtual bool IsRunning() = 0;

View File

@@ -15,7 +15,7 @@ namespace Juliet
void InitializeEngine(JulietInit_Flags flags); void InitializeEngine(JulietInit_Flags flags);
void ShutdownEngine(); void ShutdownEngine();
void LoadApplication(IApplication& app, Arena* arena); void LoadApplication(IApplication& app);
void UnloadApplication(); void UnloadApplication();
void RunEngine(); void RunEngine();

View File

@@ -2,8 +2,8 @@
#include <Core/Container/Vector.h> #include <Core/Container/Vector.h>
#include <Core/Math/Matrix.h> #include <Core/Math/Matrix.h>
#include <Graphics/VertexData.h>
#include <Graphics/PushConstants.h> #include <Graphics/PushConstants.h>
#include <Graphics/VertexData.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet namespace Juliet
@@ -41,8 +41,9 @@ namespace Juliet
GraphicsPipeline* Pipeline; GraphicsPipeline* Pipeline;
}; };
[[nodiscard]] JULIET_API bool InitializeMeshRenderer(NonNullPtr<Arena> arena, NonNullPtr<GraphicsDevice> device, JULIET_API void InitializeMeshRenderer(NonNullPtr<Arena> arena);
NonNullPtr<Window> window); [[nodiscard]] JULIET_API bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
JULIET_API void ShutdownMeshRendererGraphics();
JULIET_API void ShutdownMeshRenderer(); JULIET_API void ShutdownMeshRenderer();
JULIET_API void LoadMeshesOnGPU(NonNullPtr<CommandList> cmdList); JULIET_API void LoadMeshesOnGPU(NonNullPtr<CommandList> cmdList);
JULIET_API void RenderMeshes(NonNullPtr<RenderPass> pass, NonNullPtr<CommandList> cmdList, PushData& pushData); JULIET_API void RenderMeshes(NonNullPtr<RenderPass> pass, NonNullPtr<CommandList> cmdList, PushData& pushData);

View File

@@ -6,8 +6,8 @@
#include <Engine/Engine.h> #include <Engine/Engine.h>
#include <Graphics/DebugDisplay.h> #include <Graphics/DebugDisplay.h>
#include <Graphics/Graphics.h> #include <Graphics/Graphics.h>
#include <Graphics/RenderPass.h>
#include <Graphics/MeshRenderer.h> #include <Graphics/MeshRenderer.h>
#include <Graphics/RenderPass.h>
#include <Graphics/SkyboxRenderer.h> #include <Graphics/SkyboxRenderer.h>
#include <time.h> #include <time.h>
@@ -41,8 +41,13 @@ namespace Juliet
DebugDisplay_Initialize(device); DebugDisplay_Initialize(device);
if (Window* window = EngineInstance.Application->GetPlatformWindow()) if (Window* window = EngineInstance.Application->GetPlatformWindow())
{ {
InitializeMeshRenderer(EngineInstance.PlatformArena, device, window); bool success = InitializeMeshRendererGraphics(device, window);
InitializeSkyboxRenderer(device, window); Assert(success);
(void)(success);
success = InitializeSkyboxRenderer(device, window);
Assert(success);
(void)(success);
} }
} }
@@ -81,7 +86,7 @@ namespace Juliet
{ {
DebugDisplay_Shutdown(device); DebugDisplay_Shutdown(device);
ShutdownSkyboxRenderer(); ShutdownSkyboxRenderer();
ShutdownMeshRenderer(); ShutdownMeshRendererGraphics();
} }
} }
@@ -148,6 +153,8 @@ namespace Juliet
void InitializeEngine(JulietInit_Flags flags) void InitializeEngine(JulietInit_Flags flags)
{ {
EngineInstance.PlatformArena = ArenaAllocate({ .AllowRealloc = true } JULIET_DEBUG_PARAM("Platform Arena"));
InitializeLogManager(); InitializeLogManager();
#if JULIET_DEBUG #if JULIET_DEBUG
@@ -165,13 +172,17 @@ namespace Juliet
ShutdownFilesystem(); ShutdownFilesystem();
ShutdownLogManager(); ShutdownLogManager();
ArenaRelease(EngineInstance.PlatformArena);
} }
void LoadApplication(IApplication& app, Arena* platformArena) void LoadApplication(IApplication& app)
{ {
EngineInstance.Application = &app; EngineInstance.Application = &app;
EngineInstance.PlatformArena = platformArena;
EngineInstance.Application->Init(); InitializeMeshRenderer(EngineInstance.PlatformArena);
EngineInstance.Application->Init(EngineInstance.PlatformArena);
// Systems depending on Window/GraphicsDevice // Systems depending on Window/GraphicsDevice
InitializeDependentSystems(); InitializeDependentSystems();
@@ -183,6 +194,9 @@ namespace Juliet
ShutdownDependentSystems(); ShutdownDependentSystems();
EngineInstance.Application->Shutdown(); EngineInstance.Application->Shutdown();
ShutdownMeshRenderer();
EngineInstance.Application = nullptr; EngineInstance.Application = nullptr;
} }

View File

@@ -15,13 +15,16 @@ namespace Juliet
MeshRenderer g_MeshRenderer; MeshRenderer g_MeshRenderer;
} // namespace } // namespace
bool InitializeMeshRenderer(NonNullPtr<Arena> arena, NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window) void InitializeMeshRenderer(NonNullPtr<Arena> arena)
{ {
bool result = true;
g_MeshRenderer.Meshes.Create(arena JULIET_DEBUG_PARAM("Meshes")); g_MeshRenderer.Meshes.Create(arena JULIET_DEBUG_PARAM("Meshes"));
g_MeshRenderer.Vertices.Create(arena JULIET_DEBUG_PARAM("Vertices")); g_MeshRenderer.Vertices.Create(arena JULIET_DEBUG_PARAM("Vertices"));
g_MeshRenderer.Indices.Create(arena JULIET_DEBUG_PARAM("Indices")); g_MeshRenderer.Indices.Create(arena JULIET_DEBUG_PARAM("Indices"));
}
bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window)
{
bool result = true;
GraphicsDevice* graphicsDevice = g_MeshRenderer.Device = device.Get(); GraphicsDevice* graphicsDevice = g_MeshRenderer.Device = device.Get();
@@ -81,10 +84,15 @@ namespace Juliet
DestroyShader(graphicsDevice, fragmentShader); DestroyShader(graphicsDevice, fragmentShader);
} }
// Load evereything that is already in the vectors
CommandList* loadCmd = AcquireCommandList(device);
LoadMeshesOnGPU(loadCmd);
SubmitCommandLists(loadCmd);
return result; return result;
} }
void ShutdownMeshRenderer() void ShutdownMeshRendererGraphics()
{ {
if (g_MeshRenderer.LoadCopyBuffer) if (g_MeshRenderer.LoadCopyBuffer)
{ {
@@ -95,7 +103,10 @@ namespace Juliet
DestroyGraphicsBuffer(g_MeshRenderer.Device, g_MeshRenderer.IndexBuffer); DestroyGraphicsBuffer(g_MeshRenderer.Device, g_MeshRenderer.IndexBuffer);
DestroyGraphicsBuffer(g_MeshRenderer.Device, g_MeshRenderer.VertexBuffer); DestroyGraphicsBuffer(g_MeshRenderer.Device, g_MeshRenderer.VertexBuffer);
}
void ShutdownMeshRenderer()
{
g_MeshRenderer.Indices.Destroy(); g_MeshRenderer.Indices.Destroy();
g_MeshRenderer.Vertices.Destroy(); g_MeshRenderer.Vertices.Destroy();
g_MeshRenderer.Meshes.Destroy(); g_MeshRenderer.Meshes.Destroy();
@@ -181,8 +192,10 @@ namespace Juliet
pushData.TextureIndex = 0; pushData.TextureIndex = 0;
pushData.VertexOffset = static_cast<uint32>(mesh.VertexOffset); pushData.VertexOffset = static_cast<uint32>(mesh.VertexOffset);
pushData.Padding = 0; pushData.Padding = 0;
pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f; pushData.Scale[0] = 1.0f;
pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.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); SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData);
DrawIndexedPrimitives(pass, static_cast<uint32>(mesh.IndexCount), 1, static_cast<uint32>(mesh.IndexOffset), DrawIndexedPrimitives(pass, static_cast<uint32>(mesh.IndexCount), 1, static_cast<uint32>(mesh.IndexOffset),
static_cast<uint32>(mesh.VertexOffset), 0); static_cast<uint32>(mesh.VertexOffset), 0);

View File

@@ -23,8 +23,8 @@
#include <Graphics/Mesh.h> #include <Graphics/Mesh.h>
#include <Graphics/MeshRenderer.h> #include <Graphics/MeshRenderer.h>
#include <Graphics/RenderPass.h> #include <Graphics/RenderPass.h>
#include <Graphics/VertexData.h>
#include <Graphics/SkyboxRenderer.h> #include <Graphics/SkyboxRenderer.h>
#include <Graphics/VertexData.h>
#ifdef JULIET_ENABLE_IMGUI #ifdef JULIET_ENABLE_IMGUI
#include <imgui.h> #include <imgui.h>
@@ -64,18 +64,13 @@ namespace
} Game; } Game;
const char* GameFunctionTable[] = { "GameInit", "GameShutdown", "GameUpdate" }; const char* GameFunctionTable[] = { "GameInit", "GameShutdown", "GameUpdate" };
Arena* PlatformArena = nullptr;
} // namespace } // namespace
void JulietApplication::Init() void JulietApplication::Init(NonNullPtr<Arena>)
{ {
Log(LogLevel::Message, LogCategory::Tool, "Initializing Juliet Application..."); Log(LogLevel::Message, LogCategory::Tool, "Initializing Juliet Application...");
Log(LogLevel::Message, LogCategory::Tool, "%s", CStr(GetBasePath())); Log(LogLevel::Message, LogCategory::Tool, "%s", CStr(GetBasePath()));
PlatformArena = ArenaAllocate({ .AllowRealloc = true } JULIET_DEBUG_PARAM("Platform Arena"));
GraphicsConfig config; GraphicsConfig config;
#if JULIET_DEBUG #if JULIET_DEBUG
config.EnableDebug = true; config.EnableDebug = true;
@@ -90,8 +85,6 @@ void JulietApplication::Init()
{ {
AttachToWindow(GraphicsDevice, MainWindow); AttachToWindow(GraphicsDevice, MainWindow);
{ {
Running = InitializeMeshRenderer(PlatformArena, GraphicsDevice, MainWindow);
// Create Depth Buffer // Create Depth Buffer
TextureCreateInfo depthCI = {}; TextureCreateInfo depthCI = {};
depthCI.Type = TextureType::Texture_2D; depthCI.Type = TextureType::Texture_2D;
@@ -126,59 +119,6 @@ void JulietApplication::Init()
SetMeshTransform(cube, MatrixTranslation(x, y, 0.0f) * rotation); 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<void**>(&Game); GameCode.Functions = reinterpret_cast<void**>(&Game);
@@ -215,8 +155,6 @@ void JulietApplication::Shutdown()
DestroyTexture(GraphicsDevice, DepthBuffer); DestroyTexture(GraphicsDevice, DepthBuffer);
} }
ShutdownMeshRenderer();
if (MainWindow && GraphicsDevice) if (MainWindow && GraphicsDevice)
{ {
DetachFromWindow(GraphicsDevice, MainWindow); DetachFromWindow(GraphicsDevice, MainWindow);
@@ -232,8 +170,6 @@ void JulietApplication::Shutdown()
DestroyGraphicsDevice(GraphicsDevice); DestroyGraphicsDevice(GraphicsDevice);
} }
ArenaRelease(PlatformArena);
Log(LogLevel::Message, LogCategory::Tool, "Juliet App shutdown Completed"); Log(LogLevel::Message, LogCategory::Tool, "Juliet App shutdown Completed");
} }

View File

@@ -18,7 +18,7 @@ namespace Juliet
class JulietApplication : public Juliet::IApplication class JulietApplication : public Juliet::IApplication
{ {
protected: protected:
void Init() override; void Init(Juliet::NonNullPtr<Juliet::Arena> arena) override;
void Shutdown() override; void Shutdown() override;
void Update() override; void Update() override;
bool IsRunning() override; bool IsRunning() override;
@@ -43,7 +43,6 @@ class JulietApplication : public Juliet::IApplication
Juliet::HotReloadCode GameCode = {}; Juliet::HotReloadCode GameCode = {};
Juliet::GraphicsPipeline* GraphicsPipeline = {}; Juliet::GraphicsPipeline* GraphicsPipeline = {};
Juliet::Texture* DepthBuffer = {}; Juliet::Texture* DepthBuffer = {};
Juliet::GraphicsPipeline* SkyboxPipeline = {};
Juliet::Arena* GameArena = nullptr; Juliet::Arena* GameArena = nullptr;
Juliet::Arena* GameScratchArena = nullptr; Juliet::Arena* GameScratchArena = nullptr;