texstore: Add a generic implementation of GL_ARB_clear_texture
authorNeil Roberts <neil@linux.intel.com>
Tue, 10 Jun 2014 15:19:58 +0000 (16:19 +0100)
committerNeil Roberts <neil@linux.intel.com>
Wed, 23 Jul 2014 10:50:38 +0000 (11:50 +0100)
Adds an implmentation of the ClearTexSubImage driver entry point that just
maps the texture and writes the values in. The extension is not yet enabled by
default because it doesn't work with multisample textures as they don't have a
simple linear layout.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/mesa/main/texstore.c
src/mesa/main/texstore.h

index c87e407fac3b4f32d525a88bfc68237ca1786505..aea53f8d12073e33f75ec66a2a0e8f21e495c170 100644 (file)
@@ -4094,6 +4094,78 @@ _mesa_store_texsubimage(struct gl_context *ctx, GLuint dims,
                      format, type, pixels, packing, "glTexSubImage");
 }
 
+static void
+clear_image_to_zero(GLubyte *dstMap, GLint dstRowStride,
+                    GLsizei width, GLsizei height,
+                    GLsizei clearValueSize)
+{
+   GLsizei y;
+
+   for (y = 0; y < height; y++) {
+      memset(dstMap, 0, clearValueSize * width);
+      dstMap += dstRowStride;
+   }
+}
+
+static void
+clear_image_to_value(GLubyte *dstMap, GLint dstRowStride,
+                     GLsizei width, GLsizei height,
+                     const GLvoid *clearValue,
+                     GLsizei clearValueSize)
+{
+   GLsizei y, x;
+
+   for (y = 0; y < height; y++) {
+      for (x = 0; x < width; x++) {
+         memcpy(dstMap, clearValue, clearValueSize);
+         dstMap += clearValueSize;
+      }
+      dstMap += dstRowStride - clearValueSize * width;
+   }
+}
+
+/*
+ * Fallback for Driver.ClearTexSubImage().
+ */
+void
+_mesa_store_cleartexsubimage(struct gl_context *ctx,
+                             struct gl_texture_image *texImage,
+                             GLint xoffset, GLint yoffset, GLint zoffset,
+                             GLsizei width, GLsizei height, GLsizei depth,
+                             const GLvoid *clearValue)
+{
+   GLubyte *dstMap;
+   GLint dstRowStride;
+   GLsizeiptr clearValueSize;
+   GLsizei z;
+
+   clearValueSize = _mesa_get_format_bytes(texImage->TexFormat);
+
+   for (z = 0; z < depth; z++) {
+      ctx->Driver.MapTextureImage(ctx, texImage,
+                                  z + zoffset, xoffset, yoffset,
+                                  width, height,
+                                  GL_MAP_WRITE_BIT,
+                                  &dstMap, &dstRowStride);
+      if (dstMap == NULL) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glClearTex*Image");
+         return;
+      }
+
+      if (clearValue) {
+         clear_image_to_value(dstMap, dstRowStride,
+                              width, height,
+                              clearValue,
+                              clearValueSize);
+      } else {
+         clear_image_to_zero(dstMap, dstRowStride,
+                             width, height,
+                             clearValueSize);
+      }
+
+      ctx->Driver.UnmapTextureImage(ctx, texImage, z + zoffset);
+   }
+}
 
 /**
  * Fallback for Driver.CompressedTexImage()
index c4cfffde677288dfe9bdfdbcacf7635d7f4764dd..dd1e1d0156226d33dd5527aae83b814520d93088 100644 (file)
@@ -117,6 +117,13 @@ _mesa_store_texsubimage(struct gl_context *ctx, GLuint dims,
                         const struct gl_pixelstore_attrib *packing);
 
 
+extern void
+_mesa_store_cleartexsubimage(struct gl_context *ctx,
+                             struct gl_texture_image *texImage,
+                             GLint xoffset, GLint yoffset, GLint zoffset,
+                             GLsizei width, GLsizei height, GLsizei depth,
+                             const GLvoid *clearValue);
+
 extern void
 _mesa_store_compressed_teximage(struct gl_context *ctx, GLuint dims,
                                 struct gl_texture_image *texImage,