diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-14 14:23:16 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-14 14:23:16 +0100 |
| commit | 1de4c9f9ae7028e0ac4371759dad52858a49a21e (patch) | |
| tree | 488a073344ebd9684b7455aa008a90c0470903db /src/3d | |
| parent | 12f83d4615a38cb0b1ed8a3eb436c4acca170479 (diff) | |
Refactor: extract setup_standard_textures helper
Eliminates repetitive Renderer3D texture initialization across 3 test files.
Creates setup_standard_textures() helper that configures standard noise
(256x256, GPU procedural) and sky (512x256, Perlin) textures.
- New: src/3d/renderer_helpers.{h,cc}
- Refactor: test_3d_physics, test_3d_render, test_mesh use helper
- Build: Added renderer_helpers.cc to CMake 3D_SOURCES
- Result: -52 lines of boilerplate across 3 files
Production effects (Hybrid3DEffect, FlashCubeEffect) use asset-based
textures and retain custom initialization.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/3d')
| -rw-r--r-- | src/3d/renderer_helpers.cc | 29 | ||||
| -rw-r--r-- | src/3d/renderer_helpers.h | 14 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/3d/renderer_helpers.cc b/src/3d/renderer_helpers.cc new file mode 100644 index 0000000..7ee7209 --- /dev/null +++ b/src/3d/renderer_helpers.cc @@ -0,0 +1,29 @@ +// This file is part of the 64k demo project. +// Implementation of Renderer3D helper functions. + +#include "3d/renderer_helpers.h" + +void setup_standard_textures(Renderer3D& renderer, TextureManager& tex_mgr, + WGPUDevice device, WGPUQueue queue) { + tex_mgr.init(device, queue); + + // Standard noise texture (256x256, seed 1234, frequency 16) + GpuProceduralParams noise_params = {}; + noise_params.width = 256; + noise_params.height = 256; + float noise_vals[2] = {1234.0f, 16.0f}; + noise_params.params = noise_vals; + noise_params.num_params = 2; + tex_mgr.create_gpu_noise_texture("noise", noise_params); + renderer.set_noise_texture(tex_mgr.get_texture_view("noise")); + + // Standard sky texture (512x256 Perlin) + GpuProceduralParams sky_params = {}; + sky_params.width = 512; + sky_params.height = 256; + float sky_vals[5] = {42.0f, 4.0f, 1.0f, 0.5f, 6.0f}; + sky_params.params = sky_vals; + sky_params.num_params = 5; + tex_mgr.create_gpu_perlin_texture("sky", sky_params); + renderer.set_sky_texture(tex_mgr.get_texture_view("sky")); +} diff --git a/src/3d/renderer_helpers.h b/src/3d/renderer_helpers.h new file mode 100644 index 0000000..3d0167f --- /dev/null +++ b/src/3d/renderer_helpers.h @@ -0,0 +1,14 @@ +// This file is part of the 64k demo project. +// Helper functions for Renderer3D setup and common initialization patterns. + +#pragma once + +#include "3d/renderer.h" +#include "gpu/texture_manager.h" + +// Sets up standard noise and sky textures for Renderer3D. +// Creates GPU-procedural noise (256x256, seed 1234, freq 16) and +// Perlin sky (512x256) textures in the TextureManager, then binds +// them to the renderer. +void setup_standard_textures(Renderer3D& renderer, TextureManager& tex_mgr, + WGPUDevice device, WGPUQueue queue); |
