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.8 KiB
C++
48 lines
1.8 KiB
C++
#pragma once
|
||
|
||
#include <SDL3/SDL_gpu.h>
|
||
#include <SDL3/SDL_surface.h>
|
||
|
||
#include <string>
|
||
|
||
// ============================================================================
|
||
// GpuTexture — SDL_GPU texture + sampler wrapper
|
||
// Handles sprite textures, render targets, and the 1×1 white utility texture.
|
||
// ============================================================================
|
||
class GpuTexture {
|
||
public:
|
||
GpuTexture() = default;
|
||
~GpuTexture() = default;
|
||
|
||
// Load from resource path (pack or disk) using stb_image.
|
||
bool fromFile(SDL_GPUDevice* device, const std::string& file_path);
|
||
|
||
// Upload pixel data from an SDL_Surface to a new GPU texture + sampler.
|
||
// Uses nearest-neighbor filter for sprite pixel-perfect look.
|
||
bool fromSurface(SDL_GPUDevice* device, SDL_Surface* surface, bool nearest = true);
|
||
|
||
// Create an offscreen render target (COLOR_TARGET | SAMPLER usage).
|
||
bool createRenderTarget(SDL_GPUDevice* device, int w, int h, SDL_GPUTextureFormat format);
|
||
|
||
// Create a 1×1 opaque white texture (used for untextured geometry).
|
||
bool createWhite(SDL_GPUDevice* device);
|
||
|
||
// Release GPU resources.
|
||
void destroy(SDL_GPUDevice* device);
|
||
|
||
SDL_GPUTexture* texture() const { return texture_; }
|
||
SDL_GPUSampler* sampler() const { return sampler_; }
|
||
int width() const { return width_; }
|
||
int height() const { return height_; }
|
||
bool isValid() const { return texture_ != nullptr; }
|
||
|
||
private:
|
||
bool uploadPixels(SDL_GPUDevice* device, const void* pixels, int w, int h, SDL_GPUTextureFormat format);
|
||
bool createSampler(SDL_GPUDevice* device, bool nearest);
|
||
|
||
SDL_GPUTexture* texture_ = nullptr;
|
||
SDL_GPUSampler* sampler_ = nullptr;
|
||
int width_ = 0;
|
||
int height_ = 0;
|
||
};
|