Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 15 Dec 2009 20:38:01 +0000 (12:38 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 15 Dec 2009 20:38:01 +0000 (12:38 -0800)
Conflicts:
src/gallium/drivers/softpipe/sp_quad_blend.c

1  2 
src/gallium/winsys/drm/intel/gem/intel_drm_api.c
src/gallium/winsys/xlib/Makefile
src/mesa/drivers/dri/intel/intel_buffers.c
src/mesa/state_tracker/st_draw.c
src/mesa/swrast/s_triangle.c

index 9ed570ff6e46125edceaed2c75b89cbb80fbff51,01025659b9f450dfa0bb950172a1795a2dec60aa..5ed2a10af1cee27cdc7ccac70f387a849e1ba876
@@@ -4,10 -4,9 +4,10 @@@
  #include "intel_drm_winsys.h"
  #include "util/u_memory.h"
  
 -#include "i915simple/i915_context.h"
 -#include "i915simple/i915_screen.h"
 +#include "i915/i915_context.h"
 +#include "i915/i915_screen.h"
  
 +#include "trace/tr_drm.h"
  
  /*
   * Helper functions
@@@ -32,6 -31,7 +32,7 @@@ intel_drm_get_device_id(unsigned int *d
     }
  
     shutup_gcc = fgets(path, sizeof(path), file);
+    (void) shutup_gcc;
     sscanf(path, "%x", device_id);
     fclose(file);
  }
@@@ -41,7 -41,6 +42,7 @@@ intel_drm_buffer_from_handle(struct int
                               const char* name, unsigned handle)
  {
     struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer);
 +   uint32_t tile = 0, swizzle = 0;
  
     if (!buf)
        return NULL;
     if (!buf->bo)
        goto err;
  
 +   drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle);
 +   if (tile != INTEL_TILE_NONE)
 +      buf->map_gtt = TRUE;
 +
     return (struct intel_buffer *)buf;
  
  err:
@@@ -172,7 -167,6 +173,7 @@@ intel_drm_create_screen(struct drm_api 
     idws->base.destroy = intel_drm_winsys_destroy;
  
     idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size);
 +   drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem);
  
     idws->softpipe = FALSE;
     idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE);
@@@ -205,5 -199,5 +206,5 @@@ struct drm_api intel_drm_api 
  struct drm_api *
  drm_api_create()
  {
 -   return &intel_drm_api;
 +   return trace_drm_create(&intel_drm_api);
  }
index 3dc38a78e451121a03172c5ed56b2c9322459fd3,f34609386dda2b3ba96a0cdf64ac08e9143cd723..a0293fe9b4b0a9399ec619d796df813f4a93f6d0
@@@ -31,6 -31,9 +31,6 @@@ DEFINES += 
  XLIB_WINSYS_SOURCES = \
        xlib.c \
        xlib_cell.c \
 -      xlib_brw_aub.c \
 -      xlib_brw_context.c \
 -      xlib_brw_screen.c \
        xlib_llvmpipe.c \
        xlib_softpipe.c \
        xlib_trace.c 
@@@ -84,11 -87,11 +84,11 @@@ depend: $(XLIB_WINSYS_SOURCES
  
  
  install: default
-       $(INSTALL) -d $(INSTALL_DIR)/include/GL
-       $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR)
-       $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(INSTALL_DIR)/include/GL
+       $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/include/GL
+       $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/$(LIB_DIR)
+       $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(DESTDIR)$(INSTALL_DIR)/include/GL
        @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \
-               $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(INSTALL_DIR)/$(LIB_DIR); \
+               $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(DESTDIR)$(INSTALL_DIR)/$(LIB_DIR); \
        fi
  
  
index 6b12d484d85b2232d132700c1dc9781a18dfe559,4b8ac364f7906656e2be0b254e730ed1667478cb..05643189a21de4d230d95d20288d75e9e89101a0
@@@ -132,25 -132,6 +132,25 @@@ intel_get_cliprects(struct intel_contex
  }
  
  
 +/**
 + * Check if we're about to draw into the front color buffer.
 + * If so, set the intel->front_buffer_dirty field to true.
 + */
 +void
 +intel_check_front_buffer_rendering(struct intel_context *intel)
 +{
 +   const struct gl_framebuffer *fb = intel->ctx.DrawBuffer;
 +   if (fb->Name == 0) {
 +      /* drawing to window system buffer */
 +      if (fb->_NumColorDrawBuffers > 0) {
 +         if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
 +          intel->front_buffer_dirty = GL_TRUE;
 +       }
 +      }
 +   }
 +}
 +
 +
  /**
   * Update the hardware state for drawing into a window or framebuffer object.
   *
@@@ -191,10 -172,15 +191,15 @@@ intel_draw_buffer(GLcontext * ctx, stru
        return;
     }
  
-    /*
-     * How many color buffers are we drawing into?
+    /* How many color buffers are we drawing into?
+     *
+     * If there are zero buffers or the buffer is too big, don't configure any
+     * regions for hardware drawing.  We'll fallback to software below.  Not
+     * having regions set makes some of the software fallback paths faster.
      */
