Ejemplo n.º 1
0
static bool gfx_ctx_qnx_init(void *data)
{
   /* Create a screen context that will be used to 
    * create an EGL surface to receive libscreen events */

   RARCH_LOG("Initializing screen context...\n");
   if (!screen_ctx)
   {
      screen_create_context(&screen_ctx, 0);

      if (screen_request_events(screen_ctx) != BPS_SUCCESS)
      {
         RARCH_ERR("screen_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_request_events(0) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_rotation_lock(false) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_location_lock failed.\n");
         goto screen_error;
      }
   }

   const EGLint attribs[] = {
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_BLUE_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_RED_SIZE, 8,
      EGL_NONE
   };
   EGLint num_config;
   EGLint egl_version_major, egl_version_minor;
   int format = SCREEN_FORMAT_RGBX8888;

   EGLint context_attributes[] = {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
   };
   int usage;

   usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;

   RARCH_LOG("Initializing context\n");

   if ((g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY)
   {
      RARCH_ERR("eglGetDisplay failed.\n");
      goto error;
   }

   if (!eglInitialize(g_egl_dpy, &egl_version_major, &egl_version_minor))
   {
      RARCH_ERR("eglInitialize failed.\n");
      goto error;
   }

   if (!eglBindAPI(EGL_OPENGL_ES_API))
   {
      RARCH_ERR("eglBindAPI failed.\n");
      goto error;
   }

   RARCH_LOG("[BLACKBERRY QNX/EGL]: EGL version: %d.%d\n", egl_version_major, egl_version_minor);

   if (!eglChooseConfig(g_egl_dpy, attribs, &egl_config, 1, &num_config))
   {
      RARCH_ERR("eglChooseConfig failed.\n");
      goto error;
   }

   if ((g_egl_ctx = eglCreateContext(g_egl_dpy, egl_config, 0, context_attributes)) == EGL_NO_CONTEXT)
   {
      RARCH_ERR("eglCreateContext failed.\n");
      goto error;
   }

   if(!screen_win)
   {
      if (screen_create_window(&screen_win, screen_ctx))
      {
	     RARCH_ERR("screen_create_window failed:.\n");
	     goto error;
      }
   }

   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n");
      goto error;
   }

   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n");
      goto error;
   }

   if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp))
   {
      RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
      goto error;
   }

   int screen_resolution[2];

   if (screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
      goto error;
   }

#ifndef HAVE_BB10
   int angle = atoi(getenv("ORIENTATION"));

   screen_display_mode_t screen_mode;
   if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode))
   {
      RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n");
      goto error;
   }

   int size[2];
   if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   int buffer_size[2] = {size[0], size[1]};

   if ((angle == 0) || (angle == 180)) {
      if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   } else if ((angle == 90) || (angle == 270)){
      if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
            ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   } else {
      RARCH_ERR("Navigator returned an unexpected orientation angle.\n");
      goto error;
   }


   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n");
      goto error;
   }
#endif

   if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS))
   {
      RARCH_ERR("screen_create_window_buffers failed.\n");
      goto error;
   }

   if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, egl_config, screen_win, 0)))
   {
      RARCH_ERR("eglCreateWindowSurface failed.\n");
      goto error;
   }


   if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx))
   {
      RARCH_ERR("eglMakeCurrent failed.\n");
      goto error;
   }

   return true;

error:
   RARCH_ERR("EGL error: %d.\n", eglGetError());
   gfx_ctx_qnx_destroy(data);
screen_error:
   screen_stop_events(screen_ctx);
   return false;
}
Ejemplo n.º 2
0
bool Game::InitDisplay()
{
   /*
   * Here specify the attributes of the desired configuration.
   * Below, we select an EGLConfig with at least 8 bits per color
   * component compatible with on-screen windows
   */
   const EGLint attribs[] =
   {
      EGL_RED_SIZE,        8,
      EGL_GREEN_SIZE,      8,
      EGL_BLUE_SIZE,       8,
      EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
      EGL_DEPTH_SIZE,      24,
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //Maybe EGL_CONFORMANT for windows and Android?
      EGL_NONE
   };
   EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                           EGL_GREEN_SIZE,      8,
                           EGL_BLUE_SIZE,       8,
                           EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                           EGL_RENDERABLE_TYPE, 0,
                           EGL_NONE};

   EGLint w, h, format;
   EGLint numConfigs;
   EGLConfig config[64];
   EGLSurface surface;
   EGLContext context;

   EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

   int maj;
   int min;
   eglInitialize(display, &maj, &min);
   Log::Debug("EGLInitialise", "EGL Major:%d Minor:%d", maj, min);

   /* Here, the application chooses the configuration it desires. In this
   * sample, we have a very simplified selection process, where we pick
   * the first EGLConfig that matches our criteria */
   eglChooseConfig(display, attribs, &config[0], 64, &numConfigs);

   for(int i = 0; i < numConfigs; i++)
   {
      int val[1];
      eglGetConfigAttrib(display, config[i], EGL_CONFORMANT, &val[0]);
      Log::Debug("EGLInitialise", "EGL_CONFORMANT: %d", val[0]);
      Log::Debug("EGLInitialise", "GL2: %d", val[0] & EGL_OPENGL_ES2_BIT);
      Log::Debug("EGLInitialise", "GL1: %d", val[0] & EGL_OPENGL_ES_BIT);
   }

   if(numConfigs == 0)
   {
      Log::Error("EGLInitialise", "No EGL configs were returned.");
      return true;
   }

   /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
   * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
   * As soon as we picked a EGLConfig, we can safely reconfigure the
   * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
   eglGetConfigAttrib(display, config[0], EGL_NATIVE_VISUAL_ID, &format);

#ifdef ANDROID
   ANativeWindow_setBuffersGeometry(mDisplay.app->window, 0, 0, format); //TODO!
   surface = eglCreateWindowSurface(display, config[0], mDisplay.app->window, NULL);
#endif
#ifdef _WIN32
   mDisplay.WindowHandle = create_window(mDisplay.Width, mDisplay.Height);
   surface = EGL_CHECK(eglCreateWindowSurface(display, config[0], (EGLNativeWindowType)mDisplay.WindowHandle, NULL));
#endif
#ifdef __QNX__
   int screen_format = SCREEN_FORMAT_RGBX8888;
   int usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
   int screen_resolution[2];
   screen_display_mode_t screen_mode;
   int size[2];
   int angle = std::atoi(std::getenv("ORIENTATION"));

   screen_create_window(&mDisplay.qnx_screen_win, mDisplay.qnx_screen_context);
   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_FORMAT, &screen_format);
   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_USAGE, &usage);
   screen_get_window_property_pv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&mDisplay.qnx_screen_disp);
   screen_get_display_property_iv(mDisplay.qnx_screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
   screen_get_display_property_pv(mDisplay.qnx_screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
   screen_get_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);

   int buffer_size[2] = {size[0], size[1]};

   if ((angle == 0) || (angle == 180)) {
       if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
           ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
               buffer_size[1] = size[0];
               buffer_size[0] = size[1];
       }
   } else if ((angle == 90) || (angle == 270)){
       if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
           ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
               buffer_size[1] = size[0];
               buffer_size[0] = size[1];
       }
   } else {
        return true;
   }

   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
   screen_set_window_property_iv(mDisplay.qnx_screen_win, SCREEN_PROPERTY_ROTATION, &angle);
   screen_create_window_buffers(mDisplay.qnx_screen_win, 2);

   surface = EGL_CHECK(eglCreateWindowSurface(display, config[0], (EGLNativeWindowType)mDisplay.qnx_screen_win, NULL));
