示例#1
0
void GlContext::create(uint32_t _width, uint32_t _height)
{
    m_eglLibrary = eglOpen();

    BX_UNUSED(_width, _height);
    EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
    EGLNativeWindowType nwt = (EGLNativeWindowType)NULL;
#	if BX_PLATFORM_WINDOWS
    ndt = GetDC(g_bgfxHwnd);
    nwt = g_bgfxHwnd;
#	endif // BX_PLATFORM_
    m_display = eglGetDisplay(ndt);
    BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);

    EGLint major = 0;
    EGLint minor = 0;
    EGLBoolean success = eglInitialize(m_display, &major, &minor);
    BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);

    EGLint attrs[] =
    {
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

#	if BX_PLATFORM_ANDROID
        EGL_DEPTH_SIZE, 16,
#	else
        EGL_DEPTH_SIZE, 24,
#	endif // BX_PLATFORM_
        EGL_STENCIL_SIZE, 8,

        EGL_NONE
    };

    EGLint numConfig = 0;
    EGLConfig config;
    success = eglChooseConfig(m_display, attrs, &config, 1, &numConfig);
    BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");

#	if BX_PLATFORM_ANDROID
    EGLint format;
    eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
    ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
    nwt = g_bgfxAndroidWindow;
#	endif // BX_PLATFORM_ANDROID

    m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL);
    BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");

    EGLint contextAttrs[] =
    {
#	if BGFX_CONFIG_RENDERER_OPENGLES >= 30
        EGL_CONTEXT_CLIENT_VERSION, 3,
#	elif BGFX_CONFIG_RENDERER_OPENGLES
        EGL_CONTEXT_CLIENT_VERSION, 2,
#	endif // BGFX_CONFIG_RENDERER_

        EGL_NONE
    };

    m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttrs);
    BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");

    success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
    BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");

    eglSwapInterval(m_display, 0);

#	if BX_PLATFORM_EMSCRIPTEN
    emscripten_set_canvas_size(_width, _height);
#	endif // BX_PLATFORM_EMSCRIPTEN

    import();
}
示例#2
0
int main(int argc, char* argv[])
{
#else
int SymbianMain()
{
    int argc = 0;
    char** argv = NULL;
#endif
    Config cfg = {0};
    bglContext* context;
#ifdef PERFMONITOR
    FILE* perf = fopen("pinball_perf.pmo","wb");

    if(perf == NULL)
    {
        printf("ERROR: couldn't open perf monitor file");
//        si_fail("Failed to open perfomance monitor file");
    }
#endif
    
	cfg.rBits = 5;
	cfg.gBits = 6;
	cfg.bBits = 5;
	cfg.aBits = 0;
	cfg.bitsPerPixel = 16;
	cfg.depthBits = 16;
	cfg.stencilBits = 0;
	cfg.sampleBuffers = 0;
	cfg.samples = 0;
	cfg.winW = SAMPLE_WINDOW_WIDTH;
	cfg.winH = SAMPLE_WINDOW_HEIGHT;
	
    context = eglOpen(&cfg);

    /* Create pinball class */
    {
        BBPinballCreateParams params;
        memset(&params, 0, sizeof(params));

        params.getTime          = getCurrentTime;

        params.display          = context->display;
        params.config           = context->config;
        params.mainContext      = context->context;
        params.mainSurface      = context->surface;

        params.surfaceWidth     = SAMPLE_WINDOW_WIDTH;
        params.surfaceHeight    = SAMPLE_WINDOW_HEIGHT;

		bbParseParameters(&params,argc,argv);

        g_pinball = BBPinball_create(&params);
        if (!g_pinball)
        {
            return 0;
        }
    }

#ifdef PERFMONITOR
    pmRegisterMonitor(&cycles_arm11); /* add a core cycle counter */
    pmRegisterMonitor(&branchmiss_arm11); /* add a branch prediction miss counter */
    pmRegisterMonitor(&iexec_arm11); /* add a instructions executed counter */
    pmInitialize(perf, "Pinball demo");
    pmStart();
    
#define CALIB() \
    pmProbe(ENTRY_PROBE_ID(calibration)); \
    pmProbe(EXIT_PROBE_ID(calibration));

    CALIB();
    CALIB();
    CALIB();
    CALIB();
    CALIB();
    CALIB();
#endif

    for(;;)
    {
#ifdef PERFMONITOR
        pmProbe(ENTRY_PROBE_ID(mainProbe));
#endif
		if (BBPinball_main(g_pinball))
			break;
#ifdef PERFMONITOR
        pmProbe(EXIT_PROBE_ID(mainProbe));
#endif
    }
    
#ifdef PERFMONITOR
    pmStop();
    pmFinalize();
#endif

    return 0;
}
示例#3
0
	void GlContext::create(uint32_t _width, uint32_t _height)
	{
#	if BX_PLATFORM_RPI
		bcm_host_init();
#	endif // BX_PLATFORM_RPI

		m_eglLibrary = eglOpen();

		if (NULL == g_platformData.context)
		{
#	if BX_PLATFORM_RPI
			g_platformData.ndt = EGL_DEFAULT_DISPLAY;
#	endif // BX_PLATFORM_RPI

			BX_UNUSED(_width, _height);
			EGLNativeDisplayType ndt = (EGLNativeDisplayType)g_platformData.ndt;
			EGLNativeWindowType  nwh = (EGLNativeWindowType )g_platformData.nwh;

#	if BX_PLATFORM_WINDOWS
			if (NULL == g_platformData.ndt)
			{
				ndt = GetDC( (HWND)g_platformData.nwh);
			}
#	endif // BX_PLATFORM_WINDOWS

			m_display = eglGetDisplay(ndt);
			BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);

			EGLint major = 0;
			EGLint minor = 0;
			EGLBoolean success = eglInitialize(m_display, &major, &minor);
			BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);

			BX_TRACE("EGL info:");
			const char* clientApis = eglQueryString(m_display, EGL_CLIENT_APIS);
			BX_TRACE("   APIs: %s", clientApis); BX_UNUSED(clientApis);

			const char* vendor = eglQueryString(m_display, EGL_VENDOR);
			BX_TRACE(" Vendor: %s", vendor); BX_UNUSED(vendor);

			const char* version = eglQueryString(m_display, EGL_VERSION);
			BX_TRACE("Version: %s", version); BX_UNUSED(version);

			const char* extensions = eglQueryString(m_display, EGL_EXTENSIONS);
			BX_TRACE("Supported EGL extensions:");
			dumpExtensions(extensions);

			EGLint attrs[] =
			{
				EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

#	if BX_PLATFORM_ANDROID
				EGL_DEPTH_SIZE, 16,
#	else
				EGL_DEPTH_SIZE, 24,
#	endif // BX_PLATFORM_
				EGL_STENCIL_SIZE, 8,

				EGL_NONE
			};

			EGLint numConfig = 0;
			success = eglChooseConfig(m_display, attrs, &m_config, 1, &numConfig);
			BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");

#	if BX_PLATFORM_ANDROID

			EGLint format;
			eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
			ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);

#	elif BX_PLATFORM_RPI
			DISPMANX_DISPLAY_HANDLE_T dispmanDisplay = vc_dispmanx_display_open(0);
			DISPMANX_UPDATE_HANDLE_T  dispmanUpdate  = vc_dispmanx_update_start(0);

			VC_RECT_T dstRect = { 0, 0, int32_t(_width),        int32_t(_height)       };
			VC_RECT_T srcRect = { 0, 0, int32_t(_width)  << 16, int32_t(_height) << 16 };

			DISPMANX_ELEMENT_HANDLE_T dispmanElement = vc_dispmanx_element_add(dispmanUpdate
				, dispmanDisplay
				, 0
				, &dstRect
				, 0
				, &srcRect
				, DISPMANX_PROTECTION_NONE
				, NULL
				, NULL
				, DISPMANX_NO_ROTATE
				);

			s_dispmanWindow.element = dispmanElement;
			s_dispmanWindow.width   = _width;
			s_dispmanWindow.height  = _height;
			nwh = &s_dispmanWindow;

			vc_dispmanx_update_submit_sync(dispmanUpdate);
#	endif // BX_PLATFORM_ANDROID

			m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
			BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");

			const bool hasEglKhrCreateContext = !!bx::findIdentifierMatch(extensions, "EGL_KHR_create_context");
			const bool hasEglKhrNoError       = !!bx::findIdentifierMatch(extensions, "EGL_KHR_create_context_no_error");

			const uint32_t gles = BGFX_CONFIG_RENDERER_OPENGLES;

			for (uint32_t ii = 0; ii < 2; ++ii)
			{
				bx::StaticMemoryBlockWriter writer(s_contextAttrs, sizeof(s_contextAttrs) );

				EGLint flags = 0;

#	if BX_PLATFORM_RPI
				BX_UNUSED(hasEglKhrCreateContext, hasEglKhrNoError);
#	else
				if (hasEglKhrCreateContext)
				{
					bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR) );
					bx::write(&writer, EGLint(gles / 10) );

					bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR) );
					bx::write(&writer, EGLint(gles % 10) );

					flags |= BGFX_CONFIG_DEBUG && hasEglKhrNoError ? 0
						| EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
						: 0
						;

					if (0 == ii)
					{
						flags |= BGFX_CONFIG_DEBUG ? 0
							| EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR
//							| EGL_OPENGL_ES3_BIT_KHR
							: 0
							;

						bx::write(&writer, EGLint(EGL_CONTEXT_FLAGS_KHR) );
						bx::write(&writer, flags);
					}
				}
				else
#	endif // BX_PLATFORM_RPI
				{
					bx::write(&writer, EGLint(EGL_CONTEXT_CLIENT_VERSION) );
					bx::write(&writer, 2);
				}

				bx::write(&writer, EGLint(EGL_NONE) );

				m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, s_contextAttrs);
				if (NULL != m_context)
				{
					break;
				}

				BX_TRACE("Failed to create EGL context with EGL_CONTEXT_FLAGS_KHR (%08x).", flags);
			}

			BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");

			success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
			BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
			m_current = NULL;

			eglSwapInterval(m_display, 0);
		}

		import();

		g_internalData.context = m_context;
	}