code for functional Z buffer surface
authorBrian <brian.paul@tungstengraphics.com>
Mon, 25 Jun 2007 15:43:02 +0000 (09:43 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Mon, 25 Jun 2007 15:43:02 +0000 (09:43 -0600)
src/mesa/drivers/x11/xm_surface.c
src/mesa/drivers/x11/xmesaP.h
src/mesa/state_tracker/st_atom_framebuffer.c

index a937df3..30c9049 100644 (file)
@@ -54,6 +54,7 @@ struct xmesa_surface
 {
    struct softpipe_surface sps;
    struct xmesa_renderbuffer *xrb;  /** ptr back to matching xmesa_renderbuffer */
+   struct gl_renderbuffer *rb; /* ptr to matching gl_renderbuffer */
 };
 
 
@@ -242,15 +243,85 @@ xmesa_get_color_surface(GLcontext *ctx, GLuint buf)
 }
 
 
+static void
+read_quad_z(struct softpipe_surface *sps,
+            GLint x, GLint y, GLfloat zzzz[QUAD_SIZE])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(sps);
+   struct gl_renderbuffer *rb = xmsurf->rb;
+   GLushort temp[4];
+   GLuint i;
+   GET_CURRENT_CONTEXT(ctx);
+   rb->GetRow(ctx, rb, 2, x, y,     temp);
+   rb->GetRow(ctx, rb, 2, x, y + 1, temp + 2);
+   for (i = 0; i < 4; i++) {
+      zzzz[i] = USHORT_TO_FLOAT(temp[i]);
+   }
+}
+
+static void
+write_quad_z(struct softpipe_surface *sps,
+             GLint x, GLint y, const GLfloat zzzz[QUAD_SIZE])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(sps);
+   struct gl_renderbuffer *rb = xmsurf->rb;
+   GLushort temp[4];
+   GLuint i;
+   GET_CURRENT_CONTEXT(ctx);
+   for (i = 0; i < 4; i++) {
+      CLAMPED_FLOAT_TO_USHORT(temp[i], zzzz[i]);
+   }
+   rb->PutRow(ctx, rb, 2, x, y,     temp,     NULL);
+   rb->PutRow(ctx, rb, 2, x, y + 1, temp + 2, NULL);
+}
+
+
+static struct xmesa_surface *
+create_z_surface(XMesaContext xmctx, struct gl_renderbuffer *rb)
+{
+   struct xmesa_surface *xmsurf;
+
+   xmsurf = CALLOC_STRUCT(xmesa_surface);
+   if (xmsurf) {
+      xmsurf->sps.surface.width = rb->Width;
+      xmsurf->sps.surface.height = rb->Height;
+      xmsurf->sps.read_quad_z = read_quad_z;
+      xmsurf->sps.write_quad_z = write_quad_z;
+      xmsurf->rb = rb;
+   }
+   return xmsurf;
+}
+
+/**
+ * Return a pipe_surface that wraps the current Z/depth buffer.
+ * XXX this is pretty much a total hack until gl_renderbuffers and
+ * pipe_surfaces are merged...
+ */
 struct pipe_surface *
-xmesa_get_z_surface(GLcontext *ctx, GLuint i)
+xmesa_get_z_surface(GLcontext *ctx)
 {
-   return NULL;
+   XMesaContext xmctx = XMESA_CONTEXT(ctx);
+   struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer;
+   static struct xmesa_surface *xms = NULL;
+
+   if (!rb)
+      return NULL;
+
+   if (!xms) {
+      xms = create_z_surface(xmctx, rb);
+   }
+   else if (xms->sps.surface.width != rb->Width ||
+            xms->sps.surface.height != rb->Height) {
+      free_surface(&xms->sps);
+      xms = create_z_surface(xmctx, rb);
+   }
+
+   return (struct pipe_surface *) &xms->sps.surface;
 }
 
 
 struct pipe_surface *
-xmesa_get_stencil_surface(GLcontext *ctx, GLuint i)
+xmesa_get_stencil_surface(GLcontext *ctx)
 {
    return NULL;
 }
index 1d5df3d..c0eed4c 100644 (file)
@@ -593,10 +593,10 @@ struct pipe_surface *
 xmesa_get_color_surface(GLcontext *ctx, GLuint buf);
 
 struct pipe_surface *
-xmesa_get_z_surface(GLcontext *ctx, GLuint i);
+xmesa_get_z_surface(GLcontext *ctx);
 
 struct pipe_surface *
-xmesa_get_stencil_surface(GLcontext *ctx, GLuint i);
+xmesa_get_stencil_surface(GLcontext *ctx);
 
 
 #endif
index 8e98cbc..595f390 100644 (file)
@@ -40,10 +40,10 @@ extern struct pipe_surface *
 xmesa_get_color_surface(GLcontext *ctx, GLuint i);
 
 extern struct pipe_surface *
-xmesa_get_z_surface(GLcontext *ctx, GLuint i);
+xmesa_get_z_surface(GLcontext *ctx);
 
 extern struct pipe_surface *
-xmesa_get_stencil_surface(GLcontext *ctx, GLuint i);
+xmesa_get_stencil_surface(GLcontext *ctx);
 
 
 /**
@@ -64,12 +64,12 @@ update_framebuffer_state( struct st_context *st )
       framebuffer.cbufs[i] = xmesa_get_color_surface(st->ctx, i);
    }
 
-   if (st->ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer) {
-      framebuffer.zbuf = xmesa_get_z_surface(st->ctx, i);
+   if (st->ctx->DrawBuffer->_DepthBuffer/*Attachment[BUFFER_DEPTH].Renderbuffer*/) {
+      framebuffer.zbuf = xmesa_get_z_surface(st->ctx);
    }
 
    if (st->ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer) {
-      framebuffer.sbuf = xmesa_get_stencil_surface(st->ctx, i);
+      framebuffer.sbuf = xmesa_get_stencil_surface(st->ctx);
    }
 
    if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) {