diff options
Diffstat (limited to 'src/gpu/texture_manager.h')
| -rw-r--r-- | src/gpu/texture_manager.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/gpu/texture_manager.h b/src/gpu/texture_manager.h index 23fdbe8..5a2b9f8 100644 --- a/src/gpu/texture_manager.h +++ b/src/gpu/texture_manager.h @@ -23,6 +23,13 @@ struct GpuTexture { int height; }; +struct GpuProceduralParams { + int width; + int height; + const float* params; + int num_params; +}; + class TextureManager { public: void init(WGPUDevice device, WGPUQueue queue); @@ -36,11 +43,72 @@ class TextureManager { void create_texture(const std::string& name, int width, int height, const uint8_t* data); + // GPU procedural generation + void create_gpu_noise_texture(const std::string& name, + const GpuProceduralParams& params); + void create_gpu_perlin_texture(const std::string& name, + const GpuProceduralParams& params); + void create_gpu_grid_texture(const std::string& name, + const GpuProceduralParams& params); + +#if !defined(STRIP_GPU_COMPOSITE) + enum class SamplerType { + LinearClamp, + LinearRepeat, + NearestClamp, + NearestRepeat + }; + + // GPU composite generation (multi-input textures) + void create_gpu_composite_texture(const std::string& name, + const std::string& shader_func, + const char* shader_code, + const void* uniform_data, + size_t uniform_size, + int width, int height, + const std::vector<std::string>& input_names, + SamplerType sampler = SamplerType::LinearClamp); +#endif + +#if !defined(STRIP_ALL) + // On-demand lazy generation (stripped in final builds) + WGPUTextureView get_or_generate_gpu_texture(const std::string& name, + const GpuProceduralParams& params); +#endif + // Retrieves a texture view by name (returns nullptr if not found) WGPUTextureView get_texture_view(const std::string& name); private: + struct ComputePipelineInfo { + WGPUComputePipeline pipeline; + const char* shader_code; + size_t uniform_size; + int num_input_textures; + }; + + WGPUComputePipeline get_or_create_compute_pipeline(const std::string& func_name, + const char* shader_code, + size_t uniform_size, + int num_input_textures = 0); + void dispatch_compute(const std::string& func_name, WGPUTexture target, + const GpuProceduralParams& params, const void* uniform_data, + size_t uniform_size); + +#if !defined(STRIP_GPU_COMPOSITE) + void dispatch_composite(const std::string& func_name, WGPUTexture target, + const GpuProceduralParams& params, + const void* uniform_data, size_t uniform_size, + const std::vector<WGPUTextureView>& input_views, + SamplerType sampler_type); +#endif + WGPUDevice device_; WGPUQueue queue_; std::map<std::string, GpuTexture> textures_; + std::map<std::string, ComputePipelineInfo> compute_pipelines_; +#if !defined(STRIP_GPU_COMPOSITE) + WGPUSampler get_or_create_sampler(SamplerType type); + std::map<SamplerType, WGPUSampler> samplers_; +#endif }; |
