st/mesa: flush the glBitmap cache before changing framebuffer state
authorMarek Olšák <maraeo@gmail.com>
Sun, 22 Jul 2012 02:31:59 +0000 (04:31 +0200)
committerMarek Olšák <maraeo@gmail.com>
Mon, 23 Jul 2012 17:23:53 +0000 (19:23 +0200)
This fixes the piglit EXT_framebuffer_multisample/bitmap tests.

Note that we must not rely on ctx->DrawBuffer when flushing the cache, because
that's already updated with a new framebuffer. We want to draw into the old
framebuffer where glBitmap was called.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/state_tracker/st_atom_framebuffer.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_context.h

index a8907c1577a4650a341bdf65a7dd4c3d10e3d6ac..6f94a47c6b5e33eb0689b555fbfd3d700897d090 100644 (file)
@@ -33,6 +33,7 @@
  
 #include "st_context.h"
 #include "st_atom.h"
+#include "st_cb_bitmap.h"
 #include "st_cb_fbo.h"
 #include "st_texture.h"
 #include "pipe/p_context.h"
@@ -103,6 +104,9 @@ update_framebuffer_state( struct st_context *st )
    struct st_renderbuffer *strb;
    GLuint i;
 
+   st_flush_bitmap_cache(st);
+
+   st->state.fb_orientation = st_fb_orientation(fb);
    framebuffer->width = fb->Width;
    framebuffer->height = fb->Height;
 
index f48c9c19200b2c47dd7b47f86a2944e099601227..c2605887428a402d584ebac66f89eb5ea1838486 100644 (file)
@@ -335,9 +335,8 @@ setup_bitmap_vertex_data(struct st_context *st, bool normalized,
                         struct pipe_resource **vbuf,
                         unsigned *vbuf_offset)
 {
-   const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
-   const GLfloat fb_width = (GLfloat)fb->Width;
-   const GLfloat fb_height = (GLfloat)fb->Height;
+   const GLfloat fb_width = (GLfloat)st->state.framebuffer.width;
+   const GLfloat fb_height = (GLfloat)st->state.framebuffer.height;
    const GLfloat x0 = (GLfloat)x;
    const GLfloat x1 = (GLfloat)(x + width);
    const GLfloat y0 = (GLfloat)y;
@@ -502,10 +501,9 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
 
    /* viewport state: viewport matching window dims */
    {
-      const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
-      const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
-      const GLfloat width = (GLfloat)fb->Width;
-      const GLfloat height = (GLfloat)fb->Height;
+      const GLboolean invert = st->state.fb_orientation == Y_0_TOP;
+      const GLfloat width = (GLfloat)st->state.framebuffer.width;
+      const GLfloat height = (GLfloat)st->state.framebuffer.height;
       struct pipe_viewport_state vp;
       vp.scale[0] =  0.5f * width;
       vp.scale[1] = height * (invert ? -0.5f : 0.5f);
@@ -636,43 +634,41 @@ st_flush_bitmap_cache(struct st_context *st)
    if (!st->bitmap.cache->empty) {
       struct bitmap_cache *cache = st->bitmap.cache;
 
-      if (st->ctx->DrawBuffer) {
-         struct pipe_context *pipe = st->pipe;
-         struct pipe_sampler_view *sv;
+      struct pipe_context *pipe = st->pipe;
+      struct pipe_sampler_view *sv;
 
-         assert(cache->xmin <= cache->xmax);
-/*         printf("flush size %d x %d  at %d, %d\n",
-                cache->xmax - cache->xmin,
-                cache->ymax - cache->ymin,
-                cache->xpos, cache->ypos);
+      assert(cache->xmin <= cache->xmax);
+
+/*    printf("flush size %d x %d  at %d, %d\n",
+             cache->xmax - cache->xmin,
+             cache->ymax - cache->ymin,
+             cache->xpos, cache->ypos);
 */
 
-         /* The texture transfer has been mapped until now.
+      /* The texture transfer has been mapped until now.
           * So unmap and release the texture transfer before drawing.
           */
-         if (cache->trans) {
-            if (0)
-               print_cache(cache);
-            pipe_transfer_unmap(pipe, cache->trans);
-            cache->buffer = NULL;
-
-            pipe->transfer_destroy(pipe, cache->trans);
-            cache->trans = NULL;
-         }
-
-         sv = st_create_texture_sampler_view(st->pipe, cache->texture);
-         if (sv) {
-            draw_bitmap_quad(st->ctx,
-                             cache->xpos,
-                             cache->ypos,
-                             cache->zpos,
-                             BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
-                             sv,
-                             cache->color);
-
-            pipe_sampler_view_reference(&sv, NULL);
-         }
+      if (cache->trans) {
+         if (0)
+            print_cache(cache);
+         pipe_transfer_unmap(pipe, cache->trans);
+         cache->buffer = NULL;
+
+         pipe->transfer_destroy(pipe, cache->trans);
+         cache->trans = NULL;
+      }
+
+      sv = st_create_texture_sampler_view(st->pipe, cache->texture);
+      if (sv) {
+         draw_bitmap_quad(st->ctx,
+                          cache->xpos,
+                          cache->ypos,
+                          cache->zpos,
+                          BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
+                          sv,
+                          cache->color);
+
+         pipe_sampler_view_reference(&sv, NULL);
       }
 
       /* release/free the texture */
index a3f44b3aba4ee4842cb41ac94160d7aab89d95c1..be8fef189ef5f9ece0c64a969198bc9ee87215b4 100644 (file)
@@ -117,6 +117,8 @@ struct st_context
       GLuint num_vertex_textures;
 
       GLuint poly_stipple[32];  /**< In OpenGL's bottom-to-top order */
+
+      GLuint fb_orientation;
    } state;
 
    char vendor[100];