#endif

   if(surface == EGL_NO_SURFACE) {
      Log::Error("EGLInitialise", "EGL Surface creation failed.");
      return true;
   }

   const EGLint attribs2[] =
   {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
   };
   context = eglCreateContext(display, config[0], NULL, attribs2);

   if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
      Log::Error("EGLInitialise", "Unable to eglMakeCurrent");
      return true;
   }

#ifdef __QNX__
   eglSwapInterval(display, 1);
#endif

   eglQuerySurface(display, surface, EGL_WIDTH, &w);
   eglQuerySurface(display, surface, EGL_HEIGHT, &h);

   mDisplay.Display = display;
   mDisplay.Context = context;
   mDisplay.Surface = surface;
   mDisplay.Width = w;
   mDisplay.Height = h;
   mTP->camera->SetResolution(Vector2f((float)mDisplay.Width, (float)mDisplay.Height));

   // Initialize GL state.
   GL_CHECK(glViewport(0, 0, w, h));
   GL_CHECK(glEnable(GL_DEPTH_TEST));
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   GL_CHECK(glEnable(GL_BLEND));
   GL_CHECK(glEnable(GL_ALPHA));


   Effect::CacheTick(*mTP, EffectClearLevel::Initialise);
   Texture::CacheTick(*mTP, TextureClearLevel::Initialise);
   Font::CacheTick(*mTP, FontClearLevel::Initialise);
   //Initialise graphics
   for(std::vector<GameObject*>::iterator it = mGO.begin(); it != mGO.end(); ++it)
   {
      (*it)->InitialiseGraphics(*mTP);
   }

   return false;
}
int OpenGLView::initGL()
{
    int numberDisplays;
    int numberModes;
    int returnCode;
    EGLBoolean status;
    int type;
    EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
    EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                            EGL_GREEN_SIZE,      8,
                            EGL_BLUE_SIZE,       8,
                            EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
                            EGL_NONE};

    // try this first as it will fail if an HDMI display is not attached
    if (m_api == GL_ES_2) {
        m_egl_ctx = eglCreateContext(m_egl_disp, m_egl_conf, EGL_NO_CONTEXT, attributes);
    } else {
        m_egl_ctx = eglCreateContext(m_egl_disp, m_egl_conf, EGL_NO_CONTEXT, NULL);
    }
    if (m_egl_ctx == EGL_NO_CONTEXT) {
        perror("eglCreateContext");
        return EXIT_FAILURE;
    }

	screen_get_context_property_iv(m_screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &numberDisplays);

	m_screen_dpy = (screen_display_t *)calloc(numberDisplays, sizeof(screen_display_t));
	screen_get_context_property_pv(m_screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)m_screen_dpy);


	for (int index = 0; index < numberDisplays; index++) {
		int displayID;

        returnCode = screen_get_display_property_iv(m_screen_dpy[index], SCREEN_PROPERTY_ID,  (int *)&displayID);
    	if (returnCode) {
    		perror("display ID");
    		return EXIT_FAILURE;
    	} else {
			if (displayID == m_display) {
			    screen_get_display_property_iv(m_screen_dpy[index], SCREEN_PROPERTY_TYPE,  &type);
			    if (type == SCREEN_DISPLAY_TYPE_HDMI) {
			    	returnCode = screen_create_window(&m_screen_win, m_screen_ctx);
			    	if (returnCode) {
			            perror("screen_create_window");
			            return EXIT_FAILURE;
			        }
			    } else {
			    	returnCode = screen_create_window_type(&m_screen_win, m_screen_ctx, SCREEN_CHILD_WINDOW);
			    	if (returnCode) {
			            perror("screen_create_window (child window)");
			            return EXIT_FAILURE;
			        }
			    }
			    if (type == SCREEN_DISPLAY_TYPE_HDMI) {
					returnCode = screen_set_window_property_pv(m_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&(m_screen_dpy[index]));
					if (returnCode) {
						perror("window display");
						return EXIT_FAILURE;
					}
		        }
			}
        }
	}

	qDebug()  << "OpenGLView::initialize: "<< m_screen_ctx << ":" << m_egl_disp << ":" << m_egl_conf << ":" << m_egl_ctx << ":" << m_screen_win;


	int format = SCREEN_FORMAT_RGBA8888;
	returnCode = screen_set_window_property_iv(m_screen_win, SCREEN_PROPERTY_FORMAT, &format);
	if (returnCode) {
		perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
		return EXIT_FAILURE;
	}

	if (m_transparency > 0) {
		returnCode = setWindowTransparency(m_transparency);
		if (returnCode) {
			perror("transparency");
			return EXIT_FAILURE;
		}
	}

	returnCode = screen_get_window_property_pv(m_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_disp);
	if (returnCode) {
		perror("screen_get_window_property_pv");
		return EXIT_FAILURE;
	}

	int angle = atoi(getenv("ORIENTATION"));

	screen_get_display_property_iv(m_screen_disp, SCREEN_PROPERTY_MODE_COUNT, &numberModes);

	m_screen_modes = (screen_display_mode_t *)calloc(numberModes, sizeof(screen_display_mode_t));
	returnCode = screen_get_display_property_pv(m_screen_disp, SCREEN_PROPERTY_MODE, (void**)m_screen_modes);
	if (returnCode) {
		perror("screen modes");
		return EXIT_FAILURE;
	}

    int dpi = calculateDPI();
    if (dpi == EXIT_FAILURE) {
        fprintf(stderr, "Unable to calculate dpi\n");
        return EXIT_FAILURE;
    }

	returnCode = setWindowPosition(m_x, m_y);
	if (returnCode) {
		perror("window position");
		return EXIT_FAILURE;
	}

	returnCode = setWindowSize(m_width, m_height);
	if (returnCode) {
		perror("window size");
		return EXIT_FAILURE;
	}

	returnCode = setWindowZ(m_z);
	if (returnCode) {
		perror("z order");
		return EXIT_FAILURE;
	}

	returnCode = setWindowBufferSize(m_width, m_height);
	if (returnCode) {
		perror("buffer size");
		return EXIT_FAILURE;
	}

	returnCode = setWindowAngle(m_angle);
	if (returnCode) {
		perror("angle");
		return EXIT_FAILURE;
	}

	returnCode = screen_create_window_buffers(m_screen_win, m_nbuffers);
	if (returnCode) {
		perror("screen_create_window_buffers");
		return EXIT_FAILURE;
	}


    if (m_api == GL_ES_1) {
        m_usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION;
    } else if (m_api == GL_ES_2) {
    	attrib_list[9] = EGL_OPENGL_ES2_BIT;
    	m_usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
    } else if (m_api == VG) {
    	attrib_list[9] = EGL_OPENVG_BIT;
    	m_usage = SCREEN_USAGE_OPENVG | SCREEN_USAGE_ROTATION;
    } else {
        fprintf(stderr, "invalid api setting\n");
        return EXIT_FAILURE;
    }

	returnCode = setWindowUsage(m_usage);
	if (returnCode) {
		perror("screen_set_window_property_iv(window usage)");
		return EXIT_FAILURE;
	}

	qDebug()  << "OpenGLView::initGL:eglCreateContext "<< m_egl_ctx;
	m_egl_surf = eglCreateWindowSurface(m_egl_disp, m_egl_conf, m_screen_win, NULL);
	if (m_egl_surf == EGL_NO_SURFACE) {
		OpenGLThread::eglPrintError("eglCreateWindowSurface");
		return EXIT_FAILURE;
	}

	getGLContext();

    EGLint interval = 1;
    status = eglSwapInterval(m_egl_disp, interval);
	if (status != EGL_TRUE) {
		OpenGLThread::eglPrintError("eglSwapInterval");
		return EXIT_FAILURE;
	}

    status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_WIDTH, &m_surface_width);
	if (status != EGL_TRUE) {
		perror("query surface width");
		return EXIT_FAILURE;
	}

    status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_HEIGHT, &m_surface_height);
	if (status != EGL_TRUE) {
		perror("query surface height");
		return EXIT_FAILURE;
	}

	returnCode = joinWindowGroup(m_group);
	if (returnCode) {
		perror("window group");
		return EXIT_FAILURE;
	}

	returnCode = setScreenWindowID(m_id);
	if (returnCode) {
		perror("window ID");
		return EXIT_FAILURE;
	}

	qDebug()  << "OpenGLView::initGL: "<< angle << ":" << numberModes << ":" << m_screen_modes[0].width << ":" << m_screen_modes[0].height << ":" << m_egl_disp << ":" << dpi;

	setInitialized(true);

	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
