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"
|
2012-11-08 17:54:10 +00:00
|
|
|
#include "cogl-util-gl-private.h"
|
|
|
|
#include "cogl-error-private.h"
|
2012-11-08 23:00:49 +00:00
|
|
|
#include "cogl-texture-gl-private.h"
|
2009-07-27 23:37:11 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2012-11-19 17:28:52 +00:00
|
|
|
static GLuint
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_gen (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2012-11-19 17:28:52 +00:00
|
|
|
CoglPixelFormat internal_format)
|
2010-01-25 11:21:05 +00:00
|
|
|
{
|
2012-11-19 17:28:52 +00:00
|
|
|
GLuint tex;
|
2010-01-25 11:21:05 +00:00
|
|
|
|
2012-11-19 17:28:52 +00:00
|
|
|
GE (ctx, glGenTextures (1, &tex));
|
2010-01-25 11:21:05 +00:00
|
|
|
|
2012-11-19 17:28:52 +00:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, tex, FALSE);
|
2010-01-25 11:21:05 +00:00
|
|
|
|
2012-11-19 17:28:52 +00: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 21:04:59 +00:00
|
|
|
|
2012-11-19 17:28:52 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2010-01-25 11:21:05 +00:00
|
|
|
}
|
2012-11-19 17:28:52 +00:00
|
|
|
|
|
|
|
return tex;
|
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);
|
|
|
|
}
|
|
|
|
|
2012-11-08 23:00:49 +00:00
|
|
|
_cogl_texture_gl_prep_alignment_for_pixels_upload (ctx, pixels_rowstride);
|
2012-03-21 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11-08 23:00:49 +00:00
|
|
|
_cogl_texture_gl_prep_alignment_for_pixels_download (ctx,
|
|
|
|
pixels_bpp,
|
2012-03-22 11:40:16 +00:00
|
|
|
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,
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBitmap *src_bmp,
|
|
|
|
CoglError **error)
|
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
|
2012-11-08 17:54:10 +00:00
|
|
|
return _cogl_bitmap_copy (src_bmp, error);
|
2010-12-17 16:09:26 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
2012-11-09 17:55:54 +00:00
|
|
|
CoglTexture *texture,
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBool is_foreign,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height,
|
2012-11-09 17:55:54 +00:00
|
|
|
int level,
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
GLuint source_gl_format,
|
|
|
|
GLuint source_gl_type,
|
|
|
|
CoglError **error)
|
2009-07-27 23:37:11 +00:00
|
|
|
{
|
2012-11-09 17:55:54 +00:00
|
|
|
GLenum gl_target;
|
|
|
|
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
|
|
|
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;
|
2012-11-08 17:54:10 +00:00
|
|
|
GLenum gl_error;
|
|
|
|
CoglBool status = TRUE;
|
|
|
|
CoglError *internal_error = NULL;
|
2012-11-09 17:55:54 +00:00
|
|
|
int level_width;
|
|
|
|
int level_height;
|
|
|
|
|
|
|
|
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
|
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,
|
2012-11-08 22:14:18 +00:00
|
|
|
source_format,
|
|
|
|
error);
|
|
|
|
if (!slice_bmp)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-11-08 17:54:10 +00: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 13:10:57 +00:00
|
|
|
|
|
|
|
src_x = src_y = 0;
|
2010-12-17 16:09:26 +00:00
|
|
|
}
|
|
|
|
else
|
2012-11-08 17:54:10 +00:00
|
|
|
{
|
|
|
|
slice_bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp, error);
|
|
|
|
if (!slice_bmp)
|
|
|
|
return FALSE;
|
|
|
|
}
|
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
|
|
|
|
2012-11-08 17:54:10 +00: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)
|
|
|
|
{
|
2012-11-19 20:14:55 +00:00
|
|
|
_cogl_propagate_error (error, internal_error);
|
2012-11-08 17:54:10 +00:00
|
|
|
cogl_object_unref (slice_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-15 12:05:55 +00:00
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2009-07-27 23:37:11 +00:00
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
2012-11-09 17:55:54 +00:00
|
|
|
_cogl_texture_get_level_size (texture,
|
|
|
|
level,
|
|
|
|
&level_width,
|
|
|
|
&level_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (level_width == width && level_height == height)
|
|
|
|
{
|
|
|
|
/* GL gets upset if you use glTexSubImage2D to define the
|
|
|
|
* contents of a mipmap level so we make sure to use
|
|
|
|
* glTexImage2D if we are uploading a full mipmap level.
|
|
|
|
*/
|
|
|
|
ctx->glTexImage2D (gl_target,
|
|
|
|
level,
|
2012-11-22 21:31:25 +00:00
|
|
|
_cogl_texture_gl_get_format (texture),
|
2012-11-09 17:55:54 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* GL gets upset if you use glTexSubImage2D to initialize the
|
|
|
|
* contents of a mipmap level so if this is the first time
|
|
|
|
* we've seen a request to upload to this level we call
|
|
|
|
* glTexImage2D first to assert that the storage for this
|
|
|
|
* level exists.
|
|
|
|
*/
|
|
|
|
if (texture->max_level < level)
|
|
|
|
{
|
|
|
|
ctx->glTexImage2D (gl_target,
|
|
|
|
level,
|
2012-11-22 21:31:25 +00:00
|
|
|
_cogl_texture_gl_get_format (texture),
|
2012-11-09 17:55:54 +00:00
|
|
|
level_width,
|
|
|
|
level_height,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->glTexSubImage2D (gl_target,
|
|
|
|
level,
|
|
|
|
dst_x, dst_y,
|
|
|
|
width, height,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data);
|
|
|
|
}
|
2012-11-08 17:54:10 +00:00
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
status = FALSE;
|
2009-07-27 23:37:11 +00:00
|
|
|
|
2012-09-19 20:59:19 +00:00
|
|
|
_cogl_bitmap_gl_unbind (slice_bmp);
|
2010-07-07 17:44:16 +00:00
|
|
|
|
|
|
|
cogl_object_unref (slice_bmp);
|
2012-11-08 17:54:10 +00:00
|
|
|
|
|
|
|
return status;
|
2009-07-27 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
2012-11-08 17:54:10 +00: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 12:15:05 +00:00
|
|
|
{
|
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;
|
2012-11-08 17:54:10 +00:00
|
|
|
GLenum gl_error;
|
2012-11-27 20:07:47 +00:00
|
|
|
CoglError *internal_error = NULL;
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBool status = TRUE;
|
|
|
|
|
|
|
|
bmp = prepare_bitmap_alignment_for_upload (ctx, source_bmp, error);
|
|
|
|
if (!bmp)
|
|
|
|
return FALSE;
|
2009-11-30 12:15:05 +00:00
|
|
|
|
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
|
|
|
|
2012-11-27 20:07:47 +00:00
|
|
|
data = _cogl_bitmap_gl_bind (bmp,
|
|
|
|
COGL_BUFFER_ACCESS_READ,
|
|
|
|
0, /* hints */
|
|
|
|
&internal_error);
|
|
|
|
|
|
|
|
/* NB: _cogl_bitmap_gl_bind() may return NULL when successful so we
|
|
|
|
* have to explicitly check the cogl error pointer to catch
|
|
|
|
* problems... */
|
|
|
|
if (internal_error)
|
2012-11-08 17:54:10 +00:00
|
|
|
{
|
|
|
|
cogl_object_unref (bmp);
|
2012-11-27 20:07:47 +00:00
|
|
|
_cogl_propagate_error (error, internal_error);
|
2012-11-08 17:54:10 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-07 17:44:16 +00:00
|
|
|
|
2012-11-08 17:54:10 +00: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 12:05:55 +00:00
|
|
|
|
2012-09-19 20:59:19 +00:00
|
|
|
_cogl_bitmap_gl_unbind (bmp);
|
2009-11-30 12:15:05 +00:00
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
cogl_object_unref (bmp);
|
2012-11-08 17:54:10 +00:00
|
|
|
|
|
|
|
return status;
|
2009-11-30 12:15:05 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
static CoglBool
|
2012-03-22 17:04:47 +00:00
|
|
|
_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
|
2012-11-08 17:54:10 +00: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 21:04:59 +00:00
|
|
|
{
|
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;
|
2012-11-08 17:54:10 +00:00
|
|
|
GLenum gl_error;
|
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 */
|
|
|
|
|
2012-11-08 17:54:10 +00: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 21:04:59 +00:00
|
|
|
|
2012-03-13 14:46:18 +00:00
|
|
|
bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
bmp_width,
|
|
|
|
height,
|
2012-11-08 22:14:18 +00:00
|
|
|
source_bmp_format,
|
|
|
|
error);
|
|
|
|
if (!bmp)
|
|
|
|
return FALSE;
|
2010-07-07 17:44:16 +00:00
|
|
|
|
2010-07-01 21:04:59 +00:00
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
{
|
2012-11-08 17:54:10 +00: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 17:44:16 +00:00
|
|
|
|
2012-09-19 20:59:19 +00:00
|
|
|
data = _cogl_bitmap_gl_bind (bmp,
|
2012-11-08 17:54:10 +00: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 12:05:55 +00:00
|
|
|
|
2012-09-19 20:59:19 +00:00
|
|
|
_cogl_bitmap_gl_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
|
|
|
{
|
2012-11-08 17:54:10 +00:00
|
|
|
data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, error);
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
2010-07-15 12:05:55 +00:00
|
|
|
|
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
|
|
|
|
2012-11-08 17:54:10 +00: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 17:44:16 +00:00
|
|
|
|
2012-09-19 20:59:19 +00:00
|
|
|
_cogl_bitmap_gl_unbind (source_bmp);
|
2010-07-01 21:04:59 +00:00
|
|
|
}
|
2012-11-08 17:54:10 +00:00
|
|
|
|
|
|
|
return TRUE;
|
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 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_find_best_gl_get_data_format
|
|
|
|
};
|