-int
-st_unbind_texture_surface(struct pipe_surface *ps, int target, int level)
-{
- GET_CURRENT_CONTEXT(ctx);
- 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_object *stObj;
- struct st_texture_image *stImage;
-
- switch (target) {
- case ST_TEXTURE_2D:
- target = GL_TEXTURE_2D;
- break;
- case ST_TEXTURE_RECT:
- target = GL_TEXTURE_RECTANGLE_ARB;
- break;
- default:
- return 0;
- }
-
- texObj = _mesa_select_tex_object(ctx, texUnit, target);
-
- _mesa_lock_texture(ctx, texObj);
-
- texImage = _mesa_get_tex_image(ctx, texObj, target, level);
- stObj = st_texture_object(texObj);
- stImage = st_texture_image(texImage);
-
- /* Make sure the pipe surface is still bound. The texture object is still
- * considered surface based even if this is the last bound surface. */
- if (stImage->pt == ps->texture) {
- pipe_texture_reference(&stImage->pt, NULL);
- _mesa_clear_texture_image(ctx, texImage);
-
- _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
- }
-
- _mesa_unlock_texture(ctx, texObj);
-
- return 1;
-}
-
-
-/** Redirect rendering into stfb's surface to a texture image */
-int
-st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex,
- int target, int format, int level)
-{
- 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);
-
- /* plug in new surface/texture info */
- pipe_texture_reference(&strb->texture, stImage->pt);
- strb->surface = screen->get_tex_surface(screen, strb->texture,
- face, level, slice,
- (PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE));
-
- st->dirty.st |= ST_NEW_FRAMEBUFFER;
-
- return 1;
-}
-
-
-/** Undo surface-to-texture binding */
-int
-st_release_teximage(struct st_framebuffer *stfb, uint surfIndex,
- int target, int format, int level)