Re-org of surface/framebuffer state.
authorBrian <brian.paul@tungstengraphics.com>
Wed, 20 Jun 2007 01:19:31 +0000 (19:19 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 20 Jun 2007 01:19:31 +0000 (19:19 -0600)
We should be able to render to any depth/format of X window now.

12 files changed:
src/mesa/drivers/x11/xm_surface.c [new file with mode: 0644]
src/mesa/drivers/x11/xmesaP.h
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_context.h
src/mesa/pipe/softpipe/sp_state.h
src/mesa/pipe/softpipe/sp_state_surface.c
src/mesa/pipe/softpipe/sp_surface.h
src/mesa/pipe/softpipe/sp_tile_output.c
src/mesa/sources
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_atom_framebuffer.c

diff --git a/src/mesa/drivers/x11/xm_surface.c b/src/mesa/drivers/x11/xm_surface.c
new file mode 100644 (file)
index 0000000..c0c56c0
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file xm_surface.h
+ * Code to allow the softpipe code to write to X windows/buffers.
+ * This is a bit of a hack for now.  We've basically got two different
+ * abstractions for color buffers: gl_renderbuffer and softpipe_surface.
+ * They'll need to get merged someday...
+ * For now, they're separate things that point to each other.
+ */
+
+
+#include "glxheader.h"
+#include "GL/xmesa.h"
+#include "xmesaP.h"
+#include "context.h"
+#include "imports.h"
+#include "macros.h"
+#include "framebuffer.h"
+#include "renderbuffer.h"
+
+#include "pipe/p_state.h"
+#include "pipe/softpipe/sp_context.h"
+#include "pipe/softpipe/sp_surface.h"
+
+
+/**
+ * An xm_surface is derived from a softpipe_surface
+ */
+struct xmesa_surface
+{
+   struct softpipe_surface sps;
+   struct xmesa_renderbuffer *xrb;  /** ptr back to matching xmesa_renderbuffer */
+};
+
+
+/**
+ * Cast wrapper
+ */
+static INLINE struct xmesa_surface *
+xmesa_surface(struct softpipe_surface *sps)
+{
+   return (struct xmesa_surface *) sps;
+}
+
+
+/**
+ * quad reading/writing
+ * These functions are just wrappers around the existing renderbuffer
+ * functions.
+ */
+
+static void
+read_quad_f(struct softpipe_surface *gs, GLint x, GLint y,
+            GLfloat (*rgba)[NUM_CHANNELS])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(gs);
+   struct xmesa_renderbuffer *xrb = xmsurf->xrb;
+   GLubyte temp[16];
+   GLfloat *dst = (GLfloat *) rgba;
+   GLuint i;
+   GET_CURRENT_CONTEXT(ctx);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y,     temp);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, temp + 8);
+   for (i = 0; i < 16; i++) {
+      dst[i] = UBYTE_TO_FLOAT(temp[i]);
+   }
+}
+
+static void
+read_quad_f_swz(struct softpipe_surface *gs, GLint x, GLint y,
+                GLfloat (*rrrr)[QUAD_SIZE])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(gs);
+   struct xmesa_renderbuffer *xrb = xmsurf->xrb;
+   GLubyte temp[16];
+   GLfloat *dst = (GLfloat *) rrrr;
+   GLuint i, j;
+   GET_CURRENT_CONTEXT(ctx);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y,     temp);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, temp + 8);
+   for (i = 0; i < 4; i++) {
+      for (j = 0; j < 4; j++) {
+         dst[j * 4 + i] = UBYTE_TO_FLOAT(temp[i * 4 + j]);
+      }
+   }
+}
+
+static void
+write_quad_f(struct softpipe_surface *gs, GLint x, GLint y,
+             GLfloat (*rgba)[NUM_CHANNELS])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(gs);
+   struct xmesa_renderbuffer *xrb = xmsurf->xrb;
+   GLubyte temp[16];
+   const GLfloat *src = (const GLfloat *) rgba;
+   GLuint i;
+   GET_CURRENT_CONTEXT(ctx);
+   for (i = 0; i < 16; i++) {
+      temp[i] = FLOAT_TO_UBYTE(src[i]);
+   }
+   xrb->Base.PutRow(ctx, &xrb->Base, 2, x, y,     temp,     NULL);
+   xrb->Base.PutRow(ctx, &xrb->Base, 2, x, y + 1, temp + 8, NULL);
+}
+
+static void
+write_quad_f_swz(struct softpipe_surface *gs, GLint x, GLint y,
+                 GLfloat (*rrrr)[QUAD_SIZE])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(gs);
+   struct xmesa_renderbuffer *xrb = xmsurf->xrb;
+   GLubyte temp[16];
+   const GLfloat *src = (const GLfloat *) rrrr;
+   GLuint i, j;
+   GET_CURRENT_CONTEXT(ctx);
+   for (i = 0; i < 4; i++) {
+      for (j = 0; j < 4; j++) {
+         temp[j * 4 + i] = FLOAT_TO_UBYTE(src[i * 4 + j]);
+      }
+   }
+   xrb->Base.PutRow(ctx, &xrb->Base, 2, x, y,     temp,     NULL);
+   xrb->Base.PutRow(ctx, &xrb->Base, 2, x, y + 1, temp + 8, NULL);
+}
+
+static void
+read_quad_ub(struct softpipe_surface *gs, GLint x, GLint y,
+             GLubyte (*rgba)[NUM_CHANNELS])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(gs);
+   struct xmesa_renderbuffer *xrb = xmsurf->xrb;
+   GET_CURRENT_CONTEXT(ctx);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y,     rgba);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, rgba + 2);
+}
+
+static void
+write_quad_ub(struct softpipe_surface *gs, GLint x, GLint y,
+              GLubyte (*rgba)[NUM_CHANNELS])
+{
+   struct xmesa_surface *xmsurf = xmesa_surface(gs);
+   struct xmesa_renderbuffer *xrb = xmsurf->xrb;
+   GET_CURRENT_CONTEXT(ctx);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y,     rgba);
+   xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, rgba + 2);
+}
+
+
+static struct xmesa_surface *
+create_surface(XMesaContext xmctx, struct xmesa_renderbuffer *xrb)
+{
+   struct xmesa_surface *xmsurf;
+
+   xmsurf = CALLOC_STRUCT(xmesa_surface);
+   if (xmsurf) {
+      xmsurf->xrb = xrb;
+      xmsurf->sps.surface.width = xrb->Base.Width;
+      xmsurf->sps.surface.height = xrb->Base.Height;
+
+      xmsurf->sps.read_quad_f = read_quad_f;
+      xmsurf->sps.read_quad_f_swz = read_quad_f_swz;
+      xmsurf->sps.read_quad_ub = read_quad_ub;
+      xmsurf->sps.write_quad_f = write_quad_f;
+      xmsurf->sps.write_quad_f_swz = write_quad_f_swz;
+      xmsurf->sps.write_quad_ub = write_quad_ub;
+#if 0
+      if (xrb->ximage) {
+         xmsurf->sps.surface.ptr = (GLubyte *) xrb->ximage->data;
+         xmsurf->sps.surface.stride = xrb->ximage->bytes_per_line;
+         xmsurf->sps.surface.cpp = xrb->ximage->depth;
+
+      }
+#endif
+   }
+   return xmsurf;
+}
+
+
+static void
+free_surface(struct softpipe_surface *sps)
+{
+   /* XXX may need to do more in the future */
+   free(sps);
+}
+
+
+/**
+ * Return generic surface pointer corresponding to the current color buffer.
+ */
+struct pipe_surface *
+xmesa_get_color_surface(GLcontext *ctx, GLuint buf)
+{
+   XMesaContext xmctx = XMESA_CONTEXT(ctx);
+   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][buf];   
+   struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
+   struct softpipe_surface *sps = (struct softpipe_surface *) xrb->pSurface;
+
+   if (!sps) {
+      xrb->pSurface = create_surface(xmctx, xrb);
+   }
+   else if (sps->surface.width != rb->Width ||
+            sps->surface.height != rb->Height) {
+      free_surface(sps);
+      xrb->pSurface = create_surface(xmctx, xrb);
+   }
+
+   return (struct pipe_surface *) xrb->pSurface;
+}
+
index 8f0bd34..c36b096 100644 (file)
@@ -196,6 +196,8 @@ struct xmesa_renderbuffer
    GLint bottom;       /* used for FLIP macro, equals height - 1 */
 
    ClearFunc clearFunc;
+
+   void *pSurface;      /** pipe surface */
 };
 
 
@@ -585,4 +587,9 @@ GLboolean xmesa_get_cbuf_details( GLcontext *ctx,
                                  GLint *stride,
                                  GLuint *format );
 
+
+struct pipe_surface;
+struct pipe_surface *
+xmesa_get_color_surface(GLcontext *ctx, GLuint buf);
+
 #endif
index 9a05426..018f673 100644 (file)
@@ -73,7 +73,6 @@ struct pipe_context *softpipe_create( void )
    softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect;
    softpipe->pipe.set_fs_state = softpipe_set_fs_state;
    softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
-   softpipe->pipe.set_cbuf_state = softpipe_set_cbuf_state;
    softpipe->pipe.draw_vb = softpipe_draw_vb;
 
 
index efe453e..a873301 100644 (file)
@@ -54,7 +54,6 @@ enum interp_mode {
 #define G_NEW_SETUP     0x2
 #define G_NEW_FS        0x4
 #define G_NEW_BLEND     0x8
-#define G_NEW_CBUF      0x10
 #define G_NEW_CLIP      0x20
 #define G_NEW_SCISSOR   0x40
 #define G_NEW_STIPPLE   0x80
@@ -74,17 +73,11 @@ struct softpipe_context {
    struct pipe_fs_state     fs;
    struct pipe_blend_state  blend;
    struct pipe_alpha_test_state alpha_test;
-   struct pipe_surface      cbuf;
    struct pipe_clip_state   clip;
    struct pipe_scissor_rect scissor;
    struct pipe_poly_stipple poly_stipple;
    GLuint dirty;
 
-
-   /* Cbuf derived state??? 
-    */
-   struct softpipe_surface *cbuf_surface;
-
    /* Clip derived state:
     */
    GLfloat plane[12][4];
index bdf1011..5002ce8 100644 (file)
@@ -56,9 +56,6 @@ void softpipe_set_fs_state( struct pipe_context *,
 void softpipe_set_polygon_stipple( struct pipe_context *,
                                  const struct pipe_poly_stipple * );
 
-void softpipe_set_cbuf_state( struct pipe_context *,
-                            const struct pipe_surface * );
-
 void softpipe_update_derived( struct softpipe_context *softpipe );
 
 #endif
index d089fe0..99332fd 100644 (file)
 #include "sp_surface.h"
 
 
-/* This is all a total hack.
- */
-void softpipe_set_cbuf_state( struct pipe_context *pipe,
-                            const struct pipe_surface *surface )
-{
-   struct softpipe_context *softpipe = softpipe_context(pipe);
-
-   if (softpipe->cbuf_surface == NULL) {
-      softpipe->cbuf_surface = CALLOC_STRUCT(softpipe_surface);
-      softpipe->cbuf_surface->type = &gs_rgba8;
-   }
-
-   softpipe->cbuf_surface->surface = *surface;
-   softpipe->dirty |= G_NEW_CBUF;
-}
-
-
 /*
  * XXX this might get moved someday
  */
index 08b6889..dde6b90 100644 (file)
@@ -38,12 +38,16 @@ struct softpipe_surface;
 
 #define G_SURFACE_RGBA_8888  0x1
 
-/* Internal structs and helpers for the primitive clip/setup pipeline:
+
+/**
+ * Softpipe surface is derived from pipe_surface.
  */
-struct softpipe_surface_type {
-   
-   GLuint format;
+struct softpipe_surface {
+   struct pipe_surface surface;
 
+   /**
+    * Functions for read/writing surface data
+    */
    void (*read_quad_f)( struct softpipe_surface *,
                        GLint x, GLint y,
                        GLfloat (*rgba)[NUM_CHANNELS] );
@@ -69,47 +73,6 @@ struct softpipe_surface_type {
    void (*write_quad_ub)( struct softpipe_surface *,
                          GLint x, GLint y,
                          GLubyte (*rgba)[NUM_CHANNELS] );
-
-
 };
 
-
-struct softpipe_surface {
-   struct softpipe_surface_type *type;
-   struct pipe_surface surface;
-};
-
-
-static INLINE void gs_read_quad_f( struct softpipe_surface *gs,
-                                  GLint x, GLint y,
-                                  GLfloat (*rgba)[NUM_CHANNELS] )
-{
-   gs->type->read_quad_f(gs, x, y, rgba);
-}
-
-static INLINE void gs_read_quad_f_swz( struct softpipe_surface *gs,
-                                      GLint x, GLint y,
-                                      GLfloat (*rrrr)[QUAD_SIZE] )
-{
-   gs->type->read_quad_f_swz(gs, x, y, rrrr);
-}
-
-static INLINE void gs_write_quad_f( struct softpipe_surface *gs,
-                                   GLint x, GLint y,
-                                   GLfloat (*rgba)[NUM_CHANNELS] )
-{
-   gs->type->write_quad_f(gs, x, y, rgba);
-}
-
-static INLINE void gs_write_quad_f_swz( struct softpipe_surface *gs,
-                                       GLint x, GLint y,
-                                       GLfloat (*rrrr)[QUAD_SIZE] )
-{
-   gs->type->write_quad_f_swz(gs, x, y, rrrr);
-}
-
-/* Like this, or hidden?
- */
-struct softpipe_surface_type gs_rgba8;
-
 #endif
index b1eb9e8..d4add4b 100644 (file)
@@ -55,38 +55,35 @@ static void mask_copy( GLfloat (*dest)[4],
 }
 
 
-/* Write to the output, taking mask into account.
+/**
+ * Write quad to framebuffer, taking mask into account.
  *
  * Note that surfaces support only full quad reads and writes.
  */
 void quad_output( struct softpipe_context *softpipe,
                  struct quad_header *quad )
 {
+   GLuint i;
 
-   if (quad->mask != MASK_ALL) 
-   {
-      GLfloat tmp[4][QUAD_SIZE];
+   for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
+      struct softpipe_surface *sps
+         = (struct softpipe_surface *) softpipe->framebuffer.cbufs[i];
 
-      /* Yes, we'll probably have a masked write as well, but this is
-       * how blend will be done at least.
-       */
-      gs_read_quad_f_swz( softpipe->cbuf_surface, 
-                          quad->x0,
-                          quad->y0,
-                          tmp );
-   
-      mask_copy( tmp, quad->outputs.color, quad->mask );
+      if (quad->mask != MASK_ALL) {
+         GLfloat tmp[4][QUAD_SIZE];
 
-      gs_write_quad_f_swz( softpipe->cbuf_surface, 
-                          quad->x0,
-                          quad->y0,
-                          tmp );
-   }
-   else 
-   {
-      gs_write_quad_f_swz( softpipe->cbuf_surface, 
-                          quad->x0,
-                          quad->y0,
-                          quad->outputs.color );
+         /* Yes, we'll probably have a masked write as well, but this is
+          * how blend will be done at least.
+          */
+
+         sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp);
+
+         mask_copy( tmp, quad->outputs.color, quad->mask );
+
+         sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp);
+      }
+      else {
+         sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color);
+      }
    }
 }
index d07d4da..eb67dd9 100644 (file)
@@ -169,7 +169,6 @@ SOFTPIPE_SOURCES = \
        pipe/softpipe/sp_state_fs.c \
        pipe/softpipe/sp_state_setup.c \
        pipe/softpipe/sp_state_surface.c \
-       pipe/softpipe/sp_surface.c \
        pipe/softpipe/sp_tile_fs.c \
        pipe/softpipe/sp_tile_output.c 
 
@@ -177,7 +176,6 @@ STATETRACKER_SOURCES = \
        state_tracker/st_atom.c \
        state_tracker/st_atom_alphatest.c \
        state_tracker/st_atom_blend.c \
-       state_tracker/st_atom_cbuf.c \
        state_tracker/st_atom_clip.c \
        state_tracker/st_atom_depth.c \
        state_tracker/st_atom_fs.c \
@@ -190,8 +188,6 @@ STATETRACKER_SOURCES = \
        state_tracker/st_draw.c \
        state_tracker/st_context.c 
 
-
-
 SHADER_SOURCES = \
        shader/arbprogparse.c \
        shader/arbprogram.c \
index 0272080..228e788 100644 (file)
@@ -43,7 +43,6 @@
 static const struct st_tracked_state *atoms[] =
 {
    &st_update_framebuffer,
-   &st_update_cbuf,
    &st_update_clip,
    &st_update_fs,
    &st_update_setup,
index 8575bfe..8a75c9c 100644 (file)
@@ -45,7 +45,6 @@ void st_validate_state( struct st_context *st );
 
 
 const struct st_tracked_state st_update_framebuffer;
-const struct st_tracked_state st_update_cbuf;
 const struct st_tracked_state st_update_clip;
 const struct st_tracked_state st_update_depth;
 const struct st_tracked_state st_update_fs;
index 849616f..f203e1d 100644 (file)
 #include "pipe/p_context.h"
 
 
-static struct pipe_surface *
-xmesa_get_color_surface(GLcontext *ctx, GLuint i)
-{
-   return NULL;
-}
+extern struct pipe_surface *
+xmesa_get_color_surface(GLcontext *ctx, GLuint i);
 
 
 /**