[Mesa-dev] [PATCH 06/14] mesa: Add a function to set up the default renderbuffer accessors.

Eric Anholt eric at anholt.net
Sun Apr 17 12:00:01 PDT 2011


---
 src/mesa/main/renderbuffer.c |  180 ++++++++++++++++++++++++------------------
 src/mesa/main/renderbuffer.h |    2 +
 2 files changed, 104 insertions(+), 78 deletions(-)

diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 281f07c..de01cfc 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -923,39 +923,19 @@ put_mono_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
 }
 
-
-
 /**
- * This is a software fallback for the gl_renderbuffer->AllocStorage
- * function.
- * Device drivers will typically override this function for the buffers
- * which it manages (typically color buffers, Z and stencil).
- * Other buffers (like software accumulation and aux buffers) which the driver
- * doesn't manage can be handled with this function.
+ * This is the default software fallback for gl_renderbuffer's span
+ * access functions.
  *
- * This one multi-purpose function can allocate stencil, depth, accum, color
- * or color-index buffers!
- *
- * This function also plugs in the appropriate GetPointer, Get/PutRow and
- * Get/PutValues functions.
+ * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
+ * are packed in the type of rb->Format, and that subsequent rows appear
+ * rb->RowStride pixels later.
  */
-GLboolean
-_mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                                GLenum internalFormat,
-                                GLuint width, GLuint height)
+void
+_mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
 {
-   GLuint pixelSize;
-
-   switch (internalFormat) {
-   case GL_RGB:
-   case GL_R3_G3_B2:
-   case GL_RGB4:
-   case GL_RGB5:
-   case GL_RGB8:
-   case GL_RGB10:
-   case GL_RGB12:
-   case GL_RGB16:
-      rb->Format = MESA_FORMAT_RGB888;
+   switch (rb->Format) {
+   case MESA_FORMAT_RGB888:
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->GetPointer = get_pointer_ubyte3;
       rb->GetRow = get_row_ubyte3;
@@ -965,18 +945,9 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_ubyte3;
       rb->PutValues = put_values_ubyte3;
       rb->PutMonoValues = put_mono_values_ubyte3;
-      pixelSize = 3 * sizeof(GLubyte);
       break;
-   case GL_RGBA:
-   case GL_RGBA2:
-   case GL_RGBA4:
-   case GL_RGB5_A1:
-   case GL_RGBA8:
-#if 1
-   case GL_RGB10_A2:
-   case GL_RGBA12:
-#endif
-      rb->Format = MESA_FORMAT_RGBA8888;
+
+   case MESA_FORMAT_RGBA8888:
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->GetPointer = get_pointer_ubyte4;
       rb->GetRow = get_row_ubyte4;
@@ -986,12 +957,9 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_ubyte4;
       rb->PutValues = put_values_ubyte4;
       rb->PutMonoValues = put_mono_values_ubyte4;
-      pixelSize = 4 * sizeof(GLubyte);
       break;
-   case GL_RGBA16:
-   case GL_RGBA16_SNORM:
-      /* for accum buffer */
-      rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
+
+   case MESA_FORMAT_SIGNED_RGBA_16:
       rb->DataType = GL_SHORT;
       rb->GetPointer = get_pointer_ushort4;
       rb->GetRow = get_row_ushort4;
@@ -1001,11 +969,10 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_ushort4;
       rb->PutValues = put_values_ushort4;
       rb->PutMonoValues = put_mono_values_ushort4;
-      pixelSize = 4 * sizeof(GLushort);
       break;
+
 #if 0
-   case GL_ALPHA8:
-      rb->Format = MESA_FORMAT_A8;
+   case MESA_FORMAT_A8:
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->GetPointer = get_pointer_alpha8;
       rb->GetRow = get_row_alpha8;
@@ -1015,15 +982,10 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_alpha8;
       rb->PutValues = put_values_alpha8;
       rb->PutMonoValues = put_mono_values_alpha8;
-      pixelSize = sizeof(GLubyte);
       break;
 #endif
-   case GL_STENCIL_INDEX:
-   case GL_STENCIL_INDEX1_EXT:
-   case GL_STENCIL_INDEX4_EXT:
-   case GL_STENCIL_INDEX8_EXT:
-   case GL_STENCIL_INDEX16_EXT:
-      rb->Format = MESA_FORMAT_S8;
+
+   case MESA_FORMAT_S8:
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->GetPointer = get_pointer_ubyte;
       rb->GetRow = get_row_ubyte;
@@ -1033,11 +995,9 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_ubyte;
       rb->PutValues = put_values_ubyte;
       rb->PutMonoValues = put_mono_values_ubyte;
-      pixelSize = sizeof(GLubyte);
       break;
-   case GL_DEPTH_COMPONENT:
-   case GL_DEPTH_COMPONENT16:
-      rb->Format = MESA_FORMAT_Z16;
+
+   case MESA_FORMAT_Z16:
       rb->DataType = GL_UNSIGNED_SHORT;
       rb->GetPointer = get_pointer_ushort;
       rb->GetRow = get_row_ushort;
@@ -1047,9 +1007,10 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_ushort;
       rb->PutValues = put_values_ushort;
       rb->PutMonoValues = put_mono_values_ushort;
-      pixelSize = sizeof(GLushort);
       break;
-   case GL_DEPTH_COMPONENT24:
+
+   case MESA_FORMAT_Z32:
+   case MESA_FORMAT_X8_Z24:
       rb->DataType = GL_UNSIGNED_INT;
       rb->GetPointer = get_pointer_uint;
       rb->GetRow = get_row_uint;
@@ -1059,11 +1020,10 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_uint;
       rb->PutValues = put_values_uint;
       rb->PutMonoValues = put_mono_values_uint;
-      rb->Format = MESA_FORMAT_X8_Z24;
-      pixelSize = sizeof(GLuint);
       break;
-   case GL_DEPTH_COMPONENT32:
-      rb->DataType = GL_UNSIGNED_INT;
+
+   case MESA_FORMAT_Z24_S8:
+      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
       rb->GetPointer = get_pointer_uint;
       rb->GetRow = get_row_uint;
       rb->GetValues = get_values_uint;
@@ -1072,28 +1032,92 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
       rb->PutMonoRow = put_mono_row_uint;
       rb->PutValues = put_values_uint;
       rb->PutMonoValues = put_mono_values_uint;
+      break;
+
+   default:
+      break;
+   }
+}
+
+/**
+ * This is a software fallback for the gl_renderbuffer->AllocStorage
+ * function.
+ * Device drivers will typically override this function for the buffers
+ * which it manages (typically color buffers, Z and stencil).
+ * Other buffers (like software accumulation and aux buffers) which the driver
+ * doesn't manage can be handled with this function.
+ *
+ * This one multi-purpose function can allocate stencil, depth, accum, color
+ * or color-index buffers!
+ *
+ * This function also plugs in the appropriate GetPointer, Get/PutRow and
+ * Get/PutValues functions.
+ */
+GLboolean
+_mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
+                                GLenum internalFormat,
+                                GLuint width, GLuint height)
+{
+   switch (internalFormat) {
+   case GL_RGB:
+   case GL_R3_G3_B2:
+   case GL_RGB4:
+   case GL_RGB5:
+   case GL_RGB8:
+   case GL_RGB10:
+   case GL_RGB12:
+   case GL_RGB16:
+      rb->Format = MESA_FORMAT_RGB888;
+      break;
+   case GL_RGBA:
+   case GL_RGBA2:
+   case GL_RGBA4:
+   case GL_RGB5_A1:
+   case GL_RGBA8:
+#if 1
+   case GL_RGB10_A2:
+   case GL_RGBA12:
+#endif
+      rb->Format = MESA_FORMAT_RGBA8888;
+      break;
+   case GL_RGBA16:
+   case GL_RGBA16_SNORM:
+      /* for accum buffer */
+      rb->Format = MESA_FORMAT_SIGNED_RGBA_16;
+      break;
+#if 0
+   case GL_ALPHA8:
+      rb->Format = MESA_FORMAT_A8;
+      break;
+#endif
+   case GL_STENCIL_INDEX:
+   case GL_STENCIL_INDEX1_EXT:
+   case GL_STENCIL_INDEX4_EXT:
+   case GL_STENCIL_INDEX8_EXT:
+   case GL_STENCIL_INDEX16_EXT:
+      rb->Format = MESA_FORMAT_S8;
+      break;
+   case GL_DEPTH_COMPONENT:
+   case GL_DEPTH_COMPONENT16:
+      rb->Format = MESA_FORMAT_Z16;
+      break;
+   case GL_DEPTH_COMPONENT24:
+      rb->Format = MESA_FORMAT_X8_Z24;
+      break;
+   case GL_DEPTH_COMPONENT32:
       rb->Format = MESA_FORMAT_Z32;
-      pixelSize = sizeof(GLuint);
       break;
    case GL_DEPTH_STENCIL_EXT:
    case GL_DEPTH24_STENCIL8_EXT:
       rb->Format = MESA_FORMAT_Z24_S8;
-      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
-      rb->GetPointer = get_pointer_uint;
-      rb->GetRow = get_row_uint;
-      rb->GetValues = get_values_uint;
-      rb->PutRow = put_row_uint;
-      rb->PutRowRGB = NULL;
-      rb->PutMonoRow = put_mono_row_uint;
-      rb->PutValues = put_values_uint;
-      rb->PutMonoValues = put_mono_values_uint;
-      pixelSize = sizeof(GLuint);
       break;
    default:
       /* unsupported format */
       return GL_FALSE;
    }
 
+   _mesa_set_renderbuffer_accessors(rb);
+
    ASSERT(rb->DataType);
    ASSERT(rb->GetPointer);
    ASSERT(rb->GetRow);
@@ -1113,7 +1137,7 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
 
    if (width > 0 && height > 0) {
       /* allocate new buffer storage */
-      rb->Data = malloc(width * height * pixelSize);
+      rb->Data = malloc(width * height * _mesa_get_format_bytes(rb->Format));
 
       if (rb->Data == NULL) {
          rb->Width = 0;
@@ -1121,7 +1145,7 @@ _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *
 	 rb->RowStride = 0;
          _mesa_error(ctx, GL_OUT_OF_MEMORY,
                      "software renderbuffer allocation (%d x %d x %d)",
-                     width, height, pixelSize);
+                     width, height, _mesa_get_format_bytes(rb->Format));
          return GL_FALSE;
       }
    }
diff --git a/src/mesa/main/renderbuffer.h b/src/mesa/main/renderbuffer.h
index 4702a8e..39d9b30 100644
--- a/src/mesa/main/renderbuffer.h
+++ b/src/mesa/main/renderbuffer.h
@@ -46,6 +46,8 @@ _mesa_delete_renderbuffer(struct gl_renderbuffer *rb);
 extern struct gl_renderbuffer *
 _mesa_new_soft_renderbuffer(struct gl_context *ctx, GLuint name);
 
+extern void
+_mesa_set_renderbuffer_accessors(struct gl_renderbuffer *rb);
 
 extern GLboolean
 _mesa_soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
-- 
1.7.4.1



More information about the mesa-dev mailing list