}
}
-
-
/**
- * 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;
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;
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;
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;
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;
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;
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;
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;
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);
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;
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;
}
}