- [FIX] Render final a textura, per a evitar la merda que clava la GPU si s'usa acceleració hardware

This commit is contained in:
2025-11-18 10:08:35 +01:00
parent aaa847b4be
commit 22b62dd46b
4 changed files with 20 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.vscode/* .vscode/*
dilemmaker dilemmaker
build/* build/*
*.exe

View File

@@ -7,6 +7,7 @@ namespace draw
{ {
SDL_Window *sdl_window {nullptr}; // La finestra de SDL SDL_Window *sdl_window {nullptr}; // La finestra de SDL
SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL
SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot
SDL_Texture *sdl_source {nullptr}; SDL_Texture *sdl_source {nullptr};
void init(const char *titol, const uint16_t width, const uint16_t height) void init(const char *titol, const uint16_t width, const uint16_t height)
@@ -22,9 +23,17 @@ namespace draw
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n"); SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n");
exit(1); exit(1);
} }
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
//SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND); //SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND);
} }
void resizeSystemTexture(const uint16_t width, const uint16_t height)
{
SDL_DestroyTexture(sdl_texture);
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
}
void quit() void quit()
{ {
SDL_DestroyRenderer(sdl_renderer); SDL_DestroyRenderer(sdl_renderer);
@@ -82,7 +91,7 @@ namespace draw
void setDestination(SDL_Texture *surf) void setDestination(SDL_Texture *surf)
{ {
SDL_SetRenderTarget(sdl_renderer, surf); SDL_SetRenderTarget(sdl_renderer, surf ? surf : sdl_texture);
} }
void setSource(SDL_Texture *surf) void setSource(SDL_Texture *surf)
@@ -185,7 +194,10 @@ namespace draw
// Refresca la pantalla // Refresca la pantalla
void render() void render()
{ {
SDL_SetRenderTarget(sdl_renderer, nullptr);
SDL_RenderTexture(sdl_renderer, sdl_texture, nullptr, nullptr);
SDL_RenderPresent(sdl_renderer); SDL_RenderPresent(sdl_renderer);
SDL_SetRenderTarget(sdl_renderer, sdl_texture);
} }
} }

View File

@@ -7,6 +7,7 @@ namespace draw
enum flip { none, horizontal, vertical, both }; enum flip { none, horizontal, vertical, both };
void init(const char *titol, const uint16_t width, const uint16_t height); void init(const char *titol, const uint16_t width, const uint16_t height);
void resizeSystemTexture(const uint16_t width, const uint16_t height);
void quit(); void quit();
SDL_Texture *createSurface(const uint16_t w, const uint16_t h); SDL_Texture *createSurface(const uint16_t w, const uint16_t h);

View File

@@ -114,6 +114,10 @@ int main(int argc, char *argv[])
{ {
game::windowHasFocus = false; game::windowHasFocus = false;
} }
if (e.type == SDL_EVENT_WINDOW_RESIZED)
{
draw::resizeSystemTexture(e.window.data1, e.window.data2);
}
} }
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame) if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)