From 50ce9dc871d6f0e8524aebf4f8e7ec430209273f Mon Sep 17 00:00:00 2001 From: Bastien Date: Fri, 21 Sep 2018 13:05:42 +0200 Subject: [PATCH] Update Mirror Window context creation --- examples/opengl/gl.c | 89 +++----------------------------------------- 1 file changed, 5 insertions(+), 84 deletions(-) diff --git a/examples/opengl/gl.c b/examples/opengl/gl.c index e0a1426..076ef65 100644 --- a/examples/opengl/gl.c +++ b/examples/opengl/gl.c @@ -17,6 +17,8 @@ #include +#include "context.inl" + #ifdef __unix #include #endif @@ -118,82 +120,6 @@ static const EGLint egl_surface_attribs[] = { EGL_NONE, }; -void CreateContext( - EGLint api, - EGLNativeWindowType native_window, - EGLDisplay* out_display, - EGLConfig* out_config, - EGLContext* out_context, - EGLSurface* out_window_surface) { - - EGLint ignore; - EGLBoolean ok; - - ok = eglBindAPI(api); - if (!ok) - exit(-1); - - EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (display == EGL_NO_DISPLAY) - exit(-1); - - ok = eglInitialize(display, &ignore, &ignore); - if (!ok) - exit(-1); - - EGLint configs_size = 256; - EGLConfig configs [configs_size]; - EGLint num_configs; - ok = eglChooseConfig( - display, - egl_config_attribs, - configs, - configs_size, // num requested configs - &num_configs); // num returned configs - if (!ok) - exit(-1); - if (num_configs == 0) - exit(-1); - EGLConfig config = configs[0]; - - EGLContext context = eglCreateContext( - display, - config, - EGL_NO_CONTEXT, // can't share between 2 different drivers - egl_context_attribs); - if (!context) - exit(-1); - - EGLSurface surface = eglCreateWindowSurface( - display, - config, - native_window, - egl_surface_attribs); - if (!surface) - exit(-1); - - ok = eglMakeCurrent(display, surface, surface, context); - if (!ok) - exit(-1); - - // Check if surface is double buffered. - EGLint render_buffer; - ok = eglQueryContext( - display, - context, - EGL_RENDER_BUFFER, - &render_buffer); - if (!ok) - exit(-1); - if (render_buffer == EGL_SINGLE_BUFFER) - printf("warn: EGL surface is single buffered\n"); - - *out_display = display; - *out_config = config; - *out_context = context; - *out_window_surface = surface; -} - void init_gl(gl_ctx* ctx, int w, int h) { memset(ctx, 0, sizeof(gl_ctx)); @@ -217,16 +143,11 @@ void init_gl(gl_ctx* ctx, int w, int h) ctx->h = h; ctx->is_fullscreen = 0; - CreateContext(EGL_OPENGL_API, - ctx->x_window, - &ctx->egl_display, - &ctx->egl_config, - &ctx->egl_context, - &ctx->egl_surface); + bool bContextCreated = create_context(EGL_DEFAULT_DISPLAY, ctx->x_window, egl_config_attribs, egl_context_attribs, egl_surface_attribs, &ctx->egl_display, &ctx->egl_context, &ctx->egl_surface); - if(ctx->egl_context == EGL_NO_CONTEXT) + if(!bContextCreated || ctx->egl_context == EGL_NO_CONTEXT) { - printf("CreateContext\n"); + printf("CreateContext failed\n"); exit(-1); }