comparison src/video/photon/SDL_photon.c @ 3411:d15a4daa4a58

Fixes in GLES configuration selection. Support for an old QNX 6.3.2.
author Mike Gorchak <lestat@i.com.ua>
date Thu, 22 Oct 2009 06:08:36 +0000
parents f96615051c8c
children 0cbfec87e4f1
comparison
equal deleted inserted replaced
3410:f4bc25567731 3411:d15a4daa4a58
326 uint32_t it; 326 uint32_t it;
327 uint32_t jt; 327 uint32_t jt;
328 char *override; 328 char *override;
329 329
330 /* By default Photon do not uses swap on VSYNC */ 330 /* By default Photon do not uses swap on VSYNC */
331 #if defined(SDL_VIDEO_OPENGL_ES)
331 phdata->swapinterval = 0; 332 phdata->swapinterval = 0;
333 #endif /* SDL_VIDEO_OPENGL_ES */
332 334
333 for (it = 0; it < phdata->avail_rids; it++) { 335 for (it = 0; it < phdata->avail_rids; it++) {
334 didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); 336 didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
335 if (didata == NULL) { 337 if (didata == NULL) {
336 /* memory allocation error */ 338 /* memory allocation error */
1468 SDL_SetError 1470 SDL_SetError
1469 ("Photon: GF initialization failed, no OpenGL ES support"); 1471 ("Photon: GF initialization failed, no OpenGL ES support");
1470 return NULL; 1472 return NULL;
1471 } 1473 }
1472 1474
1473 /* Prepare attributes list to pass them to OpenGL ES */ 1475 /* Prepare attributes list to pass them to OpenGL ES egl interface */
1474 attr_pos = 0; 1476 attr_pos = 0;
1475 wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID; 1477 wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
1476 wdata->gles_attributes[attr_pos++] = 1478 wdata->gles_attributes[attr_pos++] =
1477 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); 1479 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
1478 wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE; 1480 wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
1499 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; 1501 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1500 } 1502 }
1501 1503
1502 /* Setup depth buffer bits */ 1504 /* Setup depth buffer bits */
1503 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; 1505 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
1504 wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size; 1506 if (_this->gl_config.depth_size)
1507 {
1508 wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
1509 }
1510 else
1511 {
1512 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1513 }
1505 1514
1506 /* Setup stencil bits */ 1515 /* Setup stencil bits */
1507 if (_this->gl_config.stencil_size) { 1516 if (_this->gl_config.stencil_size) {
1508 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; 1517 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
1509 wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size; 1518 wdata->gles_attributes[attr_pos++] = _this->gl_config.stencil_size;
1510 } else { 1519 } else {
1511 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; 1520 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
1512 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; 1521 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
1513 } 1522 }
1514 1523
1620 1629
1621 /* Now check each configuration to find out the best */ 1630 /* Now check each configuration to find out the best */
1622 for (cit = 0; cit < configs; cit++) { 1631 for (cit = 0; cit < configs; cit++) {
1623 uint32_t stencil_found; 1632 uint32_t stencil_found;
1624 uint32_t depth_found; 1633 uint32_t depth_found;
1634 EGLint cur_depth;
1635 EGLint cur_stencil;
1625 1636
1626 stencil_found = 0; 1637 stencil_found = 0;
1627 depth_found = 0; 1638 depth_found = 0;
1628 1639
1629 if (_this->gl_config.stencil_size) { 1640 if (_this->gl_config.stencil_size) {
1630 status = 1641 status =
1631 eglGetConfigAttrib(phdata->egldisplay, 1642 eglGetConfigAttrib(phdata->egldisplay,
1632 wdata->gles_configs[cit], EGL_STENCIL_SIZE, 1643 wdata->gles_configs[cit], EGL_STENCIL_SIZE,
1633 &attr_value); 1644 &cur_stencil);
1634 if (status == EGL_TRUE) { 1645 if (status == EGL_TRUE) {
1635 if (attr_value != 0) { 1646 if (cur_stencil != 0) {
1636 stencil_found = 1; 1647 stencil_found = 1;
1637 } 1648 }
1638 } 1649 }
1639 } else { 1650 } else {
1640 stencil_found = 1; 1651 stencil_found = 1;
1642 1653
1643 if (_this->gl_config.depth_size) { 1654 if (_this->gl_config.depth_size) {
1644 status = 1655 status =
1645 eglGetConfigAttrib(phdata->egldisplay, 1656 eglGetConfigAttrib(phdata->egldisplay,
1646 wdata->gles_configs[cit], EGL_DEPTH_SIZE, 1657 wdata->gles_configs[cit], EGL_DEPTH_SIZE,
1647 &attr_value); 1658 &cur_depth);
1648 if (status == EGL_TRUE) { 1659 if (status == EGL_TRUE) {
1649 if (attr_value != 0) { 1660 if (cur_depth != 0) {
1650 depth_found = 1; 1661 depth_found = 1;
1651 } 1662 }
1652 } 1663 }
1653 } else { 1664 } else {
1654 depth_found = 1; 1665 depth_found = 1;
1655 } 1666 }
1656 1667
1657 /* Exit from loop if found appropriate configuration */ 1668 /* Exit from loop if found appropriate configuration */
1658 if ((depth_found != 0) && (stencil_found != 0)) { 1669 if ((depth_found != 0) && (stencil_found != 0)) {
1659 break; 1670 /* Store last satisfied configuration id */
1660 } 1671 wdata->gles_config = cit;
1661 } 1672
1662 1673 if (cur_depth==_this->gl_config.depth_size)
1663 /* If best could not be found, use first */ 1674 {
1664 if (cit == configs) { 1675 /* Exact match on depth bits */
1676 if (!_this->gl_config.stencil_size)
1677 {
1678 /* Stencil is not required */
1679 break;
1680 }
1681 else
1682 {
1683 if (cur_stencil==_this->gl_config.stencil_size)
1684 {
1685 /* Exact match on stencil bits */
1686 break;
1687 }
1688 }
1689 }
1690 }
1691 }
1692
1693 /* If best could not be found, use first or last satisfied */
1694 if ((cit == configs) && (wdata->gles_config==0)) {
1665 cit = 0; 1695 cit = 0;
1666 } 1696 wdata->gles_config = cit;
1667 wdata->gles_config = cit; 1697 }
1668 1698
1669 /* Create OpenGL ES context */ 1699 /* Create OpenGL ES context */
1670 wdata->gles_context = 1700 wdata->gles_context =
1671 eglCreateContext(phdata->egldisplay, 1701 eglCreateContext(phdata->egldisplay,
1672 wdata->gles_configs[wdata->gles_config], 1702 wdata->gles_configs[wdata->gles_config],
2373 2403
2374 /* Check if expose come to one of the our windows */ 2404 /* Check if expose come to one of the our windows */
2375 if ((wdata != NULL) && (window != NULL)) { 2405 if ((wdata != NULL) && (window != NULL)) {
2376 /* Check if window uses OpenGL ES */ 2406 /* Check if window uses OpenGL ES */
2377 if (wdata->uses_gles == SDL_TRUE) { 2407 if (wdata->uses_gles == SDL_TRUE) {
2408 #if defined(SDL_VIDEO_OPENGL_ES)
2378 /* Cycle through each rectangle */ 2409 /* Cycle through each rectangle */
2379 for (it = 0; it < event->num_rects; it++) { 2410 for (it = 0; it < event->num_rects; it++) {
2380 /* Blit OpenGL ES pixmap surface directly to window region */ 2411 /* Blit OpenGL ES pixmap surface directly to window region */
2381 PgFFlush(Ph_START_DRAW); 2412 PgFFlush(Ph_START_DRAW);
2382 PgSetRegionCx(PhDCGetCurrent(), 2413 PgSetRegionCx(PhDCGetCurrent(),
2389 &rects[it], NULL, 2420 &rects[it], NULL,
2390 &rects[it]); 2421 &rects[it]);
2391 PgFFlush(Ph_DONE_DRAW); 2422 PgFFlush(Ph_DONE_DRAW);
2392 PgWaitHWIdle(); 2423 PgWaitHWIdle();
2393 } 2424 }
2425 #endif /* SDL_VIDEO_OPENGL_ES */
2394 } else { 2426 } else {
2395 /* Cycle through each rectangle */ 2427 /* Cycle through each rectangle */
2396 for (it = 0; it < event->num_rects; 2428 for (it = 0; it < event->num_rects;
2397 it++) { 2429 it++) {
2398 /* Blit 2D pixmap surface directly to window region */ 2430 /* Blit 2D pixmap surface directly to window region */
2422 src_rect.ul.x = 0; 2454 src_rect.ul.x = 0;
2423 src_rect.ul.y = 0; 2455 src_rect.ul.y = 0;
2424 src_rect.lr.x = window->w - 1; 2456 src_rect.lr.x = window->w - 1;
2425 src_rect.lr.y = window->h - 1; 2457 src_rect.lr.y = window->h - 1;
2426 2458
2459 #if defined(SDL_VIDEO_OPENGL_ES)
2427 /* We need to redraw entire window */ 2460 /* We need to redraw entire window */
2428 PgFFlush(Ph_START_DRAW); 2461 PgFFlush(Ph_START_DRAW);
2429 PgSetRegionCx(PhDCGetCurrent(), 2462 PgSetRegionCx(PhDCGetCurrent(),
2430 PtWidgetRid(wdata-> 2463 PtWidgetRid(wdata->
2431 window)); 2464 window));
2435 PgContextBlit(wdata->phsurface, 2468 PgContextBlit(wdata->phsurface,
2436 &src_rect, NULL, 2469 &src_rect, NULL,
2437 &dst_rect); 2470 &dst_rect);
2438 PgFFlush(Ph_DONE_DRAW); 2471 PgFFlush(Ph_DONE_DRAW);
2439 PgWaitHWIdle(); 2472 PgWaitHWIdle();
2473 #endif /* SDL_VIDEO_OPENGL_ES */
2440 } else { 2474 } else {
2441 PhRect_t rect; 2475 PhRect_t rect;
2442 2476
2443 /* We need to redraw entire window */ 2477 /* We need to redraw entire window */
2444 rect.ul.x = 0; 2478 rect.ul.x = 0;
2703 Ph_EV_PTR_MOTION_BUTTON | 2737 Ph_EV_PTR_MOTION_BUTTON |
2704 Ph_EV_PTR_MOTION_NOBUTTON; 2738 Ph_EV_PTR_MOTION_NOBUTTON;
2705 PhRegionChange(Ph_REGION_EV_SENSE, 0, 2739 PhRegionChange(Ph_REGION_EV_SENSE, 0,
2706 &wregion, NULL, NULL); 2740 &wregion, NULL, NULL);
2707 2741
2708 /* If window got a focus, the it is visible */ 2742 /* If window got a focus, then it is visible */
2709 SDL_SendWindowEvent(window->id, 2743 SDL_SendWindowEvent(window->id,
2710 SDL_WINDOWEVENT_SHOWN, 2744 SDL_WINDOWEVENT_SHOWN,
2711 0, 0); 2745 0, 0);
2712 } 2746 }
2713 } 2747 }