Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gl.c @ 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 | a788656ca29a |
children | 70deaf574153 |
comparison
equal
deleted
inserted
replaced
1969:5d3724f64f2b | 1970:db3ba6c0d0df |
---|---|
32 | 32 |
33 /* OpenGL renderer implementation */ | 33 /* OpenGL renderer implementation */ |
34 | 34 |
35 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); | 35 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); |
36 static int GL_ActivateRenderer(SDL_Renderer * renderer); | 36 static int GL_ActivateRenderer(SDL_Renderer * renderer); |
37 static int GL_DisplayModeChanged(SDL_Renderer * renderer); | |
37 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 38 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
38 static int GL_SetTexturePalette(SDL_Renderer * renderer, | 39 static int GL_SetTexturePalette(SDL_Renderer * renderer, |
39 SDL_Texture * texture, | 40 SDL_Texture * texture, |
40 const SDL_Color * colors, int firstcolor, | 41 const SDL_Color * colors, int firstcolor, |
41 int ncolors); | 42 int ncolors); |
95 }; | 96 }; |
96 | 97 |
97 typedef struct | 98 typedef struct |
98 { | 99 { |
99 SDL_GLContext context; | 100 SDL_GLContext context; |
101 SDL_bool updateSize; | |
100 SDL_bool GL_ARB_texture_rectangle_supported; | 102 SDL_bool GL_ARB_texture_rectangle_supported; |
101 int blendMode; | 103 int blendMode; |
102 int scaleMode; | 104 int scaleMode; |
103 | 105 |
104 /* OpenGL functions */ | 106 /* OpenGL functions */ |
217 SDL_OutOfMemory(); | 219 SDL_OutOfMemory(); |
218 return NULL; | 220 return NULL; |
219 } | 221 } |
220 | 222 |
221 renderer->ActivateRenderer = GL_ActivateRenderer; | 223 renderer->ActivateRenderer = GL_ActivateRenderer; |
224 renderer->DisplayModeChanged = GL_DisplayModeChanged; | |
222 renderer->CreateTexture = GL_CreateTexture; | 225 renderer->CreateTexture = GL_CreateTexture; |
223 renderer->SetTexturePalette = GL_SetTexturePalette; | 226 renderer->SetTexturePalette = GL_SetTexturePalette; |
224 renderer->GetTexturePalette = GL_GetTexturePalette; | 227 renderer->GetTexturePalette = GL_GetTexturePalette; |
225 renderer->UpdateTexture = GL_UpdateTexture; | 228 renderer->UpdateTexture = GL_UpdateTexture; |
226 renderer->LockTexture = GL_LockTexture; | 229 renderer->LockTexture = GL_LockTexture; |
280 if (data->GL_ARB_texture_rectangle_supported) { | 283 if (data->GL_ARB_texture_rectangle_supported) { |
281 data->glEnable(GL_TEXTURE_RECTANGLE_ARB); | 284 data->glEnable(GL_TEXTURE_RECTANGLE_ARB); |
282 } else { | 285 } else { |
283 data->glEnable(GL_TEXTURE_2D); | 286 data->glEnable(GL_TEXTURE_2D); |
284 } | 287 } |
285 data->glMatrixMode(GL_PROJECTION); | 288 data->updateSize = SDL_TRUE; |
286 data->glLoadIdentity(); | |
287 data->glMatrixMode(GL_MODELVIEW); | |
288 data->glLoadIdentity(); | |
289 data->glViewport(0, 0, window->w, window->h); | |
290 data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, 0.0, | |
291 1.0); | |
292 | 289 |
293 return renderer; | 290 return renderer; |
294 } | 291 } |
295 | 292 |
296 static int | 293 static int |
297 GL_ActivateRenderer(SDL_Renderer * renderer) | 294 GL_ActivateRenderer(SDL_Renderer * renderer) |
298 { | 295 { |
299 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; | 296 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; |
300 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 297 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
301 | 298 |
302 return SDL_GL_MakeCurrent(window->id, data->context); | 299 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { |
300 return -1; | |
301 } | |
302 if (data->updateSize) { | |
303 data->glMatrixMode(GL_PROJECTION); | |
304 data->glLoadIdentity(); | |
305 data->glMatrixMode(GL_MODELVIEW); | |
306 data->glLoadIdentity(); | |
307 data->glViewport(0, 0, window->w, window->h); | |
308 data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, | |
309 0.0, 1.0); | |
310 data->updateSize = SDL_FALSE; | |
311 } | |
312 return 0; | |
313 } | |
314 | |
315 static int | |
316 GL_DisplayModeChanged(SDL_Renderer * renderer) | |
317 { | |
318 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; | |
319 | |
320 data->updateSize = SDL_TRUE; | |
321 return 0; | |
303 } | 322 } |
304 | 323 |
305 static __inline__ int | 324 static __inline__ int |
306 power_of_2(int input) | 325 power_of_2(int input) |
307 { | 326 { |