comparison src/video/photon/SDL_ph_image.c @ 910:4ab6d1fd028f

Date: Sat, 26 Jun 2004 14:58:42 +0300 From: "Mike Gorchak" Subject: QNX 6.3 fixes for SDL Sam, I've added new OpenGL framework for SDL, which appeared in the new QNX version - 6.3. I've leave compatibility with previous QNX versions. And I've moved all GL specific functions to the separate module, like it done for the other platforms. SDL is now ready for the QNX 6.3 :)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 18 Jul 2004 19:46:38 +0000
parents 05c551e5bc64
children c9b51268668f
comparison
equal deleted inserted replaced
909:e247a0139900 910:4ab6d1fd028f
24 static char rcsid = 24 static char rcsid =
25 "@(#) $Id$"; 25 "@(#) $Id$";
26 #endif 26 #endif
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29
29 #include <Ph.h> 30 #include <Ph.h>
30 #include <photon/Pg.h> 31 #include <photon/Pg.h>
31 32
32 #include "SDL.h" 33 #include "SDL.h"
33 #include "SDL_error.h" 34 #include "SDL_error.h"
34 #include "SDL_endian.h" 35 #include "SDL_endian.h"
35 #include "SDL_video.h" 36 #include "SDL_video.h"
36 #include "SDL_pixels_c.h" 37 #include "SDL_pixels_c.h"
38 #include "SDL_ph_video.h"
37 #include "SDL_ph_image_c.h" 39 #include "SDL_ph_image_c.h"
38 #include "SDL_ph_modes_c.h" 40 #include "SDL_ph_modes_c.h"
41 #include "SDL_ph_gl.h"
39 42
40 int ph_SetupImage(_THIS, SDL_Surface *screen) 43 int ph_SetupImage(_THIS, SDL_Surface *screen)
41 { 44 {
42 PgColor_t* palette=NULL; 45 PgColor_t* palette=NULL;
43 int type=0; 46 int type=0;
187 190
188 int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen) 191 int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
189 { 192 {
190 OCImage.flags = screen->flags; 193 OCImage.flags = screen->flags;
191 194
192 /* Begin direct mode */ 195 /* Begin direct and fullscreen mode */
193 if (!ph_EnterFullScreen(this, screen)) 196 if (!ph_EnterFullScreen(this, screen, PH_ENTER_DIRECTMODE))
194 { 197 {
195 return -1; 198 return -1;
196 } 199 }
197 200
198 /* store palette for fullscreen */ 201 /* store palette for fullscreen */
299 return 0; 302 return 0;
300 } 303 }
301 304
302 #ifdef HAVE_OPENGL 305 #ifdef HAVE_OPENGL
303 306
304 static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
305 {
306 PhDim_t dim;
307 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
308 int exposepost=0;
309 int OGLargc;
310
311 dim.w=width;
312 dim.h=height;
313
314 if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
315 {
316 PdOpenGLContextResize(oglctx, &dim);
317 PhDCSetCurrent(oglctx);
318 return 0;
319 }
320 else
321 {
322 if (oglctx!=NULL)
323 {
324 PhDCSetCurrent(NULL);
325 PhDCRelease(oglctx);
326 oglctx=NULL;
327 exposepost=1;
328 }
329 }
330
331 OGLargc=0;
332 if (this->gl_config.depth_size)
333 {
334 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
335 OGLAttrib[OGLargc++]=this->gl_config.depth_size;
336 }
337 if (this->gl_config.stencil_size)
338 {
339 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
340 OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
341 }
342 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
343 if (flags & SDL_FULLSCREEN)
344 {
345 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
346 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
347 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
348 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
349 }
350 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
351
352 if (this->gl_config.double_buffer)
353 {
354 oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
355 }
356 else
357 {
358 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
359 }
360
361 if (oglctx==NULL)
362 {
363 SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
364 return (-1);
365 }
366
367 PhDCSetCurrent(oglctx);
368
369 PtFlush();
370
371 oglflags=flags;
372 oglbpp=bpp;
373
374 if (exposepost!=0)
375 {
376 /* OpenGL context has been recreated, so report about this fact */
377 SDL_PrivateExpose();
378 }
379
380 return 0;
381 }
382
383 int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen) 307 int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
384 { 308 {
385 this->UpdateRects = ph_OpenGLUpdate; 309 this->UpdateRects = ph_OpenGLUpdate;
386 screen->pixels=NULL; 310 screen->pixels=NULL;
387 screen->pitch=NULL; 311 screen->pitch=NULL;
388 312
389 if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0) 313 #if (_NTO_VERSION >= 630)
390 { 314 if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
391 screen->flags &= ~SDL_OPENGL; 315 {
392 return -1; 316 if (!ph_EnterFullScreen(this, screen, PH_IGNORE_DIRECTMODE))
393 } 317 {
318 screen->flags &= ~SDL_FULLSCREEN;
319 return -1;
320 }
321 }
322 #endif /* 6.3.0 */
323
324 if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
325 {
326 screen->flags &= ~SDL_OPENGL;
327 return -1;
328 }
394 329
395 return 0; 330 return 0;
396 } 331 }
397 332
398 #endif /* HAVE_OPENGL */ 333 #endif /* HAVE_OPENGL */
399 334
400 void ph_DestroyImage(_THIS, SDL_Surface* screen) 335 void ph_DestroyImage(_THIS, SDL_Surface* screen)
403 #ifdef HAVE_OPENGL 338 #ifdef HAVE_OPENGL
404 if ((screen->flags & SDL_OPENGL)==SDL_OPENGL) 339 if ((screen->flags & SDL_OPENGL)==SDL_OPENGL)
405 { 340 {
406 if (oglctx) 341 if (oglctx)
407 { 342 {
408 PhDCSetCurrent(NULL); 343 #if (_NTO_VERSION < 630)
409 PhDCRelease(oglctx); 344 PhDCSetCurrent(NULL);
345 PhDCRelease(oglctx);
346 #else
347 qnxgl_context_destroy(oglctx);
348 qnxgl_buffers_destroy(oglbuffers);
349 qnxgl_finish();
350 #endif /* 6.3.0 */
410 oglctx=NULL; 351 oglctx=NULL;
352 oglbuffers=NULL;
411 oglflags=0; 353 oglflags=0;
412 oglbpp=0; 354 oglbpp=0;
413 } 355 }
356
357 #if (_NTO_VERSION >= 630)
358 if (currently_fullscreen)
359 {
360 ph_LeaveFullScreen(this);
361 }
362 #endif /* 6.3.0 */
363
414 return; 364 return;
415 } 365 }
416 #endif /* HAVE_OPENGL */ 366 #endif /* HAVE_OPENGL */
417 367
418 if (currently_fullscreen) 368 if (currently_fullscreen)