Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixed bug recreating OpenGL textures on window resize

  • Loading branch information
slouken committed Aug 6, 2006
1 parent 4dfb64a commit dcab0337f31e0336ea951acb87bb2e5c4c7d7513
Showing with 29 additions and 18 deletions.
  1. +29 −18 src/video/SDL_renderer_sw.c
@@ -95,6 +95,7 @@ SDL_RenderDriver SW_RenderDriver = {
typedef struct
{
Uint32 format;
SDL_bool updateSize;
int current_texture;
SDL_Texture *texture[3];
SDL_Surface surface;
@@ -276,43 +277,53 @@ static int
SW_ActivateRenderer(SDL_Renderer * renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
int i, n;

if (data->renderer && data->renderer->ActivateRenderer) {
if (data->renderer->ActivateRenderer(data->renderer) < 0) {
return -1;
}
}
if (data->updateSize) {
/* Recreate the textures for the new window size */
if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
n = 2;
} else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
n = 3;
} else {
n = 1;
}
for (i = 0; i < n; ++i) {
if (data->texture[i]) {
DestroyTexture(data->renderer, data->texture[i]);
data->texture[i] = 0;
}
}
for (i = 0; i < n; ++i) {
data->texture[i] =
CreateTexture(data->renderer, data->format, window->w,
window->h);
if (!data->texture[i]) {
return -1;
}
}
data->updateSize = SDL_FALSE;
}
return 0;
}

static int
SW_DisplayModeChanged(SDL_Renderer * renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
int i, n;

if (data->renderer && data->renderer->DisplayModeChanged) {
if (data->renderer->DisplayModeChanged(data->renderer) < 0) {
return -1;
}
}

/* Recreate the textures for the new window size */
if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
n = 2;
} else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
n = 3;
} else {
n = 1;
}
for (i = 0; i < n; ++i) {
if (data->texture[i]) {
DestroyTexture(data->renderer, data->texture[i]);
}
data->texture[i] =
CreateTexture(data->renderer, data->format, window->w, window->h);
}
data->updateSize = SDL_TRUE;
return 0;
}

0 comments on commit dcab033

Please sign in to comment.