extern void gl_platform_destroy(struct gl_platform *plat) { if (!plat) /* In what case would platform be invalid here? */ return; gl_context_destroy(plat); }
extern void gl_platform_destroy(struct gl_platform *plat) { if (!plat) /* In what case would platform be invalid here? */ return; struct gl_windowinfo *wi = plat->swap.wi; gl_context_destroy(plat); gl_windowinfo_destroy(wi); }
extern struct gl_platform *gl_platform_create(gs_device_t *device, uint32_t adapter) { /* There's some trickery here... we're mixing libX11, xcb, and GLX For an explanation see here: http://xcb.freedesktop.org/MixingCalls/ Essentially, GLX requires Xlib. Everything else we use xcb. */ struct gl_platform * plat = bmalloc(sizeof(struct gl_platform)); Display * display = open_windowless_display(); if (!display) { goto fail_display_open; } XSetEventQueueOwner(display, XCBOwnsEventQueue); XSetErrorHandler(x_error_handler); /* We assume later that cur_swap is already set. */ device->plat = plat; plat->display = display; if (!gl_context_create(plat)) { blog(LOG_ERROR, "Failed to create context!"); goto fail_context_create; } if (!glXMakeContextCurrent(plat->display, plat->pbuffer, plat->pbuffer, plat->context)) { blog(LOG_ERROR, "Failed to make context current."); goto fail_make_current; } if (!gladLoadGL()) { blog(LOG_ERROR, "Failed to load OpenGL entry functions."); goto fail_load_gl; } blog(LOG_INFO, "OpenGL version: %s\n", glGetString(GL_VERSION)); goto success; fail_make_current: gl_context_destroy(plat); fail_context_create: fail_load_gl: XCloseDisplay(display); fail_display_open: bfree(plat); plat = NULL; success: UNUSED_PARAMETER(adapter); return plat; }
extern struct gl_platform *gl_platform_create(gs_device_t *device, const struct gs_init_data *info) { /* There's some trickery here... we're mixing libX11, xcb, and GLX For an explanation see here: http://xcb.freedesktop.org/MixingCalls/ Essentially, GLX requires Xlib. Everything else we use xcb. */ struct gl_windowinfo *wi = gl_windowinfo_create(info); struct gl_platform * plat = bmalloc(sizeof(struct gl_platform)); Display * display; print_info_stuff(info); if (!wi) { blog(LOG_ERROR, "Failed to create window info!"); goto fail_wi_create; } display = XOpenDisplay(XDisplayString(info->window.display)); if (!display) { blog(LOG_ERROR, "Unable to open new X connection!"); goto fail_display_open; } XSetEventQueueOwner(display, XCBOwnsEventQueue); XSetErrorHandler(x_error_handler); /* We assume later that cur_swap is already set. */ device->cur_swap = &plat->swap; device->plat = plat; plat->display = display; plat->swap.device = device; plat->swap.info = *info; plat->swap.wi = wi; if (!gl_platform_init_swapchain(&plat->swap)) { blog(LOG_ERROR, "Failed to initialize swap chain!"); goto fail_init_swapchain; } if (!gl_context_create(plat)) { blog(LOG_ERROR, "Failed to create context!"); goto fail_context_create; } if (!glXMakeCurrent(plat->display, wi->window, plat->context)) { blog(LOG_ERROR, "Failed to make context current."); goto fail_make_current; } if (!gladLoadGL()) { blog(LOG_ERROR, "Failed to load OpenGL entry functions."); goto fail_load_gl; } blog(LOG_INFO, "OpenGL version: %s\n", glGetString(GL_VERSION)); goto success; fail_make_current: gl_context_destroy(plat); fail_context_create: fail_load_gl: fail_init_swapchain: XCloseDisplay(display); fail_display_open: fail_wi_create: gl_windowinfo_destroy(wi); free(plat); plat = NULL; success: return plat; }