EGLint GLContext::Resume( ANativeWindow* window ) { if( egl_context_initialized_ == false ) { Init( window ); return EGL_SUCCESS; } int32_t original_widhth = screen_width_; int32_t original_height = screen_height_; //Create surface window_ = window; surface_ = eglCreateWindowSurface( display_, config_, window_, NULL ); eglQuerySurface( display_, surface_, EGL_WIDTH, &screen_width_ ); eglQuerySurface( display_, surface_, EGL_HEIGHT, &screen_height_ ); if( screen_width_ != original_widhth || screen_height_ != original_height ) { //Screen resized LOGI( "Screen resized" ); } if( eglMakeCurrent( display_, surface_, surface_, context_ ) == EGL_TRUE ) return EGL_SUCCESS; EGLint err = eglGetError(); LOGW( "Unable to eglMakeCurrent %d", err ); if( err == EGL_CONTEXT_LOST ) { //Recreate context LOGI( "Re-creating egl context" ); InitEGLContext(); } else { //Recreate surface Terminate(); InitEGLSurface(); InitEGLContext(); } return err; }
bool GLContext::Init(ANativeWindow* window) { if (egl_context_initialized_) return true; // // Initialize EGL // window_ = window; InitEGLSurface(); InitEGLContext(); InitGLES(); egl_context_initialized_ = true; return true; }
bool GLContext::Init(ANativeWindow *window, const int32_t msaa) { if (egl_context_initialized_) return true; // //Initialize EGL // window_ = window; msaa_size_ = msaa; InitEGLSurface(); InitEGLContext(); InitGLES(); egl_context_initialized_ = true; return true; }
EGLint GLContext::Swap() { bool b = eglSwapBuffers(display_, surface_); if (!b) { EGLint err = eglGetError(); if (err == EGL_BAD_SURFACE) { // Recreate surface InitEGLSurface(); return EGL_SUCCESS; // Still consider glContext is valid } else if (err == EGL_CONTEXT_LOST || err == EGL_BAD_CONTEXT) { // Context has been lost!! context_valid_ = false; Terminate(); InitEGLContext(); } return err; } return EGL_SUCCESS; }
EGLint GLContext::Swap() { bool b = eglSwapBuffers(display_, surface_); if (!b) { EGLint err = eglGetError(); if (err == EGL_BAD_SURFACE) { //Recreate surface InitEGLSurface(); err = EGL_SUCCESS; //Still consider glContext is valid } else if (err == EGL_CONTEXT_LOST || err == EGL_BAD_CONTEXT) { //Context has been lost!! context_valid_ = false; Terminate(); InitEGLContext(); } return err; } if (restoreInterval_ && swapInterval_ != SWAPINTERVAL_DEFAULT) { eglSwapInterval(display_, swapInterval_); //Restore Swap interval } return EGL_SUCCESS; }