intel: Share passthrough transform setup between glBitmap and glDrawPixels.
authorEric Anholt <eric@anholt.net>
Wed, 31 Dec 2008 08:29:49 +0000 (00:29 -0800)
committerEric Anholt <eric@anholt.net>
Wed, 31 Dec 2008 08:35:17 +0000 (00:35 -0800)
The DrawPixels path was missing glViewport care, so blender's toolbar icons
would go to the wrong places.

Bug #19118.

src/mesa/drivers/dri/intel/intel_context.h
src/mesa/drivers/dri/intel/intel_pixel.c
src/mesa/drivers/dri/intel/intel_pixel.h
src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
src/mesa/drivers/dri/intel/intel_pixel_draw.c

index 4100677750c69b588af86710642e07ddc8a6dc4b..048286c196bb9659ec49be3f077e6bb43834abd1 100644 (file)
@@ -165,6 +165,9 @@ struct intel_context
       GLboolean saved_fp_enable;
       struct gl_vertex_program *saved_vp;
       GLboolean saved_vp_enable;
+
+      GLint saved_vp_x, saved_vp_y;
+      GLsizei saved_vp_width, saved_vp_height;
    } meta;
 
    GLint refcount;
index 91027d37e741e1ec252e3e4fe93a04b32d9b1ddb..cf2f32d38453623f956dceca209ce64b37b0872f 100644 (file)
@@ -29,6 +29,7 @@
 #include "main/state.h"
 #include "main/context.h"
 #include "main/enable.h"
+#include "main/matrix.h"
 #include "swrast/swrast.h"
 #include "shader/arbprogram.h"
 #include "shader/program.h"
@@ -171,6 +172,40 @@ intel_check_blit_format(struct intel_region * region,
    return GL_FALSE;
 }
 
+void
+intel_meta_set_passthrough_transform(struct intel_context *intel)
+{
+   GLcontext *ctx = &intel->ctx;
+
+   intel->meta.saved_vp_x = ctx->Viewport.X;
+   intel->meta.saved_vp_y = ctx->Viewport.Y;
+   intel->meta.saved_vp_width = ctx->Viewport.Width;
+   intel->meta.saved_vp_height = ctx->Viewport.Height;
+
+   _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();
+}
+
+void
+intel_meta_restore_transform(struct intel_context *intel)
+{
+   _mesa_MatrixMode(GL_PROJECTION);
+   _mesa_PopMatrix();
+   _mesa_MatrixMode(GL_MODELVIEW);
+   _mesa_PopMatrix();
+
+   _mesa_Viewport(intel->meta.saved_vp_x, intel->meta.saved_vp_y,
+                 intel->meta.saved_vp_width, intel->meta.saved_vp_height);
+}
+
 /**
  * Set up a vertex program to pass through the position and first texcoord
  * for pixel path.
index 9556efc71c2e2db72092dca34c99afc3acfbb334..76b8781316b8643821cf187033e01b1170f348a8 100644 (file)
@@ -31,7 +31,8 @@
 #include "main/mtypes.h"
 
 void intelInitPixelFuncs(struct dd_function_table *functions);
-
+void intel_meta_set_passthrough_transform(struct intel_context *intel);
+void intel_meta_restore_transform(struct intel_context *intel);
 void intel_meta_set_passthrough_vertex_program(struct intel_context *intel);
 void intel_meta_restore_vertex_program(struct intel_context *intel);
 void intel_meta_set_fragment_program(struct intel_context *intel,
index 88e181a51f232b5657f68ad7330cb414b71a9f37..1d7f15f10a550e5cf8b77b1ba542b25b40be711a 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"
@@ -425,7 +424,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,20 +450,11 @@ 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);
 
    vertices[0][0] = dst_x;
    vertices[0][1] = dst_y;
@@ -498,14 +488,10 @@ intel_texture_bitmap(GLcontext * ctx,
    _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);
index 8ebbc95a1d0ba1c0e5e9e32eb103238464ed49d3..0d66935ad278b6d79058bf64f545ff88cbf48d43 100644 (file)
@@ -36,7 +36,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"
@@ -68,6 +67,7 @@ intel_texture_drawpixels(GLcontext * ctx,
                         const struct gl_pixelstore_attrib *unpack,
                         const GLvoid *pixels)
 {
+   struct intel_context *intel = intel_context(ctx);
    GLuint texname;
    GLfloat vertices[4][4];
    GLfloat texcoords[4][2];
@@ -117,7 +117,7 @@ intel_texture_drawpixels(GLcontext * ctx,
       return GL_FALSE;
    }
 
-   _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT |
+   _mesa_PushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT |
                    GL_CURRENT_BIT);
    _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
 
@@ -138,14 +138,7 @@ intel_texture_drawpixels(GLcontext * ctx,
    _mesa_TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format,
                    type, pixels);
 
-   _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_passthrough_transform(intel);
 
    /* Create the vertex buffer based on the current raster pos.  The x and y
     * we're handed are ctx->Current.RasterPos[0,1] rounded to integers.
@@ -184,10 +177,7 @@ intel_texture_drawpixels(GLcontext * ctx,
    _mesa_Enable(GL_TEXTURE_COORD_ARRAY);
    CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4));
 
-   _mesa_MatrixMode(GL_PROJECTION);
-   _mesa_PopMatrix();
-   _mesa_MatrixMode(GL_MODELVIEW);
-   _mesa_PopMatrix();
+   intel_meta_restore_transform(intel);
    _mesa_PopClientAttrib();
    _mesa_PopAttrib();
 
@@ -205,6 +195,7 @@ intel_stencil_drawpixels(GLcontext * ctx,
                         const struct gl_pixelstore_attrib *unpack,
                         const GLvoid *pixels)
 {
+   struct intel_context *intel = intel_context(ctx);
    GLuint texname, rb_name, fb_name, old_fb_name;
    GLfloat vertices[4][2];
    GLfloat texcoords[4][2];
@@ -267,7 +258,7 @@ intel_stencil_drawpixels(GLcontext * ctx,
       return GL_FALSE;
    }
 
-   _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT |
+   _mesa_PushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT |
                    GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
    old_fb_name = ctx->DrawBuffer->Name;
@@ -335,14 +326,7 @@ intel_stencil_drawpixels(GLcontext * ctx,
    ctx->Unpack = old_unpack;
    _mesa_free(stencil_pixels);
 
-   _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_passthrough_transform(intel);
 
    vertices[0][0] = x;
    vertices[0][1] = y;
@@ -368,12 +352,10 @@ intel_stencil_drawpixels(GLcontext * ctx,
    _mesa_Enable(GL_TEXTURE_COORD_ARRAY);
    CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4));
 
+   intel_meta_restore_transform(intel);
+
    _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, old_fb_name);
 
-   _mesa_MatrixMode(GL_PROJECTION);
-   _mesa_PopMatrix();
-   _mesa_MatrixMode(GL_MODELVIEW);
-   _mesa_PopMatrix();
    _mesa_PopClientAttrib();
    _mesa_PopAttrib();