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.
This commit is contained in:
Neil Roberts 2011-02-10 18:22:27 +00:00
parent 5cc062c16c
commit f947fe958f
2 changed files with 57 additions and 0 deletions

View File

@ -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 */

View File

@ -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 <string.h>
#include <math.h>
@ -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)
{