- Depth buffer
- Debug display basics
- Basic vector + matrix maths
Made partially with gemini + antigravity
This commit is contained in:
2026-01-11 22:07:38 -05:00
parent fa1933c169
commit bfd042abbf
28 changed files with 959 additions and 67 deletions

View File

@@ -8,6 +8,8 @@
#include <Core/JulietInit.h>
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Graphics/Camera.h>
#include <Graphics/DebugDisplay.h>
#include <Graphics/Graphics.h>
#include <Graphics/GraphicsConfig.h>
#include <Graphics/GraphicsPipeline.h>
@@ -93,9 +95,12 @@ void JulietApplication::Init()
pipelineCI.PrimitiveType = PrimitiveType::TriangleList;
pipelineCI.TargetInfo = { .ColorTargetDescriptions = &colorTargetDescription,
.NumColorTargets = 1,
.DepthStencilFormat = {},
.HasDepthStencilTarget = false };
.DepthStencilFormat = TextureFormat::D32_FLOAT,
.HasDepthStencilTarget = true };
pipelineCI.RasterizerState.FillMode = FillMode::Solid;
pipelineCI.DepthStencilState.EnableDepthTest = true;
pipelineCI.DepthStencilState.EnableDepthWrite = true;
pipelineCI.DepthStencilState.CompareOperation = CompareOperation::Less;
GraphicsPipeline = CreateGraphicsPipeline(GraphicsDevice, pipelineCI);
if (GraphicsPipeline == nullptr)
@@ -104,6 +109,23 @@ void JulietApplication::Init()
Running = false;
}
// Create Depth Buffer
TextureCreateInfo depthCI = {};
depthCI.Type = TextureType::Texture_2D;
depthCI.Width = 1280;
depthCI.Height = 720;
depthCI.Format = TextureFormat::D32_FLOAT;
depthCI.Flags = TextureUsageFlag::DepthStencilTarget;
depthCI.LayerCount = 1;
depthCI.MipLevelCount = 1;
depthCI.SampleCount = TextureSampleCount::One;
DepthBuffer = CreateTexture(GraphicsDevice, depthCI);
if (DepthBuffer == nullptr)
{
LogError(LogCategory::Game, "Failed to create depth buffer!");
Running = false;
}
// Create Buffers
BufferCreateInfo bufferCI = {};
bufferCI.Size = 256;
@@ -138,6 +160,9 @@ void JulietApplication::Init()
{
Game.Init();
}
// Initialize DebugDisplay
DebugDisplay_Initialize(GraphicsDevice);
}
}
@@ -151,6 +176,12 @@ void JulietApplication::Shutdown()
ShutdownHotReloadCode(GameCode);
}
// Shutdown DebugDisplay before graphics device
if (GraphicsDevice)
{
DebugDisplay_Shutdown(GraphicsDevice);
}
if (GraphicsPipeline)
{
DestroyGraphicsPipeline(GraphicsDevice, GraphicsPipeline);
@@ -163,6 +194,10 @@ void JulietApplication::Shutdown()
{
DestroyGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
}
if (DepthBuffer)
{
DestroyTexture(GraphicsDevice, DepthBuffer);
}
if (MainWindow && GraphicsDevice)
{
@@ -275,7 +310,7 @@ void JulietApplication::Update()
{
ColorTargetInfo colorTargetInfo = {};
colorTargetInfo.TargetTexture = swapChainTexture;
colorTargetInfo.ClearColor = { .R = .5f, .G = .8f, .B = .0f, .A = 1.f };
colorTargetInfo.ClearColor = { .R = .0f, .G = .0f, .B = .0f, .A = 1.f };
colorTargetInfo.LoadOperation = LoadOperation::Clear;
colorTargetInfo.StoreOperation = StoreOperation::Store;
@@ -303,7 +338,22 @@ void JulietApplication::Update()
TransitionBufferToReadable(cmdList, ConstantBuffer);
}
RenderPass* renderPass = BeginRenderPass(cmdList, colorTargetInfo);
// Test lines and sphere - GIANT SCALE
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 10.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, false); // X-Axis (Red)
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, true); // Y-Axis (Green)
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 10.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, true); // Z-Axis (Blue) - Up
DebugDisplay_DrawSphere({ 0.0f, 0.0f, 0.0f }, 5.0f, { 1.0f, 1.0f, 0.0f, 1.0f }, true); // Yellow sphere
// Prepare debug data (outside render pass)
DebugDisplay_Prepare(cmdList);
DepthStencilTargetInfo depthTargetInfo = {};
depthTargetInfo.TargetTexture = DepthBuffer;
depthTargetInfo.ClearDepth = 1.0f;
depthTargetInfo.LoadOperation = LoadOperation::Clear;
depthTargetInfo.StoreOperation = StoreOperation::Store;
RenderPass* renderPass = BeginRenderPass(cmdList, colorTargetInfo, &depthTargetInfo);
BindGraphicsPipeline(renderPass, GraphicsPipeline);
// Pass descriptor index via Push Constants AFTER finding the pipeline (RootSignature)
@@ -311,6 +361,23 @@ void JulietApplication::Update()
SetPushConstants(cmdList, ShaderStage::Vertex, 0, 1, &descriptorIndex);
DrawPrimitives(renderPass, 6, 1, 0, 0);
// Debug Display - render shapes (inside render pass)
static float orbitTime = 0.0f;
orbitTime += 0.016f; // Rough approximation for 60fps
float radius = 30.0f;
Camera debugCamera = {};
debugCamera.Position = { cosf(orbitTime) * radius, sinf(orbitTime) * radius, 10.0f }; // Rotate in XY plane
debugCamera.Target = { 0.0f, 0.0f, 0.0f };
debugCamera.Up = { 0.0f, 0.0f, 1.0f }; // Z-Up
debugCamera.FOV = 1.047f; // 60 degrees
debugCamera.AspectRatio = 1200.0f / 800.0f;
debugCamera.NearPlane = 0.1f;
debugCamera.FarPlane = 1000.0f;
DebugDisplay_Flush(cmdList, renderPass, debugCamera);
EndRenderPass(renderPass);
}