int
bbutil_init_egl(screen_context_t ctx, enum RENDERING_API api) {
    int usage;
    int format = SCREEN_FORMAT_RGBX8888;
    EGLint interval = 1;
    int rc, num_configs;
    EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

    EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                            EGL_GREEN_SIZE,      8,
                            EGL_BLUE_SIZE,       8,
                            EGL_BLUE_SIZE,       8,
                            EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
                            EGL_NONE};

    if (api == GL_ES_1) {
        usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION;
    } else if (api == GL_ES_2) {
    	attrib_list[11] = EGL_OPENGL_ES2_BIT;
        usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
    } else if (api == VG) {
    	attrib_list[11] = EGL_OPENVG_BIT;
        usage = SCREEN_USAGE_OPENVG | SCREEN_USAGE_ROTATION;
    } else {
        fprintf(stderr, "invalid api setting\n");
        return EXIT_FAILURE;
    }

    //Simple egl initialization
    screen_ctx = ctx;

    egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (egl_disp == EGL_NO_DISPLAY) {
        bbutil_egl_perror("eglGetDisplay");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglInitialize(egl_disp, NULL, NULL);
    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglInitialize");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    if ((api == GL_ES_1) || (api == GL_ES_2)) {
        rc = eglBindAPI(EGL_OPENGL_ES_API);
    } else if (api == VG) {
        rc = eglBindAPI(EGL_OPENVG_API);
    }

    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglBindApi");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    if(!eglChooseConfig(egl_disp, attrib_list, &egl_conf, 1, &num_configs)) {
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    if (api == GL_ES_2) {
        egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, attributes);
    } else {
        egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, NULL);
    }

    if (egl_ctx == EGL_NO_CONTEXT) {
        bbutil_egl_perror("eglCreateContext");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_create_window(&screen_win, screen_ctx);
    if (rc) {
        perror("screen_create_window");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format);
    if (rc) {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
    if (rc) {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp);
    if (rc) {
        perror("screen_get_window_property_pv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    int angle = atoi(getenv("ORIENTATION"));

	screen_display_mode_t screen_mode;
	rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
	if (rc) {
		perror("screen_get_display_property_pv");
		bbutil_terminate();
		return EXIT_FAILURE;
	}

	int size[2];
	rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
	if (rc) {
		perror("screen_get_window_property_iv");
		bbutil_terminate();
		return EXIT_FAILURE;
	}

	int buffer_size[2] = {size[0], size[1]};

	if ((angle == 0) || (angle == 180)) {
		if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
			((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
				buffer_size[1] = size[0];
				buffer_size[0] = size[1];
		}
	} else if ((angle == 90) || (angle == 270)){
		if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
			((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
				buffer_size[1] = size[0];
				buffer_size[0] = size[1];
		}
	} else {
		 fprintf(stderr, "Navigator returned an unexpected orientation angle.\n");
		 bbutil_terminate();
		 return EXIT_FAILURE;
	}

	rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
    if (rc) {
        perror("screen_set_window_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);
    if (rc) {
        perror("screen_set_window_property_iv");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = screen_create_window_buffers(screen_win, nbuffers);
    if (rc) {
        perror("screen_create_window_buffers");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, NULL);
    if (egl_surf == EGL_NO_SURFACE) {
        bbutil_egl_perror("eglCreateWindowSurface");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx);
    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglMakeCurrent");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    rc = eglSwapInterval(egl_disp, interval);
    if (rc != EGL_TRUE) {
        bbutil_egl_perror("eglSwapInterval");
        bbutil_terminate();
        return EXIT_FAILURE;
    }

    initialized = 1;

    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
// Video
int init_GLES2(screen_context_t ctx) {
	int usage = SCREEN_USAGE_ROTATION | SCREEN_USAGE_OPENGL_ES2;
	int format = SCREEN_FORMAT_RGBX8888;
	int num_configs;

	EGLint attrib_list[]= {
				EGL_RED_SIZE,        8,
				EGL_GREEN_SIZE,      8,
				EGL_BLUE_SIZE,       8,
				EGL_DEPTH_SIZE,	     24,
				EGL_STENCIL_SIZE,    8,
				EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
				EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
				EGL_NONE};

	const EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
	const EGLint egl_surfaceAttr[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };

	screen_ctx = ctx;
	screen_create_window(&screen_win, screen_ctx);
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format);
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
	screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp);

	// This must be landscape.
	int screen_resolution[2];
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
	int angle = atoi(getenv("ORIENTATION"));
	pixel_xres = screen_resolution[0]; pixel_yres = screen_resolution[1];

	screen_display_mode_t screen_mode;
	screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);

	int size[2];
	screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);

	int buffer_size[2] = {size[0], size[1]};

	if ((angle == 0) || (angle == 180)) {
		if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
		((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
			buffer_size[1] = size[0];
			buffer_size[0] = size[1];
			pixel_yres = screen_resolution[0];
			pixel_xres = screen_resolution[1];
		}
	} else if ((angle == 90) || (angle == 270)){
		if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
		((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
			buffer_size[1] = size[0];
			buffer_size[0] = size[1];
			pixel_yres = screen_resolution[0];
			pixel_xres = screen_resolution[1];
		}
	}
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
	screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);

	screen_create_window_buffers(screen_win, 2); // Double buffered
	egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	eglInitialize(egl_disp, NULL, NULL);

	eglChooseConfig(egl_disp, attrib_list, &egl_conf, 1, &num_configs);
	egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, attributes);

	egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, egl_surfaceAttr);

	eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx);
	eglSwapInterval(egl_disp, 1);

	return 0;
}
bool CIrrDeviceBB10::createWindow()
{
	if ( Close )
		return false;

	int rc = screen_create_window(&bspScreenWindow, bspScreenCtx);
	if(rc)
	{
		os::Printer::log("Screen create window failed!");
		return false;
	}

	if(video::EDT_OGLES1 != CreationParams.DriverType && video::EDT_OGLES2 !=CreationParams.DriverType)
		return false;

	bspformat = SCREEN_FORMAT_RGBX8888;
	if(CreationParams.Bits==16)
		bspformat = SCREEN_FORMAT_RGBX4444;

	bspUsage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION;
	if(video::EDT_OGLES2 ==CreationParams.DriverType)
		bspUsage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;

	//window properties
	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_FORMAT, &bspformat);

	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_USAGE, &bspUsage);

	screen_display_t screenDisplay;
	rc = screen_get_window_property_pv(bspScreenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screenDisplay);

	int screenResolution[2];
	rc = screen_get_display_property_iv(screenDisplay, SCREEN_PROPERTY_SIZE, screenResolution);

	int angle = atoi(getenv("ORIENTATION"));

	screen_display_mode_t screenDisplayMode;
	rc = screen_get_display_property_pv(screenDisplay, SCREEN_PROPERTY_MODE, (void**)&screenDisplayMode);

	int bufferSize[2];
	rc = screen_get_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_BUFFER_SIZE, bufferSize);

	int newBufferSize[2] = {bufferSize[0], bufferSize[1]};
	if ((angle == 0) || (angle == 180)) 
	{
		if (((screenDisplayMode.width > screenDisplayMode.height) && (bufferSize[0] < bufferSize[1])) 
			|| ((screenDisplayMode.width < screenDisplayMode.height) && (bufferSize[0] > bufferSize[1])))
		{
			newBufferSize[1] = bufferSize[0];
			newBufferSize[0] = bufferSize[1];
		}
	}
	else if ((angle == 90) || (angle == 270))
	{
		if (((screenDisplayMode.width > screenDisplayMode.height) && (bufferSize[0] > bufferSize[1]))
			|| ((screenDisplayMode.width < screenDisplayMode.height && bufferSize[0] < bufferSize[1]))) 
		{
			newBufferSize[1] = bufferSize[0];
			newBufferSize[0] = bufferSize[1];
		}
	} 
	else
	{
		os::Printer::log("Navigator returned an unexpected orientation angle.\n");
		return false;
	}

	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_BUFFER_SIZE, newBufferSize);

	rc = screen_set_window_property_iv(bspScreenWindow, SCREEN_PROPERTY_ROTATION, &angle);

	rc = screen_create_window_buffers(bspScreenWindow, 2);
	return true;
}
Ejemplo n.º 7
0
bool CCEGLView::initGL()
{
    int rc = 0;
    int screenFormat = SCREEN_FORMAT_RGBA8888;
#ifdef __X86__
    int screenUsage = SCREEN_USAGE_OPENGL_ES2;
#else
    int screenUsage = SCREEN_USAGE_DISPLAY|SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display
#endif
//    int screenSwapInterval = WINDOW_VSYNC ? 1 : 0;
    int screenTransparency = SCREEN_TRANSPARENCY_NONE;
    int angle = atoi(getenv("ORIENTATION"));

    // Hard-coded to (0,0).
    int windowPosition[] =
    {
        0, 0
    };

    EGLint eglConfigCount;
    EGLConfig config;

    // Hard-coded to 32-bit/OpenGL ES 2.0.
    const EGLint eglConfigAttrs[] =
    {
        EGL_RED_SIZE,           8,
        EGL_GREEN_SIZE,         8,
        EGL_BLUE_SIZE,          8,
        EGL_ALPHA_SIZE,         8,
        EGL_DEPTH_SIZE,         24,
        EGL_STENCIL_SIZE,       8,
        EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
        EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
        EGL_NONE
    };

    const EGLint eglContextAttrs[] =
    {
        EGL_CONTEXT_CLIENT_VERSION,    2,
        EGL_NONE
    };

    const EGLint eglSurfaceAttrs[] =
    {
        EGL_RENDER_BUFFER,    EGL_BACK_BUFFER,
        EGL_NONE
    };

    // Create the screen context.
    rc = screen_create_context(&m_screenContext, 0);
    if (rc)
    {
        perror("screen_create_context");
        return false;
    }

    // Create the screen window.
    rc = screen_create_window(&m_screenWindow, m_screenContext);
    if (rc)
    {
        perror("screen_create_window");
        return false;
    }

    // Set/get any window prooperties.
    rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_FORMAT, &screenFormat);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
        return false;
    }

    rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_USAGE, &screenUsage);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)");
        return false;
    }


	char *width_str = getenv("WIDTH");
	char *height_str = getenv("HEIGHT");

	if (width_str && height_str)
	{
		int screen_res[2];
		screen_res[0] = atoi(width_str);
		screen_res[1] = atoi(height_str);

		int rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, screen_res);
		if (rc)
		{
			fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
			return false;
		}
	}
	else
	{

	    screen_display_t screen_display;
	    rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display);
	    if (rc)
	    {
	        perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)");
	        return false;
	    }

	    screen_display_mode_t screen_mode;
	    rc = screen_get_display_property_pv(screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
	    if (rc)
	    {
	        perror("screen_get_display_property_pv(SCREEN_PROPERTY_MODE)");
	        return false;
	    }

	    int size[2];
	    rc = screen_get_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, size);
	    if (rc)
	    {
	        perror("screen_get_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
	        return false;
	    }

	    int buffer_size[2] = { size[0], size[1] };

		if ((angle == 0) || (angle == 180))
		{
			if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
				((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
			{
				buffer_size[1] = size[0];
				buffer_size[0] = size[1];
			}
		}
		else if ((angle == 90) || (angle == 270))
		{
			if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
				((screen_mode.width < screen_mode.height) && (size[0] < size[1])))
			{
				buffer_size[1] = size[0];
				buffer_size[0] = size[1];
			}
		}
		else
		{
			perror("Navigator returned an unexpected orientation angle.");
			return false;
		}

	    rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_ROTATION, &angle);
	    if (rc)
	    {
	        perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)");
	        return false;
	    }

	    rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
	    if (rc)
	    {
	        perror("screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
	        return false;
	    }
	}

    if (windowPosition[0] != 0 || windowPosition[1] != 0)
    {
        rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_POSITION, windowPosition);
        if (rc)
        {
            perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)");
            return false;
        }
    }

    rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_TRANSPARENCY, &screenTransparency);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY)");
        return false;
    }

    // Double buffered.
    rc = screen_create_window_buffers(m_screenWindow, 2);
    if (rc)
    {
        perror("screen_create_window_buffers");
        return false;
    }

    // Create screen event object.
    rc = screen_create_event(&m_screenEvent);
    if (rc)
    {
        perror("screen_create_event");
        return false;
    }

    // Request screen events.
    screen_request_events(m_screenContext);

    // Get the EGL display and initialize.
    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (m_eglDisplay == EGL_NO_DISPLAY)
    {
        perror("eglGetDisplay");
        return false;
    }
    if (eglInitialize(m_eglDisplay, NULL, NULL) != EGL_TRUE)
    {
        perror("eglInitialize");
        return false;
    }

    if (eglChooseConfig(m_eglDisplay, eglConfigAttrs, &config, 1, &eglConfigCount) != EGL_TRUE || eglConfigCount == 0)
    {
        checkErrorEGL("eglChooseConfig");
        return false;
    }

    m_eglContext = eglCreateContext(m_eglDisplay, config, EGL_NO_CONTEXT, eglContextAttrs);
    if (m_eglContext == EGL_NO_CONTEXT)
    {
        checkErrorEGL("eglCreateContext");
        return false;
    }

    m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_screenWindow, eglSurfaceAttrs);
    if (m_eglSurface == EGL_NO_SURFACE)
    {
        checkErrorEGL("eglCreateWindowSurface");
        return false;
    }

    if (eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext) != EGL_TRUE)
    {
        checkErrorEGL("eglMakeCurrent");
        return false;
    }

    EGLint width, height;

    if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE) )
    	return EXIT_FAILURE;

	eglQuerySurface(m_eglDisplay, m_eglSurface, EGL_WIDTH, &width);
    eglQuerySurface(m_eglDisplay, m_eglSurface, EGL_HEIGHT, &height);

    m_obScreenSize.width = width;
    m_obScreenSize.height = height;

    // Set vsync.
