comparison src/video/photon/SDL_ph_video.c @ 309:2de77f7b7a28

*** empty log message ***
author Sam Lantinga <slouken@libsdl.org>
date Mon, 11 Mar 2002 17:38:56 +0000
parents f6ffac90895c
children 3333b6e68289
comparison
equal deleted inserted replaced
308:ee32ed29a507 309:2de77f7b7a28
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 59
60 #ifdef HAVE_OPENGL 60 #ifdef HAVE_OPENGL
61 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
61 static void ph_GL_SwapBuffers(_THIS); 62 static void ph_GL_SwapBuffers(_THIS);
62 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); 63 static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
63 #endif /* HAVE_OPENGL */ 64 #endif /* HAVE_OPENGL */
64 65
65 #ifdef HAVE_OPENGL
66 PdOpenGLContext_t* OGLContext=NULL;
67 #endif /* HAVE_OPENGL */
68
69 static int ph_Available(void) 66 static int ph_Available(void)
70 { 67 {
71 return 1; 68 int phstat=-1;
69
70 phstat=PtInit(0);
71 if (phstat==0)
72 {
73 return 1;
74 }
75 else
76 {
77 return 0;
78 }
72 } 79 }
73 80
74 static SDL_VideoDevice *ph_CreateDevice(int devindex) 81 static SDL_VideoDevice *ph_CreateDevice(int devindex)
75 { 82 {
76 SDL_VideoDevice *device; 83 SDL_VideoDevice *device;
77 84
78 /* Initialize all variables that we clean on shutdown */ 85 /* Initialize all variables that we clean on shutdown */
79 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); 86 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
80 if ( device ) { 87 if (device) {
81 memset(device, 0, (sizeof *device)); 88 memset(device, 0, (sizeof *device));
82 device->hidden = (struct SDL_PrivateVideoData *) 89 device->hidden = (struct SDL_PrivateVideoData *)
83 malloc((sizeof *device->hidden)); 90 malloc((sizeof *device->hidden));
84 device->gl_data = NULL; 91 device->gl_data = NULL;
85 } 92 }
96 /* Set the function pointers */ 103 /* Set the function pointers */
97 device->CreateYUVOverlay = ph_CreateYUVOverlay; 104 device->CreateYUVOverlay = ph_CreateYUVOverlay;
98 device->VideoInit = ph_VideoInit; 105 device->VideoInit = ph_VideoInit;
99 device->ListModes = ph_ListModes; 106 device->ListModes = ph_ListModes;
100 device->SetVideoMode = ph_SetVideoMode; 107 device->SetVideoMode = ph_SetVideoMode;
101 device->ToggleFullScreen = ph_ToggleFullScreen; 108 device->ToggleFullScreen = ph_ToggleFullScreen;
102 device->UpdateMouse = NULL; 109 device->UpdateMouse = NULL;
103 device->SetColors = ph_SetColors; 110 device->SetColors = ph_SetColors;
104 device->UpdateRects = NULL; /* ph_ResizeImage; */ 111 device->UpdateRects = NULL; /* ph_ResizeImage */
105 device->VideoQuit = ph_VideoQuit; 112 device->VideoQuit = ph_VideoQuit;
106 device->AllocHWSurface = ph_AllocHWSurface; 113 device->AllocHWSurface = ph_AllocHWSurface;
107 device->CheckHWBlit = NULL; 114 device->CheckHWBlit = NULL;
108 device->FillHWRect = NULL; 115 device->FillHWRect = NULL;
109 device->SetHWColorKey = NULL; 116 device->SetHWColorKey = NULL;
147 ph_Available, ph_CreateDevice 154 ph_Available, ph_CreateDevice
148 }; 155 };
149 156
150 static void ph_DeleteDevice(SDL_VideoDevice *device) 157 static void ph_DeleteDevice(SDL_VideoDevice *device)
151 { 158 {
152 159 if (device)
153 if ( device ) { 160 {
154 if ( device->hidden ) { 161 if (device->hidden)
162 {
155 free(device->hidden); 163 free(device->hidden);
156 device->hidden = NULL; 164 device->hidden = NULL;
157 } 165 }
158 if ( device->gl_data ) { 166 if (device->gl_data)
167 {
159 free(device->gl_data); 168 free(device->gl_data);
160 device->gl_data = NULL; 169 device->gl_data = NULL;
161 } 170 }
162 free(device); 171 free(device);
163 device = NULL; 172 device = NULL;
164 } 173 }
165 } 174 }
166 175
167 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) 176 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
168 { 177 {
169 PtArg_t arg[1]; 178 PgColor_t ph_palette[_Pg_MAX_PALETTE];
170 PhDim_t dim; 179 int i;
171 PgColor_t ph_palette[_Pg_MAX_PALETTE]; 180 unsigned long *tempptr;
172 int i; 181 int rtnval;
173 unsigned long *tempptr; 182 PgVideoModeInfo_t my_mode_info;
174 int rtnval; 183 PgHWCaps_t my_hwcaps;
175 // PgDisplaySettings_t mysettings; 184
176 PgVideoModeInfo_t my_mode_info; 185 window=NULL;
177 PgHWCaps_t my_hwcaps; 186 oglctx=NULL;
178 187
179 if( NULL == ( event = malloc( EVENT_SIZE ) ) ) 188 if (NULL == (event = malloc(EVENT_SIZE)))
180 exit( EXIT_FAILURE ); 189 {
181 190 exit(EXIT_FAILURE);
182 /* Create a widget 'window' to capture events */ 191 }
183 dim.w=0; //JB test320; 192
184 dim.h=0; //JB test240; 193 /* Create the blank cursor */
185 //We need to return BytesPerPixel as it in used by CreateRGBsurface 194 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
186 195 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
187 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); 196 (int)BLANK_CHOTX, (int)BLANK_CHOTY);
188 197
189 /* 198 if (SDL_BlankCursor == NULL)
190 PtSetArg(&arg[1], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED); 199 {
191 PtSetArg(&arg[2], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | 200 printf("ph_VideoInit: could not create blank cursor\n");
192 Ph_WM_STATE_ISMAX | 201 }
193 Ph_WM_STATE_ISFOCUS); 202
194 203 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
195 PtSetArg(&arg[3], Pt_ARG_WINDOW_RENDER_FLAGS,Pt_FALSE,~0); 204 {
196 PtSetArg(&arg[4], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, 205 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n");
197 Ph_WM_FFRONT | 206 }
198 Ph_WM_CLOSE | 207
199 Ph_WM_TOFRONT | 208 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
200 Ph_WM_CONSWITCH); 209 {
201 */ 210 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n");
202 211 }
203 212
204 window=PtAppInit(NULL, NULL, NULL, 1, arg); 213 /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
205 214 vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
206 if(window == NULL) 215 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
207 {
208 printf("Photon application init failed, probably Photon is not running.\n");
209 exit( EXIT_FAILURE );
210 }
211
212 //PgSetDrawBufferSize(16 *1024);
213 PgSetRegion(PtWidgetRid(window));
214 PgSetClipping(0,NULL);
215 PtRealizeWidget(window);
216
217
218 /* Get the available video modes */
219 // if(ph_GetVideoModes(this) < 0)
220 // return -1;
221
222 /* Create the blank cursor */
223 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
224 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
225 (int)BLANK_CHOTX, (int)BLANK_CHOTY);
226
227 if(SDL_BlankCursor == NULL)
228 printf("could not create blank cursor\n");
229
230 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
231 {
232 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n");
233 }
234 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
235 {
236 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n");
237 }
238
239 //We need to return BytesPerPixel as it in used by CreateRGBsurface
240 vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
241 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
242 216
243 //return a palette if we are in 256 color mode 217 /* return a palette if we are in 256 color mode */
244 if(vformat->BitsPerPixel == 8) 218 if (vformat->BitsPerPixel == 8)
245 { 219 {
246 vformat->palette = malloc(sizeof(SDL_Palette)); 220 vformat->palette = malloc(sizeof(SDL_Palette));
247 memset(vformat->palette, 0, sizeof(SDL_Palette)); 221 memset(vformat->palette, 0, sizeof(SDL_Palette));
248 vformat->palette->ncolors = 256; 222 vformat->palette->ncolors = 256;
249 vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); 223 vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
250 224
251 //fill the palette 225 /* fill the palette */
252 rtnval = PgGetPalette(ph_palette); 226 rtnval = PgGetPalette(ph_palette);
253 if(rtnval < 0) 227 if (rtnval < 0)
254 printf("ph_VideoInit: PgGetPalette failed\n"); 228 {
255 229 fprintf(stderr, "ph_VideoInit: PgGetPalette failed\n");
256 tempptr = (unsigned long *)vformat->palette->colors; 230 }
257 231
258 for(i=0;i<256; i++) 232 tempptr = (unsigned long *)vformat->palette->colors;
259 { 233
260 *tempptr = (((unsigned long)ph_palette[i]) << 8); 234 for(i=0;i<256; i++)
261 tempptr++; 235 {
262 236 *tempptr = (((unsigned long)ph_palette[i]) << 8);
263 } 237 tempptr++;
264 238 }
265 } 239 }
266
267 240
268 currently_fullscreen = 0; 241 currently_fullscreen = 0;
269 242
270 this->info.wm_available = 1; 243 this->info.wm_available = 1;
271 244
274 247
275 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, 248 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
276 int width, int height, int bpp, Uint32 flags) 249 int width, int height, int bpp, Uint32 flags)
277 { 250 {
278 PgDisplaySettings_t settings; 251 PgDisplaySettings_t settings;
279 int mode, actual_width, actual_height; 252 int mode;
280 PtArg_t arg[5]; 253 PtArg_t arg[32];
281 PhDim_t dim; 254 PhDim_t dim;
282 int rtnval; 255 int rtnval;
283 PgColor_t ph_palette[_Pg_MAX_PALETTE]; 256 PgColor_t ph_palette[_Pg_MAX_PALETTE];
284 int i; 257 int i;
285 unsigned long *tempptr; 258 unsigned long *tempptr;
286 259 int pargc;
287 #ifdef HAVE_OPENGL
288 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
289 int OGLargc;
290 #endif /* HAVE_OPENGL */
291
292 actual_width = width;
293 actual_height = height;
294 260
295 dim.w=width; 261 dim.w=width;
296 dim.h=height; 262 dim.h=height;
297 263
298 /* Lock the event thread, in multi-threading environments */ 264 /* Lock the event thread, in multi-threading environments */
299 SDL_Lock_EventThread(); 265 SDL_Lock_EventThread();
300 266
301 /* Initialize the window */ 267 /* create window if no OpenGL support selected */
302 if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */ 268 if ((flags & SDL_OPENGL)!=SDL_OPENGL)
303 { 269 {
304 /* Get the video mode and set it */ 270 pargc=0;
305 if (flags & SDL_ANYFORMAT) 271
306 { 272 PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0);
307 if ((mode = get_mode_any_format(width, height, bpp)) == 0) 273 PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
274
275 if (window!=NULL)
276 {
277 PtUnrealizeWidget(window);
278 PtDestroyWidget(window);
279 window=NULL;
280 }
281
282 window=PtCreateWidget(PtWindow, NULL, pargc-1, arg);
283 PtRealizeWidget(window);
284
285 PtFlush();
286 }
287
288 #ifdef HAVE_OPENGL
289 if (flags & SDL_OPENGL)
290 {
291 /* ph_SetupOpenGLContext creates also window as need */
292 if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0)
293 {
294 current->flags=flags;
295 /* setup OGL update function ... ugly method */
296 ph_ResizeImage(this, current, flags);
297 }
298 else
299 {
300 /* if context creation fail, report no OpenGL to high level */
301 current->flags=(flags & (~SDL_OPENGL));
302 }
303 #else
304 if (flags & SDL_OPENGL) /* if no built-in OpenGL support */
305 {
306 fprintf(stderr, "error: no OpenGL support, try to recompile library.\n");
307 current->flags=(flags & (~SDL_OPENGL));
308 return NULL;
309 #endif /* HAVE_OPENGL */
310 }
311 else
312 {
313 /* Initialize the window */
314 if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */
315 {
316 /* Get the video mode and set it */
317 if (flags & SDL_ANYFORMAT)
308 { 318 {
309 fprintf(stderr,"error: get_mode_any_format failed\n"); 319 if ((mode = get_mode_any_format(width, height, bpp)) == 0)
310 exit(1); 320 {
321 fprintf(stderr,"error: get_mode_any_format failed\n");
322 exit(1);
323 }
311 } 324 }
312 } 325 else
326 {
327 if ((mode = get_mode(width, height, bpp)) == 0)
328 {
329 fprintf(stderr,"error: get_mode failed\n");
330 exit(1);
331 }
332 }
333 settings.mode = mode;
334 settings.refresh = 0;
335 settings.flags = 0;
336
337 if (PgSetVideoMode( &settings ) < 0)
338 {
339 fprintf(stderr,"error: PgSetVideoMode failed\n");
340 }
341
342 /* Get the true height and width */
343
344 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
345
346 /* Begin direct mode */
347
348 ph_EnterFullScreen(this);
349
350 } /* end fullscreen flag */
313 else 351 else
314 { 352 {
315 if ((mode = get_mode(width, height, bpp)) == 0) 353 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */
316 { 354 {
317 fprintf(stderr,"error: get_mode failed\n"); 355 /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */
318 exit(1); 356 current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */
319 } 357 }
320 } 358 else /* must be SDL_SWSURFACE */
321 settings.mode = mode; 359 {
322 settings.refresh = 0; 360 current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */
323 settings.flags = 0; 361 }
324 362 }
325 if (PgSetVideoMode( &settings ) < 0)
326 {
327 fprintf(stderr,"error: PgSetVideoMode failed\n");
328 }
329
330 /* Get the true height and width */
331
332 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
333
334 /* Begin direct mode */
335
336 ph_EnterFullScreen(this);
337
338 } /* end fullscreen flag */
339 else
340 {
341 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */
342 {
343 /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */
344 current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */
345 }
346 else /* must be SDL_SWSURFACE */
347 {
348 current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */
349 }
350
351 #ifdef HAVE_OPENGL
352 if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */
353 {
354 OGLargc=0;
355 if (this->gl_config.depth_size)
356 {
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 }
374 if (OGLContext==NULL)
375 {
376 fprintf(stderr,"error: cannot create OpenGL context.\n");
377 exit(1);
378 }
379 PhDCSetCurrent(OGLContext);
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
388 #endif /* HAVE_OPENGL */
389
390 }
391 363
392 /* If we are setting video to use the palette make sure we have allocated memory for it */ 364 /* If we are setting video to use the palette make sure we have allocated memory for it */
393 if(bpp == 8) 365 if (bpp==8)
394 { 366 {
395 current->format->palette = malloc(sizeof(SDL_Palette)); 367 current->format->palette = malloc(sizeof(SDL_Palette));
396 memset(current->format->palette, 0, sizeof(SDL_Palette)); 368 memset(current->format->palette, 0, sizeof(SDL_Palette));
397 current->format->palette->ncolors = 256; 369 current->format->palette->ncolors = 256;
398 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); 370 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
399 /* fill the palette */ 371 /* fill the palette */
400 rtnval = PgGetPalette(ph_palette); 372 rtnval = PgGetPalette(ph_palette);
401 373
402 tempptr = (unsigned long *)current->format->palette->colors; 374 tempptr = (unsigned long *)current->format->palette->colors;
403 375
404 for(i=0;i<256; i++) 376 for(i=0; i<256; i++)
405 { 377 {
406 *tempptr = (((unsigned long)ph_palette[i]) << 8); 378 *tempptr = (((unsigned long)ph_palette[i]) << 8);
407 tempptr++; 379 tempptr++;
408 380 }
409 } 381 }
410 } 382
411 383 }
412 384
413 /* Current window dimensions */ 385 current->w = width;
414 PtGetResource( window, Pt_ARG_DIM, &dim, 0 ); 386 current->h = height;
415 387 current->format->BitsPerPixel = bpp;
416 /* If we need to resize the window */ 388 current->format->BytesPerPixel = (bpp+7)/8;
417 if((dim.w != width)||(dim.h != height)) 389 current->pitch = SDL_CalculatePitch(current);
418 { 390 /* Must call at least once it setup image planes */
419 dim.w=width; 391 ph_ResizeImage(this, current, flags);
420 dim.h=height;
421 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
422 PtSetResources( window, 1, arg );
423 current->w = width;
424 current->h = height;
425 current->format->BitsPerPixel = bpp;
426 current->format->BytesPerPixel = (bpp+7)/8;
427 current->pitch = SDL_CalculatePitch(current);
428 /* Must call at least once it setup image planes */
429 ph_ResizeImage(this, current, flags);
430 }
431 392
432 SDL_Unlock_EventThread(); 393 SDL_Unlock_EventThread();
433 394
434 /* We're done! */ 395 /* We're done! */
435 return(current); 396 return(current);
436 } 397 }
437 398
438 static void ph_VideoQuit(_THIS) 399 static void ph_VideoQuit(_THIS)
439 { 400 {
401 PhRegion_t region_info;
402
440 ph_DestroyImage(this, SDL_VideoSurface); 403 ph_DestroyImage(this, SDL_VideoSurface);
441 404
442 if (currently_fullscreen) 405 if (currently_fullscreen)
443 { 406 {
444 PdDirectStop( directContext ); 407 PdDirectStop(directContext);
445 PdReleaseDirectContext( directContext ); 408 PdReleaseDirectContext(directContext);
446 directContext=0; 409 directContext=0;
447 currently_fullscreen = 0; 410 currently_fullscreen=0;
448 } 411 }
449 } 412
450 413 #ifdef HAVE_OPENGL
414 if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
415 ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
416 {
417 region_info.cursor_type=Ph_CURSOR_POINTER;
418 region_info.rid=PtWidgetRid(window);
419 PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
420 }
421
422 PtFlush();
423 #endif /* HAVE_OPENGL */
424
425 if (window)
426 {
427 PtUnrealizeWidget(window);
428 PtDestroyWidget(window);
429 window=NULL;
430 }
431
432 #ifdef HAVE_OPENGL
433 if (oglctx)
434 {
435 PhDCSetCurrent(NULL);
436 PhDCRelease(oglctx);
437 oglctx=NULL;
438 }
439 #endif /* HAVE_OPENGL */
440 }
451 441
452 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 442 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
453 { 443 {
454 PgColor_t *in, *out; 444 PgColor_t *in, *out;
455 int i, j; 445 int i, j;
506 } 496 }
507 return alloct_all; 497 return alloct_all;
508 } 498 }
509 499
510 #ifdef HAVE_OPENGL 500 #ifdef HAVE_OPENGL
501
502 int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
503 {
504 PtArg_t args[8];
505 PhDim_t dim;
506 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
507 int OGLargc;
508 int pargc;
509
510 dim.w=width;
511 dim.h=height;
512
513 if (oglctx!=NULL)
514 {
515 PhDCSetCurrent(NULL);
516 PhDCRelease(oglctx);
517 oglctx=NULL;
518 }
519
520 OGLargc=0;
521 if (this->gl_config.depth_size)
522 {
523 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
524 OGLAttrib[OGLargc++]=this->gl_config.depth_size;
525 }
526 if (this->gl_config.stencil_size)
527 {
528 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
529 OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
530 }
531 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
532 if (flags & SDL_FULLSCREEN)
533 {
534 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
535 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
536 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
537 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
538 }
539 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
540
541 if (this->gl_config.double_buffer)
542 {
543 oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
544 }
545 else
546 {
547 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
548 }
549 if (oglctx==NULL)
550 {
551 fprintf(stderr,"error: cannot create OpenGL context.\n");
552 return (-1);
553 }
554
555 PhDCSetCurrent(oglctx);
556
557 pargc=0;
558
559 PtSetArg(&args[pargc++], Pt_ARG_DIM, &dim, 0);
560 PtSetArg(&args[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
561 PtSetArg(&args[pargc++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
562
563 if (flags & SDL_FULLSCREEN)
564 {
565 PhPoint_t pos;
566
567 pos.x=0;
568 pos.y=0;
569
570 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0);
571 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
572 PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS);
573 PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0);
574 }
575
576 if (window!=NULL)
577 {
578 PtUnrealizeWidget(window);
579 PtDestroyWidget(window);
580 window=NULL;
581 }
582
583 window=PtCreateWidget(PtWindow, NULL, pargc-1, args);
584 PtRealizeWidget(window);
585
586 /* disable mouse for fullscreen */
587 if (flags & SDL_FULLSCREEN)
588 {
589 PhRegion_t region_info;
590
591 region_info.cursor_type=Ph_CURSOR_NONE;
592 region_info.rid=PtWidgetRid(window);
593 PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
594 }
595
596 PtFlush();
597
598 return 0;
599 }
600
511 void ph_GL_SwapBuffers(_THIS) 601 void ph_GL_SwapBuffers(_THIS)
512 { 602 {
513 PgSetRegion(PtWidgetRid(window)); 603 PgSetRegion(PtWidgetRid(window));
514 PdOpenGLContextSwapBuffers(OGLContext); 604 PdOpenGLContextSwapBuffers(oglctx);
515 } 605 }
516 606
517 int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) 607 int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
518 { 608 {
519 switch (attrib) 609 switch (attrib)