i965: Add support for GL_ALPHA framebuffer objects.
authorEric Anholt <eric@anholt.net>
Tue, 25 May 2010 18:45:05 +0000 (11:45 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 10 Jun 2010 07:40:00 +0000 (00:40 -0700)
src/mesa/drivers/dri/common/spantmp2.h
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/intel/intel_blit.c
src/mesa/drivers/dri/intel/intel_fbo.c
src/mesa/drivers/dri/intel/intel_reg.h
src/mesa/drivers/dri/intel/intel_span.c

index 98422a8564761b8341413812ea02f7bc6a92f0dc..1dab7336b9b20e1fca6a4ed9618f24b4775c93af 100644 (file)
      } while (0)
 # endif
 
+#elif (SPANTMP_PIXEL_FMT == GL_ALPHA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_BYTE)
+
+/**
+ ** GL_ALPHA, GL_UNSIGNED_BYTE
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (     buf + (_x) + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+# define INIT_MONO_PIXEL(p, color)                       \
+     p = color[3]
+
+# define WRITE_RGBA(_x, _y, r, g, b, a)                                 \
+   PUT_VALUE(_x, _y, a | (r & 0 /* quiet warnings */))
+
+#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+     do {                                                              \
+        GLubyte p = GET_VALUE(_x, _y);                                 \
+       rgba[0] = 0;                                                    \
+       rgba[1] = 0;                                                    \
+       rgba[2] = 0;                                                    \
+       rgba[3] = p;                                                    \
+     } while (0)
+
 #else
 #error SPANTMP_PIXEL_FMT must be set to a valid value!
 #endif
index a9ad2ce3713eefd59d7f01548183f8f5e9ced358..3998054eb448ba7f289b8f11ecb67943ef4d040e 100644 (file)
@@ -515,6 +515,9 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
       case MESA_FORMAT_ARGB4444:
         key.surface_format = BRW_SURFACEFORMAT_B4G4R4A4_UNORM;
         break;
+      case MESA_FORMAT_A8:
+        key.surface_format = BRW_SURFACEFORMAT_A8_UNORM;
+        break;
       default:
         _mesa_problem(ctx, "Bad renderbuffer format: %d\n", irb->Base.Format);
       }
index fecf12763e10370a560524c47a6d7bf12a8a298c..2c85ad3c36fafa91cab6485000a0bb3661a80931 100644 (file)
@@ -64,6 +64,24 @@ static GLuint translate_raster_op(GLenum logicop)
    }
 }
 
+static uint32_t
+br13_for_cpp(int cpp)
+{
+   switch (cpp) {
+   case 4:
+      return BR13_8888;
+      break;
+   case 2:
+      return BR13_565;
+      break;
+   case 1:
+      return BR13_8;
+      break;
+   default:
+      assert(0);
+      return 0;
+   }
+}
 
 /* Copy BitBlt
  */
