static void *osmesa_ctx_init(video_frame_info_t *video_info, void *video_driver) { #ifdef HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS const int attribs[] = { OSMESA_FORMAT, g_osmesa_format, OSMESA_DEPTH_BITS, 0, OSMESA_STENCIL_BITS, 0, OSMESA_ACCUM_BITS, 0, OSMESA_PROFILE, g_osmesa_profile, OSMESA_CONTEXT_MAJOR_VERSION, g_osmesa_major, OSMESA_CONTEXT_MINOR_VERSION, g_osmesa_minor, 0, 0 }; #endif gfx_ctx_osmesa_data_t *osmesa = (gfx_ctx_osmesa_data_t*) calloc(1, sizeof(gfx_ctx_osmesa_data_t)); if (!osmesa) goto error; #ifdef HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS osmesa->ctx = OSMesaCreateContextAttribs(attribs, NULL); #endif #ifdef HAVE_OSMESA_CREATE_CONTEXT_EXT if (!osmesa->ctx) osmesa->ctx = OSMesaCreateContextExt(g_osmesa_format, 0, 0, 0, NULL); #endif if (!osmesa->ctx) { #if defined(HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS) || defined(HAVE_OSMESA_CREATE_CONTEXT_EXT) RARCH_WARN("[osmesa]: Falling back to standard context creation.\n"); #endif osmesa->ctx = OSMesaCreateContext(g_osmesa_format, NULL); } if (!osmesa->ctx) goto error; osmesa->pixsize = g_osmesa_bpp; return osmesa; error: if (osmesa) free(osmesa); RARCH_WARN("[omesa]: Failed to initialize the context driver.\n"); return NULL; }
OSGLContext_osmesa::OSGLContext_osmesa(const FramebufferConfig& pixelFormatAttrs, int /*major*/, int /*minor*/, bool /*coreProfile*/, const GLRendererID& rendererID, const OSGLContext_osmesa* shareContex) : _imp(new OSGLContext_osmesaPrivate()) { GLenum format = GL_RGBA; int depthBits = pixelFormatAttrs.depthBits; int stencilBits = pixelFormatAttrs.stencilBits; int accumBits = pixelFormatAttrs.accumRedBits + pixelFormatAttrs.accumGreenBits + pixelFormatAttrs.accumBlueBits + pixelFormatAttrs.accumAlphaBits; /* Create an RGBA-mode context */ #if defined(OSMESA_GALLIUM_DRIVER) && (OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 1102) /* specify Z, stencil, accum sizes */ { int cpuDriver = rendererID.renderID; int attribs[100], n = 0; attribs[n++] = OSMESA_FORMAT; attribs[n++] = format; attribs[n++] = OSMESA_DEPTH_BITS; attribs[n++] = depthBits; attribs[n++] = OSMESA_STENCIL_BITS; attribs[n++] = stencilBits; attribs[n++] = OSMESA_ACCUM_BITS; attribs[n++] = accumBits; attribs[n++] = OSMESA_GALLIUM_DRIVER; attribs[n++] = (int)cpuDriver; attribs[n++] = 0; _imp->ctx = OSMesaCreateContextAttribs( attribs, shareContex ? shareContex->_imp->ctx : 0); } #else Q_UNUSED(rendererID); #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 /* specify Z, stencil, accum sizes */ _imp->ctx = OSMesaCreateContextExt( format, depthBits, stencilBits, accumBits, shareContex ? shareContex->_imp->ctx : 0); #else _imp->ctx = OSMesaCreateContext( format, shareContex ? shareContex->_imp->ctx : 0); #endif #endif if (!_imp->ctx) { throw std::runtime_error("OSMesaCreateContext failed"); } }
/** * New in Mesa 3.5 * * Create context and specify size of ancillary buffers. */ GLAPI OSMesaContext GLAPIENTRY OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist) { int attribs[100], n = 0; attribs[n++] = OSMESA_FORMAT; attribs[n++] = format; attribs[n++] = OSMESA_DEPTH_BITS; attribs[n++] = depthBits; attribs[n++] = OSMESA_STENCIL_BITS; attribs[n++] = stencilBits; attribs[n++] = OSMESA_ACCUM_BITS; attribs[n++] = accumBits; attribs[n++] = 0; return OSMesaCreateContextAttribs(attribs, sharelist); }
GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig) { OSMesaContext share = NULL; const int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits + fbconfig->accumBlueBits + fbconfig->accumAlphaBits; if (ctxconfig->client == GLFW_OPENGL_ES_API) { _glfwInputError(GLFW_API_UNAVAILABLE, "OSMesa: OpenGL ES is not available on OSMesa"); return GLFW_FALSE; } if (ctxconfig->share) share = ctxconfig->share->context.osmesa.handle; if (OSMesaCreateContextAttribs) { int index = 0, attribs[40]; setAttrib(OSMESA_FORMAT, OSMESA_RGBA); setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); setAttrib(OSMESA_ACCUM_BITS, accumBits); if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) { setAttrib(OSMESA_PROFILE, OSMESA_CORE_PROFILE); } else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) { setAttrib(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); } if (ctxconfig->major != 1 || ctxconfig->minor != 0) { setAttrib(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); setAttrib(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); } if (ctxconfig->forward) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "OSMesa: Foward-compatible contexts not supported"); return GLFW_FALSE; } setAttrib(0, 0); window->context.osmesa.handle = OSMesaCreateContextAttribs(attribs, share); } else { if (ctxconfig->profile) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "OSMesa: OpenGL profiles unavailable"); return GLFW_FALSE; } window->context.osmesa.handle = OSMesaCreateContextExt(OSMESA_RGBA, fbconfig->depthBits, fbconfig->stencilBits, accumBits, share); } if (window->context.osmesa.handle == NULL) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, "OSMesa: Failed to create context"); return GLFW_FALSE; } window->context.makeCurrent = makeContextCurrentOSMesa; window->context.swapBuffers = swapBuffersOSMesa; window->context.swapInterval = swapIntervalOSMesa; window->context.extensionSupported = extensionSupportedOSMesa; window->context.getProcAddress = getProcAddressOSMesa; window->context.destroy = destroyContextOSMesa; return GLFW_TRUE; }