⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 via_context.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
    /* Parse configuration files.     */    driParseConfigFiles (&vmesa->optionCache, &viaScreen->optionCache,			 sPriv->myNum, "unichrome");    /* pick back buffer */    vmesa->hasBack = visual->doubleBufferMode;    switch(visual->depthBits) {    case 0:			       vmesa->hasDepth = GL_FALSE;       vmesa->depthBits = 0;        vmesa->depth_max = 1.0;       break;    case 16:       vmesa->hasDepth = GL_TRUE;       vmesa->depthBits = visual->depthBits;       vmesa->have_hw_stencil = GL_FALSE;       vmesa->depth_max = (GLfloat)0xffff;       vmesa->depth_clear_mask = 0xf << 28;       vmesa->ClearDepth = 0xffff;       vmesa->polygon_offset_scale = 1.0 / vmesa->depth_max;       break;    case 24:       vmesa->hasDepth = GL_TRUE;       vmesa->depthBits = visual->depthBits;       vmesa->depth_max = (GLfloat) 0xffffff;       vmesa->depth_clear_mask = 0xe << 28;       vmesa->ClearDepth = 0xffffff00;       assert(visual->haveStencilBuffer);       assert(visual->stencilBits == 8);       vmesa->have_hw_stencil = GL_TRUE;       vmesa->stencilBits = visual->stencilBits;       vmesa->stencil_clear_mask = 0x1 << 28;       vmesa->polygon_offset_scale = 2.0 / vmesa->depth_max;       break;    case 32:       vmesa->hasDepth = GL_TRUE;       vmesa->depthBits = visual->depthBits;       assert(!visual->haveStencilBuffer);       vmesa->have_hw_stencil = GL_FALSE;       vmesa->depth_max = (GLfloat)0xffffffff;       vmesa->depth_clear_mask = 0xf << 28;       vmesa->ClearDepth = 0xffffffff;       vmesa->polygon_offset_scale = 2.0 / vmesa->depth_max;       break;    default:       assert(0);        break;    }    make_empty_list(&vmesa->freed_tex_buffers);    make_empty_list(&vmesa->tex_image_list[VIA_MEM_VIDEO]);    make_empty_list(&vmesa->tex_image_list[VIA_MEM_AGP]);    make_empty_list(&vmesa->tex_image_list[VIA_MEM_SYSTEM]);    _mesa_init_driver_functions(&functions);    viaInitTextureFuncs(&functions);    /* Allocate the Mesa context */    if (sharedContextPrivate)        shareCtx = ((struct via_context *) sharedContextPrivate)->glCtx;    else        shareCtx = NULL;    vmesa->glCtx = _mesa_create_context(visual, shareCtx, &functions,					(void*) vmesa);        vmesa->shareCtx = shareCtx;        if (!vmesa->glCtx) {        FREE(vmesa);        return GL_FALSE;    }    driContextPriv->driverPrivate = vmesa;    ctx = vmesa->glCtx;    if (driQueryOptionb(&vmesa->optionCache, "excess_mipmap"))        ctx->Const.MaxTextureLevels = 11;    else        ctx->Const.MaxTextureLevels = 10;    ctx->Const.MaxTextureUnits = 2;    ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;    ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;    ctx->Const.MinLineWidth = 1.0;    ctx->Const.MinLineWidthAA = 1.0;    ctx->Const.MaxLineWidth = 1.0;    ctx->Const.MaxLineWidthAA = 1.0;    ctx->Const.LineWidthGranularity = 1.0;    ctx->Const.MinPointSize = 1.0;    ctx->Const.MinPointSizeAA = 1.0;    ctx->Const.MaxPointSize = 1.0;    ctx->Const.MaxPointSizeAA = 1.0;    ctx->Const.PointSizeGranularity = 1.0;    ctx->Driver.GetString = viaGetString;    ctx->DriverCtx = (void *)vmesa;    vmesa->glCtx = ctx;    /* Initialize the software rasterizer and helper modules.     */    _swrast_CreateContext(ctx);    _vbo_CreateContext(ctx);    _tnl_CreateContext(ctx);    _swsetup_CreateContext(ctx);    /* Install the customized pipeline:     */    _tnl_destroy_pipeline(ctx);    _tnl_install_pipeline(ctx, via_pipeline);    /* Configure swrast and T&L to match hardware characteristics:     */    _swrast_allow_pixel_fog(ctx, GL_FALSE);    _swrast_allow_vertex_fog(ctx, GL_TRUE);    _tnl_allow_pixel_fog(ctx, GL_FALSE);    _tnl_allow_vertex_fog(ctx, GL_TRUE);    vmesa->hHWContext = driContextPriv->hHWContext;    vmesa->driFd = sPriv->fd;    vmesa->driHwLock = &sPriv->pSAREA->lock;    vmesa->viaScreen = viaScreen;    vmesa->driScreen = sPriv;    vmesa->sarea = saPriv;    vmesa->renderIndex = ~0;    vmesa->setupIndex = ~0;    vmesa->hwPrimitive = GL_POLYGON+1;    /* KW: Hardwire this.  Was previously set bogusly in     * viaCreateBuffer.  Needs work before PBUFFER can be used:     */    vmesa->drawType = GLX_WINDOW_BIT;    _math_matrix_ctr(&vmesa->ViewportMatrix);    /* Do this early, before VIA_FLUSH_DMA can be called:     */    if (!AllocateDmaBuffer(vmesa)) {	fprintf(stderr ,"AllocateDmaBuffer fail\n");	FreeBuffer(vmesa);        FREE(vmesa);        return GL_FALSE;    }    /* Allocate a small piece of fb memory for synchronization:     */    vmesa->breadcrumb.bpp = 32;    vmesa->breadcrumb.pitch = buffer_align( 64 ) << 2;    vmesa->breadcrumb.size = vmesa->breadcrumb.pitch;    if (!via_alloc_draw_buffer(vmesa, &vmesa->breadcrumb)) {        fprintf(stderr ,"AllocateDmaBuffer fail\n");        FreeBuffer(vmesa);        FREE(vmesa);        return GL_FALSE;    }    driInitExtensions( ctx, card_extensions, GL_TRUE );    viaInitStateFuncs(ctx);    viaInitTriFuncs(ctx);    viaInitSpanFuncs(ctx);    viaInitIoctlFuncs(ctx);    viaInitState(ctx);            if (getenv("VIA_DEBUG"))       VIA_DEBUG = driParseDebugString( getenv( "VIA_DEBUG" ),					debug_control );    if (getenv("VIA_NO_RAST") ||        driQueryOptionb(&vmesa->optionCache, "no_rast"))       FALLBACK(vmesa, VIA_FALLBACK_USER_DISABLE, 1);    if (getenv("VIA_PAGEFLIP"))       vmesa->allowPageFlip = 1;    (*sPriv->systemTime->getUST)( &vmesa->swap_ust );    vmesa->regMMIOBase = (GLuint *)((unsigned long)viaScreen->reg);    vmesa->pnGEMode = (GLuint *)((unsigned long)viaScreen->reg + 0x4);    vmesa->regEngineStatus = (GLuint *)((unsigned long)viaScreen->reg + 0x400);    vmesa->regTranSet = (GLuint *)((unsigned long)viaScreen->reg + 0x43C);    vmesa->regTranSpace = (GLuint *)((unsigned long)viaScreen->reg + 0x440);    vmesa->agpBase = viaScreen->agpBase;    return GL_TRUE;}voidviaDestroyContext(__DRIcontextPrivate *driContextPriv){    GET_CURRENT_CONTEXT(ctx);    struct via_context *vmesa =       (struct via_context *)driContextPriv->driverPrivate;    struct via_context *current = ctx ? VIA_CONTEXT(ctx) : NULL;    assert(vmesa); /* should never be null */    if (vmesa->driDrawable) {       viaWaitIdle(vmesa, GL_FALSE);       if (vmesa->doPageFlip) {	  LOCK_HARDWARE(vmesa);	  if (vmesa->pfCurrentOffset != 0) {	     fprintf(stderr, "%s - reset pf\n", __FUNCTION__);	     viaResetPageFlippingLocked(vmesa);	  }	  UNLOCK_HARDWARE(vmesa);       }    }    /* check if we're deleting the currently bound context */    if (vmesa == current) {      VIA_FLUSH_DMA(vmesa);      _mesa_make_current(NULL, NULL, NULL);    }    _swsetup_DestroyContext(vmesa->glCtx);    _tnl_DestroyContext(vmesa->glCtx);    _vbo_DestroyContext(vmesa->glCtx);    _swrast_DestroyContext(vmesa->glCtx);    /* free the Mesa context */    _mesa_destroy_context(vmesa->glCtx);    /* release our data */    FreeBuffer(vmesa);    assert (is_empty_list(&vmesa->tex_image_list[VIA_MEM_AGP]));    assert (is_empty_list(&vmesa->tex_image_list[VIA_MEM_VIDEO]));    assert (is_empty_list(&vmesa->tex_image_list[VIA_MEM_SYSTEM]));    assert (is_empty_list(&vmesa->freed_tex_buffers));    driDestroyOptionCache(&vmesa->optionCache);    FREE(vmesa);}void viaXMesaWindowMoved(struct via_context *vmesa){   __DRIdrawablePrivate *const drawable = vmesa->driDrawable;   __DRIdrawablePrivate *const readable = vmesa->driReadable;   struct via_renderbuffer * draw_buffer;   struct via_renderbuffer * read_buffer;   GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;   if (!drawable)      return;   draw_buffer =  (struct via_renderbuffer *) drawable->driverPrivate;   read_buffer =  (struct via_renderbuffer *) readable->driverPrivate;      switch (vmesa->glCtx->DrawBuffer->_ColorDrawBufferIndexes[0]) {   case BUFFER_BACK_LEFT:       if (drawable->numBackClipRects == 0) {	 vmesa->numClipRects = drawable->numClipRects;	 vmesa->pClipRects = drawable->pClipRects;      }       else {	 vmesa->numClipRects = drawable->numBackClipRects;	 vmesa->pClipRects = drawable->pBackClipRects;      }      break;   case BUFFER_FRONT_LEFT:      vmesa->numClipRects = drawable->numClipRects;      vmesa->pClipRects = drawable->pClipRects;      break;   default:      vmesa->numClipRects = 0;      break;   }   if ((draw_buffer->drawW != drawable->w)        || (draw_buffer->drawH != drawable->h)) {      calculate_buffer_parameters(vmesa, vmesa->glCtx->DrawBuffer,				  drawable);   }   draw_buffer->drawX = drawable->x;   draw_buffer->drawY = drawable->y;   draw_buffer->drawW = drawable->w;   draw_buffer->drawH = drawable->h;   if (drawable != readable) {      if ((read_buffer->drawW != readable->w) 	  || (read_buffer->drawH != readable->h)) {	 calculate_buffer_parameters(vmesa, vmesa->glCtx->ReadBuffer,				     readable);      }      read_buffer->drawX = readable->x;      read_buffer->drawY = readable->y;      read_buffer->drawW = readable->w;      read_buffer->drawH = readable->h;   }   vmesa->front.orig = (vmesa->front.offset + 			draw_buffer->drawY * vmesa->front.pitch + 			draw_buffer->drawX * bytePerPixel);   vmesa->front.origMap = (vmesa->front.map + 			draw_buffer->drawY * vmesa->front.pitch + 			draw_buffer->drawX * bytePerPixel);   vmesa->back.orig = (vmesa->back.offset +			draw_buffer->drawY * vmesa->back.pitch +			draw_buffer->drawX * bytePerPixel);   vmesa->back.origMap = (vmesa->back.map +			draw_buffer->drawY * vmesa->back.pitch +			draw_buffer->drawX * bytePerPixel);   vmesa->depth.orig = (vmesa->depth.offset +			draw_buffer->drawY * vmesa->depth.pitch +			draw_buffer->drawX * bytePerPixel);      vmesa->depth.origMap = (vmesa->depth.map +			draw_buffer->drawY * vmesa->depth.pitch +			draw_buffer->drawX * bytePerPixel);   viaCalcViewport(vmesa->glCtx);}GLbooleanviaUnbindContext(__DRIcontextPrivate *driContextPriv){    return GL_TRUE;}GLbooleanviaMakeCurrent(__DRIcontextPrivate *driContextPriv,               __DRIdrawablePrivate *driDrawPriv,               __DRIdrawablePrivate *driReadPriv){    if (VIA_DEBUG & DEBUG_DRI) {	fprintf(stderr, "driContextPriv = %016lx\n", (unsigned long)driContextPriv);	fprintf(stderr, "driDrawPriv = %016lx\n", (unsigned long)driDrawPriv);    	fprintf(stderr, "driReadPriv = %016lx\n", (unsigned long)driReadPriv);    }	    if (driContextPriv) {        struct via_context *vmesa = 	   (struct via_context *)driContextPriv->driverPrivate;	GLcontext *ctx = vmesa->glCtx;        struct gl_framebuffer *drawBuffer, *readBuffer;        drawBuffer = (GLframebuffer *)driDrawPriv->driverPrivate;        readBuffer = (GLframebuffer *)driReadPriv->driverPrivate;       if ((vmesa->driDrawable != driDrawPriv)	   || (vmesa->driReadable != driReadPriv)) {	  if (driDrawPriv->swap_interval == (unsigned)-1) {	     driDrawPriv->vblFlags =		vmesa->viaScreen->irqEnabled ?		driGetDefaultVBlankFlags(&vmesa->optionCache) :		VBLANK_FLAG_NO_IRQ;	     driDrawableInitVBlank(driDrawPriv);	  }	  vmesa->driDrawable = driDrawPriv;	  vmesa->driReadable = driReadPriv;	  if ((drawBuffer->Width != driDrawPriv->w) 	      || (drawBuffer->Height != driDrawPriv->h)) {	     _mesa_resize_framebuffer(ctx, drawBuffer,				      driDrawPriv->w, driDrawPriv->h);	     drawBuffer->Initialized = GL_TRUE;	  }	  if (!calculate_buffer_parameters(vmesa, drawBuffer, driDrawPriv)) {	     return GL_FALSE;	  }	  if (driDrawPriv != driReadPriv) {	     if ((readBuffer->Width != driReadPriv->w)		 || (readBuffer->Height != driReadPriv->h)) {		_mesa_resize_framebuffer(ctx, readBuffer,					 driReadPriv->w, driReadPriv->h);		readBuffer->Initialized = GL_TRUE;	     }	     if (!calculate_buffer_parameters(vmesa, readBuffer, driReadPriv)) {		return GL_FALSE;	     }	  }       }        _mesa_make_current(vmesa->glCtx, drawBuffer, readBuffer);	ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] );	           viaXMesaWindowMoved(vmesa);	ctx->Driver.Scissor(vmesa->glCtx,			    vmesa->glCtx->Scissor.X,			    vmesa->glCtx->Scissor.Y,			    vmesa->glCtx->Scissor.Width,			    vmesa->glCtx->Scissor.Height);    }    else {        _mesa_make_current(NULL, NULL, NULL);    }            return GL_TRUE;}void viaGetLock(struct via_context *vmesa, GLuint flags){    __DRIdrawablePrivate *dPriv = vmesa->driDrawable;    __DRIscreenPrivate *sPriv = vmesa->driScreen;    drmGetLock(vmesa->driFd, vmesa->hHWContext, flags);    DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);    if (dPriv != vmesa->driReadable) {	DRI_VALIDATE_DRAWABLE_INFO(sPriv, vmesa->driReadable);    }    if (vmesa->sarea->ctxOwner != vmesa->hHWContext) {       vmesa->sarea->ctxOwner = vmesa->hHWContext;       vmesa->newEmitState = ~0;    }    if (vmesa->lastStamp != dPriv->lastStamp) {       viaXMesaWindowMoved(vmesa);       driUpdateFramebufferSize(vmesa->glCtx, dPriv);       vmesa->newEmitState = ~0;       vmesa->lastStamp = dPriv->lastStamp;    }    if (vmesa->doPageFlip &&	vmesa->pfCurrentOffset != vmesa->sarea->pfCurrentOffset) {       fprintf(stderr, "%s - reset pf\n", __FUNCTION__);       viaResetPageFlippingLocked(vmesa);    }}voidviaSwapBuffers(__DRIdrawablePrivate *drawablePrivate){    __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *)drawablePrivate;    if (dPriv && 	dPriv->driContextPriv && 	dPriv->driContextPriv->driverPrivate) {        struct via_context *vmesa = 	   (struct via_context *)dPriv->driContextPriv->driverPrivate;        GLcontext *ctx = vmesa->glCtx;	_mesa_notifySwapBuffers(ctx);        if (ctx->Visual.doubleBufferMode) {            if (vmesa->doPageFlip) {                viaPageFlip(dPriv);            }            else {                viaCopyBuffer(dPriv);            }        }	else	    VIA_FLUSH_DMA(vmesa);    }    else {        _mesa_problem(NULL, "viaSwapBuffers: drawable has no context!\n");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -