/** @brief Release all EGL and system resources */ void EGL_Close( void ) { /* Release EGL resources */ if (eglDisplay != NULL) { peglMakeCurrent( eglDisplay, NULL, NULL, EGL_NO_CONTEXT ); if (eglContext != NULL) { peglDestroyContext( eglDisplay, eglContext ); } if (eglSurface != NULL) { peglDestroySurface( eglDisplay, eglSurface ); } peglTerminate( eglDisplay ); } eglSurface = NULL; eglContext = NULL; eglDisplay = NULL; eglColorbits = 0; eglDepthbits = 0; eglStencilbits = 0; /* Release platform resources */ FreeNativeWindow(); FreeNativeDisplay(); Platform_Close(); CheckEGLErrors( __FILE__, __LINE__ ); printf( "EGLport: Closed\n" ); }
/*====================================================== * Close EGL resources ====================================================*/ void EGL_Close() { if (g_eglDisplay != NULL) { peglMakeCurrent( g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT ); if (g_eglContext != NULL) { peglDestroyContext( g_eglDisplay, g_eglContext ); } if (g_eglSurface != NULL) { peglDestroySurface( g_eglDisplay, g_eglSurface ); } peglTerminate( g_eglDisplay ); } g_eglSurface = NULL; g_eglContext = NULL; g_eglDisplay = NULL; #if defined(USE_EGL_RAW) if (g_Window != NULL) { free(g_Window); } g_Window = NULL; #elif defined(USE_EGL_SDL) if (g_Display != NULL) { XCloseDisplay(g_Display); } g_Display = NULL; #else #error Incorrect EGL Configuration #endif /* defined(USE_EGL_RAW) */ CheckEGLErrors( __FILE__, __LINE__ ); printf( "EGL Closed\n" ); Platform_Close(); }
/*=========================================================== Initialise OpenGL settings ===========================================================*/ int8_t ConfigureEGL(EGLConfig config) { EGLBoolean result; #if defined(USE_GLES1) static const EGLint s_contextAttribs = NULL; #elif defined(USE_GLES2) static const EGLint s_contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; #else #error Incorrect Opengl-ES Configuration for s_contextAttribs #endif /* defined(USE_GLES1) */ // Cleanup in case of a reset if (g_eglDisplay != NULL) { peglMakeCurrent( g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT ); if (g_eglContext != NULL) { peglDestroyContext( g_eglDisplay, g_eglContext ); } if (g_eglSurface != NULL) { peglDestroySurface( g_eglDisplay, g_eglSurface ); } } #if defined(EGL_VERSION_1_2) // Bind GLES and create the context printf( "EGL Binding API\n" ); peglBindAPI( EGL_OPENGL_ES_API ); if ( CheckEGLErrors( __FILE__, __LINE__ ) != 0 ) { printf( "EGL ERROR: Could not bind EGL API.\n" ); return 1; } #endif /* defined(USE_EGL_SDL) */ printf( "EGL Creating Context\n" ); g_eglContext = peglCreateContext( g_eglDisplay, config, NULL, s_contextAttribs ); if (g_eglContext == EGL_NO_CONTEXT) { CheckEGLErrors( __FILE__, __LINE__ ); printf( "EGL ERROR: Unable to create GLES context!\n"); return 1; } #if defined(USE_EGL_RAW) if (g_Window == NULL) { g_Window = (NativeWindowType)malloc(16*1024); if(g_Window == NULL) { printf( "EGL ERROR: Memory for window Failed\n" ); return 1; } } else { printf( "EGL Info: Memory for window already allocated\n" ); } #elif defined(USE_EGL_SDL) // Get the SDL window handle SDL_SysWMinfo sysInfo; //Will hold our Window information SDL_VERSION(&sysInfo.version); //Set SDL version if(SDL_GetWMInfo(&sysInfo) <= 0) { printf( "EGL ERROR: Unable to get SDL window handle: %s\n", SDL_GetError() ); return 1; } g_Window = (NativeWindowType)sysInfo.info.x11.window; #else #error Incorrect EGL Configuration for g_Window #endif /* defined(USE_EGL_RAW) */ printf( "EGL Creating window surface\n" ); g_eglSurface = peglCreateWindowSurface( g_eglDisplay, config, g_Window, 0 ); if (g_eglSurface == EGL_NO_SURFACE) { CheckEGLErrors( __FILE__, __LINE__ ); printf( "EGL ERROR: Unable to create EGL surface!\n" ); return 1; } printf( "EGL Making Current\n" ); result = peglMakeCurrent( g_eglDisplay, g_eglSurface, g_eglSurface, g_eglContext ); if (result != EGL_TRUE) { CheckEGLErrors( __FILE__, __LINE__ ); printf( "EGL ERROR: Unable to make GLES context current\n" ); return 1; } CheckEGLErrors( __FILE__, __LINE__ ); printf( "EGL Complete\n" ); return 0; }