diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-01 10:51:15 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-01 10:51:15 +0100 |
| commit | 8bdc4754647c9c6691130fa91d51fee93c5fc88f (patch) | |
| tree | 2cfd7f72a21541c488ea48629eef47a6774fc2c4 /src/3d/renderer.h | |
| parent | 7905abd9f7ad35231289e729b42e3ad57a943ff5 (diff) | |
feat: Implement 3D system and procedural texture manager
- Extended mini_math.h with mat4 multiplication and affine transforms.
- Implemented TextureManager for runtime procedural texture generation and GPU upload.
- Added 3D system components: Camera, Object, Scene, and Renderer3D.
- Created test_3d_render mini-demo for interactive 3D verification.
- Fixed WebGPU validation errors regarding depthSlice and unimplemented WaitAny.
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; +}; |
