summaryrefslogtreecommitdiff
path: root/cogl/driver/gles/cogl-texture-driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'cogl/driver/gles/cogl-texture-driver.c')
-rw-r--r--cogl/driver/gles/cogl-texture-driver.c217
1 files changed, 8 insertions, 209 deletions
diff --git a/cogl/driver/gles/cogl-texture-driver.c b/cogl/driver/gles/cogl-texture-driver.c
index 1d50a198..0461ae8d 100644
--- a/cogl/driver/gles/cogl-texture-driver.c
+++ b/cogl/driver/gles/cogl-texture-driver.c
@@ -128,217 +128,16 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglTexture *tex,
g_free (slice_bmp.data);
}
-static void
-_cogl_texture_draw_and_read (CoglTexture *tex,
- CoglBitmap *target_bmp,
- GLint *viewport)
-{
- gint bpp;
- float rx1, ry1;
- float rx2, ry2;
- float tx1, ty1;
- float tx2, ty2;
- int bw, bh;
- CoglBitmap rect_bmp;
- CoglHandle handle;
-
- handle = (CoglHandle) tex;
- bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
-
- ry1 = 0; ry2 = 0;
- ty1 = 0; ty2 = 0;
-
- /* Walk Y axis until whole bitmap height consumed */
- for (bh = tex->bitmap.height; bh > 0; bh -= viewport[3])
- {
- /* Rectangle Y coords */
- ry1 = ry2;
- ry2 += (bh < viewport[3]) ? bh : viewport[3];
-
- /* Normalized texture Y coords */
- ty1 = ty2;
- ty2 = (ry2 / (float)tex->bitmap.height);
-
- rx1 = 0; rx2 = 0;
- tx1 = 0; tx2 = 0;
-
- /* Walk X axis until whole bitmap width consumed */
- for (bw = tex->bitmap.width; bw > 0; bw-=viewport[2])
- {
- /* Rectangle X coords */
- rx1 = rx2;
- rx2 += (bw < viewport[2]) ? bw : viewport[2];
-
- /* Normalized texture X coords */
- tx1 = tx2;
- tx2 = (rx2 / (float)tex->bitmap.width);
-
- /* Draw a portion of texture */
- cogl_rectangle_with_texture_coords (0, 0,
- rx2 - rx1,
- ry2 - ry1,
- tx1, ty1,
- tx2, ty2);
-
- /* Read into a temporary bitmap */
- rect_bmp.format = COGL_PIXEL_FORMAT_RGBA_8888;
- rect_bmp.width = rx2 - rx1;
- rect_bmp.height = ry2 - ry1;
- rect_bmp.rowstride = bpp * rect_bmp.width;
- rect_bmp.data = (guchar*) g_malloc (rect_bmp.rowstride *
- rect_bmp.height);
-
- _cogl_texture_driver_prep_gl_for_pixels_download (rect_bmp.rowstride,
- bpp);
- GE( glReadPixels (viewport[0], viewport[1],
- rect_bmp.width,
- rect_bmp.height,
- GL_RGBA, GL_UNSIGNED_BYTE,
- rect_bmp.data) );
-
- /* Copy to target bitmap */
- _cogl_bitmap_copy_subregion (&rect_bmp,
- target_bmp,
- 0,0,
- rx1,ry1,
- rect_bmp.width,
- rect_bmp.height);
-
- /* Free temp bitmap */
- g_free (rect_bmp.data);
- }
- }
-}
-
+/* NB: GLES doesn't support glGetTexImage2D, so cogl-texture will instead
+ * fallback to a generic render + readpixels approach to downloading
+ * texture data. (See _cogl_texture_draw_and_read() ) */
gboolean
-_cogl_texture_driver_download_from_gl (CoglTexture *tex,
- CoglBitmap *target_bmp,
- GLuint target_gl_format,
- GLuint target_gl_type)
+_cogl_texture_driver_gl_get_tex_image (GLenum gl_target,
+ GLenum dest_gl_format,
+ GLenum dest_gl_type,
+ guint8 *dest)
{
- gint bpp;
- GLint viewport[4];
- CoglBitmap alpha_bmp;
- CoglHandle prev_source;
-
- _COGL_GET_CONTEXT (ctx, FALSE);
-
-
- bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
-
- /* Viewport needs to have some size and be inside the window for this */
- GE( glGetIntegerv (GL_VIEWPORT, viewport) );
-
- if (viewport[0] < 0 || viewport[1] < 0 ||
- viewport[2] <= 0 || viewport[3] <= 0)
- return FALSE;
-
- /* Setup orthographic projection into current viewport
- (0,0 in bottom-left corner to draw the texture
- upside-down so we match the way glReadPixels works) */
-
- _cogl_set_current_matrix (COGL_MATRIX_PROJECTION);
- _cogl_current_matrix_push ();
- _cogl_current_matrix_identity ();
-
- _cogl_current_matrix_ortho (0, (float)(viewport[2]),
- 0, (float)(viewport[3]),
- (float)(0),
- (float)(100));
-
- _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
- _cogl_current_matrix_push ();
- _cogl_current_matrix_identity ();
-
- /* Direct copy operation */
-
- if (ctx->drv.texture_download_material == COGL_INVALID_HANDLE)
- {
- ctx->drv.texture_download_material = cogl_material_new ();
- cogl_material_set_blend (ctx->drv.texture_download_material,
- "RGBA = ADD (SRC_COLOR, 0)",
- NULL);
- }
-
- prev_source = cogl_handle_ref (ctx->source_material);
- cogl_set_source (ctx->drv.texture_download_material);
-
- cogl_material_set_layer (ctx->drv.texture_download_material, 0, tex);
-
- cogl_material_set_layer_combine (ctx->drv.texture_download_material,
- 0, /* layer */
- "RGBA = REPLACE (TEXTURE)",
- NULL);
-
- _cogl_texture_draw_and_read (tex, target_bmp, viewport);
-
- /* Check whether texture has alpha and framebuffer not */
- /* FIXME: For some reason even if ALPHA_BITS is 8, the framebuffer
- still doesn't seem to have an alpha buffer. This might be just
- a PowerVR issue.
- GLint r_bits, g_bits, b_bits, a_bits;
- GE( glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
- GE( glGetIntegerv (GL_RED_BITS, &r_bits) );
- GE( glGetIntegerv (GL_GREEN_BITS, &g_bits) );
- GE( glGetIntegerv (GL_BLUE_BITS, &b_bits) );
- printf ("R bits: %d\n", r_bits);
- printf ("G bits: %d\n", g_bits);
- printf ("B bits: %d\n", b_bits);
- printf ("A bits: %d\n", a_bits); */
- if ((tex->bitmap.format & COGL_A_BIT)/* && a_bits == 0*/)
- {
- guchar *srcdata;
- guchar *dstdata;
- guchar *srcpixel;
- guchar *dstpixel;
- gint x,y;
-
- /* Create temp bitmap for alpha values */
- alpha_bmp.format = COGL_PIXEL_FORMAT_RGBA_8888;
- alpha_bmp.width = target_bmp->width;
- alpha_bmp.height = target_bmp->height;
- alpha_bmp.rowstride = bpp * alpha_bmp.width;
- alpha_bmp.data = (guchar*) g_malloc (alpha_bmp.rowstride *
- alpha_bmp.height);
-
- /* Draw alpha values into RGB channels */
- cogl_material_set_layer_combine (ctx->drv.texture_download_material,
- 0, /* layer */
- "RGBA = REPLACE (TEXTURE[A])",
- NULL);
-
- _cogl_texture_draw_and_read (tex, &alpha_bmp, viewport);
-
- /* Copy temp R to target A */
- srcdata = alpha_bmp.data;
- dstdata = target_bmp->data;
-
- for (y=0; y<target_bmp->height; ++y)
- {
- for (x=0; x<target_bmp->width; ++x)
- {
- srcpixel = srcdata + x*bpp;
- dstpixel = dstdata + x*bpp;
- dstpixel[3] = srcpixel[0];
- }
- srcdata += alpha_bmp.rowstride;
- dstdata += target_bmp->rowstride;
- }
-
- g_free (alpha_bmp.data);
- }
-
- /* Restore old state */
- _cogl_set_current_matrix (COGL_MATRIX_PROJECTION);
- _cogl_current_matrix_pop ();
- _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
- _cogl_current_matrix_pop ();
-
- /* restore the original material */
- cogl_set_source (prev_source);
- cogl_handle_unref (prev_source);
-
- return TRUE;
+ return FALSE;
}
gboolean