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"
|
2009-07-27 19:37:11 -04:00
|
|
|
#include "cogl-handle.h"
|
|
|
|
#include "cogl-primitives.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2010-01-25 06:21:05 -05:00
|
|
|
_cogl_texture_driver_gen (GLenum gl_target,
|
|
|
|
GLsizei n,
|
|
|
|
GLuint *textures)
|
|
|
|
{
|
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-09 20:57:32 -05:00
|
|
|
unsigned int i;
|
2010-01-25 06:21:05 -05:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
GE (ctx, glGenTextures (n, textures));
|
2010-01-25 06:21:05 -05:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, textures[i], FALSE);
|
2010-01-25 06:21:05 -05:00
|
|
|
|
|
|
|
switch (gl_target)
|
|
|
|
{
|
2010-07-01 17:04:59 -04: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 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (gl_target,
|
|
|
|
GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR) );
|
2010-07-01 17:04:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2010-01-25 06:21:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (int pixels_rowstride,
|
|
|
|
int pixels_bpp)
|
|
|
|
{
|
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (int pixels_rowstride,
|
|
|
|
int pixels_bpp)
|
|
|
|
{
|
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_download (pixels_rowstride);
|
|
|
|
}
|
|
|
|
|
2010-12-17 11:09:26 -05:00
|
|
|
static CoglBitmap *
|
|
|
|
prepare_bitmap_alignment_for_upload (CoglBitmap *src_bmp)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
if (src_rowstride == 0)
|
|
|
|
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 07:48:24 -04:00
|
|
|
static void
|
2009-11-26 12:32:52 -05:00
|
|
|
_cogl_texture_driver_upload_subregion_to_gl (GLenum gl_target,
|
|
|
|
GLuint gl_handle,
|
2010-04-26 05:01:43 -04:00
|
|
|
gboolean is_foreign,
|
2009-07-27 19:37:11 -04: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 12:32:52 -05:00
|
|
|
GLuint source_gl_type)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
guint8 *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;
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-12-17 11:09:26 -05:00
|
|
|
/* If we are copying a sub region of the source bitmap then we need
|
|
|
|
to copy it because GLES does not support GL_UNPACK_ROW_LENGTH */
|
|
|
|
if (src_x != 0 || src_y != 0 ||
|
2012-02-25 15:18:05 -05:00
|
|
|
width != cogl_bitmap_get_width (source_bmp) ||
|
|
|
|
height != cogl_bitmap_get_height (source_bmp))
|
2010-12-17 11:09:26 -05:00
|
|
|
{
|
|
|
|
rowstride = bpp * width;
|
|
|
|
rowstride = (rowstride + 3) & ~3;
|
|
|
|
slice_bmp =
|
|
|
|
_cogl_bitmap_new_from_data (g_malloc (height * rowstride),
|
|
|
|
source_format,
|
|
|
|
width, height,
|
|
|
|
rowstride,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
|
|
|
_cogl_bitmap_copy_subregion (source_bmp,
|
|
|
|
slice_bmp,
|
|
|
|
src_x, src_y,
|
|
|
|
0, 0, /* dst_x/y */
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slice_bmp = prepare_bitmap_alignment_for_upload (source_bmp);
|
2012-02-25 15:18:05 -05:00
|
|
|
rowstride = cogl_bitmap_get_rowstride (slice_bmp);
|
2010-12-17 11:09:26 -05:00
|
|
|
}
|
2009-07-27 19:37:11 -04:00
|
|
|
|
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (rowstride, bpp);
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2010-07-15 08:05:55 -04: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 19:37:11 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexSubImage2D (gl_target, 0,
|
|
|
|
dst_x, dst_y,
|
|
|
|
width, height,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
_cogl_bitmap_unbind (slice_bmp);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
cogl_object_unref (slice_bmp);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2009-11-30 07:15:05 -05:00
|
|
|
_cogl_texture_driver_upload_to_gl (GLenum gl_target,
|
|
|
|
GLuint gl_handle,
|
2010-04-26 05:01:43 -04:00
|
|
|
gboolean is_foreign,
|
2009-11-30 07:15:05 -05:00
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLint internal_gl_format,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type)
|
|
|
|
{
|
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;
|
|
|
|
guint8 *data;
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-12-17 11:09:26 -05:00
|
|
|
bmp = prepare_bitmap_alignment_for_upload (source_bmp);
|
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 */
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (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
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
data = _cogl_bitmap_bind (bmp, COGL_BUFFER_ACCESS_READ, 0);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2011-07-06 16:51:00 -04: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 08:05:55 -04:00
|
|
|
|
|
|
|
_cogl_bitmap_unbind (bmp);
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (bmp);
|
2009-11-30 07:15:05 -05:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_driver_upload_to_gl_3d (GLenum gl_target,
|
|
|
|
GLuint gl_handle,
|
|
|
|
gboolean is_foreign,
|
|
|
|
GLint height,
|
|
|
|
GLint depth,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLint internal_gl_format,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type)
|
|
|
|
{
|
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);
|
2010-07-07 13:44:16 -04:00
|
|
|
guint8 *data;
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
_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;
|
2010-07-01 17:04:59 -04:00
|
|
|
int i;
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (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 */
|
|
|
|
|
2011-07-06 16:51:00 -04: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 17:04:59 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp = _cogl_bitmap_new_from_data (g_malloc (bpp * bmp_width * height),
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_format (source_bmp),
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp_width,
|
|
|
|
height,
|
|
|
|
bpp * bmp_width,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
{
|
|
|
|
_cogl_bitmap_copy_subregion (source_bmp,
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp,
|
2010-07-01 17:04:59 -04:00
|
|
|
0, image_height * i,
|
|
|
|
0, 0,
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp_width,
|
2010-11-23 09:07:16 -05:00
|
|
|
height);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
data = _cogl_bitmap_bind (bmp,
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
|
2011-07-06 16:51:00 -04: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 08:05:55 -04:00
|
|
|
|
|
|
|
_cogl_bitmap_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
|
|
|
{
|
2010-07-15 08:05:55 -04:00
|
|
|
data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (rowstride, bpp);
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2011-07-06 16:51:00 -04: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 13:44:16 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
_cogl_bitmap_unbind (source_bmp);
|
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() ) */
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2009-08-30 06:36:11 -04:00
|
|
|
_cogl_texture_driver_gl_get_tex_image (GLenum gl_target,
|
|
|
|
GLenum dest_gl_format,
|
|
|
|
GLenum dest_gl_type,
|
|
|
|
guint8 *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
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2010-07-01 17:04:59 -04:00
|
|
|
_cogl_texture_driver_size_supported_3d (GLenum gl_target,
|
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth)
|
|
|
|
{
|
|
|
|
GLint max_size;
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_size_supported (GLenum gl_target,
|
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
2010-07-08 13:37:01 -04:00
|
|
|
GLint max_size;
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2010-07-08 13:37:01 -04:00
|
|
|
/* 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
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_try_setting_gl_border_color (
|
|
|
|
GLuint gl_target,
|
|
|
|
const GLfloat *transparent_color)
|
|
|
|
{
|
|
|
|
/* FAIL! */
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
|
|
|
_cogl_texture_driver_pixel_format_from_gl_internal (GLenum gl_int_format,
|
|
|
|
CoglPixelFormat *out_format)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_driver_pixel_format_to_gl (CoglPixelFormat format,
|
|
|
|
GLenum *out_glintformat,
|
|
|
|
GLenum *out_glformat,
|
|
|
|
GLenum *out_gltype)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
CoglPixelFormat required_format;
|
2012-02-13 12:43:32 -05:00
|
|
|
GLenum glintformat;
|
2012-02-29 08:42:44 -05:00
|
|
|
GLenum glformat = 0;
|
2012-02-13 12:43:32 -05:00
|
|
|
GLenum gltype;
|
2009-07-27 19:37:11 -04:00
|
|
|
|
|
|
|
required_format = format;
|
|
|
|
|
|
|
|
/* Find GL equivalents */
|
2012-02-13 12:43:32 -05:00
|
|
|
switch (format)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
case COGL_PIXEL_FORMAT_A_8:
|
|
|
|
glintformat = GL_ALPHA;
|
|
|
|
glformat = GL_ALPHA;
|
|
|
|
gltype = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case COGL_PIXEL_FORMAT_G_8:
|
|
|
|
glintformat = GL_LUMINANCE;
|
|
|
|
glformat = GL_LUMINANCE;
|
|
|
|
gltype = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Just one 24-bit ordering supported */
|
|
|
|
case COGL_PIXEL_FORMAT_RGB_888:
|
|
|
|
case COGL_PIXEL_FORMAT_BGR_888:
|
|
|
|
glintformat = GL_RGB;
|
|
|
|
glformat = GL_RGB;
|
|
|
|
gltype = GL_UNSIGNED_BYTE;
|
|
|
|
required_format = COGL_PIXEL_FORMAT_RGB_888;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Just one 32-bit ordering supported */
|
|
|
|
case COGL_PIXEL_FORMAT_RGBA_8888:
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_RGBA_8888_PRE:
|
2009-07-27 19:37:11 -04:00
|
|
|
case COGL_PIXEL_FORMAT_BGRA_8888:
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
|
2009-07-27 19:37:11 -04:00
|
|
|
case COGL_PIXEL_FORMAT_ARGB_8888:
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_ARGB_8888_PRE:
|
2009-07-27 19:37:11 -04:00
|
|
|
case COGL_PIXEL_FORMAT_ABGR_8888:
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_ABGR_8888_PRE:
|
|
|
|
case COGL_PIXEL_FORMAT_RGBA_1010102:
|
|
|
|
case COGL_PIXEL_FORMAT_RGBA_1010102_PRE:
|
|
|
|
case COGL_PIXEL_FORMAT_BGRA_1010102:
|
|
|
|
case COGL_PIXEL_FORMAT_BGRA_1010102_PRE:
|
|
|
|
case COGL_PIXEL_FORMAT_ABGR_2101010:
|
|
|
|
case COGL_PIXEL_FORMAT_ABGR_2101010_PRE:
|
|
|
|
case COGL_PIXEL_FORMAT_ARGB_2101010:
|
|
|
|
case COGL_PIXEL_FORMAT_ARGB_2101010_PRE:
|
2009-07-27 19:37:11 -04:00
|
|
|
glintformat = GL_RGBA;
|
|
|
|
glformat = GL_RGBA;
|
|
|
|
gltype = GL_UNSIGNED_BYTE;
|
|
|
|
required_format = COGL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
required_format |= (format & COGL_PREMULT_BIT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* The following three types of channel ordering
|
|
|
|
* are always defined using system word byte
|
|
|
|
* ordering (even according to GLES spec) */
|
|
|
|
case COGL_PIXEL_FORMAT_RGB_565:
|
|
|
|
glintformat = GL_RGB;
|
|
|
|
glformat = GL_RGB;
|
|
|
|
gltype = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
break;
|
|
|
|
case COGL_PIXEL_FORMAT_RGBA_4444:
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_RGBA_4444_PRE:
|
2009-07-27 19:37:11 -04:00
|
|
|
glintformat = GL_RGBA;
|
|
|
|
glformat = GL_RGBA;
|
|
|
|
gltype = GL_UNSIGNED_SHORT_4_4_4_4;
|
|
|
|
break;
|
|
|
|
case COGL_PIXEL_FORMAT_RGBA_5551:
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_RGBA_5551_PRE:
|
2009-07-27 19:37:11 -04:00
|
|
|
glintformat = GL_RGBA;
|
|
|
|
glformat = GL_RGBA;
|
|
|
|
gltype = GL_UNSIGNED_SHORT_5_5_5_1;
|
|
|
|
break;
|
|
|
|
|
2012-02-13 12:43:32 -05:00
|
|
|
case COGL_PIXEL_FORMAT_ANY:
|
|
|
|
case COGL_PIXEL_FORMAT_YUV:
|
|
|
|
g_assert_not_reached ();
|
2009-07-27 19:37:11 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-29 08:42:44 -05:00
|
|
|
/* All of the pixel formats are handled above so if this hits then
|
|
|
|
we've been given an invalid pixel format */
|
|
|
|
g_assert (glformat != 0);
|
|
|
|
|
2009-07-27 19:37:11 -04:00
|
|
|
if (out_glintformat != NULL)
|
|
|
|
*out_glintformat = glintformat;
|
|
|
|
if (out_glformat != NULL)
|
|
|
|
*out_glformat = glformat;
|
|
|
|
if (out_gltype != NULL)
|
|
|
|
*out_gltype = gltype;
|
|
|
|
|
|
|
|
return required_format;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)
|
|
|
|
{
|
|
|
|
/* 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
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
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
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_driver_find_best_gl_get_data_format (
|
|
|
|
CoglPixelFormat format,
|
|
|
|
GLenum *closest_gl_format,
|
|
|
|
GLenum *closest_gl_type)
|
|
|
|
{
|
|
|
|
/* 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_pixel_format_from_gl_internal,
|
|
|
|
_cogl_texture_driver_pixel_format_to_gl,
|
|
|
|
_cogl_texture_driver_allows_foreign_gl_target,
|
|
|
|
_cogl_texture_driver_gl_generate_mipmaps,
|
|
|
|
_cogl_texture_driver_find_best_gl_get_data_format
|
|
|
|
};
|