static GLboolean dri_create_context(gl_api api, const struct gl_config * visual, __DRIcontext * cPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { struct dri_context *ctx = NULL; struct dri_context *share = (struct dri_context *)sharedContextPrivate; struct gl_context *mesaCtx = NULL; struct gl_context *sharedCtx = NULL; struct dd_function_table functions; TRACE; /* Flag filtering is handled in dri2CreateContextAttribs. */ (void) flags; if (api == API_OPENGL && (major_version > 2 || (major_version == 2 && minor_version > 1))) { *error = __DRI_CTX_ERROR_BAD_VERSION; goto context_fail; } ctx = CALLOC_STRUCT(dri_context); if (ctx == NULL) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } cPriv->driverPrivate = ctx; ctx->cPriv = cPriv; /* build table of device driver functions */ _mesa_init_driver_functions(&functions); swrast_init_driver_functions(&functions); if (share) { sharedCtx = &share->Base; } mesaCtx = &ctx->Base; /* basic context setup */ if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions, (void *) cPriv)) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } /* do bounds checking to prevent segfaults and server crashes! */ mesaCtx->Const.CheckArrayBounds = GL_TRUE; /* create module contexts */ _swrast_CreateContext( mesaCtx ); _vbo_CreateContext( mesaCtx ); _tnl_CreateContext( mesaCtx ); _swsetup_CreateContext( mesaCtx ); _swsetup_Wakeup( mesaCtx ); /* use default TCL pipeline */ { TNLcontext *tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; } _mesa_meta_init(mesaCtx); _mesa_enable_sw_extensions(mesaCtx); switch (api) { case API_OPENGL_CORE: /* XXX fix me, fall-through for now */ case API_OPENGL: _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); _mesa_enable_2_0_extensions(mesaCtx); _mesa_enable_2_1_extensions(mesaCtx); break; case API_OPENGLES: _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); break; case API_OPENGLES2: InitExtensionsES2( mesaCtx); break; } *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; context_fail: FREE(ctx); return GL_FALSE; }
static GLboolean dri_create_context(gl_api api, const struct gl_config * visual, __DRIcontext * cPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { struct dri_context *ctx = NULL; struct dri_context *share = (struct dri_context *)sharedContextPrivate; struct gl_context *mesaCtx = NULL; struct gl_context *sharedCtx = NULL; struct dd_function_table functions; TRACE; /* Flag filtering is handled in dri2CreateContextAttribs. */ (void) flags; ctx = CALLOC_STRUCT(dri_context); if (ctx == NULL) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } cPriv->driverPrivate = ctx; ctx->cPriv = cPriv; /* build table of device driver functions */ _mesa_init_driver_functions(&functions); swrast_init_driver_functions(&functions); if (share) { sharedCtx = &share->Base; } mesaCtx = &ctx->Base; /* basic context setup */ if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions)) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } /* do bounds checking to prevent segfaults and server crashes! */ mesaCtx->Const.CheckArrayBounds = GL_TRUE; /* create module contexts */ _swrast_CreateContext( mesaCtx ); _vbo_CreateContext( mesaCtx ); _tnl_CreateContext( mesaCtx ); _swsetup_CreateContext( mesaCtx ); _swsetup_Wakeup( mesaCtx ); /* use default TCL pipeline */ { TNLcontext *tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; } _mesa_meta_init(mesaCtx); _mesa_enable_sw_extensions(mesaCtx); _mesa_compute_version(mesaCtx); _mesa_initialize_dispatch_tables(mesaCtx); _mesa_initialize_vbo_vtxfmt(mesaCtx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; context_fail: free(ctx); return GL_FALSE; }
MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView* view, ulong options, BGLDispatcher* dispatcher) : BGLRenderer(view, options, dispatcher), fBitmap(NULL), fDirectModeEnabled(false), fInfo(NULL), fInfoLocker("info locker"), fContext(NULL), fVisual(NULL), fFrameBuffer(NULL), fFrontRenderBuffer(NULL), fBackRenderBuffer(NULL), fColorSpace(B_NO_COLOR_SPACE) { CALLED(); fClearColor[BE_RCOMP] = 0; fClearColor[BE_GCOMP] = 0; fClearColor[BE_BCOMP] = 0; fClearColor[BE_ACOMP] = 0; fClearIndex = 0; fColorSpace = BScreen(GLView()->Window()).ColorSpace(); // We force single buffering for the time being //options &= !BGL_DOUBLE; const GLboolean rgbFlag = ((options & BGL_INDEX) == 0); const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA); const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE); const GLboolean stereoFlag = false; const GLint depth = (options & BGL_DEPTH) ? 16 : 0; const GLint stencil = (options & BGL_STENCIL) ? 8 : 0; const GLint accum = (options & BGL_ACCUM) ? 16 : 0; const GLint index = (options & BGL_INDEX) ? 32 : 0; const GLint red = rgbFlag ? 8 : 0; const GLint green = rgbFlag ? 8 : 0; const GLint blue = rgbFlag ? 8 : 0; const GLint alpha = alphaFlag ? 8 : 0; fOptions = options; // | BGL_INDIRECT; struct dd_function_table functions; fVisual = _mesa_create_visual(rgbFlag, dblFlag, stereoFlag, red, green, blue, alpha, index, depth, stencil, accum, accum, accum, alpha ? accum : 0, 1); // Initialize device driver function table _mesa_init_driver_functions(&functions); functions.GetString = _GetString; functions.UpdateState = _UpdateState; functions.GetBufferSize = NULL; functions.Error = _Error; functions.Viewport = _Viewport; functions.Flush = _Flush; // create core context fContext = _mesa_create_context(fVisual, NULL, &functions, this); if (!fContext) { _mesa_destroy_visual(fVisual); return; } /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext(fContext); _vbo_CreateContext(fContext); _tnl_CreateContext(fContext); _swsetup_CreateContext(fContext); _swsetup_Wakeup(fContext); // Use default TCL pipeline TNL_CONTEXT(fContext)->Driver.RunPipeline = _tnl_run_pipeline; _mesa_enable_sw_extensions(fContext); _mesa_enable_1_3_extensions(fContext); _mesa_enable_1_4_extensions(fContext); _mesa_enable_1_5_extensions(fContext); _mesa_enable_2_0_extensions(fContext); _mesa_enable_2_1_extensions(fContext); // create core framebuffer fFrameBuffer = (struct msr_framebuffer*)_mesa_calloc( sizeof(*fFrameBuffer)); _mesa_initialize_framebuffer(&fFrameBuffer->Base, fVisual); fFrontRenderBuffer = (struct msr_renderbuffer*)_mesa_calloc( sizeof(*fFrontRenderBuffer)); _mesa_init_renderbuffer(&fFrontRenderBuffer->Base, 0); fFrontRenderBuffer->Base.AllocStorage = _FrontRenderbufferStorage; fFrontRenderBuffer->Base.Data = NULL; fFrontRenderBuffer->Base.InternalFormat = GL_RGBA; fFrontRenderBuffer->Base._BaseFormat = GL_RGBA; fFrontRenderBuffer->Base.DataType = GL_UNSIGNED_BYTE; fFrontRenderBuffer->Base.RedBits = 8 * sizeof(GLubyte); fFrontRenderBuffer->Base.GreenBits = 8 * sizeof(GLubyte); fFrontRenderBuffer->Base.BlueBits = 8 * sizeof(GLubyte); fFrontRenderBuffer->Base.AlphaBits = 8 * sizeof(GLubyte); _SetSpanFuncs(fFrontRenderBuffer, fColorSpace); _mesa_add_renderbuffer(&fFrameBuffer->Base, BUFFER_FRONT_LEFT, &fFrontRenderBuffer->Base); if (dblFlag) { fBackRenderBuffer = (struct msr_renderbuffer*)_mesa_calloc( sizeof(*fBackRenderBuffer)); _mesa_init_renderbuffer(&fBackRenderBuffer->Base, 0); fBackRenderBuffer->Base.AllocStorage = _BackRenderbufferStorage; fBackRenderBuffer->Base.Data = NULL; fBackRenderBuffer->Base.Delete = _DeleteBackBuffer; fBackRenderBuffer->Base.InternalFormat = GL_RGBA; fBackRenderBuffer->Base._BaseFormat = GL_RGBA; fBackRenderBuffer->Base.DataType = GL_UNSIGNED_BYTE; fBackRenderBuffer->Base.RedBits = 8 * sizeof(GLubyte); fBackRenderBuffer->Base.GreenBits = 8 * sizeof(GLubyte); fBackRenderBuffer->Base.BlueBits = 8 * sizeof(GLubyte); fBackRenderBuffer->Base.AlphaBits = 8 * sizeof(GLubyte); _SetSpanFuncs(fBackRenderBuffer, fColorSpace); _mesa_add_renderbuffer(&fFrameBuffer->Base, BUFFER_BACK_LEFT, &fBackRenderBuffer->Base); } _mesa_add_soft_renderbuffers(&fFrameBuffer->Base, GL_FALSE, fVisual->haveDepthBuffer, fVisual->haveStencilBuffer, fVisual->haveAccumBuffer, alphaFlag, GL_FALSE); BRect bounds = view->Bounds(); fWidth = fNewWidth = (GLint)bounds.Width(); fHeight = fNewHeight = (GLint)bounds.Height(); // some stupid applications (Quake2) don't even think about calling LockGL() // before using glGetString and its glGet*() friends... // so make sure there is at least a valid context. if (!_mesa_get_current_context()) { LockGL(); // not needed, we don't have a looper yet: UnlockLooper(); } }