gallium: Add utility helper for packing combined depth/stencil values.
authorMichel Dänzer <daenzer@vmware.com>
Sat, 4 Apr 2009 14:04:59 +0000 (16:04 +0200)
committerMichel Dänzer <daenzer@vmware.com>
Sat, 4 Apr 2009 14:04:59 +0000 (16:04 +0200)
src/gallium/auxiliary/util/u_pack_color.h
src/mesa/state_tracker/st_cb_clear.c

index e0e8aa8e9fe74f9f2c1ec896d8a5dff774f31b09..e05d0322532f946dd98c4367e3fb2f45ae8b67c9 100644 (file)
@@ -440,6 +440,26 @@ util_pack_z(enum pipe_format format, double z)
       return 0;
    }
 }
+
+/**
+ * Note: it's assumed that z is in [0,1] and s in [0,255]
+ */
+static INLINE uint
+util_pack_z_stencil(enum pipe_format format, double z, uint s)
+{
+   switch (format) {
+   case PIPE_FORMAT_S8Z24_UNORM:
+      return util_pack_z(format, z) | s << 24;
+   case PIPE_FORMAT_Z24S8_UNORM:
+      return util_pack_z(format, z) | s;
+   default:
+      debug_print_format("gallium: unhandled format in util_pack_z_stencil()",
+                         format);
+      assert(0);
+      return 0;
+   }
+}
 
 
 /**
index 020684b4e141dbab5796ddb74823228bc083e35e..bec32db0502df3dd548d86cc628d3d88c44db8d8 100644 (file)
@@ -460,19 +460,9 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
    }
    else {
       /* clear whole buffer w/out masking */
-      GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear);
-
-      switch (strb->surface->format) {
-      case PIPE_FORMAT_S8Z24_UNORM:
-         clearValue |= ctx->Stencil.Clear << 24;
-         break;
-      case PIPE_FORMAT_Z24S8_UNORM:
-         clearValue |= ctx->Stencil.Clear;
-         break;
-      default:
-         assert(0);
-      }  
-
+      GLuint clearValue = util_pack_z_stencil(strb->surface->format,
+                                              ctx->Depth.Clear,
+                                              ctx->Stencil.Clear);
       ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
    }
 }