diff options
Diffstat (limited to 'src/gpu/texture_manager.cc')
| -rw-r--r-- | src/gpu/texture_manager.cc | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/gpu/texture_manager.cc b/src/gpu/texture_manager.cc index 4240245..f2d93ad 100644 --- a/src/gpu/texture_manager.cc +++ b/src/gpu/texture_manager.cc @@ -36,11 +36,21 @@ void TextureManager::create_procedural_texture( def.gen_func(pixel_data.data(), def.width, def.height, def.params.data(), (int)def.params.size()); - WGPUExtent3D tex_size = {(uint32_t)def.width, (uint32_t)def.height, 1}; + create_texture(name, def.width, def.height, pixel_data.data()); + +#if !defined(STRIP_ALL) + std::cout << "Generated procedural texture: " << name << " (" << def.width + << "x" << def.height << ")" << std::endl; +#endif +} + +void TextureManager::create_texture(const std::string& name, int width, int height, const uint8_t* data) { + WGPUExtent3D tex_size = {(uint32_t)width, (uint32_t)height, 1}; // 2. Create GPU Texture WGPUTextureDescriptor tex_desc = {}; - tex_desc.usage = WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst; + tex_desc.usage = + WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst; tex_desc.dimension = WGPUTextureDimension_2D; tex_desc.size = tex_size; tex_desc.format = WGPUTextureFormat_RGBA8Unorm; @@ -63,11 +73,11 @@ void TextureManager::create_procedural_texture( WGPU_TEX_DATA_LAYOUT source_layout = {}; source_layout.offset = 0; - source_layout.bytesPerRow = def.width * 4; - source_layout.rowsPerImage = def.height; + source_layout.bytesPerRow = width * 4; + source_layout.rowsPerImage = height; - wgpuQueueWriteTexture(queue_, &destination, pixel_data.data(), - pixel_data.size(), &source_layout, &tex_size); + wgpuQueueWriteTexture(queue_, &destination, data, + width * height * 4, &source_layout, &tex_size); // 4. Create View WGPUTextureViewDescriptor view_desc = {}; @@ -85,15 +95,10 @@ void TextureManager::create_procedural_texture( GpuTexture gpu_tex; gpu_tex.texture = texture; gpu_tex.view = view; - gpu_tex.width = def.width; - gpu_tex.height = def.height; - + gpu_tex.width = width; + gpu_tex.height = height; + textures_[name] = gpu_tex; - -#if !defined(STRIP_ALL) - std::cout << "Generated procedural texture: " << name << " (" << def.width - << "x" << def.height << ")" << std::endl; -#endif } WGPUTextureView TextureManager::get_texture_view(const std::string& name) { |
