2009-07-27 19:37:11 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-07-27 19:37:11 -04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
#include "cogl-private.h"
|
2009-07-27 19:37:11 -04:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-bitmap.h"
|
|
|
|
#include "cogl-bitmap-private.h"
|
|
|
|
#include "cogl-texture-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2009-07-27 19:37:11 -04:00
|
|
|
#include "cogl-primitives.h"
|
2012-11-08 12:54:10 -05:00
|
|
|
#include "cogl-util-gl-private.h"
|
|
|
|
#include "cogl-error-private.h"
|
2009-07-27 19:37:11 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
#ifndef GL_TEXTURE_3D
|
|
|
|
#define GL_TEXTURE_3D 0x806F
|
|
|
|
#endif
|
|
|
|
#ifndef GL_MAX_3D_TEXTURE_SIZE_OES
|
|
|
|
#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073
|
|
|
|
#endif
|
|
|
|
|
2012-03-21 13:51:51 -04:00
|
|
|
/* This extension isn't available for GLES 1.1 so these won't be
|
|
|
|
defined */
|
|
|
|
#ifndef GL_UNPACK_ROW_LENGTH
|
|
|
|
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
|
|
|
#endif
|
|
|
|
#ifndef GL_UNPACK_SKIP_ROWS
|
|
|
|
#define GL_UNPACK_SKIP_ROWS 0x0CF3
|
|
|
|
#endif
|
|
|
|
#ifndef GL_UNPACK_SKIP_PIXELS
|
|
|
|
#define GL_UNPACK_SKIP_PIXELS 0x0CF4
|
|
|
|
#endif
|
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
static GLuint
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_gen (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2012-11-19 12:28:52 -05:00
|
|
|
CoglPixelFormat internal_format)
|
2010-01-25 06:21:05 -05:00
|
|
|
{
|
2012-11-19 12:28:52 -05:00
|
|
|
GLuint tex;
|
2010-01-25 06:21:05 -05:00
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
GE (ctx, glGenTextures (1, &tex));
|
2010-01-25 06:21:05 -05:00
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, tex, FALSE);
|
2010-01-25 06:21:05 -05:00
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
switch (gl_target)
|
|
|
|
{
|
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
case GL_TEXTURE_3D:
|
|
|
|
/* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
|
|
|
|
GE( ctx, glTexParameteri (gl_target,
|
|
|
|
GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR) );
|
|
|
|
break;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2010-01-25 06:21:05 -05:00
|
|
|
}
|
2012-11-19 12:28:52 -05:00
|
|
|
|
|
|
|
return tex;
|
2010-01-25 06:21:05 -05:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-21 13:51:51 -04:00
|
|
|
prep_gl_for_pixels_upload_full (CoglContext *ctx,
|
|
|
|
int pixels_rowstride,
|
|
|
|
int pixels_src_x,
|
|
|
|
int pixels_src_y,
|
|
|
|
int pixels_bpp)
|
|
|
|
{
|
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE))
|
|
|
|
{
|
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_ROW_LENGTH,
|
|
|
|
pixels_rowstride / pixels_bpp) );
|
|
|
|
|
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_SKIP_PIXELS, pixels_src_x) );
|
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_SKIP_ROWS, pixels_src_y) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert (pixels_src_x == 0);
|
|
|
|
g_assert (pixels_src_y == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx,
|
2012-03-22 13:04:47 -04:00
|
|
|
int pixels_rowstride,
|
2009-07-27 19:37:11 -04:00
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2012-03-21 13:51:51 -04:00
|
|
|
prep_gl_for_pixels_upload_full (ctx,
|
|
|
|
pixels_rowstride,
|
|
|
|
0, 0, /* src_x/y */
|
|
|
|
pixels_bpp);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
|
|
|
int pixels_rowstride,
|
2012-03-22 07:40:16 -04:00
|
|
|
int image_width,
|
2009-07-27 19:37:11 -04:00
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2012-03-22 07:40:16 -04:00
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_download (pixels_bpp,
|
|
|
|
image_width,
|
|
|
|
pixels_rowstride);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2010-12-17 11:09:26 -05:00
|
|
|
static CoglBitmap *
|
2012-03-22 13:04:47 -04:00
|
|
|
prepare_bitmap_alignment_for_upload (CoglContext *ctx,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBitmap *src_bmp,
|
|
|
|
CoglError **error)
|
2010-12-17 11:09:26 -05:00
|
|
|
{
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat format = cogl_bitmap_get_format (src_bmp);
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2012-02-25 15:18:05 -05:00
|
|
|
int src_rowstride = cogl_bitmap_get_rowstride (src_bmp);
|
|
|
|
int width = cogl_bitmap_get_width (src_bmp);
|
2010-12-17 11:09:26 -05:00
|
|
|
int alignment = 1;
|
|
|
|
|
2012-03-21 13:51:51 -04:00
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) ||
|
|
|
|
src_rowstride == 0)
|
2010-12-17 11:09:26 -05:00
|
|
|
return cogl_object_ref (src_bmp);
|
|
|
|
|
|
|
|
/* Work out the alignment of the source rowstride */
|
|
|
|
alignment = 1 << (_cogl_util_ffs (src_rowstride) - 1);
|
|
|
|
alignment = MIN (alignment, 8);
|
|
|
|
|
|
|
|
/* If the aligned data equals the rowstride then we can upload from
|
|
|
|
the bitmap directly using GL_UNPACK_ALIGNMENT */
|
|
|
|
if (((width * bpp + alignment - 1) & ~(alignment - 1)) == src_rowstride)
|
|
|
|
return cogl_object_ref (src_bmp);
|
|
|
|
/* Otherwise we need to copy the bitmap to pack the alignment
|
|
|
|
because GLES has no GL_ROW_LENGTH */
|
|
|
|
else
|
2012-11-08 12:54:10 -05:00
|
|
|
return _cogl_bitmap_copy (src_bmp, error);
|
2010-12-17 11:09:26 -05:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum gl_target,
|
|
|
|
GLuint gl_handle,
|
|
|
|
CoglBool is_foreign,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type,
|
|
|
|
CoglError **error)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *data;
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *slice_bmp;
|
|
|
|
int rowstride;
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum gl_error;
|
|
|
|
CoglBool status = TRUE;
|
|
|
|
CoglError *internal_error = NULL;
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2012-03-21 13:51:51 -04:00
|
|
|
/* If we have the GL_EXT_unpack_subimage extension then we can
|
|
|
|
upload from subregions directly. Otherwise we may need to copy
|
|
|
|
the bitmap */
|
|
|
|
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) &&
|
|
|
|
(src_x != 0 || src_y != 0 ||
|
|
|
|
width != cogl_bitmap_get_width (source_bmp) ||
|
|
|
|
height != cogl_bitmap_get_height (source_bmp)))
|
2010-12-17 11:09:26 -05:00
|
|
|
{
|
|
|
|
slice_bmp =
|
2012-03-13 10:46:18 -04:00
|
|
|
_cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
width, height,
|
|
|
|
source_format);
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_bitmap_copy_subregion (source_bmp,
|
|
|
|
slice_bmp,
|
|
|
|
src_x, src_y,
|
|
|
|
0, 0, /* dst_x/y */
|
|
|
|
width, height,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (slice_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-08-29 09:10:57 -04:00
|
|
|
|
|
|
|
src_x = src_y = 0;
|
2010-12-17 11:09:26 -05:00
|
|
|
}
|
|
|
|
else
|
2012-11-08 12:54:10 -05:00
|
|
|
{
|
|
|
|
slice_bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp, error);
|
|
|
|
if (!slice_bmp)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-13 10:46:18 -04:00
|
|
|
|
|
|
|
rowstride = cogl_bitmap_get_rowstride (slice_bmp);
|
2009-07-27 19:37:11 -04:00
|
|
|
|
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-21 13:51:51 -04:00
|
|
|
prep_gl_for_pixels_upload_full (ctx, rowstride, src_x, src_y, bpp);
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
data = _cogl_bitmap_gl_bind (slice_bmp, COGL_BUFFER_ACCESS_READ, 0, &internal_error);
|
|
|
|
|
|
|
|
/* NB: _cogl_bitmap_gl_bind() may return NULL when successfull so we
|
|
|
|
* have to explicitly check the cogl error pointer to catch
|
|
|
|
* problems... */
|
|
|
|
if (internal_error)
|
|
|
|
{
|
|
|
|
_cogl_propogate_error (error, internal_error);
|
|
|
|
cogl_object_unref (slice_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-15 08:05:55 -04:00
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
|
|
|
ctx->glTexSubImage2D (gl_target, 0,
|
|
|
|
dst_x, dst_y,
|
|
|
|
width, height,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data);
|
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
status = FALSE;
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2012-09-19 16:59:19 -04:00
|
|
|
_cogl_bitmap_gl_unbind (slice_bmp);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
cogl_object_unref (slice_bmp);
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
return status;
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum gl_target,
|
|
|
|
GLuint gl_handle,
|
|
|
|
CoglBool is_foreign,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLint internal_gl_format,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type,
|
|
|
|
CoglError **error)
|
2009-11-30 07:15:05 -05:00
|
|
|
{
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
2010-12-17 11:09:26 -05:00
|
|
|
int rowstride;
|
2012-02-25 15:18:05 -05:00
|
|
|
int bmp_width = cogl_bitmap_get_width (source_bmp);
|
|
|
|
int bmp_height = cogl_bitmap_get_height (source_bmp);
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *bmp;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *data;
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum gl_error;
|
|
|
|
CoglBool status = TRUE;
|
|
|
|
|
|
|
|
bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp, error);
|
|
|
|
if (!bmp)
|
|
|
|
return FALSE;
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
rowstride = cogl_bitmap_get_rowstride (bmp);
|
2009-11-30 07:15:05 -05:00
|
|
|
|
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
data = _cogl_bitmap_gl_bind (bmp, COGL_BUFFER_ACCESS_READ, 0, error);
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
|
|
|
ctx->glTexImage2D (gl_target, 0,
|
|
|
|
internal_gl_format,
|
|
|
|
bmp_width, bmp_height,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data);
|
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
status = FALSE;
|
2010-07-15 08:05:55 -04:00
|
|
|
|
2012-09-19 16:59:19 -04:00
|
|
|
_cogl_bitmap_gl_unbind (bmp);
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (bmp);
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
return status;
|
2009-11-30 07:15:05 -05:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum gl_target,
|
|
|
|
GLuint gl_handle,
|
|
|
|
CoglBool is_foreign,
|
|
|
|
GLint height,
|
|
|
|
GLint depth,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLint internal_gl_format,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type,
|
|
|
|
CoglError **error)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
2012-02-25 15:18:05 -05:00
|
|
|
int rowstride = cogl_bitmap_get_rowstride (source_bmp);
|
|
|
|
int bmp_width = cogl_bitmap_get_width (source_bmp);
|
|
|
|
int bmp_height = cogl_bitmap_get_height (source_bmp);
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *data;
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum gl_error;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
|
|
|
|
|
|
|
/* If the rowstride or image height can't be specified with just
|
|
|
|
GL_ALIGNMENT alone then we need to copy the bitmap because there
|
|
|
|
is no GL_ROW_LENGTH */
|
2010-07-07 13:44:16 -04:00
|
|
|
if (rowstride / bpp != bmp_width ||
|
|
|
|
height != bmp_height / depth)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *bmp;
|
|
|
|
int image_height = bmp_height / depth;
|
2012-03-13 10:46:18 -04:00
|
|
|
CoglPixelFormat source_bmp_format = cogl_bitmap_get_format (source_bmp);
|
2010-07-01 17:04:59 -04:00
|
|
|
int i;
|
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, bmp_width * bpp, bpp);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
/* Initialize the texture with empty data and then upload each
|
|
|
|
image with a sub-region update */
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
|
|
|
ctx->glTexImage3D (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
internal_gl_format,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
return FALSE;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
source_bmp_format);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
{
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_bitmap_copy_subregion (source_bmp,
|
|
|
|
bmp,
|
|
|
|
0, image_height * i,
|
|
|
|
0, 0,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2012-09-19 16:59:19 -04:00
|
|
|
data = _cogl_bitmap_gl_bind (bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
COGL_BUFFER_ACCESS_READ, 0, error);
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
|
|
|
ctx->glTexSubImage3D (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
0, /* xoffset */
|
|
|
|
0, /* yoffset */
|
|
|
|
i, /* zoffset */
|
|
|
|
bmp_width, /* width */
|
|
|
|
height, /* height */
|
|
|
|
1, /* depth */
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data);
|
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
_cogl_bitmap_gl_unbind (bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-15 08:05:55 -04:00
|
|
|
|
2012-09-19 16:59:19 -04:00
|
|
|
_cogl_bitmap_gl_unbind (bmp);
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
2010-07-15 08:05:55 -04:00
|
|
|
else
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
2012-11-08 12:54:10 -05:00
|
|
|
data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, error);
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
2010-07-15 08:05:55 -04:00
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
|
|
|
ctx->glTexImage3D (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
internal_gl_format,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data);
|
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
{
|
|
|
|
_cogl_bitmap_gl_unbind (source_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2012-09-19 16:59:19 -04:00
|
|
|
_cogl_bitmap_gl_unbind (source_bmp);
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* 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() ) */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
|
|
|
GLenum dest_gl_format,
|
|
|
|
GLenum dest_gl_type,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *dest)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
return FALSE;
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_size_supported_3d (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2010-07-01 17:04:59 -04:00
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
2012-03-22 13:04:47 -04:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
GLint max_size;
|
|
|
|
|
|
|
|
/* GLES doesn't support a proxy texture target so let's at least
|
|
|
|
check whether the size is greater than
|
|
|
|
GL_MAX_3D_TEXTURE_SIZE_OES */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE_OES, &max_size) );
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
return width <= max_size && height <= max_size && depth <= max_size;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2012-05-23 09:47:57 -04:00
|
|
|
GLenum gl_intformat,
|
2009-07-27 19:37:11 -04:00
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
2012-03-22 13:04:47 -04:00
|
|
|
int width,
|
|
|
|
int height)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2010-07-08 13:37:01 -04:00
|
|
|
GLint max_size;
|
|
|
|
|
|
|
|
/* GLES doesn't support a proxy texture target so let's at least
|
|
|
|
check whether the size is greater than GL_MAX_TEXTURE_SIZE */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size) );
|
2010-07-08 13:37:01 -04:00
|
|
|
|
|
|
|
return width <= max_size && height <= max_size;
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_try_setting_gl_border_color
|
|
|
|
(CoglContext *ctx,
|
|
|
|
GLuint gl_target,
|
|
|
|
const GLfloat *transparent_color)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
/* FAIL! */
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
|
|
|
GLenum gl_target)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
/* Allow 2-dimensional textures only */
|
|
|
|
if (gl_target != GL_TEXTURE_2D)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
|
|
|
GLenum gl_target)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2011-07-07 15:44:56 -04:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
|
|
|
GE( ctx, glGenerateMipmap (gl_target) );
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static CoglPixelFormat
|
2012-03-22 12:32:56 -04:00
|
|
|
_cogl_texture_driver_find_best_gl_get_data_format
|
|
|
|
(CoglContext *context,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
GLenum *closest_gl_format,
|
|
|
|
GLenum *closest_gl_type)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
/* Find closest format that's supported by GL
|
|
|
|
(Can't use _cogl_pixel_format_to_gl since available formats
|
|
|
|
when reading pixels on GLES are severely limited) */
|
|
|
|
*closest_gl_format = GL_RGBA;
|
|
|
|
*closest_gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
return COGL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
const CoglTextureDriver
|
|
|
|
_cogl_texture_driver_gles =
|
|
|
|
{
|
|
|
|
_cogl_texture_driver_gen,
|
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload,
|
|
|
|
_cogl_texture_driver_upload_subregion_to_gl,
|
|
|
|
_cogl_texture_driver_upload_to_gl,
|
|
|
|
_cogl_texture_driver_upload_to_gl_3d,
|
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download,
|
|
|
|
_cogl_texture_driver_gl_get_tex_image,
|
|
|
|
_cogl_texture_driver_size_supported,
|
|
|
|
_cogl_texture_driver_size_supported_3d,
|
|
|
|
_cogl_texture_driver_try_setting_gl_border_color,
|
|
|
|
_cogl_texture_driver_allows_foreign_gl_target,
|
|
|
|
_cogl_texture_driver_gl_generate_mipmaps,
|
|
|
|
_cogl_texture_driver_find_best_gl_get_data_format
|
|
|
|
};
|