summaryrefslogtreecommitdiff
path: root/src/gpu/effects/circle_mask_effect.h
blob: 57f23895f54862d8767979c4da2d20c89517d8f0 (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
50
// This file is part of the 64k demo project.
// It defines the CircleMaskEffect class for masking system demonstration.
// Creates a circular mask and renders green outside the circle.

#ifndef CIRCLE_MASK_EFFECT_H_
#define CIRCLE_MASK_EFFECT_H_

#include "gpu/effect.h"
#include "gpu/uniform_helper.h"

class CircleMaskEffect : public Effect {
 public:
  CircleMaskEffect(const GpuContext& ctx, float radius = 0.4f);
  ~CircleMaskEffect() override;

  void init(MainSequence* demo) override;
  void compute(WGPUCommandEncoder encoder, float time, float beat,
               float intensity, float aspect_ratio) override;
  void render(WGPURenderPassEncoder pass, float time, float beat,
              float intensity, float aspect_ratio) override;

 private:
  struct ComputeUniforms {
    float radius;
    float aspect_ratio;
    float width;
    float height;
  };

  struct RenderUniforms {
    float width;
    float height;
    float _pad1;
    float _pad2;
  };

  MainSequence* demo_ = nullptr;
  float radius_;

  WGPURenderPipeline compute_pipeline_ = nullptr;
  WGPUBindGroup compute_bind_group_ = nullptr;
  UniformBuffer<ComputeUniforms> compute_uniforms_;

  WGPURenderPipeline render_pipeline_ = nullptr;
  WGPUBindGroup render_bind_group_ = nullptr;
  WGPUSampler mask_sampler_ = nullptr;
  UniformBuffer<RenderUniforms> render_uniforms_;
};

#endif /* CIRCLE_MASK_EFFECT_H_ */