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); }
void swapchain_destroy(swapchain_t swapchain) { if (!swapchain) return; if (swapchain->device->cur_swap == swapchain) device_load_swapchain(swapchain->device, NULL); gl_windowinfo_destroy(swapchain->wi); bfree(swapchain); }
void gl_platform_destroy(struct gl_platform *platform) { if (!platform) return; glXMakeCurrent(platform->swap.wi->display, None, NULL); glXDestroyContext(platform->swap.wi->display, platform->context); XCloseDisplay(platform->swap.wi->display); gl_windowinfo_destroy(platform->swap.wi); bfree(platform); }
void gl_platform_destroy(struct gl_platform *plat) { if (plat) { if (plat->hrc) { wglMakeCurrent(NULL, NULL); wglDeleteContext(plat->hrc); } gl_windowinfo_destroy(plat->swap.wi); bfree(plat); } }
void gl_platform_destroy(struct gl_platform *platform) { if (!platform) return; Display *dpy = platform->swap.wi->display; glXMakeCurrent(dpy, None, NULL); glXDestroyContext(dpy, platform->context); gl_windowinfo_destroy(platform->swap.wi); gl_platform_cleanup_swapchain(&platform->swap); bfree(platform); }
void gs_swapchain_destroy(gs_swapchain_t *swapchain) { if (!swapchain) return; if (swapchain->device->cur_swap == swapchain) device_load_swapchain(swapchain->device, NULL); gl_platform_cleanup_swapchain(swapchain); gl_windowinfo_destroy(swapchain->wi); bfree(swapchain); }
struct gl_windowinfo *gl_windowinfo_create(struct gs_init_data *info) { struct gl_windowinfo *wi = gl_windowinfo_bare(info); PIXELFORMATDESCRIPTOR pfd; int pixel_format; if (!wi) return NULL; if (!gl_getpixelformat(wi->hdc, info, &pixel_format, &pfd)) goto fail; if (!gl_setpixelformat(wi->hdc, pixel_format, &pfd)) goto fail; return wi; fail: blog(LOG_ERROR, "gl_windowinfo_create failed"); gl_windowinfo_destroy(wi); return NULL; }
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; }