//    eglSwapInterval(m_eglDisplay, screenSwapInterval);

    return true;
}
Ejemplo n.º 8
0
int
setup_screen()
{
    if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) {
        return EXIT_FAILURE;
    }

    //Signal BPS library that navigator orientation is to be locked
    if (BPS_SUCCESS != navigator_rotation_lock(true)) {
        screen_destroy_context(screen_ctx);
        return EXIT_FAILURE;
    }

    if (screen_create_window(&screen_win, screen_ctx) != 0) {
        screen_destroy_context(screen_ctx);
        return EXIT_FAILURE;
    }

    if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail;

    int usage = SCREEN_USAGE_NATIVE;
    if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail;

    int size[2];
    if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0) goto fail;

    screen_display_t screen_disp;
    screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp);

    screen_display_mode_t screen_mode;
    if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode) != 0) goto fail;

    int buffer_size[2] = {size[0], size[1]};

    int angle = atoi(getenv("ORIENTATION"));
    if ((angle == 0) || (angle == 180)) {
       if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
          ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) {
            buffer_size[1] = size[0];
        buffer_size[0] = size[1];
       }
    } else if ((angle == 90) || (angle == 270)){
       if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
          ((screen_mode.width < screen_mode.height && size[0] < size[1]))) {
        buffer_size[1] = size[0];
        buffer_size[0] = size[1];
        }
    } else {
        goto fail;
    }

    if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail;

    if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle) != 0) goto fail;

    if (screen_create_window_buffers(screen_win, 1) != 0) goto fail;

    screen_buffer_t buff;
    if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail;

    int attribs[1] = {SCREEN_BLIT_END};
    if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail;

    int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]};
    if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail;

    return EXIT_SUCCESS;

