summaryrefslogtreecommitdiff
path: root/src/gpu/effects/rotating_cube_effect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/effects/rotating_cube_effect.cc')
-rw-r--r--src/gpu/effects/rotating_cube_effect.cc67
1 files changed, 19 insertions, 48 deletions
diff --git a/src/gpu/effects/rotating_cube_effect.cc b/src/gpu/effects/rotating_cube_effect.cc
index cd31100..96b02f1 100644
--- a/src/gpu/effects/rotating_cube_effect.cc
+++ b/src/gpu/effects/rotating_cube_effect.cc
@@ -4,7 +4,9 @@
#include "gpu/effects/rotating_cube_effect.h"
#include "generated/assets.h"
+#include "gpu/bind_group_builder.h"
#include "gpu/effects/shader_composer.h"
+#include "gpu/gpu.h"
#include "gpu/sampler_cache.h"
#include "util/asset_manager_utils.h"
@@ -35,17 +37,11 @@ void RotatingCubeEffect::init(MainSequence* demo) {
gpu_create_buffer(ctx_.device, sizeof(ObjectData),
WGPUBufferUsage_Storage | WGPUBufferUsage_CopyDst);
- const WGPUTextureDescriptor tex_desc = {
- .usage =
- WGPUTextureUsage_TextureBinding | WGPUTextureUsage_RenderAttachment,
- .dimension = WGPUTextureDimension_2D,
- .size = {1, 1, 1},
- .format = WGPUTextureFormat_RGBA8Unorm,
- .mipLevelCount = 1,
- .sampleCount = 1,
- };
- noise_texture_ = wgpuDeviceCreateTexture(ctx_.device, &tex_desc);
- noise_view_ = wgpuTextureCreateView(noise_texture_, nullptr);
+ TextureWithView noise = gpu_create_texture_2d(
+ ctx_.device, 1, 1, WGPUTextureFormat_RGBA8Unorm,
+ WGPUTextureUsage_TextureBinding | WGPUTextureUsage_RenderAttachment, 1);
+ noise_texture_ = noise.texture;
+ noise_view_ = noise.view;
noise_sampler_ = SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::linear());
mask_sampler_ = SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::clamp());
@@ -68,45 +64,20 @@ void RotatingCubeEffect::init(MainSequence* demo) {
WGPUShaderModule shader_module =
wgpuDeviceCreateShaderModule(ctx_.device, &shader_desc);
- const WGPUBindGroupLayoutEntry bgl_entries_0[] = {
- {.binding = 0,
- .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment,
- .buffer = {.type = WGPUBufferBindingType_Uniform,
- .minBindingSize = sizeof(Uniforms)}},
- {.binding = 1,
- .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment,
- .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage,
- .minBindingSize = sizeof(ObjectData)}},
- {.binding = 3,
- .visibility = WGPUShaderStage_Fragment,
- .texture = {.sampleType = WGPUTextureSampleType_Float,
- .viewDimension = WGPUTextureViewDimension_2D}},
- {.binding = 4,
- .visibility = WGPUShaderStage_Fragment,
- .sampler = {.type = WGPUSamplerBindingType_Filtering}},
- };
- const WGPUBindGroupLayoutDescriptor bgl_desc_0 = {
- .entryCount = 4,
- .entries = bgl_entries_0,
- };
WGPUBindGroupLayout bgl_0 =
- wgpuDeviceCreateBindGroupLayout(ctx_.device, &bgl_desc_0);
+ BindGroupLayoutBuilder()
+ .uniform(0, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment,
+ sizeof(Uniforms))
+ .storage(1, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment,
+ sizeof(ObjectData))
+ .texture(3, WGPUShaderStage_Fragment)
+ .sampler(4, WGPUShaderStage_Fragment)
+ .build(ctx_.device);
- const WGPUBindGroupLayoutEntry bgl_entries_1[] = {
- {.binding = 0,
- .visibility = WGPUShaderStage_Fragment,
- .texture = {.sampleType = WGPUTextureSampleType_Float,
- .viewDimension = WGPUTextureViewDimension_2D}},
- {.binding = 1,
- .visibility = WGPUShaderStage_Fragment,
- .sampler = {.type = WGPUSamplerBindingType_Filtering}},
- };
- const WGPUBindGroupLayoutDescriptor bgl_desc_1 = {
- .entryCount = 2,
- .entries = bgl_entries_1,
- };
- WGPUBindGroupLayout bgl_1 =
- wgpuDeviceCreateBindGroupLayout(ctx_.device, &bgl_desc_1);
+ WGPUBindGroupLayout bgl_1 = BindGroupLayoutBuilder()
+ .texture(0, WGPUShaderStage_Fragment)
+ .sampler(1, WGPUShaderStage_Fragment)
+ .build(ctx_.device);
const WGPUBindGroupLayout bgls[] = {bgl_0, bgl_1};
const WGPUPipelineLayoutDescriptor pl_desc = {