Beispiel #1
0
void tdfxGetLock( tdfxContextPtr fxMesa )
{
    __DRIcontextPrivate *cPriv = fxMesa->driContext;
    __DRIdrawablePrivate *const drawable = cPriv->driDrawablePriv;
    __DRIdrawablePrivate *const readable = cPriv->driReadablePriv;
    __DRIscreenPrivate *sPriv = drawable->driScreenPriv;
    TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) (((char *) sPriv->pSAREA) +
					fxMesa->fxScreen->sarea_priv_offset);
    unsigned int stamp = drawable->lastStamp;

    drmGetLock( fxMesa->driFd, fxMesa->hHWContext, 0 );

    /* This macro will update drawable's cliprects if needed */
    DRI_VALIDATE_DRAWABLE_INFO(sPriv, drawable);
    if (drawable != readable) {
	DRI_VALIDATE_DRAWABLE_INFO(sPriv, readable);
    }

    if ( saPriv->fifoOwner != fxMesa->hHWContext ) {
        fxMesa->Glide.grDRIImportFifo( saPriv->fifoPtr, saPriv->fifoRead );
    }

    if ( saPriv->ctxOwner != fxMesa->hHWContext ) {
        /* This sequence looks a little odd. Glide mirrors the state, and
	 * when you get the state you are forcing the mirror to be up to
	 * date, and then getting a copy from the mirror. You can then force
	 * that state onto the hardware when you set the state.
	 */
        void *state;
        FxI32 stateSize;
        fxMesa->Glide.grGet(GR_GLIDE_STATE_SIZE, 4, &stateSize);
        state = malloc(stateSize);
        fxMesa->Glide.grGlideGetState( state );
        fxMesa->Glide.grGlideSetState( state );
        free( state );
    }

#if 0
    if ( saPriv->texOwner != fxMesa->hHWContext ) {
        tdfxTMRestoreTextures_NoLock( fxMesa );
    }
