Added basic concept of Mesh

Right now can create a quad or a cube.
Need a mesh renderer taht keep the buffer and all to optimally handle the mega buffer.
This commit is contained in:
2026-02-15 17:44:48 -05:00
parent c2a5cb84b2
commit 87831d0fd6
22 changed files with 285 additions and 163 deletions

View File

@@ -20,7 +20,9 @@
#include <Graphics/Graphics.h>
#include <Graphics/GraphicsConfig.h>
#include <Graphics/GraphicsPipeline.h>
#include <Graphics/Mesh.h>
#include <Graphics/RenderPass.h>
#include <Graphics/VertexData.h>
#include <Juliet.h>
#ifdef JULIET_ENABLE_IMGUI
@@ -63,12 +65,6 @@ namespace
const char* GameFunctionTable[] = { "GameInit", "GameShutdown", "GameUpdate" };
} // namespace
struct Vertex
{
float Position[2];
float Color[4];
};
void JulietApplication::Init()
{
Log(LogLevel::Message, LogCategory::Tool, "Initializing Juliet Application...");
@@ -88,7 +84,6 @@ void JulietApplication::Init()
if (Running)
{
AttachToWindow(GraphicsDevice, MainWindow);
{
// Create graphics pipeline
String entryPoint = WrapString("main");
@@ -146,12 +141,12 @@ void JulietApplication::Init()
// Create Buffers - Using StructuredBuffer for bindless SRV access in shader
BufferCreateInfo bufferCI = {};
bufferCI.Size = 256;
bufferCI.Size = 1024;
bufferCI.Usage = BufferUsage::StructuredBuffer; // SRV for ResourceDescriptorHeap access
ConstantBuffer = CreateGraphicsBuffer(GraphicsDevice, bufferCI);
TransferBufferCreateInfo transferCI = {};
transferCI.Size = 256;
transferCI.Size = 1024;
transferCI.Usage = TransferBufferUsage::Upload;
TransferBuffer = CreateGraphicsTransferBuffer(GraphicsDevice, transferCI);
@@ -176,6 +171,10 @@ void JulietApplication::Init()
}
}
CubeArena = ArenaAllocate({ .ReserveSize = Kilobytes(1llu), .CommitSize = Kilobytes(1llu) } JULIET_DEBUG_PARAM("CubeArena"));
CubeMesh = CreateCubeMesh(CubeArena);
// CubeMesh = CreateQuadMesh(CubeArena);
if (vertexShader)
{
DestroyShader(GraphicsDevice, vertexShader);
@@ -209,6 +208,8 @@ void JulietApplication::Shutdown()
{
Log(LogLevel::Message, LogCategory::Tool, "Shutting down Juliet Application...");
ArenaRelease(CubeArena);
if (GameCode.IsValid)
{
Game.Shutdown();
@@ -283,10 +284,10 @@ void JulietApplication::Update()
ImGui::ShowDemoWindow();
#endif
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 10.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, false);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, true);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 10.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, true);
DebugDisplay_DrawSphere({ 0.0f, 0.0f, 0.0f }, 5.0f, { 1.0f, 1.0f, 0.0f, 1.0f }, true);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, false);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, true);
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, true);
DebugDisplay_DrawSphere({ 0.0f, 0.0f, 0.0f }, 0.5f, { 1.0f, 1.0f, 0.0f, 1.0f }, true);
Game.Update(0.0f);
@@ -362,28 +363,49 @@ void JulietApplication::Update()
void JulietApplication::OnPreRender(CommandList* cmd)
{
index_t index = 0;
// Buffer uploads
if (ConstantBuffer && TransferBuffer)
{
void* ptr = MapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
if (ptr)
{
auto vertices = static_cast<Vertex*>(ptr);
Vertex* vertices = static_cast<Vertex*>(ptr);
// Triangle 1
vertices[0] = { { -0.5f, -0.5f }, { 1.0f, 0.0f, 0.0f, 1.0f } }; // Red
vertices[1] = { { 0.0f, 0.5f }, { 0.0f, 1.0f, 0.0f, 1.0f } }; // Green
vertices[2] = { { 0.5f, -0.5f }, { 0.0f, 0.0f, 1.0f, 1.0f } }; // Blue
// // Triangle 1
// vertices[index++] = { { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }; // Red
// vertices[index++] = { { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }; // Green
// vertices[index++] = { { 0.5f, -0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }; // Blue
//
// // Triangle 2
// vertices[index++] = { { -0.5f, 0.5f, 0.0f }, { 1.0f, 1.0f, 0.0f, 1.0f } }; // Yellow
// vertices[index++] = { { 0.0f, 0.8f, 0.0f }, { 0.0f, 1.0f, 1.0f, 1.0f } }; // Cyan
// vertices[index++] = { { 0.5f, 0.5f, 0.0f }, { 1.0f, 0.0f, 1.0f, 1.0f } }; // Magenta
// Triangle 2
vertices[3] = { { -0.5f, 0.5f }, { 1.0f, 1.0f, 0.0f, 1.0f } }; // Yellow
vertices[4] = { { 0.0f, 0.8f }, { 0.0f, 1.0f, 1.0f, 1.0f } }; // Cyan
vertices[5] = { { 0.5f, 0.5f }, { 1.0f, 0.0f, 1.0f, 1.0f } }; // Magenta
if (CubeMesh)
{
CubeMesh->VertexOffset = index;
size_t vertexSize = CubeMesh->VertexCount * sizeof(Vertex);
MemCopy(vertices + index, CubeMesh->Vertices, vertexSize);
CubeMesh->IndexByteOffset = (index + CubeMesh->VertexCount) * sizeof(Vertex);
// Align
CubeMesh->IndexByteOffset = (CubeMesh->IndexByteOffset + 255) & static_cast<size_t>(~255);
size_t indexSize = CubeMesh->IndexCount * sizeof(uint16);
CubeMesh->IndexOffset = 0;
uint8* ptrOneByte = static_cast<uint8*>(ptr);
uint16* dst = reinterpret_cast<uint16*>(ptrOneByte + CubeMesh->IndexByteOffset);
MemCopy(dst, CubeMesh->Indices, indexSize);
}
UnmapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer);
}
CopyBuffer(cmd, ConstantBuffer, TransferBuffer, 256);
CopyBuffer(cmd, ConstantBuffer, TransferBuffer, CubeMesh->IndexByteOffset + (CubeMesh->IndexCount * sizeof(uint16)));
TransitionBufferToReadable(cmd, ConstantBuffer);
}
}
@@ -396,14 +418,19 @@ void JulietApplication::OnRender(RenderPass* pass, CommandList* cmd)
struct PushData
{
float ViewProjection[16];
Matrix ViewProjection;
uint32 BufferIndex;
} pushData = {};
pushData.BufferIndex = descriptorIndex;
} pushData = {};
pushData.BufferIndex = descriptorIndex;
pushData.ViewProjection = Camera_GetViewProjectionMatrix(GetDebugCamera());
SetPushConstants(cmd, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData);
DrawPrimitives(pass, 6, 1, 0, 0);
SetIndexBuffer(cmd, ConstantBuffer, IndexFormat::UInt16, CubeMesh->IndexCount, CubeMesh->IndexByteOffset);
// DrawIndexedPrimitives(pass, static_cast<uint32>(CubeMesh->IndexCount), 1, 0, 0, 0);
DrawIndexedPrimitives(pass, static_cast<uint32>(CubeMesh->IndexCount), 1,
static_cast<uint32>(CubeMesh->IndexOffset), static_cast<uint32>(CubeMesh->VertexOffset), 0);
}
ColorTargetInfo JulietApplication::GetColorTargetInfo(Texture* swapchainTexture)
@@ -428,18 +455,32 @@ DepthStencilTargetInfo* JulietApplication::GetDepthTargetInfo()
Camera JulietApplication::GetDebugCamera()
{
static float orbitTime = 0.0f;
orbitTime += 0.016f;
static float time = 0.0f;
time += 0.016f;
float orbitSpeed = 0.5f;
float currentOrbitTime = time * orbitSpeed;
// --- Adjusted for 1-Meter Scale ---
float baseRadius = 2.5f; // Hover 2.5 meters away (down from 15.0f)
float radius = baseRadius;
/* Uncomment for active zoom
float zoomAmplitude = 1.0f; // Oscillate between 1.5m and 3.5m away
float zoomSpeed = 0.8f;
radius = baseRadius + (sinf(time * zoomSpeed) * zoomAmplitude);
*/
float zHeight = radius * 0.5f; // Keep a nice downward viewing angle
float radius = 30.0f;
Camera cam = {};
cam.Position = { cosf(orbitTime) * radius, sinf(orbitTime) * radius, 10.0f };
cam.Position = { cosf(currentOrbitTime) * radius, sinf(currentOrbitTime) * radius, zHeight };
cam.Target = { 0.0f, 0.0f, 0.0f };
cam.Up = { 0.0f, 0.0f, 1.0f };
cam.FOV = 1.047f;
cam.AspectRatio = 1200.0f / 800.0f;
cam.NearPlane = 0.1f;
cam.FarPlane = 1000.0f;
return cam;
}
@@ -447,7 +488,6 @@ bool JulietApplication::IsRunning()
{
return Running;
}
namespace
{
JulietApplication EditorApplication;

View File

@@ -8,6 +8,7 @@
namespace Juliet
{
struct Mesh;
struct GraphicsTransferBuffer;
struct GraphicsBuffer;
struct GraphicsDevice;
@@ -45,11 +46,14 @@ class JulietApplication : public Juliet::IApplication
Juliet::GraphicsTransferBuffer* TransferBuffer = {};
Juliet::Texture* DepthBuffer = {};
Juliet::Mesh* CubeMesh = {};
Juliet::Arena* CubeArena = nullptr;
Juliet::Arena* GameArena = nullptr;
Juliet::Arena* GameScratchArena = nullptr;
bool Running = false;
int AutoCloseFrameCount = -1;
bool Running = false;
};
JulietApplication& GetEditorApplication();