From b3eded8d56219fa19029a1b9bb7e7e7584f093d9 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 17 Feb 2026 12:35:59 +0100 Subject: refactor(effects): Factor shared initialization into Effect base class Eliminate ~100 lines of duplicated code across effect subclasses by moving common resource initialization to the base Effect class. Most effects repeatedly created uniforms buffers, samplers, and dummy textures with identical configurations. Changes: - Add shared members to Effect: uniforms_buffer_, sampler_, dummy_texture_* - Add helpers: init_uniforms_buffer(), create_*_sampler(), create_dummy_scene_texture() - Add gpu_create_*_sampler() and gpu_create_dummy_scene_texture() to gpu.h - Move HEADLESS_RETURN_IF_NULL to Effect constructor - Update 7 effects to use base class helpers (Flash, Heptagon, Passthrough, Placeholder, GaussianBlur, Particles, PeakMeter) Benefits: Improved consistency, easier maintenance, reduced binary size. Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/effect.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/gpu/effect.h') diff --git a/src/gpu/effect.h b/src/gpu/effect.h index f5cdf2d..82aa6e1 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -6,6 +6,7 @@ #include "gpu/gpu.h" #include "gpu/sequence.h" +#include "gpu/uniform_helper.h" #include #include @@ -51,6 +52,24 @@ class Effect { int width_ = 1280; int height_ = 720; + // Common resources for most effects + UniformBuffer uniforms_buffer_; + WGPUSampler sampler_ = nullptr; + WGPUTexture dummy_texture_ = nullptr; + WGPUTextureView dummy_texture_view_ = nullptr; + + // Helper: Initialize uniforms buffer (call in subclass constructor) + void init_uniforms_buffer(); + + // Helper: Create linear sampler (call in subclass constructor) + void create_linear_sampler(); + + // Helper: Create nearest sampler (call in subclass constructor) + void create_nearest_sampler(); + + // Helper: Create dummy texture for scene effects (call in subclass constructor) + void create_dummy_scene_texture(); + private: float start_time_; float end_time_; -- cgit v1.2.3