Mercurial > sdl-ios-xcode
changeset 1970:db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 06 Aug 2006 04:39:13 +0000 |
parents | 5d3724f64f2b |
children | 5432b63cc919 |
files | src/events/SDL_windowevents.c src/video/SDL_renderer_gl.c src/video/SDL_renderer_sw.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/cocoa/SDL_cocoaopengl.m test/common.c |
diffstat | 7 files changed, 96 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/events/SDL_windowevents.c Sun Aug 06 00:09:04 2006 +0000 +++ b/src/events/SDL_windowevents.c Sun Aug 06 04:39:13 2006 +0000 @@ -72,6 +72,7 @@ } window->w = data1; window->h = data2; + SDL_OnWindowResized(window); break; case SDL_WINDOWEVENT_MINIMIZED: if (window->flags & SDL_WINDOW_MINIMIZED) {
--- a/src/video/SDL_renderer_gl.c Sun Aug 06 00:09:04 2006 +0000 +++ b/src/video/SDL_renderer_gl.c Sun Aug 06 04:39:13 2006 +0000 @@ -34,6 +34,7 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); static int GL_ActivateRenderer(SDL_Renderer * renderer); +static int GL_DisplayModeChanged(SDL_Renderer * renderer); static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, @@ -97,6 +98,7 @@ typedef struct { SDL_GLContext context; + SDL_bool updateSize; SDL_bool GL_ARB_texture_rectangle_supported; int blendMode; int scaleMode; @@ -219,6 +221,7 @@ } renderer->ActivateRenderer = GL_ActivateRenderer; + renderer->DisplayModeChanged = GL_DisplayModeChanged; renderer->CreateTexture = GL_CreateTexture; renderer->SetTexturePalette = GL_SetTexturePalette; renderer->GetTexturePalette = GL_GetTexturePalette; @@ -282,13 +285,7 @@ } else { data->glEnable(GL_TEXTURE_2D); } - data->glMatrixMode(GL_PROJECTION); - data->glLoadIdentity(); - data->glMatrixMode(GL_MODELVIEW); - data->glLoadIdentity(); - data->glViewport(0, 0, window->w, window->h); - data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, 0.0, - 1.0); + data->updateSize = SDL_TRUE; return renderer; } @@ -299,7 +296,29 @@ GL_RenderData *data = (GL_RenderData *) renderer->driverdata; SDL_Window *window = SDL_GetWindowFromID(renderer->window); - return SDL_GL_MakeCurrent(window->id, data->context); + if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { + return -1; + } + if (data->updateSize) { + data->glMatrixMode(GL_PROJECTION); + data->glLoadIdentity(); + data->glMatrixMode(GL_MODELVIEW); + data->glLoadIdentity(); + data->glViewport(0, 0, window->w, window->h); + data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, + 0.0, 1.0); + data->updateSize = SDL_FALSE; + } + return 0; +} + +static int +GL_DisplayModeChanged(SDL_Renderer * renderer) +{ + GL_RenderData *data = (GL_RenderData *) renderer->driverdata; + + data->updateSize = SDL_TRUE; + return 0; } static __inline__ int
--- a/src/video/SDL_renderer_sw.c Sun Aug 06 00:09:04 2006 +0000 +++ b/src/video/SDL_renderer_sw.c Sun Aug 06 04:39:13 2006 +0000 @@ -31,6 +31,8 @@ /* SDL surface based renderer implementation */ static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags); +static int SW_ActivateRenderer(SDL_Renderer * renderer); +static int SW_DisplayModeChanged(SDL_Renderer * renderer); static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, void **pixels, @@ -179,7 +181,8 @@ SDL_OutOfMemory(); return NULL; } - + renderer->ActivateRenderer = SW_ActivateRenderer; + renderer->DisplayModeChanged = SW_DisplayModeChanged; renderer->CreateTexture = SW_CreateTexture; renderer->QueryTexturePixels = SW_QueryTexturePixels; renderer->SetTexturePalette = SW_SetTexturePalette; @@ -270,6 +273,32 @@ } static int +SW_ActivateRenderer(SDL_Renderer * renderer) +{ + SW_RenderData *data = (SW_RenderData *) renderer->driverdata; + + if (data->renderer && data->renderer->ActivateRenderer) { + if (data->renderer->ActivateRenderer(data->renderer) < 0) { + return -1; + } + } + return 0; +} + +static int +SW_DisplayModeChanged(SDL_Renderer * renderer) +{ + SW_RenderData *data = (SW_RenderData *) renderer->driverdata; + + if (data->renderer && data->renderer->DisplayModeChanged) { + if (data->renderer->DisplayModeChanged(data->renderer) < 0) { + return -1; + } + } + return 0; +} + +static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
--- a/src/video/SDL_sysvideo.h Sun Aug 06 00:09:04 2006 +0000 +++ b/src/video/SDL_sysvideo.h Sun Aug 06 04:39:13 2006 +0000 @@ -56,6 +56,7 @@ struct SDL_Renderer { int (*ActivateRenderer) (SDL_Renderer * renderer); + int (*DisplayModeChanged) (SDL_Renderer * renderer); int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture); int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture, void **pixels, int *pitch); @@ -133,8 +134,7 @@ SDL_DisplayMode *display_modes; SDL_DisplayMode desktop_mode; SDL_DisplayMode current_mode; - SDL_DisplayMode desired_mode; - SDL_DisplayMode *fullscreen_mode; + SDL_DisplayMode fullscreen_mode; SDL_Palette *palette; Uint16 *gamma; @@ -389,6 +389,7 @@ extern void SDL_OnWindowShown(SDL_Window * window); extern void SDL_OnWindowHidden(SDL_Window * window); +extern void SDL_OnWindowResized(SDL_Window * window); extern void SDL_OnWindowFocusGained(SDL_Window * window); extern void SDL_OnWindowFocusLost(SDL_Window * window); extern SDL_WindowID SDL_GetFocusWindow(void);
--- a/src/video/SDL_video.c Sun Aug 06 00:09:04 2006 +0000 +++ b/src/video/SDL_video.c Sun Aug 06 04:39:13 2006 +0000 @@ -645,6 +645,7 @@ SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode) { SDL_VideoDisplay *display; + SDL_DisplayMode fullscreen_mode; int i; if (!_this) { @@ -653,18 +654,29 @@ } display = &SDL_CurrentDisplay; - if (mode) { - SDL_GetClosestDisplayMode(mode, &display->desired_mode); - display->fullscreen_mode = &display->desired_mode; - } else { - display->fullscreen_mode = NULL; + if (!mode) { + mode = &display->desktop_mode; } + SDL_GetClosestDisplayMode(mode, &fullscreen_mode); + if (SDL_memcmp + (&fullscreen_mode, &display->fullscreen_mode, + sizeof(fullscreen_mode)) == 0) { + /* Nothing to do... */ + return 0; + } + display->fullscreen_mode = fullscreen_mode; + /* Actually set the mode if we have a fullscreen window visible */ for (i = 0; i < display->num_windows; ++i) { SDL_Window *window = &display->windows[i]; if (FULLSCREEN_VISIBLE(window)) { - return SDL_SetDisplayMode(display->fullscreen_mode); + if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) { + return -1; + } + } + if (window->flags & SDL_WINDOW_FULLSCREEN) { + SDL_OnWindowResized(window); } } return 0; @@ -678,7 +690,7 @@ return -1; } if (mode) { - *mode = *SDL_CurrentDisplay.fullscreen_mode; + *mode = SDL_CurrentDisplay.fullscreen_mode; } return 0; } @@ -1197,7 +1209,7 @@ } } - SDL_SetDisplayMode(display->fullscreen_mode); + SDL_SetDisplayMode(&display->fullscreen_mode); } } else { window->flags &= ~SDL_WINDOW_FULLSCREEN; @@ -1252,12 +1264,22 @@ } void +SDL_OnWindowResized(SDL_Window * window) +{ + SDL_Renderer *renderer = window->renderer; + + if (renderer && renderer->DisplayModeChanged) { + renderer->DisplayModeChanged(renderer); + } +} + +void SDL_OnWindowFocusGained(SDL_Window * window) { SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); if (window->flags & SDL_WINDOW_FULLSCREEN) { - SDL_SetDisplayMode(display->fullscreen_mode); + SDL_SetDisplayMode(&display->fullscreen_mode); } if (display->gamma && _this->SetDisplayGammaRamp) { _this->SetDisplayGammaRamp(_this, display->gamma);
--- a/src/video/cocoa/SDL_cocoaopengl.m Sun Aug 06 00:09:04 2006 +0000 +++ b/src/video/cocoa/SDL_cocoaopengl.m Sun Aug 06 04:39:13 2006 +0000 @@ -268,6 +268,7 @@ NSOpenGLContext *nscontext = (NSOpenGLContext *)context; [nscontext setView:[windowdata->window contentView]]; + [nscontext update]; [nscontext makeCurrentContext]; } else { [NSOpenGLContext clearCurrentContext];
--- a/test/common.c Sun Aug 06 00:09:04 2006 +0000 +++ b/test/common.c Sun Aug 06 04:39:13 2006 +0000 @@ -749,15 +749,15 @@ fprintf(stderr, "Window %d hidden", event->window.windowID); break; case SDL_WINDOWEVENT_EXPOSED: - fprintf(stderr, "Window %d exposed: %d", event->window.windowID); + fprintf(stderr, "Window %d exposed", event->window.windowID); break; case SDL_WINDOWEVENT_MOVED: - fprintf(stderr, "Window %d moved to %d,%d: %d", + fprintf(stderr, "Window %d moved to %d,%d", event->window.windowID, event->window.data1, event->window.data2); break; case SDL_WINDOWEVENT_RESIZED: - fprintf(stderr, "Window %d resized to %dx%d: %d", + fprintf(stderr, "Window %d resized to %dx%d", event->window.windowID, event->window.data1, event->window.data2); break;