summaryrefslogtreecommitdiff
path: root/src/gpu/effect.h
blob: 0d7e35eb11ef43caad3a3a20e9488d6f8842cc4b (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
51
52
53
54
55
56
57
58
59
60
61
62
63
// Effect: Base class for effects with multi-input/multi-output support

#ifndef EFFECT_H
#define EFFECT_H
#pragma once

#include "gpu/gpu.h"
#include "gpu/sequence.h"
#include <string>
#include <vector>

class NodeRegistry;

class Effect {
 public:
  Effect(const GpuContext& ctx, const std::vector<std::string>& inputs,
         const std::vector<std::string>& outputs, float start_time,
         float end_time);
  virtual ~Effect() = default;

  // Optional: Declare temporary nodes (e.g., multi-pass intermediate buffers)
  virtual void declare_nodes(NodeRegistry& registry) {
    (void)registry;
  }

  // Dispatch render with automatic passthrough outside [start, end]
  void dispatch_render(WGPUCommandEncoder encoder,
                       const UniformsSequenceParams& params,
                       NodeRegistry& nodes);

  // Render effect (multi-input/multi-output) - override in derived classes
  virtual void render(WGPUCommandEncoder encoder,
                      const UniformsSequenceParams& params,
                      NodeRegistry& nodes) = 0;

  // Resize notification
  virtual void resize(int width, int height) {
    width_ = width;
    height_ = height;
  }

  const std::vector<std::string>& input_nodes() const {
    return input_nodes_;
  }
  const std::vector<std::string>& output_nodes() const {
    return output_nodes_;
  }

 protected:
  const GpuContext& ctx_;
  std::vector<std::string> input_nodes_;
  std::vector<std::string> output_nodes_;
  int width_ = 1280;
  int height_ = 720;

 private:
  float start_time_;
  float end_time_;

  // Auto-passthrough helper for 1:1 input/output effects
  void blit_input_to_output(WGPUCommandEncoder encoder, NodeRegistry& nodes);
};
#endif // EFFECT_H