device_t device_create(struct gs_init_data *info) { struct gs_device *device = bmalloc(sizeof(struct gs_device)); memset(device, 0, sizeof(struct gs_device)); device->plat = gl_platform_create(device, info); if (!device->plat) goto fail; if (!gl_init_extensions(device)) goto fail; gl_enable(GL_CULL_FACE); glGenProgramPipelines(1, &device->pipeline); if (!gl_success("glGenProgramPipelines")) goto fail; glBindProgramPipeline(device->pipeline); if (!gl_success("glBindProgramPipeline")) goto fail; device_leavecontext(device); device->cur_swap = gl_platform_getswap(device->plat); return device; fail: blog(LOG_ERROR, "device_create (GL) failed"); bfree(device); return NULL; }
int device_create(gs_device_t **p_device, uint32_t adapter) { struct gs_device *device = bzalloc(sizeof(struct gs_device)); int errorcode = GS_ERROR_FAIL; device->plat = gl_platform_create(device, adapter); if (!device->plat) goto fail; if (!gl_init_extensions(device)) { errorcode = GS_ERROR_NOT_SUPPORTED; goto fail; } gl_enable(GL_CULL_FACE); device_leave_context(device); device->cur_swap = NULL; *p_device = device; return GS_SUCCESS; fail: blog(LOG_ERROR, "device_create (GL) failed"); bfree(device); *p_device = NULL; return errorcode; }
struct gl_platform *gl_platform_create(device_t device, struct gs_init_data *info) { struct gl_platform *plat = bmalloc(sizeof(struct gl_platform)); struct dummy_context dummy; int pixel_format; PIXELFORMATDESCRIPTOR pfd; memset(plat, 0, sizeof(struct gl_platform)); memset(&dummy, 0, sizeof(struct dummy_context)); if (!gl_dummy_context_init(&dummy)) goto fail; if (!gl_init_extensions(device)) goto fail; /* you have to have a dummy context open before you can actually * use wglChoosePixelFormatARB */ if (!gl_getpixelformat(dummy.hdc, info, &pixel_format, &pfd)) goto fail; gl_dummy_context_free(&dummy); if (!init_default_swap(plat, device, pixel_format, &pfd, info)) goto fail; plat->hrc = gl_init_context(plat->swap.wi->hdc); if (!plat->hrc) goto fail; if (GLEW_ARB_seamless_cube_map) { glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); gl_success("GL_TEXTURE_CUBE_MAP_SEAMLESS"); } #ifdef _DEBUG if (GLEW_AMD_debug_output) { glDebugMessageEnableAMD(0, 0, 0, NULL, true); glDebugMessageCallbackAMD(gl_debug_message_amd, device); gl_success("glDebugMessageCallback"); } #endif return plat; fail: blog(LOG_ERROR, "gl_platform_create failed"); gl_platform_destroy(plat); gl_dummy_context_free(&dummy); return NULL; }
struct gl_platform *gl_platform_create(gs_device_t *device, uint32_t adapter) { struct gl_platform *plat = bzalloc(sizeof(struct gl_platform)); struct dummy_context dummy; struct gs_init_data info = {0}; int pixel_format; PIXELFORMATDESCRIPTOR pfd; memset(&dummy, 0, sizeof(struct dummy_context)); init_dummy_swap_info(&info); if (!gl_dummy_context_init(&dummy)) goto fail; if (!gl_init_extensions(dummy.hdc)) goto fail; if (!register_dummy_class()) return false; if (!create_dummy_window(plat)) return false; /* you have to have a dummy context open before you can actually * use wglChoosePixelFormatARB */ if (!gl_getpixelformat(dummy.hdc, &info, &pixel_format, &pfd)) goto fail; gl_dummy_context_free(&dummy); if (!init_default_swap(plat, device, pixel_format, &pfd)) goto fail; plat->hrc = gl_init_context(plat->window.hdc); if (!plat->hrc) goto fail; if (!gladLoadGL()) { blog(LOG_ERROR, "Failed to initialize OpenGL entry functions."); goto fail; } UNUSED_PARAMETER(adapter); return plat; fail: blog(LOG_ERROR, "gl_platform_create failed"); gl_platform_destroy(plat); gl_dummy_context_free(&dummy); return NULL; }
struct gl_platform *gl_platform_create(device_t device, struct gs_init_data *info) { struct gl_platform *plat = bmalloc(sizeof(struct gl_platform)); struct dummy_context dummy; int pixel_format; PIXELFORMATDESCRIPTOR pfd; memset(plat, 0, sizeof(struct gl_platform)); memset(&dummy, 0, sizeof(struct dummy_context)); if (!gl_dummy_context_init(&dummy)) goto fail; if (!gl_init_extensions(dummy.hdc)) goto fail; /* you have to have a dummy context open before you can actually * use wglChoosePixelFormatARB */ if (!gl_getpixelformat(dummy.hdc, info, &pixel_format, &pfd)) goto fail; gl_dummy_context_free(&dummy); if (!init_default_swap(plat, device, pixel_format, &pfd, info)) goto fail; plat->hrc = gl_init_context(plat->swap.wi->hdc); if (!plat->hrc) goto fail; if (!ogl_LoadFunctions()) { blog(LOG_ERROR, "Failed to initialize OpenGL entry functions."); goto fail; } return plat; fail: blog(LOG_ERROR, "gl_platform_create failed"); gl_platform_destroy(plat); gl_dummy_context_free(&dummy); return NULL; }
int device_create(gs_device_t *p_device, struct gs_init_data *info) { struct gs_device *device = bzalloc(sizeof(struct gs_device)); int errorcode = GS_ERROR_FAIL; device->plat = gl_platform_create(device, info); if (!device->plat) goto fail; if (!gl_init_extensions(device)) { errorcode = GS_ERROR_NOT_SUPPORTED; goto fail; } gl_enable(GL_CULL_FACE); glGenProgramPipelines(1, &device->pipeline); if (!gl_success("glGenProgramPipelines")) goto fail; glBindProgramPipeline(device->pipeline); if (!gl_success("glBindProgramPipeline")) goto fail; device_leave_context(device); device->cur_swap = gl_platform_getswap(device->plat); *p_device = device; return GS_SUCCESS; fail: blog(LOG_ERROR, "device_create (GL) failed"); bfree(device); *p_device = NULL; return errorcode; }