- GET_CURRENT_CONTEXT(ctx);
- struct st_context *st = ctx->st;
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
- const GLuint unit = ctx->Texture.CurrentUnit;
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- struct st_texture_image *stImage;
- struct st_renderbuffer *strb;
- GLint face = 0, slice = 0;
-
- assert(surfIndex <= ST_SURFACE_DEPTH);
-
- strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
-
- if (strb->texture_save || strb->surface_save) {
- /* Error! */
- return 0;
- }
-
- if (target == ST_TEXTURE_2D) {
- texObj = texUnit->CurrentTex[TEXTURE_2D_INDEX];
- texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, level);
- stImage = st_texture_image(texImage);
- }
- else {
- /* unsupported target */
- return 0;
- }
-
- st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
-
- /* save the renderbuffer's surface/texture info */
- pipe_texture_reference(&strb->texture_save, strb->texture);
- pipe_surface_reference(&strb->surface_save, strb->surface);
- pipe_sampler_view_reference(&strb->sampler_view_save, strb->sampler_view);
-
- /* plug in new surface/texture info */
- pipe_texture_reference(&strb->texture, stImage->pt);
-
- /* XXX: Shouldn't we release reference to old surface here?
- */
-
- strb->surface = screen->get_tex_surface(screen, strb->texture,
- face, level, slice,
- (PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE));
-
- pipe_sampler_view_reference(&strb->sampler_view, NULL);
-
- st->dirty.st |= ST_NEW_FRAMEBUFFER;