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

Fixed loading textures when the window starts hidden.

The viewport automatically resets to the window size when you programmatically resize the window.
  • Loading branch information
slouken committed Jan 23, 2012
1 parent 9855fa5 commit 9bf2ce79c351574461d911fd94969c8c6c19e116
@@ -100,7 +100,7 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
renderer->WindowEvent(renderer, &event->window);
}

if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event->window.event == SDL_WINDOWEVENT_RESIZED) {
/* Try to keep the previous viewport centered */
int w, h;
SDL_Rect viewport;
@@ -116,10 +116,40 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
viewport.h = renderer->viewport.h;
SDL_RenderSetViewport(renderer, &viewport);
}
renderer->resized = SDL_TRUE;
} else if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
int w, h;
SDL_Rect viewport;

if (!renderer->resized) {
/* Window was programmatically resized, reset viewport */
SDL_GetWindowSize(window, &w, &h);
if (renderer->target) {
renderer->viewport_backup.x = 0;
renderer->viewport_backup.y = 0;
renderer->viewport_backup.w = w;
renderer->viewport_backup.h = h;
} else {
viewport.x = 0;
viewport.y = 0;
viewport.w = w;
viewport.h = h;
SDL_RenderSetViewport(renderer, &viewport);
}
renderer->resized = SDL_FALSE;
}
} else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) {
renderer->hidden = SDL_TRUE;
} else if (event->window.event == SDL_WINDOWEVENT_SHOWN) {
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
renderer->hidden = SDL_FALSE;
}
} else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
renderer->minimized = SDL_TRUE;
renderer->hidden = SDL_TRUE;
} else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
renderer->minimized = SDL_FALSE;
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
renderer->hidden = SDL_FALSE;
}
}
}
}
@@ -218,10 +248,10 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
renderer->magic = &renderer_magic;
renderer->window = window;

if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
renderer->minimized = SDL_TRUE;
if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
renderer->hidden = SDL_TRUE;
} else {
renderer->minimized = SDL_FALSE;
renderer->hidden = SDL_FALSE;
}

SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
@@ -974,8 +1004,8 @@ SDL_RenderClear(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, -1);

/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
return renderer->RenderClear(renderer);
@@ -1004,8 +1034,8 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
if (count < 1) {
return 0;
}
/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
return renderer->RenderDrawPoints(renderer, points, count);
@@ -1036,8 +1066,8 @@ SDL_RenderDrawLines(SDL_Renderer * renderer,
if (count < 2) {
return 0;
}
/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
return renderer->RenderDrawLines(renderer, points, count);
@@ -1089,8 +1119,8 @@ SDL_RenderDrawRects(SDL_Renderer * renderer,
return 0;
}

/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
for (i = 0; i < count; ++i) {
@@ -1132,8 +1162,8 @@ SDL_RenderFillRects(SDL_Renderer * renderer,
if (count < 1) {
return 0;
}
/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
return renderer->RenderFillRects(renderer, rects, count);
@@ -1193,8 +1223,8 @@ SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
texture = texture->native;
}

/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
return renderer->RenderCopy(renderer, texture, &real_srcrect,
@@ -1246,8 +1276,8 @@ SDL_RenderPresent(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, );

/* Don't draw while we're minimized */
if (renderer->minimized) {
/* Don't draw while we're hidden */
if (renderer->hidden) {
return;
}
renderer->RenderPresent(renderer);
@@ -100,7 +100,8 @@ struct SDL_Renderer

/* The window associated with the renderer */
SDL_Window *window;
SDL_bool minimized;
SDL_bool hidden;
SDL_bool resized;

/* The drawable area within the window */
SDL_Rect viewport;
@@ -412,7 +412,9 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
static void
GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
event->event == SDL_WINDOWEVENT_SHOWN ||
event->event == SDL_WINDOWEVENT_HIDDEN) {
/* Rebind the context to the window area and update matrices */
SDL_CurrentContext = NULL;
}
@@ -370,7 +370,9 @@ GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;

if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
event->event == SDL_WINDOWEVENT_SHOWN ||
event->event == SDL_WINDOWEVENT_HIDDEN) {
/* Rebind the context to the window area and update matrices */
SDL_CurrentContext = NULL;
}
@@ -241,7 +241,9 @@ GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;

if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
event->event == SDL_WINDOWEVENT_SHOWN ||
event->event == SDL_WINDOWEVENT_HIDDEN) {
/* Rebind the context to the window area */
SDL_CurrentContext = NULL;
}
@@ -107,6 +107,11 @@ static SDL_VideoDevice *_this = NULL;
return retval; \
}

#define INVALIDATE_GLCONTEXT() \
_this->current_glwin = NULL; \
_this->current_glctx = NULL;


/* Support for framebuffer emulation using an accelerated renderer */

#define SDL_WINDOWTEXTUREDATA "_SDL_WindowTextureData"
@@ -1846,12 +1851,14 @@ SDL_GetWindowGrab(SDL_Window * window)
void
SDL_OnWindowShown(SDL_Window * window)
{
INVALIDATE_GLCONTEXT();
SDL_OnWindowRestored(window);
}

void
SDL_OnWindowHidden(SDL_Window * window)
{
INVALIDATE_GLCONTEXT();
SDL_UpdateFullscreenMode(window, SDL_FALSE);
}

@@ -200,14 +200,16 @@
SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
NSOpenGLContext *nscontext = (NSOpenGLContext *)context;

if (window->flags & SDL_WINDOW_SHOWN) {
#ifndef FULLSCREEN_TOGGLEABLE
if (window->flags & SDL_WINDOW_FULLSCREEN) {
[nscontext setFullScreen];
} else
if (window->flags & SDL_WINDOW_FULLSCREEN) {
[nscontext setFullScreen];
} else
#endif
{
[nscontext setView:[windowdata->nswindow contentView]];
[nscontext update];
{
[nscontext setView:[windowdata->nswindow contentView]];
[nscontext update];
}
}
[nscontext makeCurrentContext];
} else {

0 comments on commit 9bf2ce7

Please sign in to comment.