fail:
    perror(NULL);
    cleanup_screen();
    return EXIT_FAILURE;
}
Ejemplo n.º 9
0
Platform* Platform::create(Game* game, void* attachToWindow)
{
    FileSystem::setResourcePath("./app/native/");
    Platform* platform = new Platform(game);

    // Query game config
    int samples = 0;
    Properties* config = Game::getInstance()->getConfig()->getNamespace("window", true);
    if (config)
    {
        samples = std::max(config->getInt("samples"), 0);
    }

    __gestureSet = gestures_set_alloc();
    swipe_gesture_alloc(NULL, gesture_callback, __gestureSet);
    pinch_gesture_alloc(NULL, gesture_callback, __gestureSet);
    tap_gesture_alloc(NULL, gesture_callback, __gestureSet);

    bps_initialize();

    // Initialize navigator and orientation
    static const int SENSOR_RATE = 25000;
    sensor_set_rate(SENSOR_TYPE_AZIMUTH_PITCH_ROLL, SENSOR_RATE);
    sensor_set_skip_duplicates(SENSOR_TYPE_AZIMUTH_PITCH_ROLL, true);
    sensor_request_events(SENSOR_TYPE_AZIMUTH_PITCH_ROLL);
    navigator_request_events(0);
    navigator_rotation_lock(true);
    __orientationAngle = atoi(getenv("ORIENTATION"));

    int rc = 0;
    int screenFormat = SCREEN_FORMAT_RGBA8888;
#ifdef __X86__
    int screenUsage = SCREEN_USAGE_OPENGL_ES2;
#else
    int screenUsage = SCREEN_USAGE_DISPLAY|SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display
#endif
    int screenSwapInterval = WINDOW_VSYNC ? 1 : 0;
    int screenTransparency = SCREEN_TRANSPARENCY_NONE;

    char *width_str = getenv("WIDTH");
    char *height_str = getenv("HEIGHT");

    // Hard-coded to (0,0).
    int windowPosition[] =
    {
        0, 0
    };

    EGLint eglConfigCount;

    // Hard-coded to 32-bit/OpenGL ES 2.0.
    // NOTE: EGL_SAMPLE_BUFFERS and EGL_SAMPLES MUST remain at the beginning of the attribute list
    // since they are expected to be at indices 0-3 in config fallback code later.
    EGLint eglConfigAttrs[] =
    {
        EGL_SAMPLE_BUFFERS,     samples > 0 ? 1 : 0,
        EGL_SAMPLES,            samples,
        EGL_RED_SIZE,           8,
        EGL_GREEN_SIZE,         8,
        EGL_BLUE_SIZE,          8,
        EGL_ALPHA_SIZE,         8,
        EGL_DEPTH_SIZE,         24,
        EGL_STENCIL_SIZE,       8,
        EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
        EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
        EGL_NONE
    };

    const EGLint eglContextAttrs[] =
    {
        EGL_CONTEXT_CLIENT_VERSION,    2,
        EGL_NONE
    };

    const EGLint eglSurfaceAttrs[] =
    {
        EGL_RENDER_BUFFER,    EGL_BACK_BUFFER,
        EGL_NONE
    };

    // Create the screen context.
    rc = screen_create_context(&__screenContext, 0);
    if (rc)
    {
        perror("screen_create_context");
        goto error;
    }

    // Create the screen window.
    rc = screen_create_window(&__screenWindow, __screenContext);
    if (rc)
    {
        perror("screen_create_window");
        goto error;
    }

    // Set/get any window properties.
    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_FORMAT, &screenFormat);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
        goto error;
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_USAGE, &screenUsage);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)");
        goto error;
    }

    if (width_str && height_str)
    {
        __screenWindowSize[0] = atoi(width_str);
        __screenWindowSize[1] = atoi(height_str);
    }
    else
    {
        screen_display_t screen_display;
        rc = screen_get_window_property_pv(__screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display);
        if (rc)
        {
            perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)");
            goto error;
        }

        screen_display_mode_t screen_mode;
        rc = screen_get_display_property_pv(screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
        if (rc)
        {
            perror("screen_get_display_property_pv(SCREEN_PROPERTY_MODE)");
            goto error;
        }

        int size[2];
        rc = screen_get_window_property_iv(__screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, size);
        if (rc)
        {
            perror("screen_get_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
            goto error;
        }

        __screenWindowSize[0] = size[0];
        __screenWindowSize[1] = size[1];

        if ((__orientationAngle == 0) || (__orientationAngle == 180))
        {
            if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
                ((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
            {
                __screenWindowSize[1] = size[0];
                __screenWindowSize[0] = size[1];
            }
        }
        else if ((__orientationAngle == 90) || (__orientationAngle == 270))
        {
            if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
                ((screen_mode.width < screen_mode.height) && (size[0] < size[1])))
            {
                __screenWindowSize[1] = size[0];
                __screenWindowSize[0] = size[1];
            }
        }
        else
        {
            perror("Navigator returned an unexpected orientation angle.");
            goto error;
        }


        rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_ROTATION, &__orientationAngle);
        if (rc)
        {
            perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)");
            goto error;
        }
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, __screenWindowSize);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
        goto error;
    }

    if (windowPosition[0] != 0 || windowPosition[1] != 0)
    {
        rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_POSITION, windowPosition);
        if (rc)
        {
            perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)");
            goto error;
        }
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_TRANSPARENCY, &screenTransparency);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY)");
        goto error;
    }

    // Double buffered.
    rc = screen_create_window_buffers(__screenWindow, 2);
    if (rc)
    {
        perror("screen_create_window_buffers");
        goto error;
    }

    // Create screen event object.
    rc = screen_create_event(&__screenEvent);
    if (rc)
    {
        perror("screen_create_event");
        goto error;
    }

    // Request screen events.
    screen_request_events(__screenContext);

    // Get the EGL display and initialize.
    __eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (__eglDisplay == EGL_NO_DISPLAY)
    {
        perror("eglGetDisplay");
        goto error;
    }
    if (eglInitialize(__eglDisplay, NULL, NULL) != EGL_TRUE)
    {
        perror("eglInitialize");
        goto error;
    }

    if (eglChooseConfig(__eglDisplay, eglConfigAttrs, &__eglConfig, 1, &eglConfigCount) != EGL_TRUE || eglConfigCount == 0)
    {
    	bool success = false;
    	while (samples)
    	{
    		// Try lowering the MSAA sample count until we find a supported config
    		GP_WARN("Failed to find a valid EGL configuration with EGL samples=%d. Trying samples=%d instead.", samples, samples/2);
    		samples /= 2;
    		eglConfigAttrs[1] = samples > 0 ? 1 : 0;
    		eglConfigAttrs[3] = samples;
    		if (eglChooseConfig(__eglDisplay, eglConfigAttrs, &__eglConfig, 1, &eglConfigCount) == EGL_TRUE && eglConfigCount > 0)
    		{
    			success = true;
    			break;
    		}
    	}

    	if (!success)
    	{
			checkErrorEGL("eglChooseConfig");
			goto error;
    	}
    }

    __eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextAttrs);
    if (__eglContext == EGL_NO_CONTEXT)
    {
        checkErrorEGL("eglCreateContext");
        goto error;
    }

    __eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, __screenWindow, eglSurfaceAttrs);
    if (__eglSurface == EGL_NO_SURFACE)
    {
        checkErrorEGL("eglCreateWindowSurface");
        goto error;
    }

    if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) != EGL_TRUE)
    {
        checkErrorEGL("eglMakeCurrent");
        goto error;
    }

    // Set vsync.
    eglSwapInterval(__eglDisplay, screenSwapInterval);

    // Initialize OpenGL ES extensions.
    __glExtensions = (const char*)glGetString(GL_EXTENSIONS);

    if (strstr(__glExtensions, "GL_OES_vertex_array_object") || strstr(__glExtensions, "GL_ARB_vertex_array_object"))
    {
        glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
        glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
        glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
        glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES");
    }

    return platform;

