i965: Fix all non-snb regression in the snb attribute interpolation commit.
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_dd.c
index bace05af89c4c0fd51dadd9908c178c9a6d8b1bf..2cbbeb811415eaeccfa8665d798ed6e4556bdb2f 100644 (file)
 #include "tdfx_context.h"
 #include "tdfx_dd.h"
 #include "tdfx_lock.h"
-#include "tdfx_vb.h"
 #include "tdfx_pixels.h"
 
-#include "context.h"
-#include "enums.h"
-#include "framebuffer.h"
-#include "swrast/swrast.h"
-#if defined(USE_X86_ASM)
-#include "x86/common_x86_asm.h"
-#endif
+#include "utils.h"
+#include "main/context.h"
 
 
 #define DRIVER_DATE    "20061113"
@@ -64,67 +58,40 @@ static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
 {
    tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
 
-   switch ( name ) {
+   switch (name) {
    case GL_RENDERER:
    {
       /* The renderer string must be per-context state to handle
        * multihead correctly.
        */
-      char *buffer = fxMesa->rendererString;
-      char hardware[100];
+      char *const buffer = fxMesa->rendererString;
+      char hardware[64];
 
       LOCK_HARDWARE(fxMesa);
-      strcpy( hardware, fxMesa->Glide.grGetString(GR_HARDWARE) );
+      strncpy(hardware, fxMesa->Glide.grGetString(GR_HARDWARE),
+             sizeof(hardware));
+      hardware[sizeof(hardware) - 1] = '\0';
       UNLOCK_HARDWARE(fxMesa);
 
-      strcpy( buffer, "Mesa DRI " );
-      strcat( buffer, DRIVER_DATE );
-      strcat( buffer, " " );
-
-      if ( strcmp( hardware, "Voodoo3 (tm)" ) == 0 ) {
-        strcat( buffer, "Voodoo3" );
-      }
-      else if ( strcmp( hardware, "Voodoo Banshee (tm)" ) == 0 ) {
-        strcat( buffer, "VoodooBanshee" );
-      }
-      else if ( strcmp( hardware, "Voodoo4 (tm)" ) == 0 ) {
-        strcat( buffer, "Voodoo4" );
+      if ((strncmp(hardware, "Voodoo3", 7) == 0)
+         || (strncmp(hardware, "Voodoo4", 7) == 0)
+         || (strncmp(hardware, "Voodoo5", 7) == 0)) {
+        hardware[7] = '\0';
       }
-      else if ( strcmp( hardware, "Voodoo5 (tm)" ) == 0 ) {
-        strcat( buffer, "Voodoo5" );
+      else if (strncmp(hardware, "Voodoo Banshee", 14) == 0) {
+        strcpy(&hardware[6], "Banshee");
       }
       else {
         /* unexpected result: replace spaces with hyphens */
         int i;
-        for ( i = 0 ; hardware[i] && i < 60 ; i++ ) {
-           if ( hardware[i] == ' ' || hardware[i] == '\t' )
+        for (i = 0; i < sizeof(hardware) && hardware[i]; i++) {
+           if (hardware[i] == ' ' || hardware[i] == '\t') {
               hardware[i] = '-';
+           }
         }
-         strcat( buffer, hardware );
       }
 
-      /* Append any CPU-specific information.
-       */
-#ifdef USE_X86_ASM
-      if ( _mesa_x86_cpu_features ) {
-        strncat( buffer, " x86", 4 );
-      }
-#endif
-#ifdef USE_MMX_ASM
-      if ( cpu_has_mmx ) {
-        strncat( buffer, "/MMX", 4 );
-      }
-#endif
-#ifdef USE_3DNOW_ASM
-      if ( cpu_has_3dnow ) {
-        strncat( buffer, "/3DNow!", 7 );
-      }
-#endif
-#ifdef USE_SSE_ASM
-      if ( cpu_has_xmm ) {
-        strncat( buffer, "/SSE", 4 );
-      }
-#endif
+      (void) driGetRendererString(buffer, hardware, DRIVER_DATE, 0);
       return (const GLubyte *) buffer;
    }
    case GL_VENDOR:
@@ -135,6 +102,55 @@ static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
 }
 
 
+static void
+tdfxBeginQuery(GLcontext *ctx, struct gl_query_object *q)
+{
+   tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
+
+   (void) q;
+
+   if (q->Target == GL_SAMPLES_PASSED_ARB) {
+      LOCK_HARDWARE(fxMesa);
+      fxMesa->Glide.grFinish();
+      fxMesa->Glide.grReset(GR_STATS_PIXELS);
+      UNLOCK_HARDWARE(fxMesa);
+   }
+}
+
+
+static void
+tdfxEndQuery(GLcontext *ctx, struct gl_query_object *q)
+{
+   tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
+   FxI32 total_pixels;
+   FxI32 z_fail_pixels;
+
+
+   if (q->Target == GL_SAMPLES_PASSED_ARB) {
+      LOCK_HARDWARE(fxMesa);
+      fxMesa->Glide.grFinish();
+
+      fxMesa->Glide.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, sizeof(FxI32),
+                         &z_fail_pixels);
+      fxMesa->Glide.grGet(GR_STATS_PIXELS_IN, sizeof(FxI32), &total_pixels);
+
+      q->Result = total_pixels - z_fail_pixels;
+      
+      /* Apparently, people have seen z_fail_pixels > total_pixels under
+       * some conditions on some 3Dfx hardware.  The occlusion query spec
+       * requires that we clamp to 0.
+       */
+      if (q->Result < 0) {
+        q->Result = 0;
+      }
+
+      q->Ready = GL_TRUE;
+
+      UNLOCK_HARDWARE(fxMesa);
+   }
+}
+
+
 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a)        \
    ((vis->redBits == r) &&                         \
     (vis->greenBits == g) &&                       \
@@ -148,7 +164,9 @@ void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
       fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ );
    }
 
-   functions->GetString                = tdfxDDGetString;
+   functions->GetString         = tdfxDDGetString;
+   functions->BeginQuery        = tdfxBeginQuery;
+   functions->EndQuery          = tdfxEndQuery;
 
    /* Accelerated paths
     */