intel: Remove a gratuitous MI_FLUSH after clearing with a blit.
[mesa.git] / src / mesa / drivers / dri / intel / intel_pixel_bitmap.c
index 88e181a51f232b5657f68ad7330cb414b71a9f37..1db7f5594e9dd3849c242621071cce19692d748b 100644 (file)
@@ -39,7 +39,6 @@
 #include "main/texobj.h"
 #include "main/texstate.h"
 #include "main/texparam.h"
-#include "main/matrix.h"
 #include "main/varray.h"
 #include "main/attrib.h"
 #include "main/enable.h"
@@ -205,6 +204,14 @@ do_blit_bitmap( GLcontext *ctx,
    /* Update draw buffer bounds */
    _mesa_update_state(ctx);
 
+   if (ctx->Depth.Test) {
+      /* The blit path produces incorrect results when depth testing is on.
+       * It seems the blit Z coord is always 1.0 (the far plane) so fragments
+       * will likely be obscured by other, closer geometry.
+       */
+      return GL_FALSE;
+   }
+
    if (!dst)
        return GL_FALSE;
 
@@ -358,6 +365,7 @@ intel_texture_bitmap(GLcontext * ctx,
    GLubyte *unpacked_bitmap;
    GLubyte *a8_bitmap;
    int x, y;
+   GLfloat dst_z;
 
    /* We need a fragment program for the KIL effect */
    if (!ctx->Extensions.ARB_fragment_program ||
@@ -425,7 +433,7 @@ intel_texture_bitmap(GLcontext * ctx,
    }
 
    /* Save GL state before we start setting up our drawing */
-   _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_CURRENT_BIT |
+   _mesa_PushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT |
                    GL_VIEWPORT_BIT);
    _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT |
                          GL_CLIENT_PIXEL_STORE_BIT);
@@ -451,36 +459,30 @@ intel_texture_bitmap(GLcontext * ctx,
                    GL_ALPHA, GL_UNSIGNED_BYTE, a8_bitmap);
    _mesa_free(a8_bitmap);
 
-   _mesa_Viewport(0, 0, ctx->DrawBuffer->Width, ctx->DrawBuffer->Height);
-   _mesa_MatrixMode(GL_PROJECTION);
-   _mesa_PushMatrix();
-   _mesa_LoadIdentity();
-   _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1);
-
-   _mesa_MatrixMode(GL_MODELVIEW);
-   _mesa_PushMatrix();
-   _mesa_LoadIdentity();
-
    intel_meta_set_fragment_program(intel, &intel->meta.bitmap_fp, fp);
    _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0,
                                     ctx->Current.RasterColor);
    intel_meta_set_passthrough_vertex_program(intel);
+   intel_meta_set_passthrough_transform(intel);
+
+   /* convert rasterpos Z from [0,1] to NDC coord in [-1,1] */
+   dst_z = -1.0 + 2.0 * ctx->Current.RasterPos[2];
 
    vertices[0][0] = dst_x;
    vertices[0][1] = dst_y;
-   vertices[0][2] = ctx->Current.RasterPos[2];
+   vertices[0][2] = dst_z;
    vertices[0][3] = 1.0;
    vertices[1][0] = dst_x + width;
    vertices[1][1] = dst_y;
-   vertices[1][2] = ctx->Current.RasterPos[2];
+   vertices[1][2] = dst_z;
    vertices[1][3] = 1.0;
    vertices[2][0] = dst_x + width;
    vertices[2][1] = dst_y + height;
-   vertices[2][2] = ctx->Current.RasterPos[2];
+   vertices[2][2] = dst_z;
    vertices[2][3] = 1.0;
    vertices[3][0] = dst_x;
    vertices[3][1] = dst_y + height;
-   vertices[3][2] = ctx->Current.RasterPos[2];
+   vertices[3][2] = dst_z;
    vertices[3][3] = 1.0;
 
    texcoords[0][0] = 0.0;
@@ -493,19 +495,16 @@ intel_texture_bitmap(GLcontext * ctx,
    texcoords[3][1] = 1.0;
 
    _mesa_VertexPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), &vertices);
+   _mesa_ClientActiveTextureARB(GL_TEXTURE0);
    _mesa_TexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &texcoords);
    _mesa_Enable(GL_VERTEX_ARRAY);
    _mesa_Enable(GL_TEXTURE_COORD_ARRAY);
    CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4));
 
+   intel_meta_restore_transform(intel);
    intel_meta_restore_fragment_program(intel);
    intel_meta_restore_vertex_program(intel);
 
-   _mesa_MatrixMode(GL_PROJECTION);
-   _mesa_PopMatrix();
-   _mesa_MatrixMode(GL_MODELVIEW);
-   _mesa_PopMatrix();
-
    _mesa_PopClientAttrib();
    _mesa_Disable(GL_TEXTURE_2D); /* asserted that it was disabled at entry */
    _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + old_active_texture);