diff options
Diffstat (limited to 'src/mesa/state_tracker/st_texture.c')
-rw-r--r-- | src/mesa/state_tracker/st_texture.c | 96 |
1 files changed, 92 insertions, 4 deletions
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 73cebff33f7..29b16347625 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -27,8 +27,11 @@ #include "st_context.h" #include "st_format.h" +#include "st_public.h" #include "st_texture.h" +#include "st_cb_fbo.h" #include "main/enums.h" +#include "main/teximage.h" #undef Elements /* fix re-defined macro warning */ @@ -301,9 +304,6 @@ st_texture_image_copy(struct pipe_context *pipe, struct pipe_surface *dst_surface; GLuint i; - /* XXX this is a hack */ - const GLuint copyHeight = dst->compressed ? height / 4 : height; - for (i = 0; i < depth; i++) { GLuint srcLevel; @@ -345,9 +345,97 @@ st_texture_image_copy(struct pipe_context *pipe, 0, 0, /* destX, Y */ src_surface, 0, 0, /* srcX, Y */ - width, copyHeight); + width, height); screen->tex_surface_release(screen, &src_surface); screen->tex_surface_release(screen, &dst_surface); } } + + +/** 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->Current2D; + 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) +{ + GET_CURRENT_CONTEXT(ctx); + struct st_context *st = ctx->st; + struct st_renderbuffer *strb; + + assert(surfIndex <= ST_SURFACE_DEPTH); + + strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer); + + if (!strb->texture_save || !strb->surface_save) { + /* Error! */ + return 0; + } + + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + + /* free tex surface, restore original */ + pipe_surface_reference(&strb->surface, strb->surface_save); + pipe_texture_reference(&strb->texture, strb->texture_save); + + pipe_surface_reference(&strb->surface_save, NULL); + pipe_texture_reference(&strb->texture_save, NULL); + + st->dirty.st |= ST_NEW_FRAMEBUFFER; + + return 1; +} |