From bc86db1057f6ceb9cecd72be085bab7198136f29 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 10 Feb 2011 18:22:27 +0000 Subject: [PATCH] cogl-texture-2d: Add an internal wrapper around glCopyTexSubImage2D This adds a function called _cogl_texture_2d_copy_from_framebuffer which is a simple wrapper around glCopyTexSubImage2D. It is currently specific to the texture 2D backend. --- cogl/cogl-texture-2d-private.h | 22 +++++++++++++++++++++ cogl/cogl-texture-2d.c | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/cogl/cogl-texture-2d-private.h b/cogl/cogl-texture-2d-private.h index bd36e8ffa..e6dad37cb 100644 --- a/cogl/cogl-texture-2d-private.h +++ b/cogl/cogl-texture-2d-private.h @@ -87,4 +87,26 @@ _cogl_texture_2d_new_from_foreign (GLuint gl_handle, void _cogl_texture_2d_externally_modified (CoglHandle handle); +/* + * _cogl_texture_2d_copy_from_framebuffer: + * @handle: A handle to a 2D texture + * @dst_x: X-position to store the image within the texture + * @dst_y: Y-position to store the image within the texture + * @src_x: X-position to within the framebuffer to read from + * @src_y: Y-position to within the framebuffer to read from + * @width: width of the rectangle to copy + * @height: height of the rectangle to copy + * + * This copies a portion of the current read framebuffer into the + * texture. + */ +void +_cogl_texture_2d_copy_from_framebuffer (CoglHandle handle, + int dst_x, + int dst_y, + int src_x, + int src_y, + int width, + int height); + #endif /* __COGL_TEXTURE_2D_H */ diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index 80ec5c7bd..e47f5a554 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -38,6 +38,7 @@ #include "cogl-handle.h" #include "cogl-journal-private.h" #include "cogl-pipeline-opengl-private.h" +#include "cogl-framebuffer-private.h" #include #include @@ -441,6 +442,40 @@ _cogl_texture_2d_externally_modified (CoglHandle handle) COGL_TEXTURE_2D (handle)->mipmaps_dirty = TRUE; } +void +_cogl_texture_2d_copy_from_framebuffer (CoglHandle handle, + int dst_x, + int dst_y, + int src_x, + int src_y, + int width, + int height) +{ + CoglTexture2D *tex_2d; + + g_return_if_fail (_cogl_is_texture_2d (handle)); + + tex_2d = COGL_TEXTURE_2D (handle); + + /* Make sure the current framebuffers are bound. We explicitly avoid + flushing the clip state so we can bind our own empty state */ + _cogl_framebuffer_flush_state (_cogl_get_draw_buffer (), + _cogl_get_read_buffer (), + 0); + + _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, + tex_2d->gl_texture, + tex_2d->is_foreign); + + glCopyTexSubImage2D (GL_TEXTURE_2D, + 0, /* level */ + dst_x, dst_y, + src_x, src_y, + width, height); + + tex_2d->mipmaps_dirty = TRUE; +} + static int _cogl_texture_2d_get_max_waste (CoglTexture *tex) {