gboolean video_egl_init_context( EGLNativeWindowType window, int format ) { EGLConfig config; EGLint num_config; const EGLint *attribute_list; if( format == COLFMT_RGB565 || format == COLFMT_BGRA1555 ) { attribute_list = RGB565_attributes; } else { attribute_list = RGB888_attributes; } eglChooseConfig(display, attribute_list, &config, 1, &num_config); surface = eglCreateWindowSurface(display, config, window, NULL); if( surface == EGL_NO_SURFACE ) { /* Try alternate config in case of failure. This provides a workaround for * the Nokia N900 where eglCreateWindowSurface fails when color attributes * are specified. (bug report: https://bugs.maemo.org/show_bug.cgi?id=9335) */ eglChooseConfig(display, alt_attributes, &config, 1, &num_config); surface = eglCreateWindowSurface(display, config, window, NULL); if( surface == EGL_NO_SURFACE ) { logEGLError( "Unable to create EGL surface" ); video_egl_shutdown(); return FALSE; } } context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attributes); if( context == EGL_NO_CONTEXT ) { logEGLError( "Unable to create EGL context" ); video_egl_shutdown(); return FALSE; } if( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE ) { logEGLError( "Unable to make EGL context current" ); video_egl_shutdown(); return FALSE; } return TRUE; }
gboolean video_egl_init() { display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if( eglInitialize(display, &video_egl_major, &video_egl_minor) != EGL_TRUE ) { logEGLError( "Unable to initialise EGL display" ); return FALSE; } return TRUE; }
static void sample(TestPlatform* p, void* eglDisplay, void* nativeWinSurface, int maxFrameCount, int openglesVersion) { switch (openglesVersion) { case 1: { renderer.init = initRenderOpenGLES1; renderer.renderFrame = renderFrameOpenGLES1; renderer.destroy = destroyRenderOpenGLES1; renderer.renderableType = EGL_OPENGL_ES_BIT; renderer.clientVersion = 1; LOG(I, "Running with OpenGL ES 1.X") break; } case 2: { renderer.init = initRenderOpenGLES2; renderer.renderFrame = renderFrameOpenGLES2; renderer.destroy = destroyRenderOpenGLES2; renderer.renderableType = EGL_OPENGL_ES2_BIT; renderer.clientVersion = 2; LOG(I, "Running with OpenGL ES 2.X") break; } default: return; break; } setenv(p->ios_platform_env_key, p->ios_platform_env_value, 1); if ((display = eglGetDisplay(eglDisplay)) == EGL_NO_DISPLAY) { logEGLError( "eglGetDisplay", eglGetError()); return; } if (!eglInitialize(display, 0, 0)) { logEGLError( "eglInitialize", eglGetError()); return; } EGLint config_attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_RENDERABLE_TYPE, renderer.renderableType, EGL_NONE }; if (!eglChooseConfig(display, config_attribs, &config, 1, &numConfigs)) { logEGLError( "eglChooseConfig", eglGetError()); return; } EGLint num_attrs = 0; getEGLConfigAttributeForEGLAPIVersion(1, 4, NULL, &num_attrs); EGLint* attrs = (EGLint* ) malloc(num_attrs * sizeof(EGLint)); getEGLConfigAttributeForEGLAPIVersion(1, 4, attrs, &num_attrs); displayEGLConfig(display, config, attrs, num_attrs); init: if (!(surface = eglCreateWindowSurface(display, config, nativeWinSurface, NULL))) { logEGLError( "eglCreateWindowSurface", eglGetError()); return; } if (!eglQuerySurface(display, surface, EGL_WIDTH, &width) || !eglQuerySurface(display, surface, EGL_HEIGHT, &height)) { logEGLError( "eglQuerySurface", eglGetError()); return; } EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, renderer.clientVersion /* 1 or 2 or 3 */, EGL_NONE}; if (!(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs))) { logEGLError( "eglCreateContext", eglGetError()); return; } if (!eglMakeCurrent(display, surface, surface, context)) { logEGLError( "eglMakeCurrent", eglGetError()); return; } if (!eglSwapInterval(display, 1)) { logEGLError("eglSwapInterval()", eglGetError()); return; } EGLint error; if (!renderer.init()) { return; } int i = 0; TimeRecord_t s; TimeRecord_t e; while (i < maxFrameCount) { LOG(I, "FRAME ...") renderer.renderFrame(); START_RECORD_DURATION(&s); if (!eglSwapBuffers(display, surface)) { error = eglGetError(); logEGLError("eglSwapBuffers()", error); if (error != EGL_CONTEXT_LOST) { break; } if (!eglDestroySurface(display, surface)) { logEGLError( "eglDestroySurface", eglGetError()); break; } surface = EGL_NO_SURFACE; if (!eglDestroyContext(display, context)) { logEGLError( "eglDestroyContext", eglGetError()); break; }; context = EGL_NO_CONTEXT; if (!eglMakeCurrent(display, surface, surface, context)) { logEGLError( "eglMakeCurrent", eglGetError()); return; } goto init; } LOG(I, "FRAME DONE") END_RECORD_DURATION(&e); LOG_DURATION(&s, &e) i++; } renderer.destroy(); if (!eglDestroySurface(display, surface)) { logEGLError( "eglDestroySurface", eglGetError()); return; } surface = EGL_NO_SURFACE; if (!eglDestroyContext(display, context)) { logEGLError( "eglDestroyContext", eglGetError()); return; }; context = EGL_NO_CONTEXT; if (!eglMakeCurrent(display, surface, surface, context)) { logEGLError( "eglMakeCurrent", eglGetError()); return; } if(!eglTerminate(display)) { logEGLError( "eglTerminate", eglGetError()); return; } display = EGL_NO_DISPLAY; if(!eglReleaseThread()) { logEGLError( "eglReleaseThread", eglGetError()); return; } }