#endif

    if ((*drawable->pStamp != stamp)
	|| (saPriv->ctxOwner != fxMesa->hHWContext)) {
       driUpdateFramebufferSize(fxMesa->glCtx, drawable);
       if (drawable != readable) {
	   driUpdateFramebufferSize(fxMesa->glCtx, readable);
       }

       tdfxUpdateClipping(fxMesa->glCtx);
       tdfxUploadClipping(fxMesa);
    }

    DEBUG_LOCK();
}
void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa )
{
   if ( !fxMesa->dirty )
      return;

   if ( fxMesa->dirty & TDFX_UPLOAD_COLOR_COMBINE ) {
      if (TDFX_IS_NAPALM(fxMesa)) {
         fxMesa->Glide.grColorCombineExt(fxMesa->ColorCombineExt.SourceA,
                                         fxMesa->ColorCombineExt.ModeA,
                                         fxMesa->ColorCombineExt.SourceB,
                                         fxMesa->ColorCombineExt.ModeB,
                                         fxMesa->ColorCombineExt.SourceC,
                                         fxMesa->ColorCombineExt.InvertC,
                                         fxMesa->ColorCombineExt.SourceD,
                                         fxMesa->ColorCombineExt.InvertD,
                                         fxMesa->ColorCombineExt.Shift,
                                         fxMesa->ColorCombineExt.Invert);
      }
      else {
         /* Voodoo 3 */
         fxMesa->Glide.grColorCombine( fxMesa->ColorCombine.Function,
                                       fxMesa->ColorCombine.Factor,
                                       fxMesa->ColorCombine.Local,
                                       fxMesa->ColorCombine.Other,
                                       fxMesa->ColorCombine.Invert );
      }
      fxMesa->dirty &= ~TDFX_UPLOAD_COLOR_COMBINE;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_ALPHA_COMBINE ) {
      if (TDFX_IS_NAPALM(fxMesa)) {
         fxMesa->Glide.grAlphaCombineExt(fxMesa->AlphaCombineExt.SourceA,
                                         fxMesa->AlphaCombineExt.ModeA,
                                         fxMesa->AlphaCombineExt.SourceB,
                                         fxMesa->AlphaCombineExt.ModeB,
                                         fxMesa->AlphaCombineExt.SourceC,
                                         fxMesa->AlphaCombineExt.InvertC,
                                         fxMesa->AlphaCombineExt.SourceD,
                                         fxMesa->AlphaCombineExt.InvertD,
                                         fxMesa->AlphaCombineExt.Shift,
                                         fxMesa->AlphaCombineExt.Invert);
      }
      else {
         /* Voodoo 3 */
         fxMesa->Glide.grAlphaCombine( fxMesa->AlphaCombine.Function,
                                       fxMesa->AlphaCombine.Factor,
                                       fxMesa->AlphaCombine.Local,
                                       fxMesa->AlphaCombine.Other,
                                       fxMesa->AlphaCombine.Invert );
      }
      fxMesa->dirty &= ~TDFX_UPLOAD_ALPHA_COMBINE;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_RENDER_BUFFER ) {
      fxMesa->Glide.grRenderBuffer( fxMesa->DrawBuffer );
      fxMesa->dirty &= ~TDFX_UPLOAD_RENDER_BUFFER;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_STIPPLE) {
      fxMesa->Glide.grStipplePattern( fxMesa->Stipple.Pattern );
      fxMesa->Glide.grStippleMode( fxMesa->Stipple.Mode );
      fxMesa->dirty &= ~TDFX_UPLOAD_STIPPLE;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_ALPHA_TEST ) {
      fxMesa->Glide.grAlphaTestFunction( fxMesa->Color.AlphaFunc );
      fxMesa->dirty &= ~TDFX_UPLOAD_ALPHA_TEST;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_ALPHA_REF ) {
      fxMesa->Glide.grAlphaTestReferenceValue( fxMesa->Color.AlphaRef );
      fxMesa->dirty &= ~TDFX_UPLOAD_ALPHA_REF;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_BLEND_FUNC ) {
      if (fxMesa->Glide.grAlphaBlendFunctionExt) {
         fxMesa->Glide.grAlphaBlendFunctionExt( fxMesa->Color.BlendSrcRGB,
                                                fxMesa->Color.BlendDstRGB,
                                                fxMesa->Color.BlendEqRGB,
                                                fxMesa->Color.BlendSrcA,
                                                fxMesa->Color.BlendDstA,
                                                fxMesa->Color.BlendEqA );
      }
      else {
         fxMesa->Glide.grAlphaBlendFunction( fxMesa->Color.BlendSrcRGB,
                                             fxMesa->Color.BlendDstRGB,
                                             fxMesa->Color.BlendSrcA,
                                             fxMesa->Color.BlendDstA );
      }
      fxMesa->dirty &= ~TDFX_UPLOAD_BLEND_FUNC;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_MODE ) {
      fxMesa->Glide.grDepthBufferMode( fxMesa->Depth.Mode );
      fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_MODE;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_BIAS ) {
      fxMesa->Glide.grDepthBiasLevel( fxMesa->Depth.Bias );
      fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_BIAS;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_FUNC ) {
      fxMesa->Glide.grDepthBufferFunction( fxMesa->Depth.Func );
      fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_FUNC;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_MASK ) {
      fxMesa->Glide.grDepthMask( fxMesa->Depth.Mask );
      fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_MASK;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_DITHER) {
      fxMesa->Glide.grDitherMode( fxMesa->Color.Dither );
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_FOG_MODE ) {
      fxMesa->Glide.grFogMode( fxMesa->Fog.Mode );
      fxMesa->dirty &= ~TDFX_UPLOAD_FOG_MODE;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_FOG_COLOR ) {
      fxMesa->Glide.grFogColorValue( fxMesa->Fog.Color );
      fxMesa->dirty &= ~TDFX_UPLOAD_FOG_COLOR;
   }
   if ( fxMesa->dirty & TDFX_UPLOAD_FOG_TABLE ) {
      fxMesa->Glide.grFogTable( fxMesa->Fog.Table );
      fxMesa->dirty &= ~TDFX_UPLOAD_FOG_TABLE;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_CULL ) {
      fxMesa->Glide.grCullMode( fxMesa->CullMode );
      fxMesa->dirty &= ~TDFX_UPLOAD_CULL;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_CLIP ) {
      tdfxUploadClipping( fxMesa );
      fxMesa->dirty &= ~TDFX_UPLOAD_CLIP;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_COLOR_MASK ) {
      if ( fxMesa->Glide.grColorMaskExt
           && fxMesa->glCtx->Visual.redBits == 8) {
	 fxMesa->Glide.grColorMaskExt( fxMesa->Color.ColorMask[RCOMP],
                                       fxMesa->Color.ColorMask[GCOMP],
                                       fxMesa->Color.ColorMask[BCOMP],
                                       fxMesa->Color.ColorMask[ACOMP] );
      } else {
	 fxMesa->Glide.grColorMask( fxMesa->Color.ColorMask[RCOMP] ||
                                    fxMesa->Color.ColorMask[GCOMP] ||
                                    fxMesa->Color.ColorMask[BCOMP],
                                    /*fxMesa->Color.ColorMask[ACOMP]*/GL_FALSE/*[dBorca] no-no*/ );
      }
      fxMesa->dirty &= ~TDFX_UPLOAD_COLOR_MASK;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_CONSTANT_COLOR ) {
      fxMesa->Glide.grConstantColorValue( fxMesa->Color.MonoColor );
      fxMesa->dirty &= ~TDFX_UPLOAD_CONSTANT_COLOR;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_LINE ) {
      if (fxMesa->glCtx->Line.SmoothFlag && fxMesa->glCtx->Line.Width == 1.0)
         fxMesa->Glide.grEnable(GR_AA_ORDERED);
      else
         fxMesa->Glide.grDisable(GR_AA_ORDERED);
      fxMesa->dirty &= ~TDFX_UPLOAD_LINE;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_STENCIL ) {
      if (fxMesa->glCtx->Stencil.Enabled) {
         fxMesa->Glide.grEnable(GR_STENCIL_MODE_EXT);
         fxMesa->Glide.grStencilOp(fxMesa->Stencil.FailFunc,
                                   fxMesa->Stencil.ZFailFunc,
                                   fxMesa->Stencil.ZPassFunc);
         fxMesa->Glide.grStencilFunc(fxMesa->Stencil.Function,
                                     fxMesa->Stencil.RefValue,
                                     fxMesa->Stencil.ValueMask);
         fxMesa->Glide.grStencilMask(fxMesa->Stencil.WriteMask);
      }
      else {
         fxMesa->Glide.grDisable(GR_STENCIL_MODE_EXT);
      }
      fxMesa->dirty &= ~TDFX_UPLOAD_STENCIL;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_VERTEX_LAYOUT ) {
      fxMesa->Glide.grGlideSetVertexLayout( fxMesa->layout[fxMesa->vertexFormat] );
      /* [dborca] enable fogcoord */
      fxMesa->Glide.grVertexLayout(GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET,
	 fxMesa->Fog.Mode == GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT);
      fxMesa->dirty &= ~TDFX_UPLOAD_VERTEX_LAYOUT;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_ENV ) {
      uploadTextureEnv(fxMesa);
      fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_ENV;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_PARAMS ) {
      uploadTextureParams(fxMesa);
      fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_PARAMS;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_PALETTE ) {
      if (fxMesa->TexPalette.Data) {
         fxMesa->Glide.grTexDownloadTable(fxMesa->TexPalette.Type, fxMesa->TexPalette.Data);
      }
      fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_PALETTE;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_SOURCE ) {
      uploadTextureSource(fxMesa);
      fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_SOURCE;
   }

   if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_IMAGES ) {
      uploadTextureImages(fxMesa);
      fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_IMAGES;
   }

   fxMesa->dirty = 0;
}