diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index f14e562..3c3606f 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -78,7 +78,7 @@
  * of glBitmap calls being used to draw text.
  */
 static GLboolean UseBitmapCache = GL_TRUE;
-
+#define EPSILON 1e-06                 /*Nurbs.h for double precision compares */
 
 #define BITMAP_CACHE_WIDTH  512
 #define BITMAP_CACHE_HEIGHT 32
@@ -92,6 +92,7 @@ struct bitmap_cache
 
    GLfloat color[4];
 
+   GLfloat zvalue;
    struct pipe_texture *texture;
    struct pipe_surface *surf;
 
@@ -535,7 +536,7 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
 
    /* draw textured quad */
    offset = setup_bitmap_vertex_data(st, x, y, width, height,
-                                     ctx->Current.RasterPos[2],
+                                     z,
                                      color);
 
    util_draw_vertex_buffer(pipe, st->bitmap.vbuf, offset,
@@ -626,7 +627,7 @@ st_flush_bitmap_cache(struct st_context *st)
          draw_bitmap_quad(st->ctx,
                           cache->xpos,
                           cache->ypos,
-                          st->ctx->Current.RasterPos[2],
+                          cache->zvalue,
                           BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
                           cache->texture,
                           cache->color);
@@ -676,7 +677,8 @@ accum_bitmap(struct st_context *st,
       py = y - cache->ypos;
       if (px < 0 || px + width > BITMAP_CACHE_WIDTH ||
           py < 0 || py + height > BITMAP_CACHE_HEIGHT ||
-          !TEST_EQ_4V(st->ctx->Current.RasterColor, cache->color)) {
+          !TEST_EQ_4V(st->ctx->Current.RasterColor, cache->color) ||
+          ((fabs(st->ctx->Current.RasterPos[2] - cache->zvalue) > EPSILON))) {
          /* This bitmap would extend beyond cache bounds, or the bitmap
           * color is changing
           * so flush and continue.
@@ -693,6 +695,7 @@ accum_bitmap(struct st_context *st,
       cache->ypos = y - py;
       cache->empty = GL_FALSE;
       COPY_4FV(cache->color, st->ctx->Current.RasterColor);
+      cache->zvalue = st->ctx->Current.RasterPos[2];
    }
 
    assert(px != -999);
