intel: use driReadDrawable in do_copy_texsubimage()
[mesa.git] / src / mesa / state_tracker / st_context.c
index 2a1f21c51cad7b46d6a27ddbf191a27ea3ce792b..8514b6b3756bfd0ca5372594f2915741149216c9 100644 (file)
@@ -233,6 +233,7 @@ void st_destroy_context( struct st_context *st )
    struct pipe_context *pipe = st->pipe;
    struct cso_context *cso = st->cso_context;
    GLcontext *ctx = st->ctx;
+   GLuint i;
 
    /* need to unbind and destroy CSO objects before anything else */
    cso_release_all(st->cso_context);
@@ -240,6 +241,12 @@ void st_destroy_context( struct st_context *st )
    st_reference_fragprog(st, &st->fp, NULL);
    st_reference_vertprog(st, &st->vp, NULL);
 
+   /* release framebuffer surfaces */
+   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
+      pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL);
+   }
+   pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL);
+
    _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
 
    _vbo_DestroyContext(st->ctx);
@@ -256,9 +263,10 @@ void st_destroy_context( struct st_context *st )
 }
 
 
-void st_make_current(struct st_context *st,
-                     struct st_framebuffer *draw,
-                     struct st_framebuffer *read)
+GLboolean
+st_make_current(struct st_context *st,
+                struct st_framebuffer *draw,
+                struct st_framebuffer *read)
 {
    /* Call this periodically to detect when the user has begun using
     * GL rendering from multiple threads.
@@ -266,22 +274,15 @@ void st_make_current(struct st_context *st,
    _glapi_check_multithread();
 
    if (st) {
-      GLboolean firstTime = st->ctx->FirstTimeCurrent;
-      _mesa_make_current(st->ctx, &draw->Base, &read->Base);
-      /* Need to initialize viewport here since draw->Base->Width/Height
-       * will still be zero at this point.
-       * This could be improved, but would require rather extensive work
-       * elsewhere (allocate rb surface storage sooner)
-       */
-      if (firstTime) {
-         GLuint w = draw->InitWidth, h = draw->InitHeight;
-         _mesa_set_viewport(st->ctx, 0, 0, w, h);
-         _mesa_set_scissor(st->ctx, 0, 0, w, h);
+      if (!_mesa_make_current(st->ctx, &draw->Base, &read->Base))
+         return GL_FALSE;
 
-      }
+      _mesa_check_init_viewport(st->ctx, draw->InitWidth, draw->InitHeight);
+
+      return GL_TRUE;
    }
    else {
-      _mesa_make_current(NULL, NULL, NULL);
+      return _mesa_make_current(NULL, NULL, NULL);
    }
 }