diff options
Diffstat (limited to 'src/3d/renderer.h')
| -rw-r--r-- | src/3d/renderer.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/3d/renderer.h b/src/3d/renderer.h new file mode 100644 index 0000000..0dadc32 --- /dev/null +++ b/src/3d/renderer.h @@ -0,0 +1,60 @@ +// This file is part of the 64k demo project. +// It defines the Renderer3D class. +// Handles WebGPU pipeline creation and execution for 3D scenes. + +#pragma once + +#include "3d/camera.h" +#include "3d/scene.h" +#include "gpu/gpu.h" +#include <vector> + +// Matches the GPU struct layout +struct GlobalUniforms { + mat4 view_proj; + vec3 camera_pos; + float time; +}; + +// Matches the GPU struct layout +struct ObjectData { + mat4 model; + vec4 color; + vec4 params; // Type, etc. +}; + +class Renderer3D { + public: + void init(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); + void shutdown(); + + // Renders the scene to the given texture view + void render(const Scene& scene, const Camera& camera, float time, + WGPUTextureView target_view, WGPUTextureView depth_view_opt = nullptr); + + // Resize handler (if needed for internal buffers) + void resize(int width, int height); + + private: + void create_pipeline(); + void create_default_resources(); + void update_uniforms(const Scene& scene, const Camera& camera, float time); + + WGPUDevice device_ = nullptr; + WGPUQueue queue_ = nullptr; + WGPUTextureFormat format_ = WGPUTextureFormat_Undefined; + + WGPURenderPipeline pipeline_ = nullptr; + WGPUBindGroup bind_group_ = nullptr; + WGPUBuffer global_uniform_buffer_ = nullptr; + WGPUBuffer object_storage_buffer_ = nullptr; + + // Depth buffer management + WGPUTexture depth_texture_ = nullptr; + WGPUTextureView depth_view_ = nullptr; + int width_ = 0; + int height_ = 0; + + // Max objects capacity + static const int kMaxObjects = 100; +}; |
