Fix pow <small> and a very stypid bug with dummy srcs(0 equals to tmp0.x)</small...
[mesa.git] / src / mesa / main / renderbuffer.c
index 17fb6456e85c46ade8b16f353eeb669f31c238c9..2031662c2161830b5b19f3df78652d2ddd96dac0 100644 (file)
@@ -313,11 +313,12 @@ put_mono_values_ushort(GLcontext *ctx, struct gl_renderbuffer *rb,
 
 static void *
 get_pointer_uint(GLcontext *ctx, struct gl_renderbuffer *rb,
-                    GLint x, GLint y)
+                 GLint x, GLint y)
 {
    if (!rb->Data)
       return NULL;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    return (GLuint *) rb->Data + y * rb->Width + x;
 }
 
@@ -327,7 +328,8 @@ get_row_uint(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
              GLint x, GLint y, void *values)
 {
    const void *src = rb->GetPointer(ctx, rb, x, y);
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    _mesa_memcpy(values, src, count * sizeof(GLuint));
 }
 
@@ -338,7 +340,8 @@ get_values_uint(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 {
    GLuint *dst = (GLuint *) values;
    GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    for (i = 0; i < count; i++) {
       const GLuint *src = (GLuint *) rb->Data + y[i] * rb->Width + x[i];
       dst[i] = *src;
@@ -352,7 +355,8 @@ put_row_uint(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 {
    const GLuint *src = (const GLuint *) values;
    GLuint *dst = (GLuint *) rb->Data + y * rb->Width + x;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    if (mask) {
       GLuint i;
       for (i = 0; i < count; i++) {
@@ -373,7 +377,8 @@ put_mono_row_uint(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 {
    const GLuint val = *((const GLuint *) value);
    GLuint *dst = (GLuint *) rb->Data + y * rb->Width + x;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    if (mask) {
       GLuint i;
       for (i = 0; i < count; i++) {
@@ -398,7 +403,8 @@ put_values_uint(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 {
    const GLuint *src = (const GLuint *) values;
    GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    for (i = 0; i < count; i++) {
       if (!mask || mask[i]) {
          GLuint *dst = (GLuint *) rb->Data + y[i] * rb->Width + x[i];
@@ -415,7 +421,8 @@ put_mono_values_uint(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 {
    const GLuint val = *((const GLuint *) value);
    GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
+          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
    for (i = 0; i < count; i++) {
       if (!mask || mask[i]) {
          GLuint *dst = (GLuint *) rb->Data + y[i] * rb->Width + x[i];
@@ -937,10 +944,10 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ubyte3;
       rb->PutValues = put_values_ubyte3;
       rb->PutMonoValues = put_mono_values_ubyte3;
-      rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
-      rb->ComponentSizes[1] = 8 * sizeof(GLubyte);
-      rb->ComponentSizes[2] = 8 * sizeof(GLubyte);
-      rb->ComponentSizes[3] = 0;
+      rb->RedBits   = 8 * sizeof(GLubyte);
+      rb->GreenBits = 8 * sizeof(GLubyte);
+      rb->BlueBits  = 8 * sizeof(GLubyte);
+      rb->AlphaBits = 0;
       pixelSize = 3 * sizeof(GLubyte);
       break;
    case GL_RGBA:
@@ -958,10 +965,10 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ubyte4;
       rb->PutValues = put_values_ubyte4;
       rb->PutMonoValues = put_mono_values_ubyte4;
-      rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
-      rb->ComponentSizes[1] = 8 * sizeof(GLubyte);
-      rb->ComponentSizes[2] = 8 * sizeof(GLubyte);
-      rb->ComponentSizes[3] = 8 * sizeof(GLubyte);
+      rb->RedBits   = 8 * sizeof(GLubyte);
+      rb->GreenBits = 8 * sizeof(GLubyte);
+      rb->BlueBits  = 8 * sizeof(GLubyte);
+      rb->AlphaBits = 8 * sizeof(GLubyte);
       pixelSize = 4 * sizeof(GLubyte);
       break;
    case GL_RGB10_A2:
@@ -977,10 +984,10 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ushort4;
       rb->PutValues = put_values_ushort4;
       rb->PutMonoValues = put_mono_values_ushort4;
-      rb->ComponentSizes[0] = 8 * sizeof(GLushort);
-      rb->ComponentSizes[1] = 8 * sizeof(GLushort);
-      rb->ComponentSizes[2] = 8 * sizeof(GLushort);
-      rb->ComponentSizes[3] = 8 * sizeof(GLushort);
+      rb->RedBits   = 8 * sizeof(GLushort);
+      rb->GreenBits = 8 * sizeof(GLushort);
+      rb->BlueBits  = 8 * sizeof(GLushort);
+      rb->AlphaBits = 8 * sizeof(GLushort);
       pixelSize = 4 * sizeof(GLushort);
       break;
 #if 00
@@ -995,10 +1002,10 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_alpha8;
       rb->PutValues = put_values_alpha8;
       rb->PutMonoValues = put_mono_values_alpha8;
-      rb->ComponentSizes[0] = 0; /*red*/
-      rb->ComponentSizes[1] = 0; /*green*/
-      rb->ComponentSizes[2] = 0; /*blue*/
-      rb->ComponentSizes[3] = 8 * sizeof(GLubyte);
+      rb->RedBits   = 0; /*red*/
+      rb->GreenBits = 0; /*green*/
+      rb->BlueBits  = 0; /*blue*/
+      rb->AlphaBits = 8 * sizeof(GLubyte);
       pixelSize = sizeof(GLubyte);
       break;
 #endif
@@ -1016,7 +1023,7 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ubyte;
       rb->PutValues = put_values_ubyte;
       rb->PutMonoValues = put_mono_values_ubyte;
-      rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
+      rb->StencilBits = 8 * sizeof(GLubyte);
       pixelSize = sizeof(GLubyte);
       break;
    case GL_STENCIL_INDEX16_EXT:
@@ -1030,7 +1037,7 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ushort;
       rb->PutValues = put_values_ushort;
       rb->PutMonoValues = put_mono_values_ushort;
-      rb->ComponentSizes[0] = 8 * sizeof(GLushort);
+      rb->StencilBits = 8 * sizeof(GLushort);
       pixelSize = sizeof(GLushort);
       break;
    case GL_DEPTH_COMPONENT:
@@ -1045,7 +1052,7 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ushort;
       rb->PutValues = put_values_ushort;
       rb->PutMonoValues = put_mono_values_ushort;
-      rb->ComponentSizes[0] = 8 * sizeof(GLushort);
+      rb->DepthBits = 8 * sizeof(GLushort);
       pixelSize = sizeof(GLushort);
       break;
    case GL_DEPTH_COMPONENT24:
@@ -1060,7 +1067,26 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_uint;
       rb->PutValues = put_values_uint;
       rb->PutMonoValues = put_mono_values_uint;
-      rb->ComponentSizes[0] = 8 * sizeof(GLuint);
+      if (internalFormat == GL_DEPTH_COMPONENT24)
+         rb->DepthBits = 24;
+      else
+         rb->DepthBits = 32;
+      pixelSize = sizeof(GLuint);
+      break;
+   case GL_DEPTH_STENCIL_EXT:
+   case GL_DEPTH24_STENCIL8_EXT:
+      rb->_BaseFormat = GL_DEPTH_STENCIL_EXT;
+      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;
+      rb->DepthBits = 24;
+      rb->StencilBits = 8;
       pixelSize = sizeof(GLuint);
       break;
    case GL_COLOR_INDEX8_EXT:
@@ -1074,7 +1100,7 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ubyte;
       rb->PutValues = put_values_ubyte;
       rb->PutMonoValues = put_mono_values_ubyte;
-      rb->ComponentSizes[0] = 8 * sizeof(GLubyte);
+      rb->IndexBits = 8 * sizeof(GLubyte);
       pixelSize = sizeof(GLubyte);
       break;
    case GL_COLOR_INDEX16_EXT:
@@ -1088,7 +1114,7 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_ushort;
       rb->PutValues = put_values_ushort;
       rb->PutMonoValues = put_mono_values_ushort;
-      rb->ComponentSizes[0] = 8 * sizeof(GLushort);
+      rb->IndexBits = 8 * sizeof(GLushort);
       pixelSize = sizeof(GLushort);
       break;
    case COLOR_INDEX32:
@@ -1102,7 +1128,7 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
       rb->PutMonoRow = put_mono_row_uint;
       rb->PutValues = put_values_uint;
       rb->PutMonoValues = put_mono_values_uint;
-      rb->ComponentSizes[0] = 8 * sizeof(GLuint);
+      rb->IndexBits = 8 * sizeof(GLuint);
       pixelSize = sizeof(GLuint);
       break;
    default:
@@ -1118,7 +1144,6 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
    ASSERT(rb->PutMonoRow);
    ASSERT(rb->PutValues);
    ASSERT(rb->PutMonoValues);
-   ASSERT(rb->ComponentSizes[0] > 0);
 
    /* free old buffer storage */
    if (rb->Data)
@@ -1141,53 +1166,50 @@ soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
 }
 
 
+
 /**********************************************************************/
 /**********************************************************************/
 /**********************************************************************/
 
 
 /**
- * The alpha_renderbuffer class is used to augment an RGB renderbuffer with
- * an alpha channel.  The RGB buffer can be hardware-based.
- * We basically wrap the RGB buffer.  When PutRow is called (for example),
- * we store the alpha values in this buffer, then pass on the PutRow call
- * to the wrapped RGB buffer.
+ * Here we utilize the gl_renderbuffer->Wrapper field to put an alpha
+ * buffer wrapper around an existing RGB renderbuffer (hw or sw).
+ *
+ * When PutRow is called (for example), we store the alpha values in
+ * this buffer, then pass on the PutRow call to the wrapped RGB
+ * buffer.
  */
-struct alpha_renderbuffer
-{
-   struct gl_renderbuffer Base;        /* the alpha buffer */
-   struct gl_renderbuffer *RGBbuffer;  /* the wrapped RGB buffer */
-};
 
 
 static GLboolean
-alloc_storage_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb,
+alloc_storage_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
                      GLenum internalFormat, GLuint width, GLuint height)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
+   ASSERT(arb != arb->Wrapped);
 
    /* first, pass the call to the wrapped RGB buffer */
-   if (!arb->RGBbuffer->AllocStorage(ctx, arb->RGBbuffer, internalFormat,
-                                     width, height)) {
+   if (!arb->Wrapped->AllocStorage(ctx, arb->Wrapped, internalFormat,
+                                  width, height)) {
       return GL_FALSE;
    }
 
    /* next, resize my alpha buffer */
-   if (arb->Base.Data) {
-      _mesa_free(arb->Base.Data);
+   if (arb->Data) {
+      _mesa_free(arb->Data);
    }
 
-   arb->Base.Data = _mesa_malloc(width * height * sizeof(GLubyte));
-   if (arb->Base.Data == NULL) {
-      arb->Base.Width = 0;
-      arb->Base.Height = 0;
+   arb->Data = _mesa_malloc(width * height * sizeof(GLubyte));
+   if (arb->Data == NULL) {
+      arb->Width = 0;
+      arb->Height = 0;
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "software alpha buffer allocation");
       return GL_FALSE;
    }
 
-   arb->Base.Width = width;
-   arb->Base.Height = height;
-   arb->Base.InternalFormat = internalFormat;
+   arb->Width = width;
+   arb->Height = height;
+   arb->InternalFormat = internalFormat;
 
    return GL_TRUE;
 }
@@ -1197,21 +1219,21 @@ alloc_storage_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb,
  * Delete an alpha_renderbuffer object, as well as the wrapped RGB buffer.
  */
 static void
-delete_renderbuffer_alpha8(struct gl_renderbuffer *rb)
+delete_renderbuffer_alpha8(struct gl_renderbuffer *arb)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
-   if (arb->Base.Data) {
-      _mesa_free(arb->Base.Data);
+   if (arb->Data) {
+      _mesa_free(arb->Data);
    }
-   assert(arb->RGBbuffer);
-   arb->RGBbuffer->Delete(arb->RGBbuffer);
-   arb->RGBbuffer = NULL;
+   ASSERT(arb->Wrapped);
+   ASSERT(arb != arb->Wrapped);
+   arb->Wrapped->Delete(arb->Wrapped);
+   arb->Wrapped = NULL;
    _mesa_free(arb);
 }
 
 
 static void *
-get_pointer_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb,
+get_pointer_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
                    GLint x, GLint y)
 {
    return NULL;   /* don't allow direct access! */
@@ -1219,17 +1241,17 @@ get_pointer_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb,
 
 
 static void
-get_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
+get_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
                GLint x, GLint y, void *values)
 {
    /* NOTE: 'values' is RGBA format! */
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
-   const GLubyte *src = (const GLubyte *) rb->Data + y * rb->Width + x;
+   const GLubyte *src = (const GLubyte *) arb->Data + y * arb->Width + x;
    GLubyte *dst = (GLubyte *) values;
    GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->GetRow(ctx, arb->RGBbuffer, count, x, y, values);
+   arb->Wrapped->GetRow(ctx, arb->Wrapped, count, x, y, values);
    /* second, fill in alpha values from this buffer! */
    for (i = 0; i < count; i++) {
       dst[i * 4 + 3] = src[i];
@@ -1238,34 +1260,34 @@ get_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 
 
 static void
-get_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
+get_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
                   const GLint x[], const GLint y[], void *values)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
    GLubyte *dst = (GLubyte *) values;
    GLuint i;
-   assert(rb->DataType == GL_UNSIGNED_BYTE);
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->GetValues(ctx, arb->RGBbuffer, count, x, y, values);
+   arb->Wrapped->GetValues(ctx, arb->Wrapped, count, x, y, values);
    /* second, fill in alpha values from this buffer! */
    for (i = 0; i < count; i++) {
-      const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+      const GLubyte *src = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
       dst[i * 4 + 3] = *src;
    }
 }
 
 
 static void
-put_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
+put_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
                GLint x, GLint y, const void *values, const GLubyte *mask)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
    const GLubyte *src = (const GLubyte *) values;
-   GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
+   GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
    GLuint i;
-   assert(rb->DataType == GL_UNSIGNED_BYTE);
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->PutRow(ctx, arb->RGBbuffer, count, x, y, values, mask);
+   arb->Wrapped->PutRow(ctx, arb->Wrapped, count, x, y, values, mask);
    /* second, store alpha in our buffer */
    for (i = 0; i < count; i++) {
       if (!mask || mask[i]) {
@@ -1276,16 +1298,16 @@ put_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 
 
 static void
-put_row_rgb_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
+put_row_rgb_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
                    GLint x, GLint y, const void *values, const GLubyte *mask)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
    const GLubyte *src = (const GLubyte *) values;
-   GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
+   GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
    GLuint i;
-   assert(rb->DataType == GL_UNSIGNED_BYTE);
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->PutRowRGB(ctx, arb->RGBbuffer, count, x, y, values, mask);
+   arb->Wrapped->PutRowRGB(ctx, arb->Wrapped, count, x, y, values, mask);
    /* second, store alpha in our buffer */
    for (i = 0; i < count; i++) {
       if (!mask || mask[i]) {
@@ -1296,15 +1318,15 @@ put_row_rgb_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 
 
 static void
-put_mono_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
+put_mono_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
                     GLint x, GLint y, const void *value, const GLubyte *mask)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
    const GLubyte val = ((const GLubyte *) value)[3];
-   GLubyte *dst = (GLubyte *) rb->Data + y * rb->Width + x;
-   assert(rb->DataType == GL_UNSIGNED_BYTE);
+   GLubyte *dst = (GLubyte *) arb->Data + y * arb->Width + x;
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->PutMonoRow(ctx, arb->RGBbuffer, count, x, y, value, mask);
+   arb->Wrapped->PutMonoRow(ctx, arb->Wrapped, count, x, y, value, mask);
    /* second, store alpha in our buffer */
    if (mask) {
       GLuint i;
@@ -1321,20 +1343,20 @@ put_mono_row_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 
 
 static void
-put_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
+put_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb, GLuint count,
                   const GLint x[], const GLint y[],
                   const void *values, const GLubyte *mask)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
    const GLubyte *src = (const GLubyte *) values;
    GLuint i;
-   assert(rb->DataType == GL_UNSIGNED_BYTE);
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->PutValues(ctx, arb->RGBbuffer, count, x, y, values, mask);
+   arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, values, mask);
    /* second, store alpha in our buffer */
    for (i = 0; i < count; i++) {
       if (!mask || mask[i]) {
-         GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+         GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
          *dst = src[i * 4 + 3];
       }
    }
@@ -1342,20 +1364,20 @@ put_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb, GLuint count,
 
 
 static void
-put_mono_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *rb,
+put_mono_values_alpha8(GLcontext *ctx, struct gl_renderbuffer *arb,
                        GLuint count, const GLint x[], const GLint y[],
                        const void *value, const GLubyte *mask)
 {
-   struct alpha_renderbuffer *arb = (struct alpha_renderbuffer *) rb;
    const GLubyte val = ((const GLubyte *) value)[3];
    GLuint i;
-   assert(rb->DataType == GL_UNSIGNED_BYTE);
+   ASSERT(arb != arb->Wrapped);
+   ASSERT(arb->DataType == GL_UNSIGNED_BYTE);
    /* first, pass the call to the wrapped RGB buffer */
-   arb->RGBbuffer->PutValues(ctx, arb->RGBbuffer, count, x, y, value, mask);
+   arb->Wrapped->PutValues(ctx, arb->Wrapped, count, x, y, value, mask);
    /* second, store alpha in our buffer */
    for (i = 0; i < count; i++) {
       if (!mask || mask[i]) {
-         GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->Width + x[i];
+         GLubyte *dst = (GLubyte *) arb->Data + y[i] * arb->Width + x[i];
          *dst = val;
       }
    }
@@ -1399,12 +1421,17 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
    rb->InternalFormat = GL_NONE;
    rb->_BaseFormat = GL_NONE;
    rb->DataType = GL_NONE;
-   rb->ComponentSizes[0] = 0;
-   rb->ComponentSizes[1] = 0;
-   rb->ComponentSizes[2] = 0;
-   rb->ComponentSizes[3] = 0;
+   rb->RedBits = rb->GreenBits = rb->BlueBits = rb->AlphaBits = 0;
+   rb->IndexBits = 0;
+   rb->DepthBits = 0;
+   rb->StencilBits = 0;
    rb->Data = NULL;
 
+   /* Point back to ourself so that we don't have to check for Wrapped==NULL
+    * all over the drivers.
+    */
+   rb->Wrapped = rb;
+
    rb->GetPointer = nop_get_pointer;
    rb->GetRow = NULL;
    rb->GetValues = NULL;
@@ -1619,8 +1646,10 @@ _mesa_add_alpha_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
 
    assert(MAX_COLOR_ATTACHMENTS >= 4);
 
+   /* Wrap each of the RGB color buffers with an alpha renderbuffer.
+    */
    for (b = BUFFER_FRONT_LEFT; b <= BUFFER_BACK_RIGHT; b++) {
-      struct alpha_renderbuffer *arb;
+      struct gl_renderbuffer *arb;
 
       if (b == BUFFER_FRONT_LEFT && !frontLeft)
          continue;
@@ -1637,37 +1666,40 @@ _mesa_add_alpha_renderbuffers(GLcontext *ctx, struct gl_framebuffer *fb,
       /* only GLubyte supported for now */
       assert(fb->Attachment[b].Renderbuffer->DataType == GL_UNSIGNED_BYTE);
 
-      arb = CALLOC_STRUCT(alpha_renderbuffer);
+      /* allocate alpha renderbuffer */
+      arb = _mesa_new_renderbuffer(ctx, 0);
       if (!arb) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating alpha buffer");
          return GL_FALSE;
       }
 
-      _mesa_init_renderbuffer(&arb->Base, 0);
-
-      /* wrap the RGB buffer */
-      arb->RGBbuffer = fb->Attachment[b].Renderbuffer;
-
-      /* plug in my functions */
-      arb->Base.InternalFormat = arb->RGBbuffer->InternalFormat;
-      arb->Base._BaseFormat    = arb->RGBbuffer->_BaseFormat;
-      arb->Base.DataType       = arb->RGBbuffer->DataType;
-      arb->Base.AllocStorage   = alloc_storage_alpha8;
-      arb->Base.Delete         = delete_renderbuffer_alpha8;
-      arb->Base.GetPointer     = get_pointer_alpha8;
-      arb->Base.GetRow         = get_row_alpha8;
-      arb->Base.GetValues      = get_values_alpha8;
-      arb->Base.PutRow         = put_row_alpha8;
-      arb->Base.PutRowRGB      = put_row_rgb_alpha8;
-      arb->Base.PutMonoRow     = put_mono_row_alpha8;
-      arb->Base.PutValues      = put_values_alpha8;
-      arb->Base.PutMonoValues  = put_mono_values_alpha8;
+      /* wrap the alpha renderbuffer around the RGB renderbuffer */
+      arb->Wrapped = fb->Attachment[b].Renderbuffer;
+
+      /* Set up my alphabuffer fields and plug in my functions.
+       * The functions will put/get the alpha values from/to RGBA arrays
+       * and then call the wrapped buffer's functions to handle the RGB
+       * values.
+       */
+      arb->InternalFormat = arb->Wrapped->InternalFormat;
+      arb->_BaseFormat    = arb->Wrapped->_BaseFormat;
+      arb->DataType       = arb->Wrapped->DataType;
+      arb->AllocStorage   = alloc_storage_alpha8;
+      arb->Delete         = delete_renderbuffer_alpha8;
+      arb->GetPointer     = get_pointer_alpha8;
+      arb->GetRow         = get_row_alpha8;
+      arb->GetValues      = get_values_alpha8;
+      arb->PutRow         = put_row_alpha8;
+      arb->PutRowRGB      = put_row_rgb_alpha8;
+      arb->PutMonoRow     = put_mono_row_alpha8;
+      arb->PutValues      = put_values_alpha8;
+      arb->PutMonoValues  = put_mono_values_alpha8;
 
       /* clear the pointer to avoid assertion/sanity check failure later */
       fb->Attachment[b].Renderbuffer = NULL;
 
       /* plug the alpha renderbuffer into the colorbuffer attachment */
-      _mesa_add_renderbuffer(fb, b, &arb->Base);
+      _mesa_add_renderbuffer(fb, b, arb);
    }
 
    return GL_TRUE;
@@ -1705,6 +1737,9 @@ _mesa_add_depth_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
    if (depthBits <= 16) {
       rb->InternalFormat = GL_DEPTH_COMPONENT16;
    }
+   else if (depthBits <= 24) {
+      rb->InternalFormat = GL_DEPTH_COMPONENT24;
+   }
    else {
       rb->InternalFormat = GL_DEPTH_COMPONENT32;
    }
@@ -1954,3 +1989,26 @@ _mesa_add_renderbuffer(struct gl_framebuffer *fb,
    fb->Attachment[bufferName].Complete = GL_TRUE;
    fb->Attachment[bufferName].Renderbuffer = rb;
 }
+
+
+/**
+ * Create a new combined depth/stencil renderbuffer for implementing
+ * the GL_EXT_packed_depth_stencil extension.
+ * \return new depth/stencil renderbuffer
+ */
+struct gl_renderbuffer *
+_mesa_new_depthstencil_renderbuffer(GLcontext *ctx, GLuint name)
+{
+   struct gl_renderbuffer *dsrb;
+
+   dsrb = _mesa_new_renderbuffer(ctx, name);
+   if (!dsrb)
+      return NULL;
+
+   /* init fields not covered by _mesa_new_renderbuffer() */
+   dsrb->InternalFormat = GL_DEPTH24_STENCIL8_EXT;
+   dsrb->AllocStorage = soft_renderbuffer_storage;
+
+   return dsrb;
+}
+