int MIR_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context) { if (window) { EGLSurface egl_surface = ((MIR_Window*)window->driverdata)->egl_surface; return SDL_EGL_MakeCurrent(_this, egl_surface, context); } return SDL_EGL_MakeCurrent(_this, NULL, NULL); }
int Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { int ret; if (window && context) { ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); } else { ret = SDL_EGL_MakeCurrent(_this, NULL, NULL); } WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); return ret; }
void KMSDRM_DestroyWindow(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; if(data) { /* Wait for any pending page flips and unlock buffer */ KMSDRM_WaitPageFlip(_this, data, -1); if (data->crtc_bo != NULL) { KMSDRM_gbm_surface_release_buffer(data->gs, data->crtc_bo); data->crtc_bo = NULL; } if (data->next_bo != NULL) { KMSDRM_gbm_surface_release_buffer(data->gs, data->next_bo); data->next_bo = NULL; } if (data->current_bo != NULL) { KMSDRM_gbm_surface_release_buffer(data->gs, data->current_bo); data->current_bo = NULL; } #if SDL_VIDEO_OPENGL_EGL SDL_EGL_MakeCurrent(_this, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (data->egl_surface != EGL_NO_SURFACE) { SDL_EGL_DestroySurface(_this, data->egl_surface); } #endif /* SDL_VIDEO_OPENGL_EGL */ if (data->gs != NULL) { KMSDRM_gbm_surface_destroy(data->gs); data->gs = NULL; } SDL_free(data); window->driverdata = NULL; } }
SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) { EGLint context_attrib_list[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; EGLContext egl_context, share_context = EGL_NO_CONTEXT; if (!_this->egl_data) { /* The EGL library wasn't loaded, SDL_GetError() should have info */ return NULL; } if (_this->gl_config.share_with_current_context) { share_context = (EGLContext)SDL_GL_GetCurrentContext(); } /* Bind the API */ if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API); if (_this->gl_config.major_version) { context_attrib_list[1] = _this->gl_config.major_version; } egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display, _this->egl_data->egl_config, share_context, context_attrib_list); } else { _this->egl_data->eglBindAPI(EGL_OPENGL_API); egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display, _this->egl_data->egl_config, share_context, NULL); } if (egl_context == EGL_NO_CONTEXT) { SDL_SetError("Could not create EGL context"); return NULL; } _this->egl_data->egl_swapinterval = 0; if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) { SDL_EGL_DeleteContext(_this, egl_context); SDL_SetError("Could not make EGL context current"); return NULL; } return (SDL_GLContext) egl_context; }
void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context) { EGLContext egl_context = (EGLContext) context; /* Clean up GLES and EGL */ if (!_this->egl_data) { return; } if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) { SDL_EGL_MakeCurrent(_this, NULL, NULL); _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context); } }
void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context) { EGLContext egl_context = (EGLContext) context; /* Clean up GLES and EGL */ if (!_this->egl_data) { return; } if (!egl_context && egl_context != EGL_NO_CONTEXT) { SDL_EGL_MakeCurrent(_this, NULL, NULL); _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context); } /* FIXME: This "crappy fix" comes from the X11 code, * it's required so you can create a GLX context, destroy it and create a EGL one */ SDL_EGL_UnloadLibrary(_this); }
SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) { EGLint context_attrib_list[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; EGLContext egl_context; if (!_this->egl_data) { /* The EGL library wasn't loaded, SDL_GetError() should have info */ return NULL; } if (_this->gl_config.major_version) { context_attrib_list[1] = _this->gl_config.major_version; } egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display, _this->egl_data->egl_config, EGL_NO_CONTEXT, context_attrib_list); if (egl_context == EGL_NO_CONTEXT) { SDL_SetError("Could not create EGL context"); return NULL; } _this->egl_data->egl_swapinterval = 0; if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) { SDL_EGL_DeleteContext(_this, egl_context); SDL_SetError("Could not make EGL context current"); return NULL; } return (SDL_GLContext) egl_context; }
SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) { /* max 14 values plus terminator. */ EGLint attribs[15]; int attr = 0; EGLContext egl_context, share_context = EGL_NO_CONTEXT; EGLint profile_mask = _this->gl_config.profile_mask; EGLint major_version = _this->gl_config.major_version; EGLint minor_version = _this->gl_config.minor_version; SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES); if (!_this->egl_data) { /* The EGL library wasn't loaded, SDL_GetError() should have info */ return NULL; } if (_this->gl_config.share_with_current_context) { share_context = (EGLContext)SDL_GL_GetCurrentContext(); } /* Set the context version and other attributes. */ if ((major_version < 3 || (minor_version == 0 && profile_es)) && _this->gl_config.flags == 0 && (profile_mask == 0 || profile_es)) { /* Create a context without using EGL_KHR_create_context attribs. * When creating a GLES context without EGL_KHR_create_context we can * only specify the major version. When creating a desktop GL context * we can't specify any version, so we only try in that case when the * version is less than 3.0 (matches SDL's GLX/WGL behavior.) */ if (profile_es) { attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION; attribs[attr++] = SDL_max(major_version, 1); } } else { #ifdef EGL_KHR_create_context /* The Major/minor version, context profiles, and context flags can * only be specified when this extension is available. */ if (SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) { attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR; attribs[attr++] = major_version; attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR; attribs[attr++] = minor_version; /* SDL profile bits match EGL profile bits. */ if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { attribs[attr++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR; attribs[attr++] = profile_mask; } /* SDL flags match EGL flags. */ if (_this->gl_config.flags != 0) { attribs[attr++] = EGL_CONTEXT_FLAGS_KHR; attribs[attr++] = _this->gl_config.flags; } } else #endif /* EGL_KHR_create_context */ { SDL_SetError("Could not create EGL context (context attributes are not supported)"); return NULL; } } attribs[attr++] = EGL_NONE; /* Bind the API */ if (profile_es) { _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API); } else { _this->egl_data->eglBindAPI(EGL_OPENGL_API); } egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display, _this->egl_data->egl_config, share_context, attribs); if (egl_context == EGL_NO_CONTEXT) { SDL_SetError("Could not create EGL context"); return NULL; } _this->egl_data->egl_swapinterval = 0; if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) { SDL_EGL_DeleteContext(_this, egl_context); SDL_SetError("Could not make EGL context current"); return NULL; } return (SDL_GLContext) egl_context; }
SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) { /* max 14 values plus terminator. */ EGLint attribs[15]; int attr = 0; EGLContext egl_context, share_context = EGL_NO_CONTEXT; EGLint profile_mask = _this->gl_config.profile_mask; EGLint major_version = _this->gl_config.major_version; EGLint minor_version = _this->gl_config.minor_version; SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES); if (!_this->egl_data) { /* The EGL library wasn't loaded, SDL_GetError() should have info */ return NULL; } if (_this->gl_config.share_with_current_context) { share_context = (EGLContext)SDL_GL_GetCurrentContext(); } #if SDL_VIDEO_DRIVER_ANDROID if ((_this->gl_config.flags & SDL_GL_CONTEXT_DEBUG_FLAG) != 0) { /* If SDL_GL_CONTEXT_DEBUG_FLAG is set but EGL_KHR_debug unsupported, unset. * This is required because some Android devices like to complain about it * by "silently" failing, logging a hint which could be easily overlooked: * E/libEGL (26984): validate_display:255 error 3008 (EGL_BAD_DISPLAY) * The following explicitly checks for EGL_KHR_debug before EGL 1.5 */ int egl_version_major = _this->egl_data->egl_version_major; int egl_version_minor = _this->egl_data->egl_version_minor; if (((egl_version_major < 1) || (egl_version_major == 1 && egl_version_minor < 5)) && !SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_debug")) { /* SDL profile bits match EGL profile bits. */ _this->gl_config.flags &= ~SDL_GL_CONTEXT_DEBUG_FLAG; } } #endif /* Set the context version and other attributes. */ if ((major_version < 3 || (minor_version == 0 && profile_es)) && _this->gl_config.flags == 0 && (profile_mask == 0 || profile_es)) { /* Create a context without using EGL_KHR_create_context attribs. * When creating a GLES context without EGL_KHR_create_context we can * only specify the major version. When creating a desktop GL context * we can't specify any version, so we only try in that case when the * version is less than 3.0 (matches SDL's GLX/WGL behavior.) */ if (profile_es) { attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION; attribs[attr++] = SDL_max(major_version, 1); } } else { #ifdef EGL_KHR_create_context /* The Major/minor version, context profiles, and context flags can * only be specified when this extension is available. */ if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context")) { attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR; attribs[attr++] = major_version; attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR; attribs[attr++] = minor_version; /* SDL profile bits match EGL profile bits. */ if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { attribs[attr++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR; attribs[attr++] = profile_mask; } /* SDL flags match EGL flags. */ if (_this->gl_config.flags != 0) { attribs[attr++] = EGL_CONTEXT_FLAGS_KHR; attribs[attr++] = _this->gl_config.flags; } } else #endif /* EGL_KHR_create_context */ { SDL_SetError("Could not create EGL context (context attributes are not supported)"); return NULL; } } if (_this->gl_config.no_error) { #ifdef EGL_KHR_create_context_no_error if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context_no_error")) { attribs[attr++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR; attribs[attr++] = _this->gl_config.no_error; } else #endif { SDL_SetError("EGL implementation does not support no_error contexts"); return NULL; } } attribs[attr++] = EGL_NONE; /* Bind the API */ if (profile_es) { _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API); } else { _this->egl_data->eglBindAPI(EGL_OPENGL_API); } egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display, _this->egl_data->egl_config, share_context, attribs); if (egl_context == EGL_NO_CONTEXT) { SDL_EGL_SetError("Could not create EGL context", "eglCreateContext"); return NULL; } _this->egl_data->egl_swapinterval = 0; if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) { /* Save the SDL error set by SDL_EGL_MakeCurrent */ char errorText[1024]; SDL_strlcpy(errorText, SDL_GetError(), SDL_arraysize(errorText)); /* Delete the context, which may alter the value returned by SDL_GetError() */ SDL_EGL_DeleteContext(_this, egl_context); /* Restore the SDL error */ SDL_SetError("%s", errorText); return NULL; } return (SDL_GLContext) egl_context; }