gallium: added st_bind/release_teximage() functions
This commit is contained in:
parent
9d9143d889
commit
c074b86cbc
|
@ -47,6 +47,10 @@ struct st_renderbuffer
|
|||
|
||||
struct st_texture_object *rtt; /**< GL render to texture's texture */
|
||||
int rtt_level, rtt_face, rtt_slice;
|
||||
|
||||
/** Render to texture state */
|
||||
struct pipe_texture *texture_save;
|
||||
struct pipe_surface *surface_save;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -41,6 +41,10 @@
|
|||
#define ST_SURFACE_BACK_RIGHT 3
|
||||
#define ST_SURFACE_DEPTH 8
|
||||
|
||||
#define ST_TEXTURE_2D 0x2
|
||||
#define ST_TEXTURE_RGB 0x1
|
||||
#define ST_TEXTURE_RGBA 0x2
|
||||
|
||||
|
||||
struct st_context;
|
||||
struct st_framebuffer;
|
||||
|
@ -93,6 +97,15 @@ void st_notify_swapbuffers(struct st_framebuffer *stfb);
|
|||
void st_notify_swapbuffers_complete(struct st_framebuffer *stfb);
|
||||
|
||||
|
||||
/** 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);
|
||||
|
||||
/** Undo surface-to-texture binding */
|
||||
int st_release_teximage(struct st_framebuffer *stfb, uint surfIndex,
|
||||
int target, int format, int level);
|
||||
|
||||
|
||||
/** Generic function type */
|
||||
typedef void (*st_proc)();
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
@ -351,3 +354,92 @@ st_texture_image_copy(struct pipe_context *pipe,
|
|||
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 pipe_context *pipe = st->pipe;
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue