Files
vibe3_physics/source/gpu/gpu_texture.hpp
Sergio c9bcce6f9b style: aplicar fixes de clang-tidy (todo excepto uppercase-literal-suffix)
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>
2026-03-21 10:52:07 +01:00

48 lines
1.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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;
};