summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 17:39:33 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 17:39:33 +0100
commit8296fe5180b979b9d1f32f6375b41f0e0a8a399d (patch)
tree28918defcd64001105f8f631a3c0494abd580026 /src/util
parentb85635ea92ace57e4d94288031a3a61a96fcbd2a (diff)
feat(gpu): Add parameter-driven ChromaAberrationEffect
Implements Task #73 - Extends shader parametrization system to ChromaAberrationEffect following the FlashEffect pattern. Changes: - Added ChromaAberrationParams struct (offset_scale, angle) - Added ChromaUniforms with proper WGSL alignment (32 bytes) - Updated shader to compute offset direction from angle parameter - Extended seq_compiler to parse offset/angle parameters - Updated demo.seq with 2 parameterized instances: * Line 50: offset=0.03 angle=0.785 (45° diagonal, stronger) * Line 76: offset=0.01 angle=1.57 (90° vertical, subtle) Technical details: - Backward-compatible default constructor maintained - Migrated from raw buffer to UniformBuffer<ChromaUniforms> - Shader computes direction: vec2(cos(angle), sin(angle)) - Generated code creates ChromaAberrationParams initialization Testing: - All 32/32 tests pass - Demo runs without errors - Binary size: 5.6M stripped (~200-300 bytes impact) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/asset_manager.cc34
-rw-r--r--src/util/check_return.h17
2 files changed, 25 insertions, 26 deletions
diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc
index 2a41876..a0e2a97 100644
--- a/src/util/asset_manager.cc
+++ b/src/util/asset_manager.cc
@@ -86,11 +86,11 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
}
CHECK_RETURN_BEGIN(proc_gen_func_ptr == nullptr, nullptr)
- if (out_size)
- *out_size = 0;
- ERROR_MSG("Unknown procedural function at runtime: %s",
- source_record.proc_func_name_str);
- return nullptr;
+ if (out_size)
+ *out_size = 0;
+ ERROR_MSG("Unknown procedural function at runtime: %s",
+ source_record.proc_func_name_str);
+ return nullptr;
CHECK_RETURN_END
// For this demo, assuming procedural textures are RGBA8 256x256 (for
@@ -101,10 +101,10 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
size_t data_size = header_size + (size_t)width * height * 4; // RGBA8
uint8_t* generated_data = new (std::nothrow) uint8_t[data_size];
CHECK_RETURN_BEGIN(!generated_data, nullptr)
- if (out_size)
- *out_size = 0;
- ERROR_MSG("Failed to allocate memory for procedural asset");
- return nullptr;
+ if (out_size)
+ *out_size = 0;
+ ERROR_MSG("Failed to allocate memory for procedural asset");
+ return nullptr;
CHECK_RETURN_END
// Write header
@@ -114,15 +114,15 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
// Generate data after header
CHECK_RETURN_BEGIN(!proc_gen_func_ptr(generated_data + header_size, width,
- height, source_record.proc_params,
- source_record.num_proc_params),
+ height, source_record.proc_params,
+ source_record.num_proc_params),
nullptr)
- delete[] generated_data;
- if (out_size)
- *out_size = 0;
- ERROR_MSG("Procedural generation failed for asset: %s",
- source_record.proc_func_name_str);
- return nullptr;
+ delete[] generated_data;
+ if (out_size)
+ *out_size = 0;
+ ERROR_MSG("Procedural generation failed for asset: %s",
+ source_record.proc_func_name_str);
+ return nullptr;
CHECK_RETURN_END
cached_record.data = generated_data;
diff --git a/src/util/check_return.h b/src/util/check_return.h
index cd2c293..89ed4bc 100644
--- a/src/util/check_return.h
+++ b/src/util/check_return.h
@@ -45,17 +45,14 @@
// CHECK_RETURN_END
//
// Allows cleanup code before return.
-#define CHECK_RETURN_BEGIN(cond, retval) \
- if (cond) {
-
+#define CHECK_RETURN_BEGIN(cond, retval) if (cond) {
#define ERROR_MSG(...) \
do { \
fprintf(stderr, "Error: " __VA_ARGS__); \
fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
} while (0)
-#define CHECK_RETURN_END \
- }
+#define CHECK_RETURN_END }
// Warning message (non-fatal, execution continues)
// Usage: WARN_IF(count == 0, "No items found");
@@ -84,7 +81,6 @@
// Block-based check - cleanup code preserved, messages stripped
#define CHECK_RETURN_BEGIN(cond, retval) if (cond) {
-
#define ERROR_MSG(...) ((void)0)
#define CHECK_RETURN_END }
@@ -103,7 +99,8 @@
// CHECK_RETURN_IF:
// - Simple error checks with no cleanup needed (90% of cases)
// - Input validation: CHECK_RETURN_IF(argc < 2, 1, "Too few arguments")
-// - Null checks: CHECK_RETURN_IF(ptr == nullptr, nullptr, "Not found: %s", name)
+// - Null checks: CHECK_RETURN_IF(ptr == nullptr, nullptr, "Not found: %s",
+// name)
// - Range checks: CHECK_RETURN_IF(x < 0 || x > max, -1, "Out of range")
//
// CHECK_RETURN_BEGIN/END:
@@ -141,13 +138,15 @@
// - Programming errors (assertion failures, invariant violations)
// - Corrupted state that cannot be recovered
// - Internal consistency checks
-// - Example: FATAL_CHECK(idx >= size, "Index out of bounds: %d >= %d", idx, size)
+// - Example: FATAL_CHECK(idx >= size, "Index out of bounds: %d >= %d", idx,
+// size)
//
// Use CHECK_RETURN for:
// - Recoverable errors (invalid input, missing files)
// - Runtime configuration issues
// - API parameter validation
-// - Example: CHECK_RETURN_IF(file == nullptr, false, "File not found: %s", path)
+// - Example: CHECK_RETURN_IF(file == nullptr, false, "File not found: %s",
+// path)
//
// Key difference:
// - FATAL_XXX: abort() - program terminates