Fixed loading textures when the window starts hidden.
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jan 2012 21:46:06 -0500
changeset 6260fd494c5f305b
parent 6259 4aef5b792087
child 6261 caf3439402fd
Fixed loading textures when the window starts hidden.
The viewport automatically resets to the window size when you programmatically resize the window.
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/video/SDL_video.c
src/video/cocoa/SDL_cocoaopengl.m
     1.1 --- a/src/render/SDL_render.c	Sun Jan 22 19:47:33 2012 -0500
     1.2 +++ b/src/render/SDL_render.c	Sun Jan 22 21:46:06 2012 -0500
     1.3 @@ -100,7 +100,7 @@
     1.4                  renderer->WindowEvent(renderer, &event->window);
     1.5              }
     1.6  
     1.7 -            if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     1.8 +            if (event->window.event == SDL_WINDOWEVENT_RESIZED) {
     1.9                  /* Try to keep the previous viewport centered */
    1.10                  int w, h;
    1.11                  SDL_Rect viewport;
    1.12 @@ -116,10 +116,40 @@
    1.13                      viewport.h = renderer->viewport.h;
    1.14                      SDL_RenderSetViewport(renderer, &viewport);
    1.15                  }
    1.16 +                renderer->resized = SDL_TRUE;
    1.17 +            } else if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
    1.18 +                int w, h;
    1.19 +                SDL_Rect viewport;
    1.20 +
    1.21 +                if (!renderer->resized) {
    1.22 +                    /* Window was programmatically resized, reset viewport */
    1.23 +                    SDL_GetWindowSize(window, &w, &h);
    1.24 +                    if (renderer->target) {
    1.25 +                        renderer->viewport_backup.x = 0;
    1.26 +                        renderer->viewport_backup.y = 0;
    1.27 +                        renderer->viewport_backup.w = w;
    1.28 +                        renderer->viewport_backup.h = h;
    1.29 +                    } else {
    1.30 +                        viewport.x = 0;
    1.31 +                        viewport.y = 0;
    1.32 +                        viewport.w = w;
    1.33 +                        viewport.h = h;
    1.34 +                        SDL_RenderSetViewport(renderer, &viewport);
    1.35 +                    }
    1.36 +                    renderer->resized = SDL_FALSE;
    1.37 +                }
    1.38 +            } else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) {
    1.39 +                renderer->hidden = SDL_TRUE;
    1.40 +            } else if (event->window.event == SDL_WINDOWEVENT_SHOWN) {
    1.41 +                if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
    1.42 +                    renderer->hidden = SDL_FALSE;
    1.43 +                }
    1.44              } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
    1.45 -                renderer->minimized = SDL_TRUE;
    1.46 +                renderer->hidden = SDL_TRUE;
    1.47              } else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
    1.48 -                renderer->minimized = SDL_FALSE;
    1.49 +                if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
    1.50 +                    renderer->hidden = SDL_FALSE;
    1.51 +                }
    1.52              }
    1.53          }
    1.54      }
    1.55 @@ -218,10 +248,10 @@
    1.56          renderer->magic = &renderer_magic;
    1.57          renderer->window = window;
    1.58  
    1.59 -        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
    1.60 -            renderer->minimized = SDL_TRUE;
    1.61 +        if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
    1.62 +            renderer->hidden = SDL_TRUE;
    1.63          } else {
    1.64 -            renderer->minimized = SDL_FALSE;
    1.65 +            renderer->hidden = SDL_FALSE;
    1.66          }
    1.67  
    1.68          SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
    1.69 @@ -974,8 +1004,8 @@
    1.70  {
    1.71      CHECK_RENDERER_MAGIC(renderer, -1);
    1.72  
    1.73 -    /* Don't draw while we're minimized */
    1.74 -    if (renderer->minimized) {
    1.75 +    /* Don't draw while we're hidden */
    1.76 +    if (renderer->hidden) {
    1.77          return 0;
    1.78      }
    1.79      return renderer->RenderClear(renderer);
    1.80 @@ -1004,8 +1034,8 @@
    1.81      if (count < 1) {
    1.82          return 0;
    1.83      }
    1.84 -    /* Don't draw while we're minimized */
    1.85 -    if (renderer->minimized) {
    1.86 +    /* Don't draw while we're hidden */
    1.87 +    if (renderer->hidden) {
    1.88          return 0;
    1.89      }
    1.90      return renderer->RenderDrawPoints(renderer, points, count);
    1.91 @@ -1036,8 +1066,8 @@
    1.92      if (count < 2) {
    1.93          return 0;
    1.94      }
    1.95 -    /* Don't draw while we're minimized */
    1.96 -    if (renderer->minimized) {
    1.97 +    /* Don't draw while we're hidden */
    1.98 +    if (renderer->hidden) {
    1.99          return 0;
   1.100      }
   1.101      return renderer->RenderDrawLines(renderer, points, count);
   1.102 @@ -1089,8 +1119,8 @@
   1.103          return 0;
   1.104      }
   1.105  
   1.106 -    /* Don't draw while we're minimized */
   1.107 -    if (renderer->minimized) {
   1.108 +    /* Don't draw while we're hidden */
   1.109 +    if (renderer->hidden) {
   1.110          return 0;
   1.111      }
   1.112      for (i = 0; i < count; ++i) {
   1.113 @@ -1132,8 +1162,8 @@
   1.114      if (count < 1) {
   1.115          return 0;
   1.116      }
   1.117 -    /* Don't draw while we're minimized */
   1.118 -    if (renderer->minimized) {
   1.119 +    /* Don't draw while we're hidden */
   1.120 +    if (renderer->hidden) {
   1.121          return 0;
   1.122      }
   1.123      return renderer->RenderFillRects(renderer, rects, count);
   1.124 @@ -1193,8 +1223,8 @@
   1.125          texture = texture->native;
   1.126      }
   1.127  
   1.128 -    /* Don't draw while we're minimized */
   1.129 -    if (renderer->minimized) {
   1.130 +    /* Don't draw while we're hidden */
   1.131 +    if (renderer->hidden) {
   1.132          return 0;
   1.133      }
   1.134      return renderer->RenderCopy(renderer, texture, &real_srcrect,
   1.135 @@ -1246,8 +1276,8 @@
   1.136  {
   1.137      CHECK_RENDERER_MAGIC(renderer, );
   1.138  
   1.139 -    /* Don't draw while we're minimized */
   1.140 -    if (renderer->minimized) {
   1.141 +    /* Don't draw while we're hidden */
   1.142 +    if (renderer->hidden) {
   1.143          return;
   1.144      }
   1.145      renderer->RenderPresent(renderer);
     2.1 --- a/src/render/SDL_sysrender.h	Sun Jan 22 19:47:33 2012 -0500
     2.2 +++ b/src/render/SDL_sysrender.h	Sun Jan 22 21:46:06 2012 -0500
     2.3 @@ -100,7 +100,8 @@
     2.4  
     2.5      /* The window associated with the renderer */
     2.6      SDL_Window *window;
     2.7 -    SDL_bool minimized;
     2.8 +    SDL_bool hidden;
     2.9 +    SDL_bool resized;
    2.10  
    2.11      /* The drawable area within the window */
    2.12      SDL_Rect viewport;
     3.1 --- a/src/render/opengl/SDL_render_gl.c	Sun Jan 22 19:47:33 2012 -0500
     3.2 +++ b/src/render/opengl/SDL_render_gl.c	Sun Jan 22 21:46:06 2012 -0500
     3.3 @@ -412,7 +412,9 @@
     3.4  static void
     3.5  GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
     3.6  {
     3.7 -    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     3.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
     3.9 +        event->event == SDL_WINDOWEVENT_SHOWN ||
    3.10 +        event->event == SDL_WINDOWEVENT_HIDDEN) {
    3.11          /* Rebind the context to the window area and update matrices */
    3.12          SDL_CurrentContext = NULL;
    3.13      }
     4.1 --- a/src/render/opengles/SDL_render_gles.c	Sun Jan 22 19:47:33 2012 -0500
     4.2 +++ b/src/render/opengles/SDL_render_gles.c	Sun Jan 22 21:46:06 2012 -0500
     4.3 @@ -370,7 +370,9 @@
     4.4  {
     4.5      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
     4.6      
     4.7 -    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     4.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
     4.9 +        event->event == SDL_WINDOWEVENT_SHOWN ||
    4.10 +        event->event == SDL_WINDOWEVENT_HIDDEN) {
    4.11          /* Rebind the context to the window area and update matrices */
    4.12          SDL_CurrentContext = NULL;
    4.13      }
     5.1 --- a/src/render/opengles2/SDL_render_gles2.c	Sun Jan 22 19:47:33 2012 -0500
     5.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sun Jan 22 21:46:06 2012 -0500
     5.3 @@ -241,7 +241,9 @@
     5.4  {
     5.5      GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
     5.6  
     5.7 -    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     5.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
     5.9 +        event->event == SDL_WINDOWEVENT_SHOWN ||
    5.10 +        event->event == SDL_WINDOWEVENT_HIDDEN) {
    5.11          /* Rebind the context to the window area */
    5.12          SDL_CurrentContext = NULL;
    5.13      }
     6.1 --- a/src/video/SDL_video.c	Sun Jan 22 19:47:33 2012 -0500
     6.2 +++ b/src/video/SDL_video.c	Sun Jan 22 21:46:06 2012 -0500
     6.3 @@ -107,6 +107,11 @@
     6.4          return retval; \
     6.5      }
     6.6  
     6.7 +#define INVALIDATE_GLCONTEXT() \
     6.8 +    _this->current_glwin = NULL; \
     6.9 +    _this->current_glctx = NULL;
    6.10 +
    6.11 +
    6.12  /* Support for framebuffer emulation using an accelerated renderer */
    6.13  
    6.14  #define SDL_WINDOWTEXTUREDATA   "_SDL_WindowTextureData"
    6.15 @@ -1846,12 +1851,14 @@
    6.16  void
    6.17  SDL_OnWindowShown(SDL_Window * window)
    6.18  {
    6.19 +    INVALIDATE_GLCONTEXT();
    6.20      SDL_OnWindowRestored(window);
    6.21  }
    6.22  
    6.23  void
    6.24  SDL_OnWindowHidden(SDL_Window * window)
    6.25  {
    6.26 +    INVALIDATE_GLCONTEXT();
    6.27      SDL_UpdateFullscreenMode(window, SDL_FALSE);
    6.28  }
    6.29  
     7.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Sun Jan 22 19:47:33 2012 -0500
     7.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Sun Jan 22 21:46:06 2012 -0500
     7.3 @@ -200,14 +200,16 @@
     7.4          SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
     7.5          NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
     7.6  
     7.7 +        if (window->flags & SDL_WINDOW_SHOWN) {
     7.8  #ifndef FULLSCREEN_TOGGLEABLE
     7.9 -        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.10 -            [nscontext setFullScreen];
    7.11 -        } else
    7.12 +            if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.13 +                [nscontext setFullScreen];
    7.14 +            } else
    7.15  #endif
    7.16 -        {
    7.17 -            [nscontext setView:[windowdata->nswindow contentView]];
    7.18 -            [nscontext update];
    7.19 +            {
    7.20 +                [nscontext setView:[windowdata->nswindow contentView]];
    7.21 +                [nscontext update];
    7.22 +            }
    7.23          }
    7.24          [nscontext makeCurrentContext];
    7.25      } else {