error:

    // TODO: cleanup

    return NULL;
}
Ejemplo n.º 10
0
int NativeWindow::initialize(bool _createFullWindow)
{
    int returnCode;
    int numberModes;
	screen_display_mode_t* screenModes;
    int type;

    if (_createFullWindow) {
    	returnCode = screen_create_window(&_screenWindow, _screenContext);
    	qDebug()  << "NativeWindow::initialize: _screenWindow (full window): " << ":" << _screenWindow << ":" << _screenContext << ":" << returnCode;

    	if (returnCode) {
            perror("screen_create_window");
            return EXIT_FAILURE;
        }

    } else {
    	returnCode = screen_create_window_type(&_screenWindow, _screenContext, SCREEN_CHILD_WINDOW);
    	qDebug()  << "NativeWindow::initialize: _screenWindow (child window): " << _screenWindow << ":" << returnCode;

    	if (returnCode) {
            perror("screen_create_window (child window)");
            return EXIT_FAILURE;
        }

    }

    _displaysMutex.lock();

    if (_screenDisplays) {
    	free (_screenDisplays);
    }

	// try this first as it will fail if an HDMI display is not attached
	screen_get_context_property_iv(_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &_numberDisplays);

	_screenDisplays = (screen_display_t *)calloc(_numberDisplays, sizeof(screen_display_t));
	screen_get_context_property_pv(_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)_screenDisplays);

	for (int index = 0; index < _numberDisplays; index++) {
		int displayID;

        returnCode = screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_ID,  (int *)&displayID);
    	qDebug()  << "NativeWindow::initialize: display: " << ":" << index << ":" << displayID << ":" << _display << ":" << _screenDisplays[index];

    	if (returnCode) {
    		perror("display ID");
    		return EXIT_FAILURE;
    	} else {
			if (displayID == _display) {
			    screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_TYPE,  &type);
			    if (type == SCREEN_DISPLAY_TYPE_HDMI) {
					returnCode = screen_set_window_property_pv(_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&(_screenDisplays[index]));

					if (returnCode) {
						perror("window display");
						return EXIT_FAILURE;
					}
		        }
			}
        }
	}

    _displaysMutex.unlock();


	qDebug()  << "NativeWindow::initialize: "<< _screenContext << ":" << _screenWindow;


    returnCode = setWindowFormat(_format);
	if (returnCode) {
		perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
		return EXIT_FAILURE;
	}

	returnCode = setWindowTransparency(_transparency);
	if (returnCode) {
		perror("transparency");
		return EXIT_FAILURE;
	}

	returnCode = screen_get_window_property_pv(_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&_screenDisplay);
	if (returnCode) {
		perror("screenDisplay");
		return EXIT_FAILURE;
	}

	int angle = atoi(getenv("ORIENTATION"));

	screen_get_display_property_iv(_screenDisplay, SCREEN_PROPERTY_MODE_COUNT, &numberModes);

	screenModes = (screen_display_mode_t *)calloc(numberModes, sizeof(screen_display_mode_t));
	returnCode = screen_get_display_property_pv(_screenDisplay, SCREEN_PROPERTY_MODE, (void**)screenModes);
	if (returnCode) {
		perror("screen modes");
		return EXIT_FAILURE;
	}

    int dpi = calculateDPI();
    if (dpi == EXIT_FAILURE) {
        fprintf(stderr, "Unable to calculate dpi\n");
        return EXIT_FAILURE;
    }

	returnCode = setWindowPosition(_x, _y);
	if (returnCode) {
		perror("window position");
		return EXIT_FAILURE;
	}

	returnCode = setWindowSize(_width, _height);
	if (returnCode) {
		perror("window size");
		return EXIT_FAILURE;
	}

	returnCode = setWindowZ(_z);
	if (returnCode) {
		perror("z order");
		return EXIT_FAILURE;
	}

	if (_sourceWidth > 0) {
        returnCode = setWindowSourcePosition(_sourceX, _sourceY);
        if (returnCode) {
            perror("source size");
            return EXIT_FAILURE;
        }

        returnCode = setWindowSourceSize(_sourceWidth, _sourceHeight);
        if (returnCode) {
            perror("source size");
            return EXIT_FAILURE;
        }
	}

    if (_bufferWidth > 0) {
        returnCode = setWindowBufferSize(_bufferWidth, _bufferHeight);
        if (returnCode) {
            perror("buffer size");
            return EXIT_FAILURE;
        }
    }

	returnCode = setWindowAngle(_angle);
	if (returnCode) {
		perror("angle");
		return EXIT_FAILURE;
	}

	returnCode = screen_create_window_buffers(_screenWindow, _nbuffers);
	if (returnCode) {
		perror("screen_create_window_buffers");
		return EXIT_FAILURE;
	}

	_usage = Graphics::getNativeWindowUsage();
    // enable this in case we need any native API access to this window
    _usage |= SCREEN_USAGE_NATIVE;

	returnCode = setWindowUsage(_usage);
	if (returnCode) {
		perror("screen_set_window_property_iv(window usage)");
		return EXIT_FAILURE;
	}

	returnCode = joinWindowGroup(_group);
	if (returnCode) {
		perror("window group");
		return EXIT_FAILURE;
	}

	returnCode = setScreenWindowID(_id);
	if (returnCode) {
		perror("window ID");
		return EXIT_FAILURE;
	}

	qDebug()  << "NativeWindow::initialize: "<< angle << ":" << numberModes << ":" << screenModes[0].width << ":" << screenModes[0].height << ":" << dpi;

	if (screenModes != NULL) {
		free(screenModes);
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
Platform* Platform::create(Game* game)
{
    FileSystem::setResourcePath("./app/native/");

    Platform* platform = new Platform(game);

    bps_initialize();
    accelerometer_set_update_frequency(FREQ_40_HZ);
    navigator_request_events(0);
    navigator_rotation_lock(true);

    // Determine initial orientation angle.
    orientation_direction_t direction;
    orientation_get(&direction, &__orientationAngle);

    int rc = 0;
    int screenFormat = SCREEN_FORMAT_RGBA8888;
    int screenUsage = SCREEN_USAGE_DISPLAY|SCREEN_USAGE_OPENGL_ES2;
    int screenSwapInterval = WINDOW_VSYNC ? 1 : 0;
    int screenTransparency = SCREEN_TRANSPARENCY_NONE;
    int angle = atoi(getenv("ORIENTATION"));

    // Hard-coded to (0,0).
    int windowPosition[] =
    {
        0, 0
    };

    EGLint eglConfigCount;

    // Hard-coded to 32-bit/OpenGL ES 2.0.
    const EGLint eglConfigAttrs[] =
    {
        EGL_RED_SIZE,           8,
        EGL_GREEN_SIZE,         8,
        EGL_BLUE_SIZE,          8,
        EGL_ALPHA_SIZE,         8,
        EGL_DEPTH_SIZE,         24,
        EGL_STENCIL_SIZE,       8,
        EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
        EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
        EGL_NONE
    };

    const EGLint eglContextAttrs[] =
    {
        EGL_CONTEXT_CLIENT_VERSION,    2,
        EGL_NONE
    };

    const EGLint eglSurfaceAttrs[] =
    {
        EGL_RENDER_BUFFER,    EGL_BACK_BUFFER,
        EGL_NONE
    };

    // Create the screen context.
    rc = screen_create_context(&__screenContext, 0);
    if (rc)
    {
        perror("screen_create_context");
        goto error;
    }

    // Create the screen window.
    rc = screen_create_window(&__screenWindow, __screenContext);
    if (rc)
    {
        perror("screen_create_window");
        goto error;
    }

    // Set/get any window prooperties.
    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_FORMAT, &screenFormat);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
        goto error;
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_USAGE, &screenUsage);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)");
        goto error;
    }

    screen_display_t screen_display;
    rc = screen_get_window_property_pv(__screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display);
    if (rc)
    {
        perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)");
        goto error;
    }

    screen_display_mode_t screen_mode;
    rc = screen_get_display_property_pv(screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
    if (rc)
    {
        perror("screen_get_display_property_pv(SCREEN_PROPERTY_MODE)");
        goto error;
    }

    int size[2];
    rc = screen_get_window_property_iv(__screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, size);
    if (rc)
    {
        perror("screen_get_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
        goto error;
    }

    __screenWindowSize[0] = size[0];
    __screenWindowSize[1] = size[1];

    if ((angle == 0) || (angle == 180))
    {
        if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
        {
            __screenWindowSize[1] = size[0];
            __screenWindowSize[0] = size[1];
        }
    }
    else if ((angle == 90) || (angle == 270))
    {
        if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] < size[1])))
        {
            __screenWindowSize[1] = size[0];
            __screenWindowSize[0] = size[1];
        }
    }
    else
    {
        perror("Navigator returned an unexpected orientation angle.");
        goto error;
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, __screenWindowSize);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
        goto error;
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_ROTATION, &angle);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)");
        goto error;
    }

    if (windowPosition[0] != 0 || windowPosition[1] != 0)
    {
        rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_POSITION, windowPosition);
        if (rc)
        {
            perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)");
            goto error;
        }
    }

    rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_TRANSPARENCY, &screenTransparency);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY)");
        goto error;
    }

    // Double buffered.
    rc = screen_create_window_buffers(__screenWindow, 2);
    if (rc)
    {
        perror("screen_create_window_buffers");
        goto error;
    }

    // Create screen event object.
    rc = screen_create_event(&__screenEvent);
    if (rc)
    {
        perror("screen_create_event");
        goto error;
    }

    // Request screen events.
    screen_request_events(__screenContext);

    // Get the EGL display and initialize.
    __eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (__eglDisplay == EGL_NO_DISPLAY)
    {
        perror("eglGetDisplay");
        goto error;
    }
    if (eglInitialize(__eglDisplay, NULL, NULL) != EGL_TRUE)
    {
        perror("eglInitialize");
        goto error;
    }

    if (eglChooseConfig(__eglDisplay, eglConfigAttrs, &__eglConfig, 1, &eglConfigCount) != EGL_TRUE || eglConfigCount == 0)
    {
        checkErrorEGL("eglChooseConfig");
        goto error;
    }

    __eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextAttrs);
    if (__eglContext == EGL_NO_CONTEXT)
    {
        checkErrorEGL("eglCreateContext");
        goto error;
    }

    __eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, __screenWindow, eglSurfaceAttrs);
    if (__eglSurface == EGL_NO_SURFACE)
    {
        checkErrorEGL("eglCreateWindowSurface");
        goto error;
    }

    if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) != EGL_TRUE)
    {
        checkErrorEGL("eglMakeCurrent");
        goto error;
    }

    // Set vsync.
    eglSwapInterval(__eglDisplay, screenSwapInterval);

    // Initialize OpenGL ES extensions.
    __glExtensions = (const char*)glGetString(GL_EXTENSIONS);

    if (strstr(__glExtensions, "GL_OES_vertex_array_object") || strstr(__glExtensions, "GL_ARB_vertex_array_object"))
    {
        // Disable VAO extension for now.
        glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
        glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArrays");
        glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
        glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES");
    }

    return platform;

