2009-07-27 23:37:11 +00: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 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-07-27 23:37:11 +00: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 23:02:04 +00:00
|
|
|
#include "cogl-private.h"
|
2009-07-27 23:37:11 +00:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-bitmap.h"
|
|
|
|
#include "cogl-bitmap-private.h"
|
|
|
|
#include "cogl-texture-private.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 13:14:10 +00:00
|
|
|
#include "cogl-object-private.h"
|
2009-07-27 23:37:11 +00:00
|
|
|
#include "cogl-primitives.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2010-07-01 21:04:59 +00: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 17:51:51 +00: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
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_gen (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
|
|
|
GLsizei n,
|
|
|
|
GLuint *textures)
|
2010-01-25 11:21:05 +00:00
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
unsigned int i;
|
2010-01-25 11:21:05 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE (ctx, glGenTextures (n, textures));
|
2010-01-25 11:21:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
2010-04-26 09:01:43 +00:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, textures[i], FALSE);
|
2010-01-25 11:21:05 +00:00
|
|
|
|
|
|
|
switch (gl_target)
|
|
|
|
{
|
2010-07-01 21:04:59 +00:00
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
case GL_TEXTURE_3D:
|
|
|
|
/* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glTexParameteri (gl_target,
|
|
|
|
GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR) );
|
2010-07-01 21:04:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2010-01-25 11:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-21 17:51:51 +00: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 17:04:47 +00:00
|
|
|
int pixels_rowstride,
|
2009-07-27 23:37:11 +00:00
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2012-03-21 17:51:51 +00:00
|
|
|
prep_gl_for_pixels_upload_full (ctx,
|
|
|
|
pixels_rowstride,
|
|
|
|
0, 0, /* src_x/y */
|
|
|
|
pixels_bpp);
|
2009-07-27 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
|
|
|
int pixels_rowstride,
|
2012-03-22 11:40:16 +00:00
|
|
|
int image_width,
|
2009-07-27 23:37:11 +00:00
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2012-03-22 11:40:16 +00:00
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_download (pixels_bpp,
|
|
|
|
image_width,
|
|
|
|
pixels_rowstride);
|
2009-07-27 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 16:09:26 +00:00
|
|
|
static CoglBitmap *
|
2012-03-22 17:04:47 +00:00
|
|
|
prepare_bitmap_alignment_for_upload (CoglContext *ctx,
|
|
|
|
CoglBitmap *src_bmp)
|
2010-12-17 16:09:26 +00:00
|
|
|
{
|
2012-02-25 20:18:05 +00:00
|
|
|
CoglPixelFormat format = cogl_bitmap_get_format (src_bmp);
|
2012-02-13 23:02:04 +00:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2012-02-25 20:18:05 +00:00
|
|
|
int src_rowstride = cogl_bitmap_get_rowstride (src_bmp);
|
|
|
|
int width = cogl_bitmap_get_width (src_bmp);
|
2010-12-17 16:09:26 +00:00
|
|
|
int alignment = 1;
|
|
|
|
|
2012-03-21 17:51:51 +00:00
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) ||
|
|
|
|
src_rowstride == 0)
|
2010-12-17 16:09:26 +00: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
|
|
|
|
return _cogl_bitmap_copy (src_bmp);
|
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2009-11-26 17:32:52 +00:00
|
|
|
GLuint gl_handle,
|
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 20:56:40 +00:00
|
|
|
CoglBool is_foreign,
|
2009-07-27 23:37:11 +00:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLuint source_gl_format,
|
2009-11-26 17:32:52 +00:00
|
|
|
GLuint source_gl_type)
|
2009-07-27 23:37:11 +00: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 20:56:40 +00:00
|
|
|
uint8_t *data;
|
2012-02-25 20:18:05 +00:00
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 23:02:04 +00:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *slice_bmp;
|
|
|
|
int rowstride;
|
2009-07-27 23:37:11 +00:00
|
|
|
|
2012-03-21 17:51:51 +00: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 16:09:26 +00:00
|
|
|
{
|
|
|
|
slice_bmp =
|
2012-03-13 14:46:18 +00:00
|
|
|
_cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
width, height,
|
|
|
|
source_format);
|
2010-12-17 16:09:26 +00:00
|
|
|
_cogl_bitmap_copy_subregion (source_bmp,
|
|
|
|
slice_bmp,
|
|
|
|
src_x, src_y,
|
|
|
|
0, 0, /* dst_x/y */
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
else
|
2012-03-22 17:04:47 +00:00
|
|
|
slice_bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp);
|
2012-03-13 14:46:18 +00:00
|
|
|
|
|
|
|
rowstride = cogl_bitmap_get_rowstride (slice_bmp);
|
2009-07-27 23:37:11 +00:00
|
|
|
|
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-21 17:51:51 +00:00
|
|
|
prep_gl_for_pixels_upload_full (ctx, rowstride, src_x, src_y, bpp);
|
2009-07-27 23:37:11 +00:00
|
|
|
|
2010-07-15 12:05:55 +00:00
|
|
|
data = _cogl_bitmap_bind (slice_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2009-07-27 23:37:11 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glTexSubImage2D (gl_target, 0,
|
|
|
|
dst_x, dst_y,
|
|
|
|
width, height,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data) );
|
2009-07-27 23:37:11 +00:00
|
|
|
|
2010-07-15 12:05:55 +00:00
|
|
|
_cogl_bitmap_unbind (slice_bmp);
|
2010-07-07 17:44:16 +00:00
|
|
|
|
|
|
|
cogl_object_unref (slice_bmp);
|
2009-07-27 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2009-11-30 12:15:05 +00:00
|
|
|
GLuint gl_handle,
|
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 20:56:40 +00:00
|
|
|
CoglBool is_foreign,
|
2009-11-30 12:15:05 +00:00
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLint internal_gl_format,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type)
|
|
|
|
{
|
2012-02-25 20:18:05 +00:00
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 23:02:04 +00:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
2010-12-17 16:09:26 +00:00
|
|
|
int rowstride;
|
2012-02-25 20:18:05 +00:00
|
|
|
int bmp_width = cogl_bitmap_get_width (source_bmp);
|
|
|
|
int bmp_height = cogl_bitmap_get_height (source_bmp);
|
2010-07-07 17:44:16 +00: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 20:56:40 +00:00
|
|
|
uint8_t *data;
|
2009-11-30 12:15:05 +00:00
|
|
|
|
2012-03-22 17:04:47 +00:00
|
|
|
bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp);
|
2012-02-25 20:18:05 +00:00
|
|
|
rowstride = cogl_bitmap_get_rowstride (bmp);
|
2009-11-30 12:15:05 +00:00
|
|
|
|
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
2009-11-30 12:15:05 +00:00
|
|
|
|
2010-04-26 09:01:43 +00:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2009-11-30 12:15:05 +00:00
|
|
|
|
2010-07-15 12:05:55 +00:00
|
|
|
data = _cogl_bitmap_bind (bmp, COGL_BUFFER_ACCESS_READ, 0);
|
2010-07-07 17:44:16 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glTexImage2D (gl_target, 0,
|
|
|
|
internal_gl_format,
|
|
|
|
bmp_width, bmp_height,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data) );
|
2010-07-15 12:05:55 +00:00
|
|
|
|
|
|
|
_cogl_bitmap_unbind (bmp);
|
2009-11-30 12:15:05 +00:00
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
cogl_object_unref (bmp);
|
2009-11-30 12:15:05 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2010-07-01 21:04:59 +00:00
|
|
|
GLuint gl_handle,
|
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 20:56:40 +00:00
|
|
|
CoglBool is_foreign,
|
2010-07-01 21:04:59 +00:00
|
|
|
GLint height,
|
|
|
|
GLint depth,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLint internal_gl_format,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type)
|
|
|
|
{
|
2012-02-25 20:18:05 +00:00
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 23:02:04 +00:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
2012-02-25 20:18:05 +00: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 20:56:40 +00:00
|
|
|
uint8_t *data;
|
2010-07-01 21:04:59 +00: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 17:44:16 +00:00
|
|
|
if (rowstride / bpp != bmp_width ||
|
|
|
|
height != bmp_height / depth)
|
2010-07-01 21:04:59 +00:00
|
|
|
{
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *bmp;
|
|
|
|
int image_height = bmp_height / depth;
|
2012-03-13 14:46:18 +00:00
|
|
|
CoglPixelFormat source_bmp_format = cogl_bitmap_get_format (source_bmp);
|
2010-07-01 21:04:59 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, bmp_width * bpp, bpp);
|
2010-07-01 21:04:59 +00:00
|
|
|
|
|
|
|
/* Initialize the texture with empty data and then upload each
|
|
|
|
image with a sub-region update */
|
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glTexImage3D (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
internal_gl_format,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
NULL) );
|
2010-07-01 21:04:59 +00:00
|
|
|
|
2012-03-13 14:46:18 +00:00
|
|
|
bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
source_bmp_format);
|
2010-07-07 17:44:16 +00:00
|
|
|
|
2010-07-01 21:04:59 +00:00
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
{
|
|
|
|
_cogl_bitmap_copy_subregion (source_bmp,
|
2010-07-07 17:44:16 +00:00
|
|
|
bmp,
|
2010-07-01 21:04:59 +00:00
|
|
|
0, image_height * i,
|
|
|
|
0, 0,
|
2010-07-07 17:44:16 +00:00
|
|
|
bmp_width,
|
2010-11-23 14:07:16 +00:00
|
|
|
height);
|
2010-07-07 17:44:16 +00:00
|
|
|
|
2010-07-15 12:05:55 +00:00
|
|
|
data = _cogl_bitmap_bind (bmp,
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( 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) );
|
2010-07-15 12:05:55 +00:00
|
|
|
|
|
|
|
_cogl_bitmap_unbind (bmp);
|
2010-07-01 21:04:59 +00:00
|
|
|
}
|
2010-07-07 17:44:16 +00:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
2010-07-01 21:04:59 +00:00
|
|
|
}
|
2010-07-15 12:05:55 +00:00
|
|
|
else
|
2010-07-01 21:04:59 +00:00
|
|
|
{
|
2010-07-15 12:05:55 +00:00
|
|
|
data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
|
2010-07-01 21:04:59 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glTexImage3D (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
internal_gl_format,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data) );
|
2010-07-07 17:44:16 +00:00
|
|
|
|
2010-07-15 12:05:55 +00:00
|
|
|
_cogl_bitmap_unbind (source_bmp);
|
2010-07-01 21:04:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-30 10:36:11 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00: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 20:56:40 +00:00
|
|
|
uint8_t *dest)
|
2009-07-27 23:37:11 +00:00
|
|
|
{
|
2009-08-30 10:36:11 +00:00
|
|
|
return FALSE;
|
2009-07-27 23:37:11 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_size_supported_3d (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2010-07-01 21:04:59 +00:00
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
2012-03-22 17:04:47 +00:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth)
|
2010-07-01 21:04:59 +00: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 20:51:00 +00:00
|
|
|
GE( ctx, glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE_OES, &max_size) );
|
2010-07-01 21:04:59 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2012-05-23 13:47:57 +00:00
|
|
|
GLenum gl_intformat,
|
2009-07-27 23:37:11 +00:00
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
2012-03-22 17:04:47 +00:00
|
|
|
int width,
|
|
|
|
int height)
|
2009-07-27 23:37:11 +00:00
|
|
|
{
|
2010-07-08 17:37:01 +00: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 20:51:00 +00:00
|
|
|
GE( ctx, glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size) );
|
2010-07-08 17:37:01 +00:00
|
|
|
|
|
|
|
return width <= max_size && height <= max_size;
|
2009-07-27 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_try_setting_gl_border_color
|
|
|
|
(CoglContext *ctx,
|
|
|
|
GLuint gl_target,
|
|
|
|
const GLfloat *transparent_color)
|
2009-07-27 23:37:11 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
|
|
|
GLenum gl_target)
|
2009-07-27 23:37:11 +00:00
|
|
|
{
|
|
|
|
/* Allow 2-dimensional textures only */
|
|
|
|
if (gl_target != GL_TEXTURE_2D)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static void
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
|
|
|
GLenum gl_target)
|
2009-07-27 23:37:11 +00:00
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
if (ctx->driver == COGL_DRIVER_GLES2)
|
|
|
|
GE( ctx, glGenerateMipmap (gl_target) );
|
2009-07-27 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
static CoglPixelFormat
|
2012-03-22 16:32:56 +00: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 23:37:11 +00: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 11:48:24 +00: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
|
|
|
|
};
|