@@ -131,18 +149,14 @@ intelEmitCopyBlit(struct intel_context *intel,
    src_pitch *= cpp;
    dst_pitch *= cpp;
 
-   BR13 = translate_raster_op(logic_op) << 16;
+   BR13 = br13_for_cpp(cpp) | translate_raster_op(logic_op) << 16;
 
    switch (cpp) {
    case 1:
-      CMD = XY_SRC_COPY_BLT_CMD;
-      break;
    case 2:
-      BR13 |= BR13_565;
       CMD = XY_SRC_COPY_BLT_CMD;
       break;
    case 4:
-      BR13 |= BR13_8888;
       CMD = XY_SRC_COPY_BLT_CMD | XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
       break;
    default:
@@ -265,12 +279,11 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
          irb->region->buffer, (pitch * cpp),
          x1, y1, x2 - x1, y2 - y1);
 
-      BR13 = 0xf0 << 16;
+      BR13 = br13_for_cpp(cpp) | 0xf0 << 16;
       CMD = XY_COLOR_BLT_CMD;
 
       /* Setup the blit command */
       if (cpp == 4) {
-        BR13 |= BR13_8888;
         if (buf == BUFFER_DEPTH || buf == BUFFER_STENCIL) {
            if (mask & BUFFER_BIT_DEPTH)
               CMD |= XY_BLT_WRITE_RGB;
@@ -280,9 +293,6 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
            /* clearing RGBA */
            CMD |= XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
         }
-      } else {
-        ASSERT(cpp == 2);
-        BR13 |= BR13_565;
       }
 
       assert(irb->region->tiling != I915_TILING_Y);
@@ -323,6 +333,10 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
            clear_val = PACK_COLOR_1555(clear[3], clear[0],
                                        clear[1], clear[2]);
            break;
+        case MESA_FORMAT_A8:
+           clear_val = PACK_COLOR_8888(clear[3], clear[3],
+                                       clear[3], clear[3]);
+           break;
         default:
            _mesa_problem(ctx, "Unexpected renderbuffer format: %d\n",
                          irb->Base.Format);
@@ -419,10 +433,7 @@ intelEmitImmediateColorExpandBlit(struct intel_context *intel,
 #endif
 
    br13 = dst_pitch | (translate_raster_op(logic_op) << 16) | (1 << 29);
-   if (cpp == 2)
-      br13 |= BR13_565;
-   else
-      br13 |= BR13_8888;
+   br13 |= br13_for_cpp(cpp);
 
    blit_cmd = XY_TEXT_IMMEDIATE_BLIT_CMD | XY_TEXT_BYTE_PACKED; /* packing? */
    if (dst_tiling != I915_TILING_NONE)
index 217be7ef6cb2b01988972da8bf16a37bfa48fd13..8f61f1f5b24ed10e4fa9cc9e09423722a4dcb2bd 100644 (file)
@@ -135,6 +135,11 @@ intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
       rb->Format = MESA_FORMAT_ARGB8888;
       rb->DataType = GL_UNSIGNED_BYTE;
       break;
+   case GL_ALPHA:
+   case GL_ALPHA8:
+      rb->Format = MESA_FORMAT_A8;
+      rb->DataType = GL_UNSIGNED_BYTE;
+      break;
    case GL_STENCIL_INDEX:
    case GL_STENCIL_INDEX1_EXT:
    case GL_STENCIL_INDEX4_EXT:
@@ -346,6 +351,10 @@ intel_create_renderbuffer(gl_format format)
       irb->Base._BaseFormat = GL_DEPTH_STENCIL;
       irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
       break;
+   case MESA_FORMAT_A8:
+      irb->Base._BaseFormat = GL_ALPHA;
+      irb->Base.DataType = GL_UNSIGNED_BYTE;
+      break;
    default:
       _mesa_problem(NULL,
                     "Unexpected intFormat in intel_create_renderbuffer");
@@ -451,6 +460,10 @@ intel_update_wrapper(GLcontext *ctx, struct intel_renderbuffer *irb,
       irb->Base.DataType = GL_UNSIGNED_BYTE;
       DBG("Render to ARGB4444 texture OK\n");
    }
+   else if (texImage->TexFormat == MESA_FORMAT_A8) {
+      irb->Base.DataType = GL_UNSIGNED_BYTE;
+      DBG("Render to A8 texture OK\n");
+   }
    else if (texImage->TexFormat == MESA_FORMAT_Z16) {
       irb->Base.DataType = GL_UNSIGNED_SHORT;
       DBG("Render to DEPTH16 texture OK\n");
@@ -660,6 +673,7 @@ intel_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
       case MESA_FORMAT_RGB565:
       case MESA_FORMAT_ARGB1555:
       case MESA_FORMAT_ARGB4444:
+      case MESA_FORMAT_A8:
         break;
       default:
         fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
index 36d8180598e48ebb949b200abc674b9ced7a8722..c1a281f261ed607b360bf14e9d4caa60df20fe92 100644 (file)
 #define XY_DST_TILED           (1 << 11)
 
 /* BR13 */
+#define BR13_8                 (0x0 << 24)
 #define BR13_565               (0x1 << 24)
 #define BR13_8888              (0x3 << 24)
 
index 059f76f289a3e754fdbd9cc68e5a255a18ce926e..c30552c5a79d9684b24b20056ef368669f884832 100644 (file)
@@ -106,6 +106,13 @@ intel_set_span_functions(struct intel_context *intel,
 #define TAG2(x,y) intel_##x##y##_xRGB8888
 #include "spantmp2.h"
 
+/* a8 color span and pixel functions */
+#define SPANTMP_PIXEL_FMT GL_ALPHA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_BYTE
+#define TAG(x) intel_##x##_A8
+#define TAG2(x,y) intel_##x##y##_A8
+#include "spantmp2.h"
+
 #define LOCAL_DEPTH_VARS                                               \
    struct intel_renderbuffer *irb = intel_renderbuffer(rb);            \
    const GLint yScale = rb->Name ? 1 : -1;                             \
@@ -341,6 +348,9 @@ intel_set_span_functions(struct intel_context *intel,
    struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
 
    switch (irb->Base.Format) {
+   case MESA_FORMAT_A8:
+      intel_InitPointers_A8(rb);
+      break;
    case MESA_FORMAT_RGB565:
       intel_InitPointers_RGB565(rb);
       break;