static CoglBool _cogl_winsys_onscreen_init (CoglOnscreen *onscreen, CoglError **error) { CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglContext *context = framebuffer->context; CoglDisplay *display = context->display; CoglDisplayEGL *egl_display = display->winsys; CoglRenderer *renderer = display->renderer; CoglRendererEGL *egl_renderer = renderer->winsys; EGLint attributes[MAX_EGL_CONFIG_ATTRIBS]; EGLConfig egl_config; EGLint config_count = 0; EGLBoolean status; _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE); egl_attributes_from_framebuffer_config (display, &framebuffer->config, attributes); status = eglChooseConfig (egl_renderer->edpy, attributes, &egl_config, 1, &config_count); if (status != EGL_TRUE || config_count == 0) { _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_ONSCREEN, "Failed to find a suitable EGL configuration"); return FALSE; } /* Update the real number of samples_per_pixel now that we have * found an egl_config... */ if (framebuffer->config.samples_per_pixel) { EGLint samples; status = eglGetConfigAttrib (egl_renderer->edpy, egl_config, EGL_SAMPLES, &samples); g_return_val_if_fail (status == EGL_TRUE, TRUE); framebuffer->samples_per_pixel = samples; } onscreen->winsys = g_slice_new0 (CoglOnscreenEGL); if (egl_renderer->platform_vtable->onscreen_init && !egl_renderer->platform_vtable->onscreen_init (onscreen, egl_config, error)) { g_slice_free (CoglOnscreenEGL, onscreen->winsys); return FALSE; } return TRUE; }
static bool _cg_winsys_onscreen_init(cg_onscreen_t *onscreen, cg_error_t **error) { cg_framebuffer_t *framebuffer = CG_FRAMEBUFFER(onscreen); cg_device_t *dev = framebuffer->dev; cg_display_t *display = dev->display; cg_display_egl_t *egl_display = display->winsys; cg_renderer_t *renderer = display->renderer; cg_renderer_egl_t *egl_renderer = renderer->winsys; EGLint attributes[MAX_EGL_CONFIG_ATTRIBS]; EGLConfig egl_config; EGLint config_count = 0; EGLBoolean status; c_return_val_if_fail(egl_display->egl_context, false); egl_attributes_from_framebuffer_config( display, &framebuffer->config, attributes); status = eglChooseConfig( egl_renderer->edpy, attributes, &egl_config, 1, &config_count); if (status != EGL_TRUE || config_count == 0) { _cg_set_error(error, CG_WINSYS_ERROR, CG_WINSYS_ERROR_CREATE_ONSCREEN, "Failed to find a suitable EGL configuration"); return false; } /* Update the real number of samples_per_pixel now that we have * found an egl_config... */ if (framebuffer->config.samples_per_pixel) { EGLint samples; status = eglGetConfigAttrib( egl_renderer->edpy, egl_config, EGL_SAMPLES, &samples); c_return_val_if_fail(status == EGL_TRUE, true); framebuffer->samples_per_pixel = samples; } onscreen->winsys = c_slice_new0(cg_onscreen_egl_t); if (egl_renderer->platform_vtable->onscreen_init && !egl_renderer->platform_vtable->onscreen_init( onscreen, egl_config, error)) { c_slice_free(cg_onscreen_egl_t, onscreen->winsys); return false; } return true; }
static bool try_create_context(cg_display_t *display, cg_error_t **error) { cg_renderer_t *renderer = display->renderer; cg_display_egl_t *egl_display = display->winsys; cg_renderer_egl_t *egl_renderer = renderer->winsys; EGLDisplay edpy; EGLConfig config; EGLint config_count = 0; EGLBoolean status; EGLint attribs[9]; EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS]; const char *error_message; c_return_val_if_fail(egl_display->egl_context == NULL, true); if (renderer->driver == CG_DRIVER_GL || renderer->driver == CG_DRIVER_GL3) eglBindAPI(EGL_OPENGL_API); egl_attributes_from_framebuffer_config( display, &display->onscreen_template->config, cfg_attribs); edpy = egl_renderer->edpy; status = eglChooseConfig(edpy, cfg_attribs, &config, 1, &config_count); if (status != EGL_TRUE || config_count == 0) { error_message = "Unable to find a usable EGL configuration"; goto fail; } egl_display->egl_config = config; if (display->renderer->driver == CG_DRIVER_GL3) { if (!(egl_renderer->private_features & CG_EGL_WINSYS_FEATURE_CREATE_CONTEXT)) { error_message = "Driver does not support GL 3 contexts"; goto fail; } /* Try to get a core profile 3.1 context with no deprecated features */ attribs[0] = EGL_CONTEXT_MAJOR_VERSION_KHR; attribs[1] = 3; attribs[2] = EGL_CONTEXT_MINOR_VERSION_KHR; attribs[3] = 1; attribs[4] = EGL_CONTEXT_FLAGS_KHR; attribs[5] = EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; attribs[6] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR; attribs[7] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; attribs[8] = EGL_NONE; } else if (display->renderer->driver == CG_DRIVER_GLES2) { attribs[0] = EGL_CONTEXT_CLIENT_VERSION; attribs[1] = 2; attribs[2] = EGL_NONE; } else attribs[0] = EGL_NONE; egl_display->egl_context = eglCreateContext(edpy, config, EGL_NO_CONTEXT, attribs); if (egl_display->egl_context == EGL_NO_CONTEXT) { error_message = "Unable to create a suitable EGL context"; goto fail; } if (egl_renderer->platform_vtable->device_created && !egl_renderer->platform_vtable->device_created(display, error)) return false; return true; fail: _cg_set_error(error, CG_WINSYS_ERROR, CG_WINSYS_ERROR_CREATE_CONTEXT, "%s", error_message); cleanup_device(display); return false; }
static gboolean try_create_context (CoglDisplay *display, gboolean with_stencil_buffer, GError **error) { CoglRenderer *renderer = display->renderer; CoglDisplayEGL *egl_display = display->winsys; CoglRendererEGL *egl_renderer = renderer->winsys; EGLDisplay edpy; EGLConfig config; EGLint config_count = 0; EGLBoolean status; EGLint attribs[3]; EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS]; const char *error_message; _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context == NULL, TRUE); if (renderer->driver == COGL_DRIVER_GL) eglBindAPI (EGL_OPENGL_API); if (display->renderer->driver == COGL_DRIVER_GLES2) { attribs[0] = EGL_CONTEXT_CLIENT_VERSION; attribs[1] = 2; attribs[2] = EGL_NONE; } else attribs[0] = EGL_NONE; /* Divert to the platform implementation if one is defined */ if (egl_renderer->platform_vtable->try_create_context) return egl_renderer->platform_vtable-> try_create_context (display, attribs, error); egl_attributes_from_framebuffer_config (display, &display->onscreen_template->config, with_stencil_buffer, cfg_attribs); edpy = egl_renderer->edpy; status = eglChooseConfig (edpy, cfg_attribs, &config, 1, &config_count); if (status != EGL_TRUE || config_count == 0) { error_message = "Unable to find a usable EGL configuration"; goto fail; } egl_display->egl_config = config; egl_display->egl_context = eglCreateContext (edpy, config, EGL_NO_CONTEXT, attribs); if (egl_display->egl_context == EGL_NO_CONTEXT) { error_message = "Unable to create a suitable EGL context"; goto fail; } if (egl_renderer->platform_vtable->context_created && !egl_renderer->platform_vtable->context_created (display, error)) return FALSE; return TRUE; fail: g_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT, "%s", error_message); return FALSE; }