gallium: Clean up driver clear() interface.
authorMichel Dänzer <daenzer@vmware.com>
Sat, 4 Apr 2009 17:01:51 +0000 (19:01 +0200)
committerMichel Dänzer <daenzer@vmware.com>
Sat, 4 Apr 2009 17:01:51 +0000 (19:01 +0200)
Only allows clearing currently bound buffers, but colour and depth/stencil in
a single call.

26 files changed:
src/gallium/auxiliary/util/u_clear.h [new file with mode: 0644]
src/gallium/auxiliary/util/u_pack_color.h
src/gallium/drivers/i915simple/i915_clear.c
src/gallium/drivers/i915simple/i915_context.h
src/gallium/drivers/nv10/nv10_clear.c
src/gallium/drivers/nv10/nv10_context.h
src/gallium/drivers/nv20/nv20_clear.c
src/gallium/drivers/nv20/nv20_context.h
src/gallium/drivers/nv30/nv30_clear.c
src/gallium/drivers/nv30/nv30_context.h
src/gallium/drivers/nv40/nv40_clear.c
src/gallium/drivers/nv40/nv40_context.h
src/gallium/drivers/nv50/nv50_context.h
src/gallium/drivers/softpipe/sp_clear.c
src/gallium/drivers/softpipe/sp_clear.h
src/gallium/drivers/trace/tr_context.c
src/gallium/include/pipe/p_context.h
src/gallium/include/pipe/p_defines.h
src/gallium/state_trackers/g3dvl/vl_basic_csc.c
src/gallium/state_trackers/python/p_context.i
src/gallium/state_trackers/python/retrace/interpreter.py
src/gallium/state_trackers/python/samples/tri.py
src/gallium/state_trackers/python/tests/regress/vertex-shader/vertex-shader.py
src/gallium/state_trackers/python/tests/texture_render.py
src/gallium/state_trackers/python/tests/texture_sample.py
src/mesa/state_tracker/st_cb_clear.c

diff --git a/src/gallium/auxiliary/util/u_clear.h b/src/gallium/auxiliary/util/u_clear.h
new file mode 100644 (file)
index 0000000..7c16b32
--- /dev/null
@@ -0,0 +1,60 @@
+/**************************************************************************
+ * 
+ * Copyright 2009 VMware, Inc.  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, sub license, 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 (including the
+ * next paragraph) 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ * 
+ **************************************************************************/
+
+/* Authors:
+ *    Michel Dänzer
+ */
+
+
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+#include "util/u_pack_color.h"
+
+
+/**
+ * Clear the given buffers to the specified values.
+ * No masking, no scissor (clear entire buffer).
+ */
+static INLINE void
+util_clear(struct pipe_context *pipe,
+           struct pipe_framebuffer_state *framebuffer, unsigned buffers,
+           const float *rgba, double depth, unsigned stencil)
+{
+   if (buffers & PIPE_CLEAR_COLOR) {
+      struct pipe_surface *ps = framebuffer->cbufs[0];
+      unsigned color;
+
+      util_pack_color(rgba, ps->format, &color);
+      pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, color);
+   }
+
+   if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
+      struct pipe_surface *ps = framebuffer->zsbuf;
+
+      pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height,
+                         util_pack_z_stencil(ps->format, depth, stencil));
+   }
+}
index e05d0322532f946dd98c4367e3fb2f45ae8b67c9..4ec7aee192b3cbd77c5c90e9f79c261a88d20972 100644 (file)
@@ -448,17 +448,19 @@ util_pack_z(enum pipe_format format, double z)
 static INLINE uint
 util_pack_z_stencil(enum pipe_format format, double z, uint s)
 {
+   unsigned packed = util_pack_z(format, z);
+
    switch (format) {
    case PIPE_FORMAT_S8Z24_UNORM:
-      return util_pack_z(format, z) | s << 24;
+      packed |= s << 24;
+      break;
    case PIPE_FORMAT_Z24S8_UNORM:
-      return util_pack_z(format, z) | s;
+      packed |= s;
    default:
-      debug_print_format("gallium: unhandled format in util_pack_z_stencil()",
-                         format);
-      assert(0);
-      return 0;
+      break;
    }
+
+   return packed;
 }
 
 
