comparison src/video/qnxgf/SDL_qnxgf.c @ 3109:7b3a09fb9c8b

Support for HID devices (mice and keyboards only for now) has been added
author Mike Gorchak <lestat@i.com.ua>
date Tue, 28 Apr 2009 04:33:30 +0000
parents 82e60908fab1
children b17f1ae7ad66
comparison
equal deleted inserted replaced
3108:aa1897bee1e9 3109:7b3a09fb9c8b
35 #include <gf/gf.h> 35 #include <gf/gf.h>
36 36
37 #include "SDL_qnxgf.h" 37 #include "SDL_qnxgf.h"
38 #include "SDL_gf_render.h" 38 #include "SDL_gf_render.h"
39 #include "SDL_gf_pixelfmt.h" 39 #include "SDL_gf_pixelfmt.h"
40 #include "SDL_gf_opengles.h"
41 #include "SDL_gf_input.h"
40 42
41 /******************************************************************************/ 43 /******************************************************************************/
42 /* SDL Generic video modes, which could provide GF */ 44 /* SDL Generic video modes, which could provide GF */
43 /* This is real pain in the ass. GF is just wrapper around a selected driver */ 45 /* This is real pain in the ass. GF is just wrapper around a selected driver */
44 /* some drivers could support double scan modes, like 320x200, 512x384, etc */ 46 /* some drivers could support double scan modes, like 320x200, 512x384, etc */
246 SDL_free(gfdata); 248 SDL_free(gfdata);
247 SDL_free(device); 249 SDL_free(device);
248 return NULL; 250 return NULL;
249 } 251 }
250 252
253 if (gfdata->gfdev_info.description==NULL)
254 {
255 gf_dev_detach(gfdata->gfdev);
256 SDL_SetError("GF: Failed to initialize graphics driver");
257 return NULL;
258 }
259
251 /* Setup amount of available displays and current display */ 260 /* Setup amount of available displays and current display */
252 device->num_displays=0; 261 device->num_displays=0;
253 device->current_display=0; 262 device->current_display=0;
254 263
255 /* Setup device shutdown function */ 264 /* Setup device shutdown function */
310 { 319 {
311 SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; 320 SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
312 uint32_t it; 321 uint32_t it;
313 uint32_t jt; 322 uint32_t jt;
314 char* override; 323 char* override;
324 int32_t status;
325
326 /* By default GF uses buffer swap on vsync */
327 gfdata->swapinterval=1;
315 328
316 /* Add each detected output to SDL */ 329 /* Add each detected output to SDL */
317 for (it=0; it<gfdata->gfdev_info.ndisplays; it++) 330 for (it=0; it<gfdata->gfdev_info.ndisplays; it++)
318 { 331 {
319 SDL_VideoDisplay display; 332 SDL_VideoDisplay display;
320 SDL_DisplayMode current_mode; 333 SDL_DisplayMode current_mode;
321 SDL_DisplayData* didata; 334 SDL_DisplayData* didata;
322 int status;
323 335
324 didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData)); 336 didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData));
325 if (didata==NULL) 337 if (didata==NULL)
326 { 338 {
327 /* memory allocation problem */ 339 /* memory allocation problem */
328 SDL_OutOfMemory(); 340 SDL_OutOfMemory();
329 return -1; 341 return -1;
330 } 342 }
331 343
344 /* Set default cursor settings, maximum 128x128 cursor */
345 didata->cursor_visible=SDL_FALSE;
346 didata->cursor.type=GF_CURSOR_BITMAP;
347 didata->cursor.hotspot.x=0;
348 didata->cursor.hotspot.y=0;
349 didata->cursor.cursor.bitmap.w=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
350 didata->cursor.cursor.bitmap.h=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
351 didata->cursor.cursor.bitmap.stride=(didata->cursor.cursor.bitmap.w+7)/
352 (sizeof(uint8_t)*8);
353 didata->cursor.cursor.bitmap.color0=0x00000000;
354 didata->cursor.cursor.bitmap.color1=0x00000000;
355 didata->cursor.cursor.bitmap.image0=SDL_calloc(sizeof(uint8_t), (didata->cursor.cursor.bitmap.w+7)*
356 didata->cursor.cursor.bitmap.h/(sizeof(uint8_t)*8));
357 if (didata->cursor.cursor.bitmap.image0==NULL)
358 {
359 SDL_free(didata);
360 SDL_OutOfMemory();
361 return -1;
362 }
363 didata->cursor.cursor.bitmap.image1=SDL_calloc(sizeof(uint8_t), (didata->cursor.cursor.bitmap.w+7)*
364 didata->cursor.cursor.bitmap.h/(sizeof(uint8_t)*8));
365 if (didata->cursor.cursor.bitmap.image1==NULL)
366 {
367 SDL_OutOfMemory();
368 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
369 SDL_free(didata);
370 return -1;
371 }
372
373 /* Query current display settings */
332 status=gf_display_query(gfdata->gfdev, it, &didata->display_info); 374 status=gf_display_query(gfdata->gfdev, it, &didata->display_info);
333 if (status==GF_ERR_OK) 375 if (status==GF_ERR_OK)
334 { 376 {
335 SDL_zero(current_mode); 377 SDL_zero(current_mode);
336 current_mode.w=didata->display_info.xres; 378 current_mode.w=didata->display_info.xres;
340 current_mode.driverdata=NULL; 382 current_mode.driverdata=NULL;
341 } 383 }
342 else 384 else
343 { 385 {
344 /* video initialization problem */ 386 /* video initialization problem */
387 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
388 SDL_free((void*)didata->cursor.cursor.bitmap.image1);
345 SDL_free(didata); 389 SDL_free(didata);
346 SDL_SetError("GF: Display query failed"); 390 SDL_SetError("GF: Display query failed");
347 return -1; 391 return -1;
348 } 392 }
349 393
350 /* Attach GF to selected display */ 394 /* Attach GF to selected display */
351 status=gf_display_attach(&didata->display, gfdata->gfdev, it, NULL); 395 status=gf_display_attach(&didata->display, gfdata->gfdev, it, NULL);
352 if (status!=GF_ERR_OK) 396 if (status!=GF_ERR_OK)
353 { 397 {
354 /* video initialization problem */ 398 /* video initialization problem */
399 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
400 SDL_free((void*)didata->cursor.cursor.bitmap.image1);
355 SDL_free(didata); 401 SDL_free(didata);
356 SDL_SetError("GF: Couldn't attach to display"); 402 SDL_SetError("GF: Couldn't attach to display");
357 return -1; 403 return -1;
358 } 404 }
359 405
362 408
363 /* Attach to main display layer */ 409 /* Attach to main display layer */
364 status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0); 410 status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
365 if (status!=GF_ERR_OK) 411 if (status!=GF_ERR_OK)
366 { 412 {
413 /* Failed to attach to main layer */
414 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
415 SDL_free((void*)didata->cursor.cursor.bitmap.image1);
416 SDL_free(didata);
367 SDL_SetError("GF: Couldn't attach to main layer, it could be busy"); 417 SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
368 418 return -1;
369 /* Failed to attach to main layer */ 419 }
420
421 /* Mark main display layer is attached */
422 didata->layer_attached=SDL_TRUE;
423
424 /* Set layer source and destination viewport */
425 gf_layer_set_src_viewport(didata->layer, 0, 0, current_mode.w-1, current_mode.h-1);
426 gf_layer_set_dst_viewport(didata->layer, 0, 0, current_mode.w-1, current_mode.h-1);
427
428 /* Create main visible on display surface */
429 status=gf_surface_create_layer(&didata->surface[0], &didata->layer,
430 1, 0, current_mode.w, current_mode.h,
431 qnxgf_sdl_to_gf_pixelformat(current_mode.format),
432 NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
433 GF_SURFACE_CREATE_SHAREABLE);
434 if (status!=GF_ERR_OK)
435 {
436 gf_layer_disable(didata->layer);
437 gf_layer_detach(didata->layer);
438 didata->layer_attached=SDL_FALSE;
439 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
440 SDL_free((void*)didata->cursor.cursor.bitmap.image1);
441 SDL_free(didata);
442 SDL_SetError("GF: Can't create main layer surface at init (%d)\n", status);
443 return -1;
444 }
445
446 /* Set just created surface as main visible on the layer */
447 // gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
448
449 /* Update layer parameters */
450 status=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
451 if (status!=GF_ERR_OK)
452 {
453 /* Free allocated surface */
454 gf_surface_free(didata->surface[0]);
455 didata->surface[0]=NULL;
456
457 /* Disable and detach from layer */
458 gf_layer_disable(didata->layer);
459 gf_layer_detach(didata->layer);
460 didata->layer_attached=SDL_FALSE;
461 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
462 SDL_free((void*)didata->cursor.cursor.bitmap.image1);
463 SDL_free(didata);
464 SDL_SetError("GF: Can't update layer parameters\n");
370 return -1; 465 return -1;
371 } 466 }
372 467
373 /* Enable layer in case if hardware supports layer enable/disable */ 468 /* Enable layer in case if hardware supports layer enable/disable */
374 gf_layer_enable(didata->layer); 469 gf_layer_enable(didata->layer);
375
376 /* Mark main display layer is attached */
377 didata->layer_attached=SDL_TRUE;
378 470
379 /* Copy device name for each display */ 471 /* Copy device name for each display */
380 SDL_strlcpy(didata->description, gfdata->gfdev_info.description, SDL_VIDEO_GF_DEVICENAME_MAX-1); 472 SDL_strlcpy(didata->description, gfdata->gfdev_info.description, SDL_VIDEO_GF_DEVICENAME_MAX-1);
381 473
382 /* Search device capabilities and possible workarounds */ 474 /* Search device capabilities and possible workarounds */
393 jt++; 485 jt++;
394 } while(1); 486 } while(1);
395 487
396 /* Initialize display structure */ 488 /* Initialize display structure */
397 SDL_zero(display); 489 SDL_zero(display);
398 display.desktop_mode = current_mode; 490 display.desktop_mode=current_mode;
399 display.current_mode = current_mode; 491 display.current_mode=current_mode;
400 display.driverdata = didata; 492 display.driverdata=didata;
401 didata->current_mode=current_mode; 493 didata->current_mode=current_mode;
402 SDL_AddVideoDisplay(&display); 494 SDL_AddVideoDisplay(&display);
403 495
404 /* Check for environment variables which could override some SDL settings */ 496 /* Check for environment variables which could override some SDL settings */
405 didata->custom_refresh=0; 497 didata->custom_refresh=0;
409 if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1) 501 if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1)
410 { 502 {
411 didata->custom_refresh=0; 503 didata->custom_refresh=0;
412 } 504 }
413 } 505 }
414 } 506
507 /* Get all display modes for this display */
508 _this->current_display=it;
509 qnxgf_getdisplaymodes(_this);
510 }
511
512 /* Restore default display */
513 _this->current_display=0;
415 514
416 /* Add GF renderer to SDL */ 515 /* Add GF renderer to SDL */
417 gf_addrenderdriver(_this); 516 gf_addrenderdriver(_this);
418 517
518 /* Add GF input devices */
519 status=gf_addinputdevices(_this);
520 if (status!=0)
521 {
522 /* SDL error is set by gf_addinputdevices() function */
523 return -1;
524 }
525
419 /* video has been initialized successfully */ 526 /* video has been initialized successfully */
420 return 1; 527 return 1;
421 } 528 }
422 529
423 void qnxgf_videoquit(_THIS) 530 void qnxgf_videoquit(_THIS)
424 { 531 {
425 SDL_DisplayData* didata; 532 SDL_DisplayData* didata;
426 uint32_t it; 533 uint32_t it;
427 534
428 /* SDL will restore our desktop mode on exit */ 535 /* Delete GF input devices */
536 gf_delinputdevices(_this);
537
538 /* SDL will restore old desktop mode on exit */
429 for(it=0; it<_this->num_displays; it++) 539 for(it=0; it<_this->num_displays; it++)
430 { 540 {
431 didata=_this->displays[it].driverdata; 541 didata=_this->displays[it].driverdata;
542
543 /* Free cursor image */
544 if (didata->cursor.cursor.bitmap.image0!=NULL)
545 {
546 SDL_free((void*)didata->cursor.cursor.bitmap.image0);
547 }
548 if (didata->cursor.cursor.bitmap.image1!=NULL)
549 {
550 SDL_free((void*)didata->cursor.cursor.bitmap.image1);
551 }
552
553 /* Free main surface */
554 if (didata->surface[0]!=NULL)
555 {
556 gf_surface_free(didata->surface[0]);
557 didata->surface[0]=NULL;
558 }
559
560 /* Free back surface */
561 if (didata->surface[1]!=NULL)
562 {
563 gf_surface_free(didata->surface[1]);
564 didata->surface[1]=NULL;
565 }
566
567 /* Free second back surface */
568 if (didata->surface[2]!=NULL)
569 {
570 gf_surface_free(didata->surface[2]);
571 didata->surface[2]=NULL;
572 }
573
574 /* Detach layer before quit */
575 if (didata->layer_attached==SDL_TRUE)
576 {
577 /* Disable layer if hardware supports this */
578 gf_layer_disable(didata->layer);
579
580 /* Detach from layer, free it for others */
581 gf_layer_detach(didata->layer);
582
583 /* Mark it as detached */
584 didata->layer_attached=SDL_FALSE;
585 }
432 586
433 /* Detach from selected display */ 587 /* Detach from selected display */
434 gf_display_detach(didata->display); 588 gf_display_detach(didata->display);
435 } 589 }
436 } 590 }
521 675
522 int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) 676 int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode)
523 { 677 {
524 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; 678 SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
525 uint32_t refresh_rate=0; 679 uint32_t refresh_rate=0;
526 int result; 680 int status;
527 681
528 /* Current display dimensions and bpp are no more valid */ 682 /* Current display dimensions and bpp are no more valid */
529 didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN; 683 didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
530 didata->current_mode.w=0; 684 didata->current_mode.w=0;
531 didata->current_mode.h=0; 685 didata->current_mode.h=0;
615 /* Let video driver decide what to do with this */ 769 /* Let video driver decide what to do with this */
616 refresh_rate=0; 770 refresh_rate=0;
617 } 771 }
618 } 772 }
619 773
774 /* Free main surface */
775 if (didata->surface[0]!=NULL)
776 {
777 gf_surface_free(didata->surface[0]);
778 didata->surface[0]=NULL;
779 }
780
781 /* Free back surface */
782 if (didata->surface[1]!=NULL)
783 {
784 gf_surface_free(didata->surface[1]);
785 didata->surface[1]=NULL;
786 }
787
788 /* Free second back surface */
789 if (didata->surface[2]!=NULL)
790 {
791 gf_surface_free(didata->surface[2]);
792 didata->surface[2]=NULL;
793 }
794
620 /* Detach layer before switch to new graphics mode */ 795 /* Detach layer before switch to new graphics mode */
621 if (didata->layer_attached==SDL_TRUE) 796 if (didata->layer_attached==SDL_TRUE)
622 { 797 {
623 /* Disable layer if hardware supports this */ 798 /* Disable layer if hardware supports this */
624 gf_layer_disable(didata->layer); 799 gf_layer_disable(didata->layer);
629 /* Mark it as detached */ 804 /* Mark it as detached */
630 didata->layer_attached=SDL_FALSE; 805 didata->layer_attached=SDL_FALSE;
631 } 806 }
632 807
633 /* Set new display video mode */ 808 /* Set new display video mode */
634 result=gf_display_set_mode(didata->display, mode->w, mode->h, refresh_rate, 809 status=gf_display_set_mode(didata->display, mode->w, mode->h, refresh_rate,
635 qnxgf_sdl_to_gf_pixelformat(mode->format), 0); 810 qnxgf_sdl_to_gf_pixelformat(mode->format), 0);
636 if (result!=GF_ERR_OK) 811 if (status!=GF_ERR_OK)
637 { 812 {
638 /* Display mode/resolution switch has been failed */ 813 /* Display mode/resolution switch has been failed */
639 SDL_SetError("GF: Mode is not supported by graphics driver"); 814 SDL_SetError("GF: Mode is not supported by graphics driver");
640 return -1; 815 return -1;
641 } 816 }
644 didata->current_mode=*mode; 819 didata->current_mode=*mode;
645 didata->current_mode.refresh_rate=refresh_rate; 820 didata->current_mode.refresh_rate=refresh_rate;
646 } 821 }
647 822
648 /* Attach to main display layer */ 823 /* Attach to main display layer */
649 result=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0); 824 status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
650 if (result!=GF_ERR_OK) 825 if (status!=GF_ERR_OK)
651 { 826 {
652 SDL_SetError("GF: Couldn't attach to main layer, it could be busy"); 827 SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
653 828
654 /* Failed to attach to main displayable layer */ 829 /* Failed to attach to main displayable layer */
655 return -1; 830 return -1;
656 } 831 }
657 832
833 /* Mark main display layer is attached */
834 didata->layer_attached=SDL_TRUE;
835
836 /* Set layer source and destination viewport */
837 gf_layer_set_src_viewport(didata->layer, 0, 0, mode->w-1, mode->h-1);
838 gf_layer_set_dst_viewport(didata->layer, 0, 0, mode->w-1, mode->h-1);
839
840 /* Create main visible on display surface */
841 status=gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0,
842 mode->w, mode->h, qnxgf_sdl_to_gf_pixelformat(mode->format),
843 NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
844 GF_SURFACE_CREATE_SHAREABLE);
845 if (status!=GF_ERR_OK)
846 {
847 gf_layer_disable(didata->layer);
848 gf_layer_detach(didata->layer);
849 didata->layer_attached=SDL_FALSE;
850 SDL_SetError("GF: Can't create main layer surface at modeswitch (%d)\n", status);
851 return -1;
852 }
853
854 /* Set just created surface as main visible on the layer */
855 gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
856
857 /* Update layer parameters */
858 status=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
859 if (status!=GF_ERR_OK)
860 {
861 /* Free main surface */
862 gf_surface_free(didata->surface[0]);
863 didata->surface[0]=NULL;
864
865 /* Detach layer */
866 gf_layer_disable(didata->layer);
867 gf_layer_detach(didata->layer);
868 didata->layer_attached=SDL_FALSE;
869 SDL_SetError("GF: Can't update layer parameters\n");
870 return -1;
871 }
872
873 /* Restore cursor if it was visible */
874 if (didata->cursor_visible==SDL_TRUE)
875 {
876 gf_cursor_set(didata->display, 0, &didata->cursor);
877 gf_cursor_enable(didata->display, 0);
878 }
879
658 /* Enable layer in case if hardware supports layer enable/disable */ 880 /* Enable layer in case if hardware supports layer enable/disable */
659 gf_layer_enable(didata->layer); 881 gf_layer_enable(didata->layer);
660
661 /* Mark main display layer is attached */
662 didata->layer_attached=SDL_TRUE;
663 882
664 return 0; 883 return 0;
665 } 884 }
666 885
667 int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette) 886 int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette)
764 return -1; 983 return -1;
765 } 984 }
766 } 985 }
767 } 986 }
768 987
769 /* Setup our own window decorations, which are depend on fullscreen mode */ 988 /* Setup our own window decorations and states, which are depend on fullscreen mode */
770 window->flags|=SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | 989 window->flags|=SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS |
771 SDL_WINDOW_MAXIMIZED | SDL_WINDOW_INPUT_GRABBED | 990 SDL_WINDOW_MAXIMIZED | SDL_WINDOW_INPUT_GRABBED |
772 SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS; 991 SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS;
773 window->flags&=~(SDL_WINDOW_RESIZABLE | SDL_WINDOW_MINIMIZED); 992 window->flags&=~(SDL_WINDOW_RESIZABLE | SDL_WINDOW_MINIMIZED);
774 993
821 SDL_SetError("GF: OpenGL ES support is not compiled in"); 1040 SDL_SetError("GF: OpenGL ES support is not compiled in");
822 return -1; 1041 return -1;
823 #endif /* SDL_VIDEO_OPENGL_ES */ 1042 #endif /* SDL_VIDEO_OPENGL_ES */
824 } 1043 }
825 1044
1045 /* Enable mouse event collecting */
1046 hiddi_enable_mouse();
1047
1048 /* By default last created window got a input focus */
1049 SDL_SetKeyboardFocus(0, window->id);
1050 SDL_SetMouseFocus(0, window->id);
1051
826 /* Window has been successfully created */ 1052 /* Window has been successfully created */
827 return 0; 1053 return 0;
828 } 1054 }
829 1055
830 int qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data) 1056 int qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data)
894 1120
895 /* Free any 3D target if it was created before */ 1121 /* Free any 3D target if it was created before */
896 if (wdata->target_created==SDL_TRUE) 1122 if (wdata->target_created==SDL_TRUE)
897 { 1123 {
898 gf_3d_target_free(wdata->target); 1124 gf_3d_target_free(wdata->target);
899 } 1125 wdata->target_created==SDL_FALSE;
900 1126 }
901 1127
902 gfdata->egl_refcount--; 1128 gfdata->egl_refcount--;
903 if (gfdata->egl_refcount==0) 1129 if (gfdata->egl_refcount==0)
904 { 1130 {
905 /* Terminate connection to OpenGL ES */ 1131 /* Terminate connection to OpenGL ES */
999 { 1225 {
1000 return function_address; 1226 return function_address;
1001 } 1227 }
1002 } 1228 }
1003 1229
1230 /* Add emulated OpenGL ES 1.1 functions */
1231 if (SDL_strcmp(proc, "glTexParameteri")==0)
1232 {
1233 return glTexParameteri;
1234 }
1235 if (SDL_strcmp(proc, "glTexParameteriv")==0)
1236 {
1237 return glTexParameteriv;
1238 }
1239 if (SDL_strcmp(proc, "glColor4ub")==0)
1240 {
1241 return glColor4ub;
1242 }
1243
1004 /* Failed to get GL ES function address pointer */ 1244 /* Failed to get GL ES function address pointer */
1005 SDL_SetError("GF: Cannot locate given function name"); 1245 SDL_SetError("GF: Cannot locate OpenGL ES function name");
1006 return NULL; 1246 return NULL;
1007 #else 1247 #else
1008 SDL_SetError("GF: OpenGL ES support is not compiled in"); 1248 SDL_SetError("GF: OpenGL ES support is not compiled in");
1009 return NULL; 1249 return NULL;
1010 #endif /* SDL_VIDEO_OPENGL_ES */ 1250 #endif /* SDL_VIDEO_OPENGL_ES */
1034 EGLBoolean status; 1274 EGLBoolean status;
1035 int32_t gfstatus; 1275 int32_t gfstatus;
1036 EGLint configs; 1276 EGLint configs;
1037 uint32_t surfaces; 1277 uint32_t surfaces;
1038 uint32_t attr_pos; 1278 uint32_t attr_pos;
1279 EGLint attr_value;
1280 EGLint cit;
1281
1282 /* Choose buffeingr scheme */
1283 if (!_this->gl_config.double_buffer)
1284 {
1285 surfaces=1;
1286 }
1287 else
1288 {
1289 surfaces=2;
1290 }
1291
1292 /* Free main surface */
1293 if (didata->surface[0]!=NULL)
1294 {
1295 gf_surface_free(didata->surface[0]);
1296 didata->surface[0]=NULL;
1297 }
1298
1299 /* Free back surface */
1300 if (didata->surface[1]!=NULL)
1301 {
1302 gf_surface_free(didata->surface[1]);
1303 didata->surface[1]=NULL;
1304 }
1305
1306 /* Free second back surface */
1307 if (didata->surface[2]!=NULL)
1308 {
1309 gf_surface_free(didata->surface[2]);
1310 didata->surface[2]=NULL;
1311 }
1312
1313 /* Detach layer before switch to new graphics mode */
1314 if (didata->layer_attached==SDL_TRUE)
1315 {
1316 /* Disable layer if hardware supports this */
1317 gf_layer_disable(didata->layer);
1318
1319 /* Detach from layer, free it for others */
1320 gf_layer_detach(didata->layer);
1321
1322 /* Mark it as detached */
1323 didata->layer_attached=SDL_FALSE;
1324 }
1325
1326 /* Attach to main display layer */
1327 gfstatus=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
1328 if (gfstatus!=GF_ERR_OK)
1329 {
1330 SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
1331
1332 /* Failed to attach to main displayable layer */
1333 return NULL;
1334 }
1335
1336 /* Mark main display layer is attached */
1337 didata->layer_attached=SDL_TRUE;
1338
1339 /* Set layer source and destination viewport */
1340 gf_layer_set_src_viewport(didata->layer, 0, 0, didata->current_mode.w-1, didata->current_mode.h-1);
1341 gf_layer_set_dst_viewport(didata->layer, 0, 0, didata->current_mode.w-1, didata->current_mode.h-1);
1342
1343 /* Create main visible on display surface */
1344 gfstatus=gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0,
1345 didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format),
1346 NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
1347 GF_SURFACE_CREATE_SHAREABLE);
1348 if (gfstatus!=GF_ERR_OK)
1349 {
1350 gf_layer_disable(didata->layer);
1351 gf_layer_detach(didata->layer);
1352 didata->layer_attached=SDL_FALSE;
1353 SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n", gfstatus);
1354 return NULL;
1355 }
1356
1357 /* Set just created surface as main visible on the layer */
1358 // gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
1359
1360 if (surfaces>1)
1361 {
1362 /* Create back display surface */
1363 gfstatus=gf_surface_create_layer(&didata->surface[1], &didata->layer, 1, 0,
1364 didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format),
1365 NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
1366 GF_SURFACE_CREATE_SHAREABLE);
1367 if (gfstatus!=GF_ERR_OK)
1368 {
1369 gf_surface_free(didata->surface[0]);
1370 gf_layer_disable(didata->layer);
1371 gf_layer_detach(didata->layer);
1372 didata->layer_attached=SDL_FALSE;
1373 SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n", gfstatus);
1374 return NULL;
1375 }
1376 }
1377
1378 /* Update layer parameters */
1379 gfstatus=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
1380 if (gfstatus!=GF_ERR_OK)
1381 {
1382 /* Free main and back surfaces */
1383 gf_surface_free(didata->surface[1]);
1384 didata->surface[1]=NULL;
1385 gf_surface_free(didata->surface[0]);
1386 didata->surface[0]=NULL;
1387
1388 /* Detach layer */
1389 gf_layer_disable(didata->layer);
1390 gf_layer_detach(didata->layer);
1391 didata->layer_attached=SDL_FALSE;
1392 SDL_SetError("GF: Can't update layer parameters\n");
1393 return NULL;
1394 }
1395
1396 /* Enable layer in case if hardware supports layer enable/disable */
1397 gf_layer_enable(didata->layer);
1039 1398
1040 /* Prepare attributes list to pass them to OpenGL ES */ 1399 /* Prepare attributes list to pass them to OpenGL ES */
1041 attr_pos=0; 1400 attr_pos=0;
1042 wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID; 1401 wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
1043 wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); 1402 wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
1067 { 1426 {
1068 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE; 1427 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
1069 wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size; 1428 wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
1070 } 1429 }
1071 1430
1072 /* OpenGL ES 1.0 uses double buffer by default, so if application */
1073 /* do not requested double buffering, switch to single buffer */
1074 if (!_this->gl_config.double_buffer)
1075 {
1076 wdata->gles_attributes[attr_pos++]=EGL_SINGLE_BUFFER;
1077 wdata->gles_attributes[attr_pos++]=EGL_TRUE;
1078 surfaces=1;
1079 }
1080 else
1081 {
1082 surfaces=2;
1083 }
1084
1085 /* Set number of samples in multisampling */ 1431 /* Set number of samples in multisampling */
1086 if (_this->gl_config.multisamplesamples) 1432 if (_this->gl_config.multisamplesamples)
1087 { 1433 {
1088 wdata->gles_attributes[attr_pos++]=EGL_SAMPLES; 1434 wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
1089 wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples; 1435 wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples;
1098 1444
1099 /* Finish attributes list */ 1445 /* Finish attributes list */
1100 wdata->gles_attributes[attr_pos]=EGL_NONE; 1446 wdata->gles_attributes[attr_pos]=EGL_NONE;
1101 1447
1102 /* Request first suitable framebuffer configuration */ 1448 /* Request first suitable framebuffer configuration */
1103 status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes, &wdata->gles_config, 1, &configs); 1449 status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes,
1450 wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
1104 if (status!=EGL_TRUE) 1451 if (status!=EGL_TRUE)
1105 { 1452 {
1106 SDL_SetError("GF: Can't find closest configuration for OpenGL ES"); 1453 SDL_SetError("GF: Can't find closest configuration for OpenGL ES");
1107 return NULL; 1454 return NULL;
1108 } 1455 }
1109 1456
1457 /* Check if nothing has been found, try "don't care" settings */
1458 if (configs==0)
1459 {
1460 int32_t it;
1461 int32_t jt;
1462 GLint depthbits[4]={32, 24, 16, EGL_DONT_CARE};
1463
1464 for (it=0; it<4; it++)
1465 {
1466 for (jt=16; jt>=0; jt--)
1467 {
1468 /* Don't care about color buffer bits, use what exist */
1469 /* Replace previous data set with EGL_DONT_CARE */
1470 attr_pos=0;
1471 wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
1472 wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
1473 wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
1474 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1475 wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
1476 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1477 wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
1478 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1479 wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
1480 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1481 wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
1482 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1483
1484 /* Try to find requested or smallest depth */
1485 if (_this->gl_config.depth_size)
1486 {
1487 wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
1488 wdata->gles_attributes[attr_pos++]=depthbits[it];
1489 }
1490 else
1491 {
1492 wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
1493 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1494 }
1495
1496 if (_this->gl_config.stencil_size)
1497 {
1498 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
1499 wdata->gles_attributes[attr_pos++]=jt;
1500 }
1501 else
1502 {
1503 wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
1504 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1505
1506 /* exit from stencil loop */
1507 jt=0;
1508 }
1509
1510 /* Don't care about antialiasing */
1511 wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
1512 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1513 wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
1514 wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
1515 wdata->gles_attributes[attr_pos]=EGL_NONE;
1516
1517 /* Request first suitable framebuffer configuration */
1518 status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes,
1519 wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
1520 if (status!=EGL_TRUE)
1521 {
1522 SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
1523 return NULL;
1524 }
1525 if (configs!=0)
1526 {
1527 break;
1528 }
1529 }
1530 if (configs!=0)
1531 {
1532 break;
1533 }
1534 }
1535
1536 /* No available configs */
1537 if (configs==0)
1538 {
1539 SDL_SetError("Photon: Can't find any configuration for OpenGL ES");
1540 return NULL;
1541 }
1542 }
1543
1544 /* Initialize config index */
1545 wdata->gles_config=0;
1546
1547 /* Now check each configuration to find out the best */
1548 for (cit=0; cit<configs; cit++)
1549 {
1550 uint32_t stencil_found;
1551 uint32_t depth_found;
1552
1553 stencil_found=0;
1554 depth_found=0;
1555
1556 if (_this->gl_config.stencil_size)
1557 {
1558 status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value);
1559 if (status==EGL_TRUE)
1560 {
1561 if (attr_value!=0)
1562 {
1563 stencil_found=1;
1564 }
1565 }
1566 }
1567 else
1568 {
1569 stencil_found=1;
1570 }
1571
1572 if (_this->gl_config.depth_size)
1573 {
1574 status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value);
1575 if (status==EGL_TRUE)
1576 {
1577 if (attr_value!=0)
1578 {
1579 depth_found=1;
1580 }
1581 }
1582 }
1583 else
1584 {
1585 depth_found=1;
1586 }
1587
1588 /* Exit from loop if found appropriate configuration */
1589 if ((depth_found!=0) && (stencil_found!=0))
1590 {
1591 break;
1592 }
1593 }
1594
1595 /* If best could not be found, use first */
1596 if (cit==configs)
1597 {
1598 cit=0;
1599 }
1600 wdata->gles_config=cit;
1601
1110 /* Create OpenGL ES context */ 1602 /* Create OpenGL ES context */
1111 wdata->gles_context=eglCreateContext(gfdata->egldisplay, wdata->gles_config, EGL_NO_CONTEXT, NULL); 1603 wdata->gles_context=eglCreateContext(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL);
1112 if (wdata->gles_context==EGL_NO_CONTEXT) 1604 if (wdata->gles_context==EGL_NO_CONTEXT)
1113 { 1605 {
1114 SDL_SetError("GF: OpenGL ES context creation has been failed"); 1606 SDL_SetError("GF: OpenGL ES context creation has been failed");
1115 return NULL; 1607 return NULL;
1116 } 1608 }
1117 1609
1118 /* Free any 3D target if it was created before */ 1610 /* Free any 3D target if it was created before */
1119 if (wdata->target_created==SDL_TRUE) 1611 if (wdata->target_created==SDL_TRUE)
1120 { 1612 {
1121 gf_3d_target_free(wdata->target); 1613 gf_3d_target_free(wdata->target);
1614 wdata->target_created==SDL_FALSE;
1122 } 1615 }
1123 1616
1124 /* Create surface(s) target for OpenGL ES */ 1617 /* Create surface(s) target for OpenGL ES */
1125 gfstatus=gf_3d_target_create(&wdata->target, didata->layer, NULL, 1618 gfstatus=gf_3d_target_create(&wdata->target, didata->layer, &didata->surface[0],
1126 surfaces, didata->current_mode.w, didata->current_mode.h, 1619 surfaces, didata->current_mode.w, didata->current_mode.h,
1127 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format)); 1620 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format));
1128
1129 if (gfstatus!=GF_ERR_OK) 1621 if (gfstatus!=GF_ERR_OK)
1130 { 1622 {
1131 /* Destroy just created context */ 1623 /* Destroy just created context */
1132 eglDestroyContext(gfdata->egldisplay, wdata->gles_context); 1624 eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
1133 wdata->gles_context=EGL_NO_CONTEXT; 1625 wdata->gles_context=EGL_NO_CONTEXT;
1141 { 1633 {
1142 wdata->target_created=SDL_TRUE; 1634 wdata->target_created=SDL_TRUE;
1143 } 1635 }
1144 1636
1145 /* Create target rendering surface on whole screen */ 1637 /* Create target rendering surface on whole screen */
1146 wdata->gles_surface=eglCreateWindowSurface(gfdata->egldisplay, wdata->gles_config, wdata->target, NULL); 1638 wdata->gles_surface=eglCreateWindowSurface(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->target, NULL);
1147 if (wdata->gles_surface==EGL_NO_SURFACE) 1639 if (wdata->gles_surface==EGL_NO_SURFACE)
1148 { 1640 {
1149 /* Destroy 3d target */ 1641 /* Destroy 3d target */
1150 gf_3d_target_free(wdata->target); 1642 gf_3d_target_free(wdata->target);
1151 wdata->target_created=SDL_FALSE; 1643 wdata->target_created=SDL_FALSE;
1190 } 1682 }
1191 1683
1192 /* Always clear stereo enable, since OpenGL ES do not supports stereo */ 1684 /* Always clear stereo enable, since OpenGL ES do not supports stereo */
1193 _this->gl_config.stereo=0; 1685 _this->gl_config.stereo=0;
1194 1686
1195 /* Failed to create GL ES context */ 1687 /* Get back samples and samplebuffers configurations. Rest framebuffer */
1688 /* parameters could be obtained through the OpenGL ES API */
1689 status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value);
1690 if (status==EGL_TRUE)
1691 {
1692 _this->gl_config.multisamplesamples=attr_value;
1693 }
1694 status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value);
1695 if (status==EGL_TRUE)
1696 {
1697 _this->gl_config.multisamplebuffers=attr_value;
1698 }
1699
1700 /* Get back stencil and depth buffer sizes */
1701 status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value);
1702 if (status==EGL_TRUE)
1703 {
1704 _this->gl_config.depth_size=attr_value;
1705 }
1706 status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value);
1707 if (status==EGL_TRUE)
1708 {
1709 _this->gl_config.stencil_size=attr_value;
1710 }
1711
1712 /* Restore cursor if it was visible */
1713 if (didata->cursor_visible==SDL_TRUE)
1714 {
1715 gf_cursor_set(didata->display, 0, &didata->cursor);
1716 gf_cursor_enable(didata->display, 0);
1717 }
1718
1719 /* GL ES context was successfully created */
1196 return wdata->gles_context; 1720 return wdata->gles_context;
1197 #else 1721 #else
1198 SDL_SetError("GF: OpenGL ES support is not compiled in"); 1722 SDL_SetError("GF: OpenGL ES support is not compiled in");
1199 return NULL; 1723 return NULL;
1200 #endif /* SDL_VIDEO_OPENGL_ES */ 1724 #endif /* SDL_VIDEO_OPENGL_ES */
1281 { 1805 {
1282 #if defined(SDL_VIDEO_OPENGL_ES) 1806 #if defined(SDL_VIDEO_OPENGL_ES)
1283 SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; 1807 SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
1284 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; 1808 SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
1285 1809
1810 /* Finish all drawings */
1811 glFinish();
1812
1813 /* Swap buffers */
1286 eglSwapBuffers(gfdata->egldisplay, wdata->gles_surface); 1814 eglSwapBuffers(gfdata->egldisplay, wdata->gles_surface);
1287 #else 1815 #else
1288 SDL_SetError("GF: OpenGL ES support is not compiled in"); 1816 SDL_SetError("GF: OpenGL ES support is not compiled in");
1289 return; 1817 return;
1290 #endif /* SDL_VIDEO_OPENGL_ES */ 1818 #endif /* SDL_VIDEO_OPENGL_ES */