Mesa (master): mesa: handle glDrawPixels images which are larger than max rect texture size

Brian Paul brianp at kemper.freedesktop.org
Wed Aug 12 02:35:43 UTC 2009


Module: Mesa
Branch: master
Commit: fd90d8000c163498646857b19ef715de3a585f9c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd90d8000c163498646857b19ef715de3a585f9c

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Aug 11 19:30:05 2009 -0600

mesa: handle glDrawPixels images which are larger than max rect texture size

---

 src/mesa/drivers/common/meta.c |   50 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 79e93d6..a8db686 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1048,6 +1048,42 @@ _mesa_meta_copy_pixels(GLcontext *ctx, GLint srcX, GLint srcY,
 
 
 /**
+ * When the glDrawPixels() image size is greater than the max rectangle
+ * texture size we use this function to break the glDrawPixels() image
+ * into tiles which fit into the max texture size.
+ */
+static void
+tiled_draw_pixels(GLcontext *ctx,
+                  GLint x, GLint y, GLsizei width, GLsizei height,
+                  GLenum format, GLenum type,
+                  const struct gl_pixelstore_attrib *unpack,
+                  const GLvoid *pixels)
+{
+   const GLint maxSize = ctx->Const.MaxTextureRectSize;
+   struct gl_pixelstore_attrib tileUnpack = *unpack;
+   GLint i, j;
+
+   for (i = 0; i < width; i += maxSize) {
+      const GLint tileWidth = MIN2(maxSize, width - i);
+      const GLint tileX = (GLint) (x + i * ctx->Pixel.ZoomX);
+
+      tileUnpack.SkipPixels = unpack->SkipPixels + i;
+
+      for (j = 0; j < height; j += maxSize) {
+         const GLint tileHeight = MIN2(maxSize, height - j);
+         const GLint tileY = (GLint) (y + j * ctx->Pixel.ZoomY);
+
+         tileUnpack.SkipRows = unpack->SkipRows + j;
+
+         _mesa_meta_draw_pixels(ctx, tileX, tileY,
+                                tileWidth, tileHeight,
+                                format, type, &tileUnpack, pixels);
+      }
+   }
+}
+
+
+/**
  * Meta implementation of ctx->Driver.DrawPixels() in terms
  * of texture mapping and polygon rendering.
  * Note: this function requires GL_ARB_texture_rectangle support.
@@ -1075,9 +1111,7 @@ _mesa_meta_draw_pixels(GLcontext *ctx,
     */
    fallback = GL_FALSE;
    if (ctx->_ImageTransferState ||
-       ctx->Fog.Enabled ||
-       width > ctx->Const.MaxTextureRectSize ||
-       height > ctx->Const.MaxTextureRectSize) {
+       ctx->Fog.Enabled) {
       fallback = GL_TRUE;
    }
 
@@ -1094,6 +1128,16 @@ _mesa_meta_draw_pixels(GLcontext *ctx,
       return;
    }
 
+   /*
+    * Check image size against max texture size, draw as tiles if needed.
+    */
+   if (width > ctx->Const.MaxTextureRectSize ||
+       height > ctx->Const.MaxTextureRectSize) {
+      tiled_draw_pixels(ctx, x, y, width, height,
+                        format, type, unpack, pixels);
+      return;
+   }
+
    /* Most GL state applies to glDrawPixels, but a there's a few things
     * we need to override:
     */




More information about the mesa-commit mailing list