diff options
Diffstat (limited to 'src/effects/rotating_cube_effect.cc')
| -rw-r--r-- | src/effects/rotating_cube_effect.cc | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc index c892dfe..42a0ba7 100644 --- a/src/effects/rotating_cube_effect.cc +++ b/src/effects/rotating_cube_effect.cc @@ -1,15 +1,15 @@ // This file is part of the 64k demo project. // It implements RotatingCube. -#include "util/fatal_error.h" #include "effects/rotating_cube_effect.h" +#include "effects/shaders.h" #include "gpu/bind_group_builder.h" #include "gpu/gpu.h" -#include "effects/shaders.h" +#include "util/fatal_error.h" RotatingCube::RotatingCube(const GpuContext& ctx, - const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs) + const std::vector<std::string>& inputs, + const std::vector<std::string>& outputs) : Effect(ctx, inputs, outputs), depth_node_(outputs[0] + "_depth") { // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL) HEADLESS_RETURN_IF_NULL(ctx_.device); @@ -113,8 +113,8 @@ void RotatingCube::declare_nodes(NodeRegistry& registry) { } void RotatingCube::render(WGPUCommandEncoder encoder, - const UniformsSequenceParams& params, - NodeRegistry& nodes) { + const UniformsSequenceParams& params, + NodeRegistry& nodes) { rotation_ += 0.016f * 1.5f; // Camera setup @@ -138,7 +138,8 @@ void RotatingCube::render(WGPUCommandEncoder encoder, const Uniforms uniforms = { .view_proj = view_proj, .inv_view_proj = view_proj.inverse(), - .camera_pos_time = vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time), + .camera_pos_time = + vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time), .params = vec4(1.0f, 0.0f, 0.0f, 0.0f), .resolution = params.resolution, .aspect_ratio = params.aspect_ratio, @@ -163,8 +164,9 @@ void RotatingCube::render(WGPUCommandEncoder encoder, if (input_tex && output_tex) { WGPUTexelCopyTextureInfo src = { .texture = input_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All}; - WGPUTexelCopyTextureInfo dst = { - .texture = output_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All}; + WGPUTexelCopyTextureInfo dst = {.texture = output_tex, + .mipLevel = 0, + .aspect = WGPUTextureAspect_All}; WGPUExtent3D copy_size = {(uint32_t)params.resolution.x, (uint32_t)params.resolution.y, 1}; wgpuCommandEncoderCopyTextureToTexture(encoder, &src, &dst, ©_size); @@ -179,7 +181,7 @@ void RotatingCube::render(WGPUCommandEncoder encoder, WGPURenderPassColorAttachment color_attachment = { .view = color_view, .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, -// .loadOp = WGPULoadOp_Clear, + // .loadOp = WGPULoadOp_Clear, .loadOp = WGPULoadOp_Load, .storeOp = WGPUStoreOp_Store, .clearValue = {0.0, 0.0, 0.0, 0.0}}; @@ -190,15 +192,16 @@ void RotatingCube::render(WGPUCommandEncoder encoder, .depthStoreOp = WGPUStoreOp_Discard, .depthClearValue = 1.0f}; - WGPURenderPassDescriptor pass_desc = { - .colorAttachmentCount = 1, - .colorAttachments = &color_attachment, - .depthStencilAttachment = &depth_attachment}; + WGPURenderPassDescriptor pass_desc = {.colorAttachmentCount = 1, + .colorAttachments = &color_attachment, + .depthStencilAttachment = + &depth_attachment}; - WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); + WGPURenderPassEncoder pass = + wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); wgpuRenderPassEncoderSetPipeline(pass, pipeline_); wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); - wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0); // 36 vertices for cube + wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0); // 36 vertices for cube wgpuRenderPassEncoderEnd(pass); wgpuRenderPassEncoderRelease(pass); } |
