Fixed occlusion_zless_triangle() to work with 16 or 32-bit Z buffers.
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 23 Jun 2004 22:47:46 +0000 (22:47 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 23 Jun 2004 22:47:46 +0000 (22:47 +0000)
Removed some unneeded lines, other minor clean-ups.

src/mesa/swrast/s_triangle.c

index ff4ebb3704d0028892c37fc0a9fbd8efbe948c7c..8c2ba368c04550e2d6a546888b478632852f4b7a 100644 (file)
@@ -102,7 +102,6 @@ _swrast_culltriangle( GLcontext *ctx,
 #define NAME flat_rgba_triangle
 #define INTERP_Z 1
 #define INTERP_FOG 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define SETUP_CODE                             \
    ASSERT(ctx->Texture._EnabledCoordUnits == 0);\
    ASSERT(ctx->Light.ShadeModel==GL_FLAT);     \
@@ -126,7 +125,6 @@ _swrast_culltriangle( GLcontext *ctx,
 #define NAME smooth_rgba_triangle
 #define INTERP_Z 1
 #define INTERP_FOG 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #define INTERP_ALPHA 1
 #define SETUP_CODE                             \
@@ -528,7 +526,6 @@ affine_span(GLcontext *ctx, struct sw_span *span,
 #define NAME affine_textured_triangle
 #define INTERP_Z 1
 #define INTERP_FOG 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #define INTERP_ALPHA 1
 #define INTERP_INT_TEX 1
@@ -801,7 +798,6 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define INTERP_Z 1
 #define INTERP_W 1
 #define INTERP_FOG 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #define INTERP_ALPHA 1
 #define INTERP_TEX 1
@@ -873,7 +869,6 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define INTERP_Z 1
 #define INTERP_W 1
 #define INTERP_FOG 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #define INTERP_SPEC 1
 #define INTERP_ALPHA 1
@@ -892,7 +887,6 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define INTERP_Z 1
 #define INTERP_W 1
 #define INTERP_FOG 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #define INTERP_ALPHA 1
 #define INTERP_SPEC 1
@@ -908,20 +902,38 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define NAME occlusion_zless_triangle
 #define DO_OCCLUSION_TEST
 #define INTERP_Z 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define SETUP_CODE                                             \
+   ASSERT(ctx->Depth.Test);                                    \
+   ASSERT(!ctx->Depth.Mask);                                   \
+   ASSERT(ctx->Depth.Func == GL_LESS);                         \
    if (ctx->OcclusionResult && !ctx->Occlusion.Active) {       \
       return;                                                  \
    }
-#define RENDER_SPAN( span )                            \
-   GLuint i;                                           \
-   for (i = 0; i < span.end; i++) {                    \
-      GLdepth z = FixedToDepth(span.z);                        \
-      if (z < zRow[i]) {                               \
-         ctx->OcclusionResult = GL_TRUE;               \
-         ctx->Occlusion.PassedCounter++;               \
-      }                                                        \
-      span.z += span.zStep;                            \
+#define RENDER_SPAN( span )                                            \
+   if (ctx->Visual.depthBits <= 16) {                                  \
+      GLuint i;                                                                \
+      const GLushort *zRow = (const GLushort *)                                \
+         _swrast_zbuffer_address(ctx, span.x, span.y);                 \
+      for (i = 0; i < span.end; i++) {                                 \
+         GLdepth z = FixedToDepth(span.z);                             \
+         if (z < zRow[i]) {                                            \
+            ctx->OcclusionResult = GL_TRUE;                            \
+            ctx->Occlusion.PassedCounter++;                            \
+         }                                                             \
+         span.z += span.zStep;                                         \
+      }                                                                        \
+   }                                                                   \
+   else {                                                              \
+      GLuint i;                                                                \
+      const GLuint *zRow = (const GLuint *)                            \
+         _swrast_zbuffer_address(ctx, span.x, span.y);                 \
+      for (i = 0; i < span.end; i++) {                                 \
+         if (span.z < zRow[i]) {                                       \
+            ctx->OcclusionResult = GL_TRUE;                            \
+            ctx->Occlusion.PassedCounter++;                            \
+         }                                                             \
+         span.z += span.zStep;                                         \
+      }                                                                        \
    }
 #include "s_tritemp.h"
 
@@ -1072,13 +1084,13 @@ _swrast_choose_triangle( GLcontext *ctx )
          envMode = ctx->Texture.Unit[0].EnvMode;
 
          /* First see if we can use an optimized 2-D texture function */
-         if (ctx->Texture._EnabledCoordUnits == 1
+         if (ctx->Texture._EnabledCoordUnits == 0x1
              && !ctx->FragmentProgram._Enabled
              && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
-             && texObj2D->WrapS==GL_REPEAT
-            && texObj2D->WrapT==GL_REPEAT
+             && texObj2D->WrapS == GL_REPEAT
+            && texObj2D->WrapT == GL_REPEAT
              && texObj2D->_IsPowerOfTwo
-             && texImg->Border==0
+             && texImg->Border == 0
              && texImg->Width == texImg->RowStride
              && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA)
             && minFilter == magFilter