summaryrefslogtreecommitdiff
path: root/src/gpu/effect.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/effect.h')
-rw-r--r--src/gpu/effect.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/gpu/effect.h b/src/gpu/effect.h
index f008c8d..7991700 100644
--- a/src/gpu/effect.h
+++ b/src/gpu/effect.h
@@ -22,16 +22,13 @@ class Effect {
}
virtual void start() {
}
- virtual void compute(WGPUCommandEncoder encoder, float time, float beat,
- float intensity, float aspect_ratio) {
+ virtual void compute(WGPUCommandEncoder encoder,
+ const CommonPostProcessUniforms& uniforms) {
(void)encoder;
- (void)time;
- (void)beat;
- (void)intensity;
- (void)aspect_ratio;
+ (void)uniforms;
}
- virtual void render(WGPURenderPassEncoder pass, float time, float beat,
- float intensity, float aspect_ratio) = 0;
+ virtual void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) = 0;
virtual void resize(int width, int height) {
width_ = width;
height_ = height;
@@ -50,6 +47,21 @@ class Effect {
return false;
}
+ // Helper: get initialized CommonPostProcessUniforms based on current dimensions
+ // If aspect_ratio < 0, computes from width_/height_
+ CommonPostProcessUniforms get_common_uniforms(float time = 0.0f, float beat = 0.0f,
+ float intensity = 0.0f,
+ float aspect_ratio = -1.0f) const {
+ return {
+ .resolution = {static_cast<float>(width_), static_cast<float>(height_)},
+ ._pad = {0.0f, 0.0f},
+ .aspect_ratio = aspect_ratio < 0.0f ? static_cast<float>(width_) / static_cast<float>(height_) : aspect_ratio,
+ .time = time,
+ .beat = beat,
+ .audio_intensity = intensity,
+ };
+ }
+
protected:
const GpuContext& ctx_;
UniformBuffer<CommonPostProcessUniforms> uniforms_;
@@ -64,10 +76,10 @@ class PostProcessEffect : public Effect {
bool is_post_process() const override {
return true;
}
- void compute(WGPUCommandEncoder, float, float, float, float) override {
+ void compute(WGPUCommandEncoder, const CommonPostProcessUniforms&) override {
}
- void render(WGPURenderPassEncoder pass, float time, float beat,
- float intensity, float aspect_ratio) override;
+ void render(WGPURenderPassEncoder pass,
+ const CommonPostProcessUniforms& uniforms) override;
virtual void update_bind_group(WGPUTextureView input_view) = 0;
protected: