sync cogl-blit and cogl-texture with master
This synchronizes parts of cogl-blit.c and cogl-texture.c with the master branch to help with cherry picking patches.
This commit is contained in:
parent
272431e102
commit
14d8ec7cca
@ -63,8 +63,7 @@ _cogl_blit_texture_render_begin (CoglBlitData *data)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cogl_push_framebuffer (fb);
|
data->fb = fb;
|
||||||
cogl_object_unref (fb);
|
|
||||||
|
|
||||||
dst_width = cogl_texture_get_width (data->dst_tex);
|
dst_width = cogl_texture_get_width (data->dst_tex);
|
||||||
dst_height = cogl_texture_get_height (data->dst_tex);
|
dst_height = cogl_texture_get_height (data->dst_tex);
|
||||||
@ -97,7 +96,7 @@ _cogl_blit_texture_render_begin (CoglBlitData *data)
|
|||||||
|
|
||||||
cogl_pipeline_set_layer_texture (pipeline, 0, data->src_tex);
|
cogl_pipeline_set_layer_texture (pipeline, 0, data->src_tex);
|
||||||
|
|
||||||
_cogl_push_source (pipeline, FALSE);
|
data->pipeline = pipeline;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -111,15 +110,17 @@ _cogl_blit_texture_render_blit (CoglBlitData *data,
|
|||||||
unsigned int width,
|
unsigned int width,
|
||||||
unsigned int height)
|
unsigned int height)
|
||||||
{
|
{
|
||||||
cogl_rectangle_with_texture_coords (dst_x, dst_y,
|
cogl_framebuffer_draw_textured_rectangle (data->fb,
|
||||||
dst_x + width,
|
data->pipeline,
|
||||||
dst_y + height,
|
dst_x, dst_y,
|
||||||
src_x / (float) data->src_width,
|
dst_x + width,
|
||||||
src_y / (float) data->src_height,
|
dst_y + height,
|
||||||
(src_x + width) /
|
src_x / (float) data->src_width,
|
||||||
(float) data->src_width,
|
src_y / (float) data->src_height,
|
||||||
(src_y + height) /
|
(src_x + width) /
|
||||||
(float) data->src_height);
|
(float) data->src_width,
|
||||||
|
(src_y + height) /
|
||||||
|
(float) data->src_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -127,9 +128,6 @@ _cogl_blit_texture_render_end (CoglBlitData *data)
|
|||||||
{
|
{
|
||||||
CoglContext *ctx = data->src_tex->context;
|
CoglContext *ctx = data->src_tex->context;
|
||||||
|
|
||||||
cogl_pop_source ();
|
|
||||||
cogl_pop_framebuffer ();
|
|
||||||
|
|
||||||
/* Attach the target texture to the texture render pipeline so that
|
/* Attach the target texture to the texture render pipeline so that
|
||||||
we don't keep a reference to the source texture forever. This is
|
we don't keep a reference to the source texture forever. This is
|
||||||
assuming that the destination texture will live for a long time
|
assuming that the destination texture will live for a long time
|
||||||
@ -140,6 +138,8 @@ _cogl_blit_texture_render_end (CoglBlitData *data)
|
|||||||
hash table key such as for the ARBfp program cache. */
|
hash table key such as for the ARBfp program cache. */
|
||||||
cogl_pipeline_set_layer_texture (ctx->blit_texture_pipeline, 0,
|
cogl_pipeline_set_layer_texture (ctx->blit_texture_pipeline, 0,
|
||||||
data->dst_tex);
|
data->dst_tex);
|
||||||
|
|
||||||
|
cogl_object_unref (data->fb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglBool
|
static CoglBool
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "cogl-object-private.h"
|
#include "cogl-object-private.h"
|
||||||
#include "cogl-texture.h"
|
#include "cogl-texture.h"
|
||||||
|
#include "cogl-framebuffer.h"
|
||||||
|
|
||||||
/* This structures and functions are used when a series of blits needs
|
/* This structures and functions are used when a series of blits needs
|
||||||
to be performed between two textures. In this case there are
|
to be performed between two textures. In this case there are
|
||||||
@ -67,7 +68,11 @@ struct _CoglBlitData
|
|||||||
complete texture data in */
|
complete texture data in */
|
||||||
unsigned char *image_data;
|
unsigned char *image_data;
|
||||||
CoglPixelFormat format;
|
CoglPixelFormat format;
|
||||||
|
|
||||||
int bpp;
|
int bpp;
|
||||||
|
|
||||||
|
CoglFramebuffer *fb;
|
||||||
|
CoglPipeline *pipeline;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -761,19 +761,20 @@ cogl_texture_set_region (CoglTexture *texture,
|
|||||||
* glGetTexImage, but may be used as a fallback in some circumstances.
|
* glGetTexImage, but may be used as a fallback in some circumstances.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
do_texture_draw_and_read (CoglTexture *texture,
|
do_texture_draw_and_read (CoglFramebuffer *fb,
|
||||||
CoglBitmap *target_bmp,
|
CoglPipeline *pipeline,
|
||||||
float *viewport)
|
CoglTexture *texture,
|
||||||
|
CoglBitmap *target_bmp,
|
||||||
|
float *viewport)
|
||||||
{
|
{
|
||||||
float rx1, ry1;
|
float rx1, ry1;
|
||||||
float rx2, ry2;
|
float rx2, ry2;
|
||||||
float tx1, ty1;
|
float tx1, ty1;
|
||||||
float tx2, ty2;
|
float tx2, ty2;
|
||||||
int bw, bh;
|
int bw, bh;
|
||||||
CoglBitmap *rect_bmp;
|
CoglBitmap *rect_bmp;
|
||||||
unsigned int tex_width, tex_height;
|
unsigned int tex_width, tex_height;
|
||||||
|
CoglContext *ctx = fb->context;
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
||||||
|
|
||||||
tex_width = cogl_texture_get_width (texture);
|
tex_width = cogl_texture_get_width (texture);
|
||||||
tex_height = cogl_texture_get_height (texture);
|
tex_height = cogl_texture_get_height (texture);
|
||||||
@ -813,11 +814,13 @@ do_texture_draw_and_read (CoglTexture *texture,
|
|||||||
tx2 = (rx2 / (float) tex_width);
|
tx2 = (rx2 / (float) tex_width);
|
||||||
|
|
||||||
/* Draw a portion of texture */
|
/* Draw a portion of texture */
|
||||||
cogl_rectangle_with_texture_coords (0, 0,
|
cogl_framebuffer_draw_textured_rectangle (fb,
|
||||||
rx2 - rx1,
|
pipeline,
|
||||||
ry2 - ry1,
|
0, 0,
|
||||||
tx1, ty1,
|
rx2 - rx1,
|
||||||
tx2, ty2);
|
ry2 - ry1,
|
||||||
|
tx1, ty1,
|
||||||
|
tx2, ty2);
|
||||||
|
|
||||||
/* Read into a temporary bitmap */
|
/* Read into a temporary bitmap */
|
||||||
rect_bmp = _cogl_bitmap_new_with_malloc_buffer
|
rect_bmp = _cogl_bitmap_new_with_malloc_buffer
|
||||||
@ -826,7 +829,7 @@ do_texture_draw_and_read (CoglTexture *texture,
|
|||||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
|
||||||
|
|
||||||
cogl_framebuffer_read_pixels_into_bitmap
|
cogl_framebuffer_read_pixels_into_bitmap
|
||||||
(cogl_get_draw_framebuffer (),
|
(fb,
|
||||||
viewport[0], viewport[1],
|
viewport[0], viewport[1],
|
||||||
COGL_READ_PIXELS_COLOR_BUFFER,
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
||||||
rect_bmp);
|
rect_bmp);
|
||||||
@ -853,23 +856,21 @@ do_texture_draw_and_read (CoglTexture *texture,
|
|||||||
*/
|
*/
|
||||||
CoglBool
|
CoglBool
|
||||||
_cogl_texture_draw_and_read (CoglTexture *texture,
|
_cogl_texture_draw_and_read (CoglTexture *texture,
|
||||||
CoglBitmap *target_bmp,
|
CoglBitmap *target_bmp,
|
||||||
GLuint target_gl_format,
|
GLuint target_gl_format,
|
||||||
GLuint target_gl_type)
|
GLuint target_gl_type)
|
||||||
{
|
{
|
||||||
int bpp;
|
int bpp;
|
||||||
CoglFramebuffer *framebuffer;
|
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||||
float viewport[4];
|
float viewport[4];
|
||||||
CoglBitmap *alpha_bmp;
|
CoglBitmap *alpha_bmp;
|
||||||
int target_width = cogl_bitmap_get_width (target_bmp);
|
int target_width = cogl_bitmap_get_width (target_bmp);
|
||||||
int target_height = cogl_bitmap_get_height (target_bmp);
|
int target_height = cogl_bitmap_get_height (target_bmp);
|
||||||
int target_rowstride = cogl_bitmap_get_rowstride (target_bmp);
|
int target_rowstride = cogl_bitmap_get_rowstride (target_bmp);
|
||||||
|
CoglContext *ctx = framebuffer->context;
|
||||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
||||||
|
|
||||||
bpp = _cogl_pixel_format_get_bytes_per_pixel (COGL_PIXEL_FORMAT_RGBA_8888);
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (COGL_PIXEL_FORMAT_RGBA_8888);
|
||||||
|
|
||||||
framebuffer = cogl_get_draw_framebuffer ();
|
|
||||||
/* Viewport needs to have some size and be inside the window for this */
|
/* Viewport needs to have some size and be inside the window for this */
|
||||||
cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
|
cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
|
||||||
if (viewport[0] < 0 || viewport[1] < 0 ||
|
if (viewport[0] < 0 || viewport[1] < 0 ||
|
||||||
@ -900,8 +901,6 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
_cogl_push_source (ctx->texture_download_pipeline, FALSE);
|
|
||||||
|
|
||||||
cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, texture);
|
cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, texture);
|
||||||
|
|
||||||
cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
|
cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
|
||||||
@ -913,7 +912,9 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
|
|||||||
COGL_PIPELINE_FILTER_NEAREST,
|
COGL_PIPELINE_FILTER_NEAREST,
|
||||||
COGL_PIPELINE_FILTER_NEAREST);
|
COGL_PIPELINE_FILTER_NEAREST);
|
||||||
|
|
||||||
do_texture_draw_and_read (texture, target_bmp, viewport);
|
do_texture_draw_and_read (framebuffer,
|
||||||
|
ctx->texture_download_pipeline,
|
||||||
|
texture, target_bmp, viewport);
|
||||||
|
|
||||||
/* Check whether texture has alpha and framebuffer not */
|
/* Check whether texture has alpha and framebuffer not */
|
||||||
/* FIXME: For some reason even if ALPHA_BITS is 8, the framebuffer
|
/* FIXME: For some reason even if ALPHA_BITS is 8, the framebuffer
|
||||||
@ -955,7 +956,9 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
|
|||||||
"RGBA = REPLACE (TEXTURE[A])",
|
"RGBA = REPLACE (TEXTURE[A])",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
do_texture_draw_and_read (texture, alpha_bmp, viewport);
|
do_texture_draw_and_read (framebuffer,
|
||||||
|
ctx->texture_download_pipeline,
|
||||||
|
texture, alpha_bmp, viewport);
|
||||||
|
|
||||||
/* Copy temp R to target A */
|
/* Copy temp R to target A */
|
||||||
|
|
||||||
@ -986,9 +989,6 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
|
|||||||
cogl_framebuffer_pop_matrix (framebuffer);
|
cogl_framebuffer_pop_matrix (framebuffer);
|
||||||
_cogl_framebuffer_pop_projection (framebuffer);
|
_cogl_framebuffer_pop_projection (framebuffer);
|
||||||
|
|
||||||
/* restore the original pipeline */
|
|
||||||
cogl_pop_source ();
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user