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"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2009-07-27 19:37:11 -04:00
|
|
|
#include "cogl-primitives.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2009-07-27 19:37:11 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_gen (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
|
|
|
GLsizei n,
|
|
|
|
GLuint *textures)
|
2010-01-25 06:21:05 -05: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-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
|
|
|
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;
|
|
|
|
|
|
|
|
case GL_TEXTURE_RECTANGLE_ARB:
|
|
|
|
/* Texture rectangles already default to GL_LINEAR so nothing
|
|
|
|
needs to be done */
|
|
|
|
break;
|
2010-01-25 06:21:05 -05:00
|
|
|
|
2010-07-01 17:04:59 -04:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2010-01-25 06:21:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 19:37:11 -04:00
|
|
|
/* OpenGL - unlike GLES - can upload a sub region of pixel data from a larger
|
|
|
|
* source buffer */
|
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
prep_gl_for_pixels_upload_full (CoglContext *ctx,
|
|
|
|
int pixels_rowstride,
|
2010-07-01 17:04:59 -04:00
|
|
|
int image_height,
|
2009-07-27 19:37:11 -04:00
|
|
|
int pixels_src_x,
|
|
|
|
int pixels_src_y,
|
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_ROW_LENGTH,
|
|
|
|
pixels_rowstride / pixels_bpp) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_SKIP_PIXELS, pixels_src_x) );
|
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_SKIP_ROWS, pixels_src_y) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2011-10-12 17:31:12 -04:00
|
|
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_IMAGE_HEIGHT, image_height) );
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2009-07-27 19:37:11 -04:00
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx,
|
|
|
|
int pixels_rowstride,
|
2009-07-27 19:37:11 -04:00
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2012-03-22 13:04:47 -04:00
|
|
|
prep_gl_for_pixels_upload_full (ctx, pixels_rowstride, 0, 0, 0, pixels_bpp);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OpenGL - unlike GLES - can download pixel data into a sub region of
|
|
|
|
* a larger destination buffer */
|
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
prep_gl_for_pixels_download_full (CoglContext *ctx,
|
2012-03-22 07:40:16 -04:00
|
|
|
int image_width,
|
2012-03-22 13:04:47 -04:00
|
|
|
int pixels_rowstride,
|
2010-07-01 17:04:59 -04:00
|
|
|
int image_height,
|
2009-07-27 19:37:11 -04:00
|
|
|
int pixels_src_x,
|
|
|
|
int pixels_src_y,
|
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_ROW_LENGTH, pixels_rowstride / pixels_bpp) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_SKIP_PIXELS, pixels_src_x) );
|
|
|
|
GE( ctx, glPixelStorei (GL_PACK_SKIP_ROWS, pixels_src_y) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2011-10-12 17:31:12 -04:00
|
|
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_IMAGE_HEIGHT, image_height) );
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2012-03-22 07:40:16 -04:00
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_download (pixels_bpp,
|
|
|
|
image_width,
|
|
|
|
pixels_rowstride);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (CoglContext *ctx,
|
2012-03-22 07:40:16 -04:00
|
|
|
int image_width,
|
2012-03-22 13:04:47 -04:00
|
|
|
int pixels_rowstride,
|
2009-07-27 19:37:11 -04:00
|
|
|
int pixels_bpp)
|
|
|
|
{
|
2012-03-22 07:40:16 -04:00
|
|
|
prep_gl_for_pixels_download_full (ctx,
|
|
|
|
pixels_rowstride,
|
|
|
|
image_width,
|
|
|
|
0 /* image height */,
|
|
|
|
0, 0, /* pixels_src_x/y */
|
|
|
|
pixels_bpp);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2009-11-26 12:32:52 -05:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-22 13:04:47 -04:00
|
|
|
prep_gl_for_pixels_upload_full (ctx,
|
|
|
|
cogl_bitmap_get_rowstride (source_bmp),
|
2010-07-15 08:05:55 -04:00
|
|
|
0,
|
|
|
|
src_x,
|
|
|
|
src_y,
|
|
|
|
bpp);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2010-07-07 13:44:16 -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) );
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
_cogl_bitmap_unbind (source_bmp);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_upload_to_gl (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2009-11-30 07:15:05 -05:00
|
|
|
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)
|
|
|
|
{
|
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);
|
2009-11-30 07:15:05 -05: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
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-22 13:04:47 -04:00
|
|
|
prep_gl_for_pixels_upload_full (ctx,
|
|
|
|
cogl_bitmap_get_rowstride (source_bmp),
|
2010-07-15 08:05:55 -04:00
|
|
|
0, 0, 0, bpp);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexImage2D (gl_target, 0,
|
|
|
|
internal_gl_format,
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_width (source_bmp),
|
|
|
|
cogl_bitmap_get_height (source_bmp),
|
2011-07-06 16:51:00 -04:00
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data) );
|
2009-11-30 07:15:05 -05:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
_cogl_bitmap_unbind (source_bmp);
|
2009-11-30 07:15:05 -05:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2010-07-01 17:04:59 -04:00
|
|
|
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)
|
|
|
|
{
|
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-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);
|
|
|
|
|
|
|
|
/* Setup gl alignment to match rowstride and top-left corner */
|
2012-03-22 13:04:47 -04:00
|
|
|
prep_gl_for_pixels_upload_full (ctx,
|
|
|
|
cogl_bitmap_get_rowstride (source_bmp),
|
2012-02-25 15:18:05 -05:00
|
|
|
(cogl_bitmap_get_height (source_bmp) /
|
2010-07-15 08:05:55 -04:00
|
|
|
depth),
|
|
|
|
0, 0, bpp);
|
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexImage3D (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
internal_gl_format,
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_width (source_bmp),
|
2011-07-06 16:51:00 -04:00
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
0,
|
|
|
|
source_gl_format,
|
|
|
|
source_gl_type,
|
|
|
|
data) );
|
2010-07-15 08:05:55 -04:00
|
|
|
|
|
|
|
_cogl_bitmap_unbind (source_bmp);
|
2010-07-01 17:04:59 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_gl_get_tex_image (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
|
|
|
GLenum dest_gl_format,
|
|
|
|
GLenum dest_gl_type,
|
2009-08-30 06:36:11 -04:00
|
|
|
guint8 *dest)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE (ctx, glGetTexImage (gl_target,
|
|
|
|
0, /* level */
|
|
|
|
dest_gl_format,
|
|
|
|
dest_gl_type,
|
|
|
|
(GLvoid *)dest));
|
2009-07-27 19:37:11 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_size_supported_3d (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2010-07-01 17:04:59 -04:00
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
2012-03-22 13:04:47 -04:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth)
|
2010-07-01 17:04:59 -04:00
|
|
|
{
|
|
|
|
GLenum proxy_target;
|
|
|
|
GLint new_width = 0;
|
|
|
|
|
|
|
|
if (gl_target == GL_TEXTURE_3D)
|
|
|
|
proxy_target = GL_PROXY_TEXTURE_3D;
|
|
|
|
else
|
|
|
|
/* Unknown target, assume it's not supported */
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Proxy texture allows for a quick check for supported size */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexImage3D (proxy_target, 0, GL_RGBA,
|
|
|
|
width, height, depth, 0 /* border */,
|
|
|
|
gl_format, gl_type, NULL) );
|
2010-07-01 17:04:59 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (proxy_target, 0,
|
|
|
|
GL_TEXTURE_WIDTH, &new_width) );
|
2010-07-01 17:04:59 -04:00
|
|
|
|
|
|
|
return new_width != 0;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_size_supported (CoglContext *ctx,
|
|
|
|
GLenum gl_target,
|
2009-07-27 19:37:11 -04:00
|
|
|
GLenum gl_format,
|
|
|
|
GLenum gl_type,
|
2012-03-22 13:04:47 -04:00
|
|
|
int width,
|
|
|
|
int height)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2010-06-10 10:33:34 -04:00
|
|
|
GLenum proxy_target;
|
|
|
|
GLint new_width = 0;
|
|
|
|
|
|
|
|
if (gl_target == GL_TEXTURE_2D)
|
|
|
|
proxy_target = GL_PROXY_TEXTURE_2D;
|
|
|
|
#if HAVE_COGL_GL
|
|
|
|
else if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
proxy_target = GL_PROXY_TEXTURE_RECTANGLE_ARB;
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
/* Unknown target, assume it's not supported */
|
|
|
|
return FALSE;
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
/* Proxy texture allows for a quick check for supported size */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexImage2D (proxy_target, 0, GL_RGBA,
|
|
|
|
width, height, 0 /* border */,
|
|
|
|
gl_format, gl_type, NULL) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (proxy_target, 0,
|
|
|
|
GL_TEXTURE_WIDTH, &new_width) );
|
2009-07-27 19:37:11 -04:00
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
return new_width != 0;
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_try_setting_gl_border_color
|
|
|
|
(CoglContext *ctx,
|
|
|
|
GLuint gl_target,
|
|
|
|
const GLfloat *transparent_color)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
/* Use a transparent border color so that we can leave the
|
|
|
|
color buffer alone when using texture co-ordinates
|
|
|
|
outside of the texture */
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameterfv (gl_target, GL_TEXTURE_BORDER_COLOR,
|
|
|
|
transparent_color) );
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static gboolean
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_allows_foreign_gl_target (CoglContext *ctx,
|
|
|
|
GLenum gl_target)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
|
|
|
/* GL_ARB_texture_rectangle textures are supported if they are
|
|
|
|
created from foreign because some chipsets have trouble with
|
|
|
|
GL_ARB_texture_non_power_of_two. There is no Cogl call to create
|
|
|
|
them directly to emphasize the fact that they don't work fully
|
|
|
|
(for example, no mipmapping and complicated shader support) */
|
|
|
|
|
|
|
|
/* Allow 2-dimensional or rectangle textures only */
|
2010-01-12 09:43:36 -05:00
|
|
|
if (gl_target != GL_TEXTURE_2D && gl_target != GL_TEXTURE_RECTANGLE_ARB)
|
2009-07-27 19:37:11 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static void
|
2012-03-22 13:04:47 -04:00
|
|
|
_cogl_texture_driver_gl_generate_mipmaps (CoglContext *ctx,
|
|
|
|
GLenum gl_target)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glGenerateMipmap (gl_target) );
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
static CoglPixelFormat
|
2012-03-22 12:32:56 -04:00
|
|
|
_cogl_texture_driver_find_best_gl_get_data_format
|
|
|
|
(CoglContext *context,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
GLenum *closest_gl_format,
|
|
|
|
GLenum *closest_gl_type)
|
2009-07-27 19:37:11 -04:00
|
|
|
{
|
2012-03-22 12:32:56 -04:00
|
|
|
return context->driver_vtable->pixel_format_to_gl (context,
|
|
|
|
format,
|
|
|
|
NULL, /* don't need */
|
|
|
|
closest_gl_format,
|
|
|
|
closest_gl_type);
|
2009-07-27 19:37:11 -04:00
|
|
|
}
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
const CoglTextureDriver
|
|
|
|
_cogl_texture_driver_gl =
|
|
|
|
{
|
|
|
|
_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
|
|
|
|
};
|