comparison src/video/photon/SDL_ph_video.c @ 291:68a8a8237c09

Date: Thu, 21 Feb 2002 09:18:24 +0200 From: "Mike Gorchak" <mike@malva.ua> Subject: Re: Patches for QNX RtP again. SDL_ph_image.c - Added OpenGL update functions - fixed some application crashes. Some dead code removed, reformatting some functions. SDL_ph_image_c.h - Added OpenGL update function prototype. SDL_ph_video.c - Added GL_GetAttribute and GL_SetAttribute functions with next supported flags: SDL_GL_DOUBLEBUFFER, SDL_GL_STENCIL_SIZE, SDL_GL_DEPTH_SIZE GetWMInfo function (stub) has been implemented by me, but not listed in device structure - fixed. SDL_ph_wm.c - fixed warning 'no return in non-void function'. README.QNX - Updating readme. Some spellcheck. ;-)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 02 Mar 2002 16:50:35 +0000
parents 3d8b6b9f1e18
children f6ffac90895c
comparison
equal deleted inserted replaced
290:9a02597bc1b0 291:68a8a8237c09
54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, 54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
55 int width, int height, int bpp, Uint32 flags); 55 int width, int height, int bpp, Uint32 flags);
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
60 #ifdef HAVE_OPENGL
59 static void ph_GL_SwapBuffers(_THIS); 61 static void ph_GL_SwapBuffers(_THIS);
62 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
63 #endif /* HAVE_OPENGL */
60 64
61 #ifdef HAVE_OPENGL 65 #ifdef HAVE_OPENGL
62 PdOpenGLContext_t* OGLContext=NULL; 66 PdOpenGLContext_t* OGLContext=NULL;
63 #endif /* HAVE_OPENGL */ 67 #endif /* HAVE_OPENGL */
64 68
65 static int ph_Available(void) 69 static int ph_Available(void)
66 { 70 {
67 return 1; 71 return 1;
68 } 72 }
69 73
70 static SDL_VideoDevice *ph_CreateDevice(int devindex) 74 static SDL_VideoDevice *ph_CreateDevice(int devindex)
71 { 75 {
72 SDL_VideoDevice *device; 76 SDL_VideoDevice *device;
110 device->FreeHWSurface = ph_FreeHWSurface; 114 device->FreeHWSurface = ph_FreeHWSurface;
111 device->SetCaption = ph_SetCaption; 115 device->SetCaption = ph_SetCaption;
112 device->SetIcon = NULL; 116 device->SetIcon = NULL;
113 device->IconifyWindow = ph_IconifyWindow; 117 device->IconifyWindow = ph_IconifyWindow;
114 device->GrabInput = ph_GrabInput; 118 device->GrabInput = ph_GrabInput;
115 device->GetWMInfo = NULL; 119 device->GetWMInfo = ph_GetWMInfo;
116 device->FreeWMCursor = ph_FreeWMCursor; 120 device->FreeWMCursor = ph_FreeWMCursor;
117 device->CreateWMCursor = ph_CreateWMCursor; 121 device->CreateWMCursor = ph_CreateWMCursor;
118 device->ShowWMCursor = ph_ShowWMCursor; 122 device->ShowWMCursor = ph_ShowWMCursor;
119 device->WarpWMCursor = ph_WarpWMCursor; 123 device->WarpWMCursor = ph_WarpWMCursor;
120 device->CheckMouseMode = ph_CheckMouseMode; 124 device->CheckMouseMode = ph_CheckMouseMode;
122 device->PumpEvents = ph_PumpEvents; 126 device->PumpEvents = ph_PumpEvents;
123 127
124 /* OpenGL support. */ 128 /* OpenGL support. */
125 device->GL_LoadLibrary = NULL; 129 device->GL_LoadLibrary = NULL;
126 device->GL_GetProcAddress = NULL; 130 device->GL_GetProcAddress = NULL;
127 device->GL_GetAttribute = NULL;
128 device->GL_MakeCurrent = NULL; 131 device->GL_MakeCurrent = NULL;
129 #ifdef HAVE_OPENGL 132 #ifdef HAVE_OPENGL
130 device->GL_SwapBuffers = ph_GL_SwapBuffers; 133 device->GL_SwapBuffers = ph_GL_SwapBuffers;
134 device->GL_GetAttribute = ph_GL_GetAttribute;
131 #else 135 #else
132 device->GL_SwapBuffers = NULL; 136 device->GL_SwapBuffers = NULL;
137 device->GL_GetAttribute = NULL;
133 #endif /* HAVE_OPENGL */ 138 #endif /* HAVE_OPENGL */
134 139
135 device->free = ph_DeleteDevice; 140 device->free = ph_DeleteDevice;
136 141
137 return device; 142 return device;
269 274
270 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, 275 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
271 int width, int height, int bpp, Uint32 flags) 276 int width, int height, int bpp, Uint32 flags)
272 { 277 {
273 PgDisplaySettings_t settings; 278 PgDisplaySettings_t settings;
274 /*
275 PgHWCaps_t my_hwcaps;
276 PgVideoModeInfo_t mode_info;
277 */
278 int mode, actual_width, actual_height; 279 int mode, actual_width, actual_height;
279 PtArg_t arg[5]; 280 PtArg_t arg[5];
280 PhDim_t dim; 281 PhDim_t dim;
281 int rtnval; 282 int rtnval;
282 PgColor_t ph_palette[_Pg_MAX_PALETTE]; 283 PgColor_t ph_palette[_Pg_MAX_PALETTE];
283 int i; 284 int i;
284 unsigned long *tempptr; 285 unsigned long *tempptr;
285 286
286 #ifdef HAVE_OPENGL 287 #ifdef HAVE_OPENGL
287 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; 288 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
288 #endif // HAVE_OPENGL 289 int OGLargc;
290 #endif /* HAVE_OPENGL */
289 291
290 actual_width = width; 292 actual_width = width;
291 actual_height = height; 293 actual_height = height;
292 294
293 dim.w=width; 295 dim.w=width;
310 } 312 }
311 else 313 else
312 { 314 {
313 if ((mode = get_mode(width, height, bpp)) == 0) 315 if ((mode = get_mode(width, height, bpp)) == 0)
314 { 316 {
315 fprintf(stderr,"error: get_mode failed\n"); 317 fprintf(stderr,"error: get_mode failed\n");
316 exit(1); 318 exit(1);
317 } 319 }
318
319
320 } 320 }
321 settings.mode = mode; 321 settings.mode = mode;
322 settings.refresh = 0; 322 settings.refresh = 0;
323 settings.flags = 0; 323 settings.flags = 0;
324 324
325 if (PgSetVideoMode( &settings ) < 0) 325 if (PgSetVideoMode( &settings ) < 0)
326 { 326 {
327 fprintf(stderr,"error: PgSetVideoMode failed\n"); 327 fprintf(stderr,"error: PgSetVideoMode failed\n");
328 } 328 }
329 329
330 /* Get the true height and width */ 330 /* Get the true height and width */
331 331
332 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */ 332 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
333 333
334 /* Begin direct mode */ 334 /* Begin direct mode */
335 ph_EnterFullScreen(this); 335
336 336 ph_EnterFullScreen(this);
337
338 337
339 } /* end fullscreen flag */ 338 } /* end fullscreen flag */
340 else 339 else
341 { 340 {
342 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ 341 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */
350 } 349 }
351 350
352 #ifdef HAVE_OPENGL 351 #ifdef HAVE_OPENGL
353 if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */ 352 if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */
354 { 353 {
355 OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS; 354 OGLargc=0;
356 OGLAttrib[1]=bpp; 355 if (this->gl_config.depth_size)
357 OGLAttrib[2]=PHOGL_ATTRIB_NONE; 356 {
358 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); 357 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
358 OGLAttrib[OGLargc++]=this->gl_config.depth_size;
359 }
360 if (this->gl_config.stencil_size)
361 {
362 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
363 OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
364 }
365 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
366 if (this->gl_config.double_buffer)
367 {
368 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
369 }
370 else
371 {
372 OGLContext=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
373 }
359 if (OGLContext==NULL) 374 if (OGLContext==NULL)
360 { 375 {
361 fprintf(stderr,"error: cannot create OpenGL context\n"); 376 fprintf(stderr,"error: cannot create OpenGL context.\n");
362 exit(1); 377 exit(1);
363 } 378 }
364 PhDCSetCurrent(OGLContext); 379 PhDCSetCurrent(OGLContext);
365 } 380 }
381 #else
382 if (flags & SDL_OPENGL) /* if no OpenGL support */
383 {
384 fprintf(stderr, "error: no OpenGL support, try to recompile library.\n");
385 exit(1);
386 }
387
366 #endif /* HAVE_OPENGL */ 388 #endif /* HAVE_OPENGL */
367 389
368 } 390 }
369 391
370 /* If we are setting video to use the palette make sure we have allocated memory for it */ 392 /* If we are setting video to use the palette make sure we have allocated memory for it */
486 } 508 }
487 509
488 #ifdef HAVE_OPENGL 510 #ifdef HAVE_OPENGL
489 void ph_GL_SwapBuffers(_THIS) 511 void ph_GL_SwapBuffers(_THIS)
490 { 512 {
491 PgSetRegion(PtWidgetRid(window)); 513 PgSetRegion(PtWidgetRid(window));
492 PdOpenGLContextSwapBuffers(OGLContext); 514 PdOpenGLContextSwapBuffers(OGLContext);
493 } 515 }
494 #endif // HAVE_OPENGL 516
495 517 int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
496 /* 518 {
497 static int ph_ResizeWindow(_THIS, 519 switch (attrib)
498 SDL_Surface *screen, int w, int h, Uint32 flags) 520 {
499 { 521 case SDL_GL_DOUBLEBUFFER:
500 PhWindowEvent_t winevent; 522 *value=this->gl_config.double_buffer;
501 523 break;
502 memset( &winevent, 0, sizeof(winevent) ); 524 case SDL_GL_STENCIL_SIZE:
503 winevent.event_f = Ph_WM_RESIZE; 525 *value=this->gl_config.stencil_size;
504 winevent.size.w = w; 526 break;
505 winevent.size.h = h; 527 case SDL_GL_DEPTH_SIZE:
506 winevent.rid = PtWidgetRid( window ); 528 *value=this->gl_config.depth_size;
507 if (PtForwardWindowEvent( &winevent ) < 0) 529 break;
508 { 530 default:
509 fprintf(stderr,"error: PtForwardWindowEvent failed.\n"); 531 *value=0;
510 } 532 return(-1);
511 current_w = w; 533 }
512 current_h = h; 534 return 0;
513 return(0); 535 }
514 } 536
515 */ 537 #endif /* HAVE_OPENGL */