Corregidos ~2570 issues automáticamente con clang-tidy --fix-errors más ajustes manuales posteriores: - modernize: designated-initializers, trailing-return-type, use-auto, avoid-c-arrays (→ std::array<>), use-ranges, use-emplace, deprecated-headers, use-equals-default, pass-by-value, return-braced-init-list, use-default-member-init - readability: math-missing-parentheses, implicit-bool-conversion, braces-around-statements, isolate-declaration, use-std-min-max, identifier-naming, else-after-return, redundant-casting, convert-member-functions-to-static, make-member-function-const, static-accessed-through-instance - performance: avoid-endl, unnecessary-value-param, type-promotion, inefficient-vector-operation - dead code: XOR_KEY (orphan tras eliminar encryptData/decryptData), dead stores en engine.cpp y png_shape.cpp - NOLINT justificado en 10 funciones con alta complejidad cognitiva (initialize, render, main, processEvents, update×3, performDemoAction, randomizeOnDemoStart, renderDebugHUD, AppLogo::update) Compilación: gcc -Wall sin warnings. clang-tidy: 0 issues. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.9 KiB
C++
48 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL_gpu.h>
|
|
|
|
#include <cstdint>
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// BallGPUData — 32-byte per-instance record stored in VRAM.
|
|
// Positions and sizes pre-converted to NDC space on CPU so the vertex shader
|
|
// needs no screen-dimension uniform.
|
|
// cx, cy : NDC center (cx = (x + w/2)/sw*2-1, cy = 1-(y+h/2)/sh*2)
|
|
// hw, hh : NDC half-size (hw = w/sw, hh = h/sh, both positive)
|
|
// r,g,b,a: RGBA in [0,1]
|
|
// ---------------------------------------------------------------------------
|
|
struct BallGPUData {
|
|
float cx, cy; // NDC center
|
|
float hw, hh; // NDC half-size (positive)
|
|
float r, g, b, a; // RGBA color [0,1]
|
|
};
|
|
static_assert(sizeof(BallGPUData) == 32, "BallGPUData must be 32 bytes");
|
|
|
|
// ============================================================================
|
|
// GpuBallBuffer — owns the GPU vertex buffer used for instanced ball rendering.
|
|
//
|
|
// Usage per frame:
|
|
// buffer.upload(device, cmd, data, count); // inside a copy pass
|
|
// // Then in render pass: bind buffer, SDL_DrawGPUPrimitives(pass, 6, count, 0, 0)
|
|
// ============================================================================
|
|
class GpuBallBuffer {
|
|
public:
|
|
static constexpr int MAX_BALLS = 500000;
|
|
|
|
bool init(SDL_GPUDevice* device);
|
|
void destroy(SDL_GPUDevice* device);
|
|
|
|
// Upload ball array to GPU via an internal copy pass.
|
|
// count is clamped to MAX_BALLS. Returns false on error or empty input.
|
|
bool upload(SDL_GPUDevice* device, SDL_GPUCommandBuffer* cmd, const BallGPUData* data, int count);
|
|
|
|
SDL_GPUBuffer* buffer() const { return gpu_buf_; }
|
|
int count() const { return count_; }
|
|
|
|
private:
|
|
SDL_GPUBuffer* gpu_buf_ = nullptr;
|
|
SDL_GPUTransferBuffer* transfer_buf_ = nullptr;
|
|
int count_ = 0;
|
|
};
|