-    if (fb->_NumColorDrawBuffers == 0) {
+    if ((fb->Width > ctx->Const.MaxRenderbufferSize)
+        || (fb->Height > ctx->Const.MaxRenderbufferSize)
+        || (fb->_NumColorDrawBuffers == 0)) {
        /* writing to 0  */
        colorRegions[0] = NULL;
        intel->constant_cliprect = GL_TRUE;
     }
     else {
        /* Get the intel_renderbuffer for the single colorbuffer we're drawing
 -       * into, and set up cliprects if it's .
 +       * into, and set up cliprects if it's a DRI1 window front buffer.
         */
        if (fb->Name == 0) {
         intel->constant_cliprect = intel->driScreen->dri2.enabled;
               intel_batchbuffer_flush(intel->batch);
            intel->front_cliprects = GL_TRUE;
            colorRegions[0] = intel_get_rb_region(fb, BUFFER_FRONT_LEFT);
 -
 -          intel->front_buffer_dirty = GL_TRUE;
         }
         else {
            if (!intel->constant_cliprect && intel->front_cliprects)
               intel_batchbuffer_flush(intel->batch);
            intel->front_cliprects = GL_FALSE;
 -          colorRegions[0]= intel_get_rb_region(fb, BUFFER_BACK_LEFT);
 +          colorRegions[0] = intel_get_rb_region(fb, BUFFER_BACK_LEFT);
         }
        }
        else {
     if (fb->_StencilBuffer && fb->_StencilBuffer->Wrapped) {
        irbStencil = intel_renderbuffer(fb->_StencilBuffer->Wrapped);
        if (irbStencil && irbStencil->region) {
 -         ASSERT(irbStencil->Base._ActualFormat == GL_DEPTH24_STENCIL8_EXT);
 +         ASSERT(irbStencil->Base.Format == MESA_FORMAT_S8_Z24);
           FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, GL_FALSE);
        }
        else {
index 68bc76b572397ce0a758673f6613af113446b23d,6f5248cbe579f2dca10fbb0abfe2adb07096d04c..5c6af1125a3da3988b8c89ab6064eb49d6af07db
   * 
   **************************************************************************/
  
 - /*
 -  * Authors:
 -  *   Keith Whitwell <keith@tungstengraphics.com>
 -  */
 +/*
 + * This file implements the st_draw_vbo() function which is called from
 + * Mesa's VBO module.  All point/line/triangle rendering is done through
 + * this function whether the user called glBegin/End, glDrawArrays,
 + * glDrawElements, glEvalMesh, or glCalList, etc.
 + *
 + * We basically convert the VBO's vertex attribute/array information into
 + * Gallium vertex state, bind the vertex buffer objects and call
 + * pipe->draw_elements(), pipe->draw_range_elements() or pipe->draw_arrays().
 + *
 + * Authors:
 + *   Keith Whitwell <keith@tungstengraphics.com>
 + */
 +
  
  #include "main/imports.h"
  #include "main/image.h"
@@@ -381,7 -371,7 +381,7 @@@ setup_interleaved_attribs(GLcontext *ct
  {
     struct pipe_context *pipe = ctx->st->pipe;
     GLuint attr;
-    const GLubyte *offset0;
+    const GLubyte *offset0 = NULL;
  
     for (attr = 0; attr < vp->num_inputs; attr++) {
        const GLuint mesaAttr = vp->index_to_input[attr];
@@@ -560,7 -550,7 +560,7 @@@ st_draw_vbo(GLcontext *ctx
     GLuint attr;
     struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
     unsigned num_vbuffers, num_velements;
-    GLboolean userSpace;
+    GLboolean userSpace = GL_FALSE;
  
     /* Gallium probably doesn't want this in some cases. */
     if (!index_bounds_valid)
index d80a6761f406d45aca3b3dc2f22a85239361b99d,a65b7b3e228ec4e5cb4e8027a811d48a9652015b..5bec6066967232a3cd5521eaeca89539c58f4cce
@@@ -134,24 -134,22 +134,24 @@@ _swrast_culltriangle( GLcontext *ctx
  
  #define SETUP_CODE                                                    \
     struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];        \
 -   struct gl_texture_object *obj =                                    \
 +   const struct gl_texture_object *obj =                              \
        ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];              \
 -   const GLint b = obj->BaseLevel;                                    \
 -   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;          \
 -   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;                \
 -   const GLint twidth_log2 = obj->Image[0][b]->WidthLog2;             \
 -   const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;   \
 -   const GLint smask = obj->Image[0][b]->Width - 1;                   \
 -   const GLint tmask = obj->Image[0][b]->Height - 1;                  \
 +   const struct gl_texture_image *texImg =                            \
 +      obj->Image[0][obj->BaseLevel];                                  \
 +   const GLfloat twidth = (GLfloat) texImg->Width;                    \
 +   const GLfloat theight = (GLfloat) texImg->Height;                  \
 +   const GLint twidth_log2 = texImg->WidthLog2;                               \
 +   const GLubyte *texture = (const GLubyte *) texImg->Data;           \
 +   const GLint smask = texImg->Width - 1;                             \
 +   const GLint tmask = texImg->Height - 1;                            \
 +   ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);                   \
     if (!rb || !texture) {                                             \
        return;                                                         \
     }
  
  #define RENDER_SPAN( span )                                           \
     GLuint i;                                                          \
 -   GLchan rgb[MAX_WIDTH][3];                                          \
 +   GLubyte rgb[MAX_WIDTH][3];                                         \
     span.intTex[0] -= FIXED_HALF; /* off-by-one error? */              \
     span.intTex[1] -= FIXED_HALF;                                      \
     for (i = 0; i < span.end; i++) {                                   \
        GLint t = FixedToInt(span.intTex[1]) & tmask;                   \
        GLint pos = (t << twidth_log2) + s;                             \
        pos = pos + pos + pos;  /* multiply by 3 */                     \
 -      rgb[i][RCOMP] = texture[pos];                                   \
 +      rgb[i][RCOMP] = texture[pos+2];                                 \
        rgb[i][GCOMP] = texture[pos+1];                                 \
 -      rgb[i][BCOMP] = texture[pos+2];                                 \
 +      rgb[i][BCOMP] = texture[pos+0];                                 \
        span.intTex[0] += span.intTexStep[0];                           \
        span.intTex[1] += span.intTexStep[1];                           \
     }                                                                  \
  
  #define SETUP_CODE                                                    \
     struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];        \
 -   struct gl_texture_object *obj =                                    \
 +   const struct gl_texture_object *obj =                              \
        ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];              \
 -   const GLint b = obj->BaseLevel;                                    \
 -   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;          \
 -   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;                \
 -   const GLint twidth_log2 = obj->Image[0][b]->WidthLog2;             \
 -   const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;   \
 -   const GLint smask = obj->Image[0][b]->Width - 1;                   \
 -   const GLint tmask = obj->Image[0][b]->Height - 1;                  \
 +   const struct gl_texture_image *texImg =                            \
 +       obj->Image[0][obj->BaseLevel];                                         \
 +   const GLfloat twidth = (GLfloat) texImg->Width;                    \
 +   const GLfloat theight = (GLfloat) texImg->Height;                  \
 +   const GLint twidth_log2 = texImg->WidthLog2;                               \
 +   const GLubyte *texture = (const GLubyte *) texImg->Data;           \
 +   const GLint smask = texImg->Width - 1;                             \
 +   const GLint tmask = texImg->Height - 1;                            \
 +   ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);                   \
     if (!rb || !texture) {                                             \
        return;                                                         \
     }
  
  #define RENDER_SPAN( span )                                           \
     GLuint i;                                                          \
 -   GLchan rgb[MAX_WIDTH][3];                                          \
 +   GLubyte rgb[MAX_WIDTH][3];                                         \
     span.intTex[0] -= FIXED_HALF; /* off-by-one error? */              \
     span.intTex[1] -= FIXED_HALF;                                      \
     for (i = 0; i < span.end; i++) {                                   \
           GLint t = FixedToInt(span.intTex[1]) & tmask;                        \
           GLint pos = (t << twidth_log2) + s;                          \
           pos = pos + pos + pos;  /* multiply by 3 */                  \
 -         rgb[i][RCOMP] = texture[pos];                                        \
 +         rgb[i][RCOMP] = texture[pos+2];                              \
           rgb[i][GCOMP] = texture[pos+1];                              \
 -         rgb[i][BCOMP] = texture[pos+2];                              \
 +         rgb[i][BCOMP] = texture[pos+0];                              \
           zRow[i] = z;                                                 \
           span.array->mask[i] = 1;                                     \
        }                                                                       \
@@@ -280,29 -276,25 +280,29 @@@ affine_span(GLcontext *ctx, SWspan *spa
      * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
      */
  
 -#define NEAREST_RGB                   \
 -   sample[RCOMP] = tex00[RCOMP];      \
 -   sample[GCOMP] = tex00[GCOMP];      \
 -   sample[BCOMP] = tex00[BCOMP];      \
 -   sample[ACOMP] = CHAN_MAX
 +#define NEAREST_RGB           \
 +   sample[RCOMP] = tex00[2];  \
 +   sample[GCOMP] = tex00[1];  \
 +   sample[BCOMP] = tex00[0];  \
 +   sample[ACOMP] = CHAN_MAX;
  
  #define LINEAR_RGB                                                    \
 -   sample[RCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\
 +   sample[RCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\
     sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\
 -   sample[BCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\
 +   sample[BCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\
     sample[ACOMP] = CHAN_MAX;
  
 -#define NEAREST_RGBA  COPY_CHAN4(sample, tex00)
 +#define NEAREST_RGBA  \
 +   sample[RCOMP] = tex00[3];  \
 +   sample[GCOMP] = tex00[2];  \
 +   sample[BCOMP] = tex00[1];  \
 +   sample[ACOMP] = tex00[0];
  
  #define LINEAR_RGBA                                                   \
 -   sample[RCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\
 -   sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\
 -   sample[BCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\
 -   sample[ACOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3])
 +   sample[RCOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3]);\
 +   sample[GCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\
 +   sample[BCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\
 +   sample[ACOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0])
  
  #define MODULATE                                                        \
     dest[RCOMP] = span->red   * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \
     dest[2] = sample[2];                       \
     dest[3] = FixedToInt(span->alpha);
  
 -#define NEAREST_RGBA_REPLACE  COPY_CHAN4(dest, tex00)
 +#define NEAREST_RGBA_REPLACE  \
 +   dest[RCOMP] = tex00[3]; \
 +   dest[GCOMP] = tex00[2]; \
 +   dest[BCOMP] = tex00[1]; \
 +   dest[ACOMP] = tex00[0]
  
  #define SPAN_NEAREST(DO_TEX, COMPS)                                   \
        for (i = 0; i < span->end; i++) {                               \
     switch (info->filter) {
     case GL_NEAREST:
        switch (info->format) {
 -      case GL_RGB:
 +      case MESA_FORMAT_RGB888:
           switch (info->envmode) {
           case GL_MODULATE:
              SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
              return;
           }
           break;
 -      case GL_RGBA:
 +      case MESA_FORMAT_RGBA8888:
           switch(info->envmode) {
           case GL_MODULATE:
              SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
        span->intTex[0] -= FIXED_HALF;
        span->intTex[1] -= FIXED_HALF;
        switch (info->format) {
 -      case GL_RGB:
 +      case MESA_FORMAT_RGB888:
           switch (info->envmode) {
           case GL_MODULATE:
              SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
              return;
           }
           break;
 -      case GL_RGBA:
 +      case MESA_FORMAT_RGBA8888:
           switch (info->envmode) {
           case GL_MODULATE:
              SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
  #define SETUP_CODE                                                    \
     struct affine_info info;                                           \
     struct gl_texture_unit *unit = ctx->Texture.Unit+0;                        \
 -   struct gl_texture_object *obj =                                    \
 +   const struct gl_texture_object *obj =                              \
        ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];              \
 -   const GLint b = obj->BaseLevel;                                    \
 -   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;          \
 -   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;                \
 -   info.texture = (const GLchan *) obj->Image[0][b]->Data;            \
 -   info.twidth_log2 = obj->Image[0][b]->WidthLog2;                    \
 -   info.smask = obj->Image[0][b]->Width - 1;                          \
 -   info.tmask = obj->Image[0][b]->Height - 1;                         \
 -   info.format = obj->Image[0][b]->_BaseFormat;                               \
 +   const struct gl_texture_image *texImg =                            \
 +      obj->Image[0][obj->BaseLevel];                                  \
 +   const GLfloat twidth = (GLfloat) texImg->Width;                    \
 +   const GLfloat theight = (GLfloat) texImg->Height;                  \
 +   info.texture = (const GLchan *) texImg->Data;                      \
 +   info.twidth_log2 = texImg->WidthLog2;                              \
 +   info.smask = texImg->Width - 1;                                    \
 +   info.tmask = texImg->Height - 1;                                   \
 +   info.format = texImg->TexFormat;                                   \
     info.filter = obj->MinFilter;                                      \
     info.envmode = unit->EnvMode;                                      \
+    info.er = 0;                                       \
+    info.eg = 0;                                       \
+    info.eb = 0;                                       \
     span.arrayMask |= SPAN_RGBA;                                               \
                                                                        \
     if (info.envmode == GL_BLEND) {                                    \
     }                                                                  \
                                                                        \
     switch (info.format) {                                             \
 -   case GL_ALPHA:                                                     \
 -   case GL_LUMINANCE:                                                 \
 -   case GL_INTENSITY:                                                 \
 -      info.tbytesline = obj->Image[0][b]->Width;                      \
 -      break;                                                          \
 -   case GL_LUMINANCE_ALPHA:                                           \
 -      info.tbytesline = obj->Image[0][b]->Width * 2;                  \
 +   case MESA_FORMAT_RGB888:                                           \
 +      info.tbytesline = texImg->Width * 3;                            \
        break;                                                          \
 -   case GL_RGB:                                                               \
 -      info.tbytesline = obj->Image[0][b]->Width * 3;                  \
 -      break;                                                          \
 -   case GL_RGBA:                                                      \
 -      info.tbytesline = obj->Image[0][b]->Width * 4;                  \
 +   case MESA_FORMAT_RGBA8888:                                         \
 +      info.tbytesline = texImg->Width * 4;                            \
        break;                                                          \
     default:                                                           \
        _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\
        return;                                                         \
     }                                                                  \
 -   info.tsize = obj->Image[0][b]->Height * info.tbytesline;
 +   info.tsize = texImg->Height * info.tbytesline;
  
  #define RENDER_SPAN( span )   affine_span(ctx, &span, &info);
  
@@@ -685,7 -683,7 +688,7 @@@ fast_persp_span(GLcontext *ctx, SWspan 
     switch (info->filter) {
     case GL_NEAREST:
        switch (info->format) {
 -      case GL_RGB:
 +      case MESA_FORMAT_RGB888:
           switch (info->envmode) {
           case GL_MODULATE:
              SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
              return;
           }
           break;
 -      case GL_RGBA:
 +      case MESA_FORMAT_RGBA8888:
           switch(info->envmode) {
           case GL_MODULATE:
              SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
  
     case GL_LINEAR:
        switch (info->format) {
 -      case GL_RGB:
 +      case MESA_FORMAT_RGB888:
           switch (info->envmode) {
           case GL_MODULATE:
              SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
              return;
           }
           break;
 -      case GL_RGBA:
 +      case MESA_FORMAT_RGBA8888:
           switch (info->envmode) {
           case GL_MODULATE:
              SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
  #define SETUP_CODE                                                    \
     struct persp_info info;                                            \
     const struct gl_texture_unit *unit = ctx->Texture.Unit+0;          \
 -   struct gl_texture_object *obj =                                    \
 +   const struct gl_texture_object *obj =                              \
        ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];              \
 -   const GLint b = obj->BaseLevel;                                    \
 -   info.texture = (const GLchan *) obj->Image[0][b]->Data;            \
 -   info.twidth_log2 = obj->Image[0][b]->WidthLog2;                    \
 -   info.smask = obj->Image[0][b]->Width - 1;                          \
 -   info.tmask = obj->Image[0][b]->Height - 1;                         \
 -   info.format = obj->Image[0][b]->_BaseFormat;                               \
 +   const struct gl_texture_image *texImg =                            \
 +      obj->Image[0][obj->BaseLevel];                                  \
 +   info.texture = (const GLchan *) texImg->Data;                      \
 +   info.twidth_log2 = texImg->WidthLog2;                              \
 +   info.smask = texImg->Width - 1;                                    \
 +   info.tmask = texImg->Height - 1;                                   \
 +   info.format = texImg->TexFormat;                                   \
     info.filter = obj->MinFilter;                                      \
     info.envmode = unit->EnvMode;                                      \
+    info.er = 0;                                       \
+    info.eg = 0;                                       \
+    info.eb = 0;                                       \
                                                                        \
     if (info.envmode == GL_BLEND) {                                    \
        /* potential off-by-one error here? (1.0f -> 2048 -> 0) */      \
     }                                                                  \
                                                                        \
     switch (info.format) {                                             \
 -   case GL_ALPHA:                                                     \
 -   case GL_LUMINANCE:                                                 \
 -   case GL_INTENSITY:                                                 \
 -      info.tbytesline = obj->Image[0][b]->Width;                      \
 -      break;                                                          \
 -   case GL_LUMINANCE_ALPHA:                                           \
 -      info.tbytesline = obj->Image[0][b]->Width * 2;                  \
 -      break;                                                          \
 -   case GL_RGB:                                                               \
 -      info.tbytesline = obj->Image[0][b]->Width * 3;                  \
 +   case MESA_FORMAT_RGB888:                                           \
 +      info.tbytesline = texImg->Width * 3;                            \
        break;                                                          \
 -   case GL_RGBA:                                                      \
 -      info.tbytesline = obj->Image[0][b]->Width * 4;                  \
 +   case MESA_FORMAT_RGBA8888:                                         \
 +      info.tbytesline = texImg->Width * 4;                            \
        break;                                                          \
     default:                                                           \
        _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\
        return;                                                         \
     }                                                                  \
 -   info.tsize = obj->Image[0][b]->Height * info.tbytesline;
 +   info.tsize = texImg->Height * info.tbytesline;
  
  #define RENDER_SPAN( span )                   \
     span.interpMask &= ~SPAN_RGBA;             \
        return;                                                         \
     }
  #define RENDER_SPAN( span )                                           \
 -   if (rb->DepthBits <= 16) {                                         \
 +   if (rb->Format == MESA_FORMAT_Z16) {                                       \
        GLuint i;                                                               \
        const GLushort *zRow = (const GLushort *)                               \
           rb->GetPointer(ctx, rb, span.x, span.y);                     \
@@@ -1053,20 -1061,19 +1059,20 @@@ _swrast_choose_triangle( GLcontext *ct
           const struct gl_texture_object *texObj2D;
           const struct gl_texture_image *texImg;
           GLenum minFilter, magFilter, envMode;
 -         GLint format;
 +         gl_format format;
           texObj2D = ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
  
           texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL;
 -         format = texImg ? texImg->TexFormat->MesaFormat : -1;
 -         minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0;
 -         magFilter = texObj2D ? texObj2D->MagFilter : (GLenum) 0;
 +         format = texImg ? texImg->TexFormat : MESA_FORMAT_NONE;
 +         minFilter = texObj2D ? texObj2D->MinFilter : GL_NONE;
 +         magFilter = texObj2D ? texObj2D->MagFilter : GL_NONE;
           envMode = ctx->Texture.Unit[0].EnvMode;
  
           /* First see if we can use an optimized 2-D texture function */
           if (ctx->Texture._EnabledCoordUnits == 0x1
               && !ctx->FragmentProgram._Current
               && !ctx->ATIFragmentShader._Enabled
 +             && ctx->Texture._EnabledUnits == 0x1
               && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
               && texObj2D->WrapS == GL_REPEAT
               && texObj2D->WrapT == GL_REPEAT
               && texImg->_IsPowerOfTwo
               && texImg->Border == 0
               && texImg->Width == texImg->RowStride
 -             && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA)
 +             && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)
               && minFilter == magFilter
               && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
               && !swrast->_FogEnabled
               && ctx->Texture.Unit[0].EnvMode != GL_COMBINE4_NV) {
            if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) {
               if (minFilter == GL_NEAREST
 -                 && format == MESA_FORMAT_RGB
 +                 && format == MESA_FORMAT_RGB888
                   && (envMode == GL_REPLACE || envMode == GL_DECAL)
                   && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)
                        && ctx->Depth.Func == GL_LESS
  #if CHAN_BITS != 8
                    USE(general_triangle);
  #else
 -                  USE(affine_textured_triangle);
 +                  if (format == MESA_FORMAT_RGBA8888 && !_mesa_little_endian()) {
 +                     /* We only handle RGBA8888 correctly on little endian
 +                      * in the optimized code above.
 +                      */
 +                     USE(general_triangle);
 +                  }
 +                  else {
 +                     USE(affine_textured_triangle);
 +                 }
  #endif
               }
            }