index cde69daacc08ddd8447e21e7c7fbd8167accd8d3..90530f2826f10e4237d8d3e22aee3b091639116d 100644 (file)
  * 
  **************************************************************************/
 
-/* Author:
+/* Authors:
  *    Brian Paul
  */
 
 
-#include "pipe/p_defines.h"
+#include "util/u_clear.h"
 #include "i915_context.h"
 #include "i915_state.h"
 
 
 /**
- * Clear the given surface to the specified value.
+ * Clear the given buffers to the specified values.
  * No masking, no scissor (clear entire buffer).
  */
 void
-i915_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-          unsigned clearValue)
+i915_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba,
+          double depth, unsigned stencil)
 {
-   pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+   util_clear(pipe, &i915_context(pipe)->framebuffer, buffers, rgba, depth,
+              stencil);
 }
index 3cdabe45f9d6ff8cf713ce81019b77ef5aeacac9..b6983ba86e7c52c3f8e065907d8695a913e88d6d 100644 (file)
@@ -314,8 +314,8 @@ void i915_emit_hardware_state(struct i915_context *i915 );
 /***********************************************************************
  * i915_clear.c: 
  */
-void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-               unsigned clearValue);
+void i915_clear( struct pipe_context *pipe, unsigned buffers, const float *rgba,
+                 double depth, unsigned stencil);
 
 
 /***********************************************************************
index be7e09cf4b0644059f3baeebb6233918398b191c..a39a2b5f525671b1cefb0b7881c4df6e833ddb93 100644 (file)
@@ -1,12 +1,14 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
+#include "util/u_clear.h"
 
 #include "nv10_context.h"
 
 void
-nv10_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-          unsigned clearValue)
+nv10_clear(struct pipe_context *pipe, unsigned buffers,
+           const float *rgba, double depth, unsigned stencil)
 {
-       pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+       util_clear(pipe, nv10_context(pipe)->framebuffer, buffers, rgba, depth,
+                  stencil);
 }
index f3b56de25a7e0ca178d8fa9f9bf855bec58398ae..f1e003c95373f752bf78a3d9f8b413eb66c9118a 100644 (file)
@@ -118,8 +118,9 @@ extern void nv10_init_surface_functions(struct nv10_context *nv10);
 extern void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen);
 
 /* nv10_clear.c */
-extern void nv10_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-                      unsigned clearValue);
+extern void nv10_clear(struct pipe_context *pipe, unsigned buffers,
+                      const float *rgba, double depth, unsigned stencil);
+
 
 /* nv10_draw.c */
 extern struct draw_stage *nv10_draw_render_stage(struct nv10_context *nv10);
index 81b6f3e78ac4690ea7f3fda1981f826ecfece170..2b4490fa5e1e8c24db818b9b5a969b22d33694f4 100644 (file)
@@ -1,12 +1,14 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
+#include "util/u_clear.h"
 
 #include "nv20_context.h"
 
 void
-nv20_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-          unsigned clearValue)
+nv20_clear(struct pipe_context *pipe, unsigned buffers,
+           const float *rgba, double depth, unsigned stencil)
 {
-       pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+       util_clear(pipe, nv20_context(pipe)->framebuffer, buffers, rgba, depth,
+                  stencil);
 }
index 8ad926db20ad4914c8b60bb4c38931fb9d5306ac..fc932f1f90e13c69c782f15e2b47fb2dadeae045 100644 (file)
@@ -118,8 +118,8 @@ extern void nv20_init_surface_functions(struct nv20_context *nv20);
 extern void nv20_screen_init_miptree_functions(struct pipe_screen *pscreen);
 
 /* nv20_clear.c */
-extern void nv20_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-                      unsigned clearValue);
+extern void nv20_clear(struct pipe_context *pipe, unsigned buffers,
+                      const float *rgba, double depth, unsigned stencil);
 
 /* nv20_draw.c */
 extern struct draw_stage *nv20_draw_render_stage(struct nv20_context *nv20);
index 71f413588ee86edd934dc97305c7be70574643e7..c4ba9266647c1c8ca4973cf8055d283bd6c2e193 100644 (file)
@@ -1,12 +1,14 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
+#include "util/u_clear.h"
 
 #include "nv30_context.h"
 
 void