error:

    // TODO: cleanup
    //

    return NULL;
}
Ejemplo n.º 12
0
static void *gfx_ctx_qnx_init(video_frame_info_t *video_info, void *video_driver)
{
   EGLint n;
   EGLint major, minor;
   EGLint context_attributes[] = {
#ifdef HAVE_OPENGLES2
           EGL_CONTEXT_CLIENT_VERSION, 2,
#elif HAVE_OPENGLES3
           EGL_CONTEXT_CLIENT_VERSION, 3,
#endif
      EGL_NONE
   };

   const EGLint attribs[] = {
#ifdef HAVE_OPENGLES2
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#elif HAVE_OPENGLES3
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
#endif
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_BLUE_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_RED_SIZE, 8,
      EGL_NONE
   };

   qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)calloc(1, sizeof(*qnx));

   if (!qnx)
       goto screen_error;

   /* Create a screen context that will be used to
    * create an EGL surface to receive libscreen events */

   RARCH_LOG("Initializing screen context...\n");
   if (!screen_ctx)
   {
      screen_create_context(&screen_ctx, 0);

      if (screen_request_events(screen_ctx) != BPS_SUCCESS)
      {
         RARCH_ERR("screen_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_request_events(0) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_request_events failed.\n");
         goto screen_error;
      }

      if (navigator_rotation_lock(false) != BPS_SUCCESS)
      {
         RARCH_ERR("navigator_location_lock failed.\n");
         goto screen_error;
      }
   }


