Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_video.c @ 279:04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 14 Feb 2002 02:15:15 +0000 |
parents | c6abdda2f666 |
children | 3d8b6b9f1e18 |
comparison
equal
deleted
inserted
replaced
278:dcd9f7b50a1c | 279:04351f59b051 |
---|---|
56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | 56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); |
57 static void ph_VideoQuit(_THIS); | 57 static void ph_VideoQuit(_THIS); |
58 static void ph_DeleteDevice(SDL_VideoDevice *device); | 58 static void ph_DeleteDevice(SDL_VideoDevice *device); |
59 static void ph_GL_SwapBuffers(_THIS); | 59 static void ph_GL_SwapBuffers(_THIS); |
60 | 60 |
61 #ifdef HAVE_OPENGL | |
61 PdOpenGLContext_t* OGLContext=NULL; | 62 PdOpenGLContext_t* OGLContext=NULL; |
63 #endif /* HAVE_OPENGL */ | |
62 | 64 |
63 static int ph_Available(void) | 65 static int ph_Available(void) |
64 { | 66 { |
65 return 1; | 67 return 1; |
66 } | 68 } |
83 return(0); | 85 return(0); |
84 } | 86 } |
85 memset(device->hidden, 0, (sizeof *device->hidden)); | 87 memset(device->hidden, 0, (sizeof *device->hidden)); |
86 | 88 |
87 /* Set the driver flags */ | 89 /* Set the driver flags */ |
88 device->handles_any_size = 1; //JB not true for fullscreen | 90 device->handles_any_size = 1; /* JB not true for fullscreen */ |
89 | 91 |
90 /* Set the function pointers */ | 92 /* Set the function pointers */ |
91 device->CreateYUVOverlay = ph_CreateYUVOverlay; | 93 device->CreateYUVOverlay = ph_CreateYUVOverlay; |
92 device->VideoInit = ph_VideoInit; | 94 device->VideoInit = ph_VideoInit; |
93 device->ListModes = ph_ListModes; | 95 device->ListModes = ph_ListModes; |
94 device->SetVideoMode = ph_SetVideoMode; | 96 device->SetVideoMode = ph_SetVideoMode; |
95 device->ToggleFullScreen = ph_ToggleFullScreen; | 97 device->ToggleFullScreen = ph_ToggleFullScreen; |
96 device->UpdateMouse = NULL; | 98 device->UpdateMouse = NULL; |
97 device->SetColors = ph_SetColors; | 99 device->SetColors = ph_SetColors; |
98 device->UpdateRects = NULL; //set in ph_ResizeImage | 100 device->UpdateRects = NULL; /* ph_ResizeImage; */ |
99 device->VideoQuit = ph_VideoQuit; | 101 device->VideoQuit = ph_VideoQuit; |
100 device->AllocHWSurface = ph_AllocHWSurface; | 102 device->AllocHWSurface = ph_AllocHWSurface; |
101 device->CheckHWBlit = NULL; | 103 device->CheckHWBlit = NULL; |
102 device->FillHWRect = NULL; | 104 device->FillHWRect = NULL; |
103 device->SetHWColorKey = NULL; | 105 device->SetHWColorKey = NULL; |
117 device->WarpWMCursor = ph_WarpWMCursor; | 119 device->WarpWMCursor = ph_WarpWMCursor; |
118 device->CheckMouseMode = ph_CheckMouseMode; | 120 device->CheckMouseMode = ph_CheckMouseMode; |
119 device->InitOSKeymap = ph_InitOSKeymap; | 121 device->InitOSKeymap = ph_InitOSKeymap; |
120 device->PumpEvents = ph_PumpEvents; | 122 device->PumpEvents = ph_PumpEvents; |
121 | 123 |
122 // OpenGL support. | 124 /* OpenGL support. */ |
123 device->GL_LoadLibrary = NULL; | 125 device->GL_LoadLibrary = NULL; |
124 device->GL_GetProcAddress = NULL; | 126 device->GL_GetProcAddress = NULL; |
125 device->GL_GetAttribute = NULL; | 127 device->GL_GetAttribute = NULL; |
126 device->GL_MakeCurrent = NULL; | 128 device->GL_MakeCurrent = NULL; |
129 #ifdef HAVE_OPENGL | |
127 device->GL_SwapBuffers = ph_GL_SwapBuffers; | 130 device->GL_SwapBuffers = ph_GL_SwapBuffers; |
131 #else | |
132 device->GL_SwapBuffers = NULL; | |
133 #endif /* HAVE_OPENGL */ | |
128 | 134 |
129 device->free = ph_DeleteDevice; | 135 device->free = ph_DeleteDevice; |
130 | 136 |
131 return device; | 137 return device; |
132 } | 138 } |
194 | 200 |
195 if(window == NULL) | 201 if(window == NULL) |
196 { | 202 { |
197 printf("Photon application init failed, probably Photon is not running.\n"); | 203 printf("Photon application init failed, probably Photon is not running.\n"); |
198 exit( EXIT_FAILURE ); | 204 exit( EXIT_FAILURE ); |
199 // PtExit(EXIT_FAILURE); // Got SEGFAULT. | |
200 } | 205 } |
201 | 206 |
202 //PgSetDrawBufferSize(16 *1024); | 207 //PgSetDrawBufferSize(16 *1024); |
203 PgSetRegion(PtWidgetRid(window)); | 208 PgSetRegion(PtWidgetRid(window)); |
204 PgSetClipping(0,NULL); | 209 PgSetClipping(0,NULL); |
214 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, | 219 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, |
215 (int)BLANK_CHOTX, (int)BLANK_CHOTY); | 220 (int)BLANK_CHOTX, (int)BLANK_CHOTY); |
216 | 221 |
217 if(SDL_BlankCursor == NULL) | 222 if(SDL_BlankCursor == NULL) |
218 printf("could not create blank cursor\n"); | 223 printf("could not create blank cursor\n"); |
219 /* Get the video mode */ | 224 |
220 /* | |
221 if (PgGetVideoMode( &mysettings ) < 0) | |
222 { | |
223 fprintf(stderr,"ph_VideoInit: PgGetVideoMode failed patch A?? \n"); | |
224 //QNX6/Patch A always fails return code even though call succeeds. fixed Patch B | |
225 } | |
226 */ | |
227 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) | 225 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
228 { | 226 { |
229 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n"); | 227 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n"); |
230 //that HAVE to work | |
231 } | 228 } |
232 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) | 229 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) |
233 { | 230 { |
234 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n"); | 231 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n"); |
235 } | 232 } |
236 | 233 |
237 //We need to return BytesPerPixel as it in used by CreateRGBsurface | 234 //We need to return BytesPerPixel as it in used by CreateRGBsurface |
238 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; | 235 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; |
239 vformat->BytesPerPixel = vformat->BitsPerPixel/8; | 236 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; |
240 | 237 |
241 //return a palette if we are in 256 color mode | 238 //return a palette if we are in 256 color mode |
242 if(vformat->BitsPerPixel == 8) | 239 if(vformat->BitsPerPixel == 8) |
243 { | 240 { |
244 vformat->palette = malloc(sizeof(SDL_Palette)); | 241 vformat->palette = malloc(sizeof(SDL_Palette)); |
245 memset(vformat->palette, 0, sizeof(SDL_Palette)); | 242 memset(vformat->palette, 0, sizeof(SDL_Palette)); |
246 vformat->palette->ncolors = 256; | 243 vformat->palette->ncolors = 256; |
249 //fill the palette | 246 //fill the palette |
250 rtnval = PgGetPalette(ph_palette); | 247 rtnval = PgGetPalette(ph_palette); |
251 if(rtnval < 0) | 248 if(rtnval < 0) |
252 printf("ph_VideoInit: PgGetPalette failed\n"); | 249 printf("ph_VideoInit: PgGetPalette failed\n"); |
253 | 250 |
254 tempptr = (unsigned long *)vformat->palette->colors; | 251 tempptr = (unsigned long *)vformat->palette->colors; |
255 | 252 |
256 for(i=0;i<256; i++) | 253 for(i=0;i<256; i++) |
257 { | 254 { |
258 *tempptr = (((unsigned long)ph_palette[i]) << 8); | 255 *tempptr = (((unsigned long)ph_palette[i]) << 8); |
259 tempptr++; | 256 tempptr++; |
271 } | 268 } |
272 | 269 |
273 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | 270 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, |
274 int width, int height, int bpp, Uint32 flags) | 271 int width, int height, int bpp, Uint32 flags) |
275 { | 272 { |
276 // PhRegion_t region_info; | |
277 PgDisplaySettings_t settings; | 273 PgDisplaySettings_t settings; |
274 /* | |
278 PgHWCaps_t my_hwcaps; | 275 PgHWCaps_t my_hwcaps; |
279 PgVideoModeInfo_t mode_info; | 276 PgVideoModeInfo_t mode_info; |
277 */ | |
280 int mode, actual_width, actual_height; | 278 int mode, actual_width, actual_height; |
281 PtArg_t arg[5]; | 279 PtArg_t arg[5]; |
282 PhDim_t dim; | 280 PhDim_t dim; |
283 int rtnval; | 281 int rtnval; |
284 PgColor_t ph_palette[_Pg_MAX_PALETTE]; | 282 PgColor_t ph_palette[_Pg_MAX_PALETTE]; |
285 int i; | 283 int i; |
286 unsigned long *tempptr; | 284 unsigned long *tempptr; |
285 | |
286 #ifdef HAVE_OPENGL | |
287 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; | 287 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; |
288 #endif // HAVE_OPENGL | |
288 | 289 |
289 actual_width = width; | 290 actual_width = width; |
290 actual_height = height; | 291 actual_height = height; |
291 | 292 |
292 dim.w=width; | 293 dim.w=width; |
294 | 295 |
295 /* Lock the event thread, in multi-threading environments */ | 296 /* Lock the event thread, in multi-threading environments */ |
296 SDL_Lock_EventThread(); | 297 SDL_Lock_EventThread(); |
297 | 298 |
298 /* Initialize the window */ | 299 /* Initialize the window */ |
299 if (flags & SDL_FULLSCREEN) //Direct Context , assume SDL_HWSURFACE also set | 300 if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */ |
300 { | 301 { |
301 /* | |
302 if (old_video_mode==-1) | |
303 { | |
304 PgGetGraphicsHWCaps(&graphics_card_caps); | |
305 old_video_mode=graphics_card_caps.current_video_mode; | |
306 old_refresh_rate=graphics_card_caps.current_rrate; | |
307 } | |
308 */ | |
309 | |
310 /* Get the video mode and set it */ | 302 /* Get the video mode and set it */ |
311 if (bpp == 0) | |
312 { | |
313 /*again same issue, same solution | |
314 if (PgGetVideoMode( &settings ) < 0) | |
315 { | |
316 fprintf(stderr,"error: PgGetVideoMode failed\n"); | |
317 } | |
318 */ | |
319 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) | |
320 { | |
321 fprintf(stderr,"ph_SetVideoMode: GetGraphicsHWCaps failed!! \n"); | |
322 //that HAVE to work | |
323 } | |
324 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &mode_info) < 0) | |
325 { | |
326 fprintf(stderr,"ph_SetVideoMode: PgGetVideoModeInfo failed\n"); | |
327 } | |
328 bpp = mode_info.bits_per_pixel; | |
329 } | |
330 if (flags & SDL_ANYFORMAT) | 303 if (flags & SDL_ANYFORMAT) |
331 { | 304 { |
332 if ((mode = get_mode_any_format(width, height, bpp)) == 0) | 305 if ((mode = get_mode_any_format(width, height, bpp)) == 0) |
333 { | 306 { |
334 fprintf(stderr,"error: get_mode_any_format failed\n"); | 307 fprintf(stderr,"error: get_mode_any_format failed\n"); |
354 fprintf(stderr,"error: PgSetVideoMode failed\n"); | 327 fprintf(stderr,"error: PgSetVideoMode failed\n"); |
355 } | 328 } |
356 | 329 |
357 /* Get the true height and width */ | 330 /* Get the true height and width */ |
358 | 331 |
359 current->flags = (flags|(~SDL_RESIZABLE)); //no resize for Direct Context | 332 current->flags = (flags|(~SDL_RESIZABLE)); /* no resize for Direct Context */ |
360 | 333 |
361 /* Begin direct mode */ | 334 /* Begin direct mode */ |
362 ph_EnterFullScreen(this); | 335 ph_EnterFullScreen(this); |
363 | 336 |
364 | 337 |
365 | 338 |
366 } //end fullscreen flag | 339 } /* end fullscreen flag */ |
367 else | 340 else |
368 { | 341 { |
369 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ | 342 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ |
370 { | 343 { |
371 // Hardware surface is Offsceen Context. ph_ResizeImage handles the switch | 344 /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */ |
372 current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context | 345 current->flags = (flags|(~SDL_RESIZABLE)); /* no stretch blit in offscreen context */ |
373 } | 346 } |
374 else // must be SDL_SWSURFACE | 347 else /* must be SDL_SWSURFACE */ |
375 { | 348 { |
376 current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface | 349 current->flags = (flags|SDL_RESIZABLE); /* yes we can resize as this is a software surface */ |
377 } | 350 } |
378 | 351 |
379 if (flags & SDL_OPENGL) // for now support OpenGL in window mode only | 352 #ifdef HAVE_OPENGL |
353 if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */ | |
380 { | 354 { |
381 OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS; | 355 OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS; |
382 OGLAttrib[1]=bpp; | 356 OGLAttrib[1]=bpp; |
383 OGLAttrib[2]=PHOGL_ATTRIB_NONE; | 357 OGLAttrib[2]=PHOGL_ATTRIB_NONE; |
384 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); | 358 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); |
387 fprintf(stderr,"error: cannot create OpenGL context\n"); | 361 fprintf(stderr,"error: cannot create OpenGL context\n"); |
388 exit(1); | 362 exit(1); |
389 } | 363 } |
390 PhDCSetCurrent(OGLContext); | 364 PhDCSetCurrent(OGLContext); |
391 } | 365 } |
366 #endif /* HAVE_OPENGL */ | |
392 | 367 |
393 } | 368 } |
394 | 369 |
395 //If we are setting video to use the palette make sure we have allocated memory for it | 370 /* If we are setting video to use the palette make sure we have allocated memory for it */ |
396 if(bpp == 8) | 371 if(bpp == 8) |
397 { | 372 { |
398 current->format->palette = malloc(sizeof(SDL_Palette)); | 373 current->format->palette = malloc(sizeof(SDL_Palette)); |
399 memset(current->format->palette, 0, sizeof(SDL_Palette)); | 374 memset(current->format->palette, 0, sizeof(SDL_Palette)); |
400 current->format->palette->ncolors = 256; | 375 current->format->palette->ncolors = 256; |
401 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); | 376 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); |
402 //fill the palette | 377 /* fill the palette */ |
403 rtnval = PgGetPalette(ph_palette); | 378 rtnval = PgGetPalette(ph_palette); |
404 | 379 |
405 tempptr = (unsigned long *)current->format->palette->colors; | 380 tempptr = (unsigned long *)current->format->palette->colors; |
406 | 381 |
407 for(i=0;i<256; i++) | 382 for(i=0;i<256; i++) |
411 | 386 |
412 } | 387 } |
413 } | 388 } |
414 | 389 |
415 | 390 |
416 //Current window dimensions | 391 /* Current window dimensions */ |
417 PtGetResource( window, Pt_ARG_DIM, &dim, 0 ); | 392 PtGetResource( window, Pt_ARG_DIM, &dim, 0 ); |
418 | 393 |
419 //If we need to resize the window | 394 /* If we need to resize the window */ |
420 if((dim.w != width)||(dim.h != height)) | 395 if((dim.w != width)||(dim.h != height)) |
421 { | 396 { |
422 dim.w=width; | 397 dim.w=width; |
423 dim.h=height; | 398 dim.h=height; |
424 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); | 399 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); |
425 PtSetResources( window, 1, arg ); | 400 PtSetResources( window, 1, arg ); |
426 current->w = width; | 401 current->w = width; |
427 current->h = height; | 402 current->h = height; |
428 current->format->BitsPerPixel = bpp; | 403 current->format->BitsPerPixel = bpp; |
429 current->format->BytesPerPixel = bpp/8; | 404 current->format->BytesPerPixel = (bpp+7)/8; |
430 current->pitch = SDL_CalculatePitch(current); | 405 current->pitch = SDL_CalculatePitch(current); |
431 //Must call at least once it setup image planes | 406 /* Must call at least once it setup image planes */ |
432 ph_ResizeImage(this, current, flags); | 407 ph_ResizeImage(this, current, flags); |
433 } | 408 } |
434 | |
435 | 409 |
436 SDL_Unlock_EventThread(); | 410 SDL_Unlock_EventThread(); |
437 | 411 |
438 /* We're done! */ | 412 /* We're done! */ |
439 return(current); | 413 return(current); |
440 } | 414 } |
441 | 415 |
442 static void ph_VideoQuit(_THIS) | 416 static void ph_VideoQuit(_THIS) |
443 { | 417 { |
444 | 418 if (SDL_Image != NULL) |
445 if(SDL_Image != NULL) | 419 { |
446 { | 420 ph_DestroyImage(this, SDL_VideoSurface); |
447 ph_DestroyImage(this, SDL_VideoSurface); | 421 } |
448 } | 422 |
449 | 423 if (currently_fullscreen) |
450 if (currently_fullscreen) | 424 { |
451 { | 425 PdDirectStop( directContext ); |
452 PdDirectStop( directContext ); | 426 PdReleaseDirectContext( directContext ); |
453 PdReleaseDirectContext( directContext ); | 427 directContext=0; |
454 directContext=0; | 428 currently_fullscreen = 0; |
455 currently_fullscreen = 0; | 429 } |
456 } | |
457 | |
458 } | 430 } |
459 | 431 |
460 | 432 |
461 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | 433 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) |
462 { | 434 { |
514 } | 486 } |
515 } | 487 } |
516 return alloct_all; | 488 return alloct_all; |
517 } | 489 } |
518 | 490 |
491 #ifdef HAVE_OPENGL | |
519 void ph_GL_SwapBuffers(_THIS) | 492 void ph_GL_SwapBuffers(_THIS) |
520 { | 493 { |
521 PgSetRegion(PtWidgetRid(window)); | 494 PgSetRegion(PtWidgetRid(window)); |
522 PdOpenGLContextSwapBuffers(OGLContext); | 495 PdOpenGLContextSwapBuffers(OGLContext); |
523 } | 496 } |
497 #endif // HAVE_OPENGL | |
524 | 498 |
525 /* | 499 /* |
526 static int ph_ResizeWindow(_THIS, | 500 static int ph_ResizeWindow(_THIS, |
527 SDL_Surface *screen, int w, int h, Uint32 flags) | 501 SDL_Surface *screen, int w, int h, Uint32 flags) |
528 { | 502 { |