Fix some issues hit when rendering to a depth-only renderbuffer (shadowtex).
authorBrian <brian.paul@tungstengraphics.com>
Thu, 8 Nov 2007 16:16:14 +0000 (09:16 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 8 Nov 2007 16:16:14 +0000 (09:16 -0700)
Added 16bpp case to translate_depth_format().
Added framebuffer_size() to determine framebuffer size.

src/mesa/pipe/i915simple/i915_state_emit.c

index ee44e526cac8eb250cbb730fae74e7da7f91cc69..d793e92a14d8d935e08f2349d2f183bfa0ff5b8f 100644 (file)
@@ -50,8 +50,44 @@ static unsigned translate_format( unsigned format )
 
 static unsigned translate_depth_format( unsigned zformat )
 {
-   assert(zformat == PIPE_FORMAT_S8_Z24);
-   return DEPTH_FRMT_24_FIXED_8_OTHER;
+   switch (zformat) {
+   case PIPE_FORMAT_S8_Z24:
+      return DEPTH_FRMT_24_FIXED_8_OTHER;
+   case PIPE_FORMAT_U_Z16:
+      return DEPTH_FRMT_16_FIXED;
+   default:
+      assert(0);
+      return 0;
+   }
+}
+
+
+/**
+ * Examine framebuffer state to determine width, height.
+ */
+static boolean
+framebuffer_size(const struct pipe_framebuffer_state *fb,
+                 uint *width, uint *height)
+{
+   if (fb->cbufs[0]) {
+      *width = fb->cbufs[0]->width;
+      *height = fb->cbufs[0]->height;
+      return TRUE;
+   }
+   else if (fb->zbuf) {
+      *width = fb->zbuf->width;
+      *height = fb->zbuf->height;
+      return TRUE;
+   }
+   else if (fb->sbuf) {
+      *width = fb->sbuf->width;
+      *height = fb->sbuf->height;
+      return TRUE;
+   }
+   else {
+      *width = *height = 0;
+      return FALSE;
+   }
 }
 
 
@@ -207,9 +243,14 @@ i915_emit_hardware_state(struct i915_context *i915 )
       }
    
       {
-        unsigned cformat = translate_format( i915->framebuffer.cbufs[0]->format );
-        unsigned zformat = 0;
+        unsigned cformat, zformat = 0;
       
+        if (i915->framebuffer.cbufs[0])
+            cformat = i915->framebuffer.cbufs[0]->format;
+         else
+            cformat = PIPE_FORMAT_U_A8_R8_G8_B8; /* arbitrary */
+         cformat = translate_format(cformat);
+
         if (i915->framebuffer.zbuf) 
            zformat = translate_depth_format( i915->framebuffer.zbuf->format );
 
@@ -322,8 +363,9 @@ i915_emit_hardware_state(struct i915_context *i915 )
    /* drawing surface size */
    /* 6 dwords, 0 relocs */
    {
-      int w = i915->framebuffer.cbufs[0]->width;
-      int h = i915->framebuffer.cbufs[0]->height;
+      uint w, h;
+      boolean k = framebuffer_size(&i915->framebuffer, &w, &h);
+      assert(k);
 
       OUT_BATCH(_3DSTATE_DRAW_RECT_CMD);
       OUT_BATCH(0);
@@ -336,4 +378,3 @@ i915_emit_hardware_state(struct i915_context *i915 )
 
    i915->hardware_dirty = 0;
 }
-