#ifdef HAVE_EGL
   if (!egl_init_context(&qnx->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor,
            &n, attribs))
   {
      egl_report_error();
      goto error;
   }

   if (!egl_create_context(&qnx->egl, context_attributes))
   {
      egl_report_error();
      goto error;
   }
#endif

   if(!screen_win)
   {
      if (screen_create_window(&screen_win, screen_ctx))
      {
             RARCH_ERR("screen_create_window failed:.\n");
	     goto error;
      }
   }

   int format = SCREEN_FORMAT_RGBX8888;
   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_FORMAT, &format))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n");
      goto error;
   }

   int usage;
#ifdef HAVE_OPENGLES2
   usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
#elif HAVE_OPENGLES3
   usage = SCREEN_USAGE_OPENGL_ES3 | SCREEN_USAGE_ROTATION;
#endif
   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_USAGE, &usage))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n");
      goto error;
   }

   if (screen_get_window_property_pv(screen_win,
            SCREEN_PROPERTY_DISPLAY, (void **)&qnx->screen_disp))
   {
      RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
      goto error;
   }

   int screen_resolution[2];

   if (screen_get_display_property_iv(qnx->screen_disp,
            SCREEN_PROPERTY_SIZE, screen_resolution))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
      goto error;
   }

#ifndef HAVE_BB10
   int angle, size[2];

   angle = atoi(getenv("ORIENTATION"));

   screen_display_mode_t screen_mode;
   if (screen_get_display_property_pv(qnx->screen_disp,
            SCREEN_PROPERTY_MODE, (void**)&screen_mode))
   {
      RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n");
      goto error;
   }

   if (screen_get_window_property_iv(screen_win,
            SCREEN_PROPERTY_BUFFER_SIZE, size))
   {
      RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   int buffer_size[2] = {size[0], size[1]};

   if ((angle == 0) || (angle == 180))
   {
      if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
            ((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
      {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   }
   else if ((angle == 90) || (angle == 270))
   {
      if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
            ((screen_mode.width < screen_mode.height && size[0] < size[1])))
      {
         buffer_size[1] = size[0];
         buffer_size[0] = size[1];
      }
   }
   else
   {
      RARCH_ERR("Navigator returned an unexpected orientation angle.\n");
      goto error;
   }


   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_BUFFER_SIZE, buffer_size))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
      goto error;
   }

   if (screen_set_window_property_iv(screen_win,
            SCREEN_PROPERTY_ROTATION, &angle))
   {
      RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n");
      goto error;
   }
#endif

   if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS))
   {
      RARCH_ERR("screen_create_window_buffers failed.\n");
      goto error;
   }

   if (!egl_create_surface(&qnx->egl, screen_win))
      goto error;

   return qnx;

error:
   RARCH_ERR("EGL error: %d.\n", eglGetError());
   gfx_ctx_qnx_destroy(video_driver);
screen_error:
   screen_stop_events(screen_ctx);
   return NULL;
}