-nv30_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-          unsigned clearValue)
+nv30_clear(struct pipe_context *pipe, unsigned buffers,
+           const float *rgba, double depth, unsigned stencil)
 {
-       pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+       util_clear(pipe, &nv30_context(pipe)->framebuffer, buffers, rgba, depth,
+                  stencil);
 }
index b9337697008c1fed3440f094d527a891fbcc19eb..4229c0a0e1478bc33842e4416e0283fdf751dd73 100644 (file)
@@ -206,7 +206,7 @@ extern boolean nv30_draw_elements(struct pipe_context *pipe,
                                  unsigned count);
 
 /* nv30_clear.c */
-extern void nv30_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-                      unsigned clearValue);
+extern void nv30_clear(struct pipe_context *pipe, unsigned buffers,
+                      const float *rgba, double depth, unsigned stencil);
 
 #endif
index 2c4e8f01fdac7ff4406784dc888eb62864713925..ddf13addf3b984e289e65ac22952762a6e6f6168 100644 (file)
@@ -1,12 +1,14 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
+#include "util/u_clear.h"
 
 #include "nv40_context.h"
 
 void
-nv40_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-          unsigned clearValue)
+nv40_clear(struct pipe_context *pipe, unsigned buffers,
+           const float *rgba, double depth, unsigned stencil)
 {
-       pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+       util_clear(pipe, &nv40_context(pipe)->framebuffer, buffers, rgba, depth,
+                  stencil);
 }
index adcfbdd85a8db81c93dc4a775c08d38e31efb729..97bc83292d4dd0edf3217bbf4af7a8e38701d3b6 100644 (file)
@@ -227,7 +227,7 @@ extern boolean nv40_draw_elements(struct pipe_context *pipe,
                                  unsigned count);
 
 /* nv40_clear.c */
-extern void nv40_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-                      unsigned clearValue);
+extern void nv40_clear(struct pipe_context *pipe, unsigned buffers,
+                      const float *rgba, double depth, unsigned stencil);
 
 #endif
index 313e435e7a5a2e0e225d7f5e39a8a5d55f718afd..7b67a7543978e643bc39e4fa7c39e960e45ced6f 100644 (file)
@@ -184,8 +184,8 @@ extern boolean nv50_draw_elements(struct pipe_context *pipe,
 extern void nv50_vbo_validate(struct nv50_context *nv50);
 
 /* nv50_clear.c */
-extern void nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-                      unsigned clearValue);
+extern void nv50_clear(struct pipe_context *pipe, unsigned buffers,
+                      const float *rgba, double depth, unsigned stencil);
 
 /* nv50_program.c */
 extern void nv50_vertprog_validate(struct nv50_context *nv50);
index a60c6c4c16fc9c66577d8ed18180cade0d6d74bd..f72c6c63e76b7c59e9b8cb2a1020e74705caa9e6 100644 (file)
@@ -2,6 +2,7 @@
  * 
  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  * All Rights Reserved.
+ * Copyright 2009 VMware, Inc.  All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -27,6 +28,7 @@
 
 /* Author:
  *    Brian Paul
+ *    Michel Dänzer
  */
 
 
 
 
 /**
- * Convert packed pixel from one format to another.
- */
-static unsigned
-convert_color(enum pipe_format srcFormat, unsigned srcColor,
-              enum pipe_format dstFormat)
-{
-   ubyte r, g, b, a;
-   unsigned dstColor;
-
-   util_unpack_color_ub(srcFormat, &srcColor, &r, &g, &b, &a);
-   util_pack_color_ub(r, g, b, a, dstFormat, &dstColor);
-
-   return dstColor;
-}
-
-
-
-/**
- * Clear the given surface to the specified value.
+ * Clear the given buffers to the specified values.
  * No masking, no scissor (clear entire buffer).
- * Note: when clearing a color buffer, the clearValue is always
- * encoded as PIPE_FORMAT_A8R8G8B8_UNORM.
  */
 void
-softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-               unsigned clearValue)
+softpipe_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba,
+               double depth, unsigned stencil)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
+   unsigned cv;
    uint i;
 
    if (softpipe->no_rast)
@@ -77,29 +60,29 @@ softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps,
    softpipe_update_derived(softpipe); /* not needed?? */
 #endif
 
-   if (ps == sp_tile_cache_get_surface(softpipe->zsbuf_cache)) {
-      sp_tile_cache_clear(softpipe->zsbuf_cache, clearValue);
-#if TILE_CLEAR_OPTIMIZATION
-      return;
-#endif
-   }
+   if (buffers & PIPE_CLEAR_COLOR) {
+      for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
+         struct pipe_surface *ps = softpipe->framebuffer.cbufs[i];
 
-   for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
-      if (ps == sp_tile_cache_get_surface(softpipe->cbuf_cache[i])) {
-         unsigned cv;
-         if (ps->format != PIPE_FORMAT_A8R8G8B8_UNORM) {
-            cv = convert_color(PIPE_FORMAT_A8R8G8B8_UNORM, clearValue,
-                               ps->format);
-         }
-         else {
-            cv = clearValue;
-         }
+         util_pack_color(rgba, ps->format, &cv);
          sp_tile_cache_clear(softpipe->cbuf_cache[i], cv);
+
+#if !TILE_CLEAR_OPTIMIZATION
+         /* non-cached surface */
+         pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, cv);
+#endif
       }
    }
 
+   if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
+      struct pipe_surface *ps = softpipe->framebuffer.zsbuf;
+
+      cv = util_pack_z_stencil(ps->format, depth, stencil);
+      sp_tile_cache_clear(softpipe->zsbuf_cache, cv);
+
 #if !TILE_CLEAR_OPTIMIZATION
-   /* non-cached surface */
-   pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+      /* non-cached surface */
+      pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, cv);
 #endif
+      }
 }
index a8ed1c4ecc41664405307d39ba795bb87266a076..2e450672f587eef2f385fbfbe10966a9af4880ed 100644 (file)
@@ -36,8 +36,8 @@
 struct pipe_context;
 
 extern void
-softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps,
-               unsigned clearValue);
+softpipe_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba,
+               double depth, unsigned stencil);
 
 
 #endif /* SP_CLEAR_H */
index b69ed2cb526701da1fcadb6156a822fca90ea7c6..6e86a5dfddfa78c51af4cfd36f0d4ef320f032d1 100644 (file)
@@ -973,21 +973,26 @@ trace_context_surface_fill(struct pipe_context *_pipe,
 
 static INLINE void
 trace_context_clear(struct pipe_context *_pipe,
-                    struct pipe_surface *surface,
-                    unsigned clearValue)
+                    unsigned surfaces,
+                    const float *rgba,
+                    double depth,
+                    unsigned stencil)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
    struct pipe_context *pipe = tr_ctx->pipe;
 
-   surface = trace_surface_unwrap(tr_ctx, surface);
-
    trace_dump_call_begin("pipe_context", "clear");
 
    trace_dump_arg(ptr, pipe);
-   trace_dump_arg(ptr, surface);
-   trace_dump_arg(uint, clearValue);
-
-   pipe->clear(pipe, surface, clearValue);;
+   trace_dump_arg(uint, surfaces);
+   trace_dump_arg(float, rgba[0]);
+   trace_dump_arg(float, rgba[1]);
+   trace_dump_arg(float, rgba[2]);
+   trace_dump_arg(float, rgba[3]);
+   trace_dump_arg(float, depth);
+   trace_dump_arg(uint, stencil);
+
+   pipe->clear(pipe, surfaces, rgba, depth, stencil);
 
    trace_dump_call_end();
 }
index 2452bf3522b2d4e64830a6e40713ebab9fe12064..29095dcdc3b464974eca6c96c5fb86ec9e7b3569 100644 (file)
@@ -205,12 +205,20 @@ struct pipe_context {
                        unsigned dstx, unsigned dsty,
                        unsigned width, unsigned height,
                        unsigned value);
-
-   void (*clear)(struct pipe_context *pipe, 
-                struct pipe_surface *ps,
-                unsigned clearValue);
    /*@}*/
 
+   /**
+    * Clear the specified set of currently bound buffers to specified values.
+    *
+    * buffers is a bitfield of PIPE_CLEAR_* values.
+    *
+    * rgba is a pointer to an array of one float for each of r, g, b, a.
+    */
+   void (*clear)(struct pipe_context *pipe,
+                 unsigned buffers,
+                const float *rgba,
+                 double depth,
+                unsigned stencil);
 
    /** Flush rendering (flags = bitmask of PIPE_FLUSH_x tokens) */
    void (*flush)( struct pipe_context *pipe,
index 8e4f253359af0fbb3dc93d73fe08246d2698dd8c..81defa445bf46f5152a695d8f6069d7bb1d9f280 100644 (file)
@@ -185,6 +185,15 @@ enum pipe_texture_target {
 #define PIPE_SURFACE_LAYOUT_LINEAR  0
 
 
+/**
+ * Clear buffer bits
+ */
+/** All color buffers currently bound */
+#define PIPE_CLEAR_COLOR        (1 << 0)
+/** Depth/stencil combined */
+#define PIPE_CLEAR_DEPTHSTENCIL (1 << 1)
+
+
 /**
  * Transfer object usage flags
  */
index b61b49a2f8a439ef685d9620942835a342d7308f..16d4f1e32c97d491b458629fa3822f73b1a0450b 100644 (file)
@@ -98,7 +98,8 @@ static int vlResizeFrameBuffer
        );
 
        /* Clear to black, in case video doesn't fill the entire window */
-       pipe->clear(pipe, basic_csc->framebuffer.cbufs[0], 0);
+       pipe->set_framebuffer_state(pipe, &basic_csc->framebuffer);
+       pipe->clear(pipe, PIPE_CLEAR_COLOR, 0, 0.0f, 0);
 
        return 0;
 }
index a0bf063d8146eb9302baecfb5d83b8308fedcc21..9a3003a56c424e3c98a077cb9be7313615d80b77 100644 (file)
@@ -308,45 +308,10 @@ error1:
       pipe_surface_reference(&_dst, NULL);
    }
 
-   void surface_clear(struct st_surface *surface, unsigned value = 0) 
+   void clear(unsigned buffers, const float *rgba, double depth = 0.0f,
+              unsigned stencil = 0)
    {
-      unsigned i;
-      struct pipe_surface *_surface = NULL;
-      if(!surface)
-          SWIG_exception(SWIG_TypeError, "surface must not be null");
-  
-      for(i = 0; i < $self->framebuffer.nr_cbufs; ++i) {
-         struct pipe_surface *cbuf = $self->framebuffer.cbufs[i];
-         if(cbuf) {
-            if(cbuf->texture == surface->texture &&
-               cbuf->face == surface->face &&
-               cbuf->level == surface->level &&
-               cbuf->zslice == surface->zslice) {                  
-               _surface = cbuf;
-               break;
-            }
-         }
-      }
-
-      if(!_surface) {
-         struct pipe_surface *zsbuf = $self->framebuffer.zsbuf;
-         if(zsbuf) {
-            if(zsbuf->texture == surface->texture &&
-               zsbuf->face == surface->face &&
-               zsbuf->level == surface->level &&
-               zsbuf->zslice == surface->zslice) {                  
-               _surface = zsbuf;
-            }
-         }
-      }
-
-      if(!_surface)
-         SWIG_exception(SWIG_ValueError, "surface not bound");
-      
-      $self->pipe->clear($self->pipe, _surface, value);
-   fail:
-      return;
+      $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
    }
 
 };
index 510adcc2425b1b7ed63df81b9783cb2766634f22..d02099389fbe3b7e0cbbd5250fd7e9b6e75e228b 100755 (executable)
@@ -531,8 +531,8 @@ class Context(Object):
             self.dirty = False
         return None
 
-    def clear(self, surface, value):
-        self.real.surface_clear(surface, value)
+    def clear(self, buffers, rgba, depth, stencil):
+        self.real.clear(buffers, rgba, depth, stencil)
         
     def _present(self):
         self.real.flush()
index 4c84d121c493ec8bdaa7b0ecc3381931cdfc97dd..4b9659861df237fb48ed7e083e988f042314b537 100644 (file)
@@ -150,8 +150,12 @@ def test(dev):
     fb.set_cbuf(0, cbuf)
     fb.set_zsbuf(zbuf)
     ctx.set_framebuffer(fb)
-    ctx.surface_clear(cbuf, 0x00000000)
-    ctx.surface_clear(zbuf, 0xffffffff)
+    rgba = FloatArray(4);
+    rgba[0] = 0.0
+    rgba[1] = 0.0
+    rgba[2] = 0.0
+    rgba[3] = 0.0
+    ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff)
     
     # vertex shader
     vs = Shader('''
index 434ac9b3fc8d4ea132cc4e63e0bbc0e039554aa7..472769f259232f1d50de2aa206caffacb7847cf6 100644 (file)
@@ -122,7 +122,12 @@ def test(dev, name):
     fb.nr_cbufs = 1
     fb.set_cbuf(0, cbuf)
     ctx.set_framebuffer(fb)
-    ctx.surface_clear(cbuf, 0x80808080)
+    rgba = FloatArray(4);
+    rgba[0] = 0.5
+    rgba[1] = 0.5
+    rgba[2] = 0.5
+    rgba[3] = 0.5
+    ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
 
     # vertex shader
     vs = Shader(file('vert-' + name + '.sh', 'rt').read())
index 580bf65c13b59765de1ad47a2868c76d3088a86b..0b76932b6ede275d521235a551932b80a1e08db3 100755 (executable)
@@ -161,7 +161,12 @@ class TextureTest(TestCase):
         fb.nr_cbufs = 1
         fb.set_cbuf(0, dst_surface)
         ctx.set_framebuffer(fb)
-        ctx.surface_clear(dst_surface, 0x00000000)
+        rgba = FloatArray(4);
+        rgba[0] = 0.0
+        rgba[1] = 0.0
+        rgba[2] = 0.0
+        rgba[3] = 0.0
+        ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
         del fb
     
         # vertex shader
index f5f49f6e515636667c193de1240d6ebd9dac9616..a382424667c7877489362b64285cd0ed1475675c 100755 (executable)
@@ -206,7 +206,12 @@ class TextureTest(TestCase):
         fb.nr_cbufs = 1
         fb.set_cbuf(0, cbuf)
         ctx.set_framebuffer(fb)
-        ctx.surface_clear(cbuf, 0x00000000)
+        rgba = FloatArray(4);
+        rgba[0] = 0.5
+        rgba[1] = 0.5
+        rgba[2] = 0.5
+        rgba[3] = 0.5
+        ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
         del fb
     
         # vertex shader
index bec32db0502df3dd548d86cc628d3d88c44db8d8..5bdc6a13309348008fe7f1da150a9b57cdb1fb83 100644 (file)
@@ -2,6 +2,7 @@
  * 
  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  * All Rights Reserved.
+ * Copyright 2009 VMware, Inc.  All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -29,6 +30,7 @@
   * Authors:
   *   Keith Whitwell <keith@tungstengraphics.com>
   *   Brian Paul
+  *   Michel Dänzer
   */
 
 #include "main/glheader.h"
@@ -373,101 +375,6 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
 
 
 
-static void
-clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
-{
-   struct st_renderbuffer *strb = st_renderbuffer(rb);
-
-   if (!strb->surface)
-      return;
-
-   if (check_clear_color_with_quad( ctx, rb )) {
-      /* masking or scissoring */
-      clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
-   }
-   else {
-      /* clear whole buffer w/out masking */
-      uint clearValue;
-      /* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM
-       * at this time!
-       */
-      util_pack_color(ctx->Color.ClearColor, PIPE_FORMAT_A8R8G8B8_UNORM, &clearValue);
-      ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
-   }
-}
-
-
-static void
-clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
-{
-   struct st_renderbuffer *strb = st_renderbuffer(rb);
-
-   if (!strb->surface)
-      return;
-
-   if (check_clear_depth_with_quad(ctx, rb)) {
-      /* scissoring or we have a combined depth/stencil buffer */
-      clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE);
-   }
-   else {
-      /* simple clear of whole buffer */
-      uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear);
-      ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
-   }
-}
-
-
-static void
-clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
-{
-   struct st_renderbuffer *strb = st_renderbuffer(rb);
-
-   if (!strb->surface)
-      return;
-
-   if (check_clear_stencil_with_quad(ctx, rb)) {
-      /* masking or scissoring or combined depth/stencil buffer */
-      clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE);
-   }
-   else {
-      /* simple clear of whole buffer */
-      GLuint clearValue = ctx->Stencil.Clear;
-
-      switch (strb->surface->format) {
-      case PIPE_FORMAT_S8Z24_UNORM:
-         clearValue <<= 24;
-         break;
-      default:
-         ; /* no-op, stencil value is in least significant bits */
-      }  
-
-      ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
-   }
-}
-
-
-static void
-clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
-{
-   struct st_renderbuffer *strb = st_renderbuffer(rb);
-
-   if (!strb->surface)
-      return;
-
-   if (check_clear_depth_stencil_with_quad(ctx, rb)) {
-      /* masking or scissoring */
-      clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE);
-   }
-   else {
-      /* clear whole buffer w/out masking */
-      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);
-   }
-}
-
-
 void st_flush_clear( struct st_context *st )
 {
    /* Release vertex buffer to avoid synchronous rendering if we were
@@ -493,51 +400,89 @@ static void st_clear(GLcontext *ctx, GLbitfield mask)
       = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
    struct gl_renderbuffer *stencilRb
       = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
-   GLbitfield cmask = mask & BUFFER_BITS_COLOR;
+   GLbitfield quad_buffers = 0;
+   GLbitfield clear_buffers = 0;
+   GLuint i;
 
-   /* This makes sure the softpipe has the latest scissor, etc values */
+   /* This makes sure the pipe has the latest scissor, etc values */
    st_validate_state( st );
 
-   /*
-    * XXX TO-DO:
-    * If we're going to use clear_with_quad() for any reason, use it to
-    * clear as many other buffers as possible.
-    * As it is now, we sometimes call clear_with_quad() three times to clear
-    * color/depth/stencil individually...
-    */
+   if (mask & BUFFER_BITS_COLOR) {
+      for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
+         GLuint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
 
-   if (cmask) {
-      GLuint b;
-      for (b = 0; cmask; b++) {
-         if (cmask & (1 << b)) {
+         if (mask & (1 << b)) {
             struct gl_renderbuffer *rb
                = ctx->DrawBuffer->Attachment[b].Renderbuffer;
+            struct st_renderbuffer *strb;
+
             assert(rb);
-            clear_color_buffer(ctx, rb);
-            cmask &= ~(1 << b); /* turn off bit */
+
+            strb = st_renderbuffer(rb);
+
+            if (!strb->surface)
+               continue;
+
+            if (check_clear_color_with_quad( ctx, rb ))
+               quad_buffers |= PIPE_CLEAR_COLOR;
+            else
+               clear_buffers |= PIPE_CLEAR_COLOR;
          }
-         assert(b < BUFFER_COUNT);
       }
    }
 
-   if (mask & BUFFER_BIT_ACCUM) {
-      st_clear_accum_buffer(ctx,
-                       ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
-   }
-
    if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {
       /* clearing combined depth + stencil */
-      clear_depth_stencil_buffer(ctx, depthRb);
+      struct st_renderbuffer *strb = st_renderbuffer(depthRb);
+
+      if (strb->surface) {
+         if (check_clear_depth_stencil_with_quad(ctx, depthRb))
+            quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+         else
+            clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+      }
    }
    else {
       /* separate depth/stencil clears */
       if (mask & BUFFER_BIT_DEPTH) {
-         clear_depth_buffer(ctx, depthRb);
+         struct st_renderbuffer *strb = st_renderbuffer(depthRb);
+
+         if (strb->surface) {
+            if (check_clear_depth_with_quad(ctx, depthRb))
+               quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+            else
+               clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+         }
       }
       if (mask & BUFFER_BIT_STENCIL) {
-         clear_stencil_buffer(ctx, stencilRb);
+         struct st_renderbuffer *strb = st_renderbuffer(stencilRb);
+
+         if (strb->surface) {
+            if (check_clear_stencil_with_quad(ctx, stencilRb))
+               quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+            else
+               clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
+         }
       }
    }
+
+   /*
+    * If we're going to use clear_with_quad() for any reason, use it for
+    * everything possible.
+    */
+   if (quad_buffers) {
+      quad_buffers |= clear_buffers;
+      clear_with_quad(ctx,
+                      quad_buffers & PIPE_CLEAR_COLOR,
+                      mask & BUFFER_BIT_DEPTH,
+                      mask & BUFFER_BIT_STENCIL);
+   } else if (clear_buffers)
+      ctx->st->pipe->clear(ctx->st->pipe, clear_buffers, ctx->Color.ClearColor,
+                           ctx->Depth.Clear, ctx->Stencil.Clear);
+
+   if (mask & BUFFER_BIT_ACCUM)
+      st_clear_accum_buffer(ctx,
+                            ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
 }