eliminat el punter al renderer de 50.000 llocs

This commit is contained in:
2024-07-28 10:45:14 +02:00
parent 7501b4936f
commit 2948684ad3
58 changed files with 492 additions and 401 deletions

View File

@@ -29,7 +29,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
// .png
if (extension == "png")
{
loadFromFile(path, renderer, verbose);
loadFromFile(path, verbose);
}
// .gif
@@ -38,7 +38,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
surface = loadSurface(path.c_str());
addPalette(path.c_str());
setPaletteColor(0, 0, 0x00000000);
createBlank(renderer, width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
flipSurface();
}
@@ -53,7 +53,7 @@ Texture::~Texture()
}
// Carga una imagen desde un fichero
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose)
bool Texture::loadFromFile(std::string path, bool verbose)
{
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
int req_format = STBI_rgb_alpha;
@@ -131,7 +131,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos
}
// Crea una textura en blanco
bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access)
bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access)
{
// Crea una textura sin inicializar
texture = SDL_CreateTexture(renderer, format, access, width, height);
@@ -187,7 +187,7 @@ void Texture::setAlpha(Uint8 alpha)
}
// Renderiza la textura en un punto específico
void Texture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
{
// Establece el destino de renderizado en la pantalla
SDL_Rect renderQuad = {x, y, width, height};
@@ -373,4 +373,10 @@ void Texture::setPalette(int palette)
paletteIndex = palette;
flipSurface();
}
}
// Obtiene el renderizador
SDL_Renderer *Texture::getRenderer()
{
return renderer;
}