summaryrefslogtreecommitdiff
path: root/src/effects/rotating_cube_effect_v2.h
blob: 19ef410f097c1addd601ceb8f58277a0f8788377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This file is part of the 64k demo project.
// It declares RotatingCubeEffectV2 (simplified v2 port).

#pragma once

#include "gpu/effect_v2.h"
#include "gpu/gpu.h"
#include "gpu/uniform_helper.h"
#include "util/mini_math.h"

class RotatingCubeEffectV2 : public EffectV2 {
 public:
  RotatingCubeEffectV2(const GpuContext& ctx,
                       const std::vector<std::string>& inputs,
                       const std::vector<std::string>& outputs);
  ~RotatingCubeEffectV2() override;

  void declare_nodes(NodeRegistry& registry) override;
  void render(WGPUCommandEncoder encoder,
              const UniformsSequenceParams& params,
              NodeRegistry& nodes) override;

 private:
  struct Uniforms {
    mat4 view_proj;
    mat4 inv_view_proj;
    vec4 camera_pos_time;
    vec4 params;
    vec2 resolution;
    float aspect_ratio;
    float _pad;
  };
  static_assert(sizeof(Uniforms) == 176, "Uniforms size mismatch");

  struct ObjectData {
    mat4 model;
    mat4 inv_model;
    vec4 color;
    vec4 params;
  };
  static_assert(sizeof(ObjectData) == 160, "ObjectData size mismatch");

  WGPURenderPipeline pipeline_ = nullptr;
  WGPUBindGroup bind_group_ = nullptr;
  GpuBuffer uniform_buffer_;
  GpuBuffer object_buffer_;
  float rotation_ = 0.0f;
  std::string depth_node_;
};