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,25 +9,26 @@ 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;
// Accessors for Engine Systems // Accessors for Engine Systems
virtual struct Window* GetPlatformWindow() = 0; virtual struct Window* GetPlatformWindow() = 0;
virtual struct GraphicsDevice* GetGraphicsDevice() = 0; virtual struct GraphicsDevice* GetGraphicsDevice() = 0;
// Render Lifecycle (Engine-Managed Render Loop) // Render Lifecycle (Engine-Managed Render Loop)
virtual void OnPreRender(CommandList* cmd) = 0; virtual void OnPreRender(CommandList* cmd) = 0;
virtual void OnRender(RenderPass* pass, CommandList* cmd) = 0; virtual void OnRender(RenderPass* pass, CommandList* cmd) = 0;
virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0; virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0;
virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0; virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0;
virtual struct Camera GetDebugCamera() = 0; virtual struct Camera GetDebugCamera() = 0;
}; };
} // namespace Juliet } // namespace Juliet

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,16 +41,17 @@ 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 ShutdownMeshRenderer(); JULIET_API void ShutdownMeshRendererGraphics();
JULIET_API void LoadMeshesOnGPU(NonNullPtr<CommandList> cmdList); JULIET_API void ShutdownMeshRenderer();
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);
// Utils // Utils
[[nodiscard]] JULIET_API MeshID AddCube(); [[nodiscard]] JULIET_API MeshID AddCube();
[[nodiscard]] JULIET_API MeshID AddQuad(); [[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 #if ALLOW_SHADER_HOT_RELOAD
JULIET_API void ReloadMeshRendererShaders(); JULIET_API void ReloadMeshRendererShaders();

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();
} }
} }
@@ -130,7 +135,7 @@ namespace Juliet
// Debug display flush (inside render pass) // Debug display flush (inside render pass)
Camera debugCamera = EngineInstance.Application->GetDebugCamera(); Camera debugCamera = EngineInstance.Application->GetDebugCamera();
DebugDisplay_Flush(cmdList, pass, debugCamera); DebugDisplay_Flush(cmdList, pass, debugCamera);
// Note: The MeshRenderer and SkyboxRenderer draw calls are still inside Application->OnRender // 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. // 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) 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();
@@ -177,12 +188,14 @@ namespace Juliet
for (Mesh& mesh : g_MeshRenderer.Meshes) for (Mesh& mesh : g_MeshRenderer.Meshes)
{ {
pushData.Model = mesh.Transform; pushData.Model = mesh.Transform;
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;
@@ -121,64 +114,11 @@ void JulietApplication::Init()
float x = static_cast<float>(col) * kSpacing - kOffset; float x = static_cast<float>(col) * kSpacing - kOffset;
float y = static_cast<float>(row) * kSpacing - kOffset; float y = static_cast<float>(row) * kSpacing - kOffset;
float seed = static_cast<float>(row * kGridSize + col); float seed = static_cast<float>(row * kGridSize + col);
Matrix rotation = MatrixRotation(seed * 0.73f, seed * 1.17f, seed * 0.53f); Matrix rotation = MatrixRotation(seed * 0.73f, seed * 1.17f, seed * 0.53f);
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");
} }
@@ -262,7 +198,7 @@ void JulietApplication::Update()
{ {
float fps = static_cast<float>(fpsFrames) / fpsTimer; float fps = static_cast<float>(fpsFrames) / fpsTimer;
float ms = (fpsTimer / static_cast<float>(fpsFrames)) * 1000.0f; float ms = (fpsTimer / static_cast<float>(fpsFrames)) * 1000.0f;
char title[64]; char title[64];
snprintf(title, sizeof(title), "Juliet | %.1f FPS | %.2f ms", static_cast<double>(fps), static_cast<double>(ms)); snprintf(title, sizeof(title), "Juliet | %.1f FPS | %.2f ms", static_cast<double>(fps), static_cast<double>(ms));
SetWindowTitle(MainWindow, WrapString(title)); SetWindowTitle(MainWindow, WrapString(title));
fpsTimer = 0.0f; fpsTimer = 0.0f;

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,13 +43,12 @@ 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;
int AutoCloseFrameCount = -1; int AutoCloseFrameCount = -1;
bool Running = false; bool Running = false;
float CameraTime = 0.0f; float CameraTime = 0.0f;
}; };
JulietApplication& GetEditorApplication(); JulietApplication& GetEditorApplication();