2010-06-10 10:33:34 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 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
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
#include "cogl-private.h"
|
2010-06-10 10:33:34 -04:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-rectangle-private.h"
|
|
|
|
#include "cogl-texture-driver.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"
|
2010-06-10 10:33:34 -04:00
|
|
|
#include "cogl-journal-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2012-08-31 14:28:27 -04:00
|
|
|
#include "cogl-error-private.h"
|
2012-11-08 12:54:10 -05:00
|
|
|
#include "cogl-util-gl-private.h"
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* These aren't defined under GLES */
|
|
|
|
#ifndef GL_TEXTURE_RECTANGLE_ARB
|
|
|
|
#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
|
|
|
|
#endif
|
|
|
|
#ifndef GL_CLAMP
|
|
|
|
#define GL_CLAMP 0x2900
|
|
|
|
#endif
|
|
|
|
#ifndef GL_CLAMP_TO_BORDER
|
|
|
|
#define GL_CLAMP_TO_BORDER 0x812D
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void _cogl_texture_rectangle_free (CoglTextureRectangle *tex_rect);
|
|
|
|
|
2011-10-14 04:25:12 -04:00
|
|
|
COGL_TEXTURE_DEFINE (TextureRectangle, texture_rectangle);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
static const CoglTextureVtable cogl_texture_rectangle_vtable;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-06-10 10:33:34 -04:00
|
|
|
can_use_wrap_mode (GLenum wrap_mode)
|
|
|
|
{
|
|
|
|
return (wrap_mode == GL_CLAMP ||
|
|
|
|
wrap_mode == GL_CLAMP_TO_EDGE ||
|
|
|
|
wrap_mode == GL_CLAMP_TO_BORDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|
|
|
GLenum wrap_mode_s,
|
|
|
|
GLenum wrap_mode_t,
|
|
|
|
GLenum wrap_mode_p)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
/* Only set the wrap mode if it's different from the current value
|
|
|
|
to avoid too many GL calls. Texture rectangle doesn't make use of
|
|
|
|
the r coordinate so we can ignore its wrap mode */
|
2012-09-10 15:35:39 -04:00
|
|
|
if (tex_rect->gl_legacy_texobj_wrap_mode_s != wrap_mode_s ||
|
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_t != wrap_mode_t)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
g_assert (can_use_wrap_mode (wrap_mode_s));
|
|
|
|
g_assert (can_use_wrap_mode (wrap_mode_t));
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_rect->gl_texture,
|
|
|
|
tex_rect->is_foreign);
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
GL_TEXTURE_WRAP_S, wrap_mode_s) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
GL_TEXTURE_WRAP_T, wrap_mode_t) );
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_s = wrap_mode_s;
|
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_t = wrap_mode_t;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_rectangle_free (CoglTextureRectangle *tex_rect)
|
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!tex_rect->is_foreign && tex_rect->gl_texture)
|
2010-10-04 10:27:38 -04:00
|
|
|
_cogl_delete_gl_texture (tex_rect->gl_texture);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
/* Chain up */
|
|
|
|
_cogl_texture_free (COGL_TEXTURE (tex_rect));
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-09-07 10:26:34 -04:00
|
|
|
_cogl_texture_rectangle_can_create (CoglContext *ctx,
|
|
|
|
unsigned int width,
|
2010-06-10 10:33:34 -04:00
|
|
|
unsigned int height,
|
2011-10-14 04:25:12 -04:00
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
GLenum gl_intformat;
|
2012-05-23 09:47:57 -04:00
|
|
|
GLenum gl_format;
|
2010-06-10 10:33:34 -04:00
|
|
|
GLenum gl_type;
|
|
|
|
|
2011-10-12 17:31:12 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_RECTANGLE))
|
2011-10-14 04:25:12 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_TYPE,
|
|
|
|
"The CoglTextureRectangle feature isn't available");
|
2011-10-14 04:25:12 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
2012-05-23 09:47:57 -04:00
|
|
|
&gl_format,
|
2012-03-22 12:32:56 -04:00
|
|
|
&gl_type);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
/* Check that the driver can create a texture with that size */
|
2012-03-22 13:04:47 -04:00
|
|
|
if (!ctx->texture_driver->size_supported (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
2010-06-10 10:33:34 -04:00
|
|
|
gl_intformat,
|
2012-05-23 09:47:57 -04:00
|
|
|
gl_format,
|
2010-06-10 10:33:34 -04:00
|
|
|
gl_type,
|
|
|
|
width,
|
|
|
|
height))
|
2011-10-14 04:25:12 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_SIZE,
|
|
|
|
"The requested texture size + format is unsupported");
|
2011-10-14 04:25:12 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-04 10:09:43 -04:00
|
|
|
static void
|
|
|
|
_cogl_texture_rectangle_set_auto_mipmap (CoglTexture *tex,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool value)
|
2012-04-04 10:09:43 -04:00
|
|
|
{
|
|
|
|
/* Rectangle textures currently never support mipmapping so there's
|
|
|
|
no point in doing anything here */
|
|
|
|
}
|
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
static CoglTextureRectangle *
|
2012-09-07 10:26:34 -04:00
|
|
|
_cogl_texture_rectangle_create_base (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat internal_format)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1);
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
|
|
|
|
2012-11-22 16:46:54 -05:00
|
|
|
_cogl_texture_init (tex, ctx, width, height, &cogl_texture_rectangle_vtable);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect->gl_texture = 0;
|
2013-08-26 16:51:55 -04:00
|
|
|
tex_rect->is_foreign = FALSE;
|
2012-11-22 18:01:08 -05:00
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
/* We default to GL_LINEAR for both filters */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_rect->gl_legacy_texobj_min_filter = GL_LINEAR;
|
|
|
|
tex_rect->gl_legacy_texobj_mag_filter = GL_LINEAR;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
/* Wrap mode not yet set */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_s = GL_FALSE;
|
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_t = GL_FALSE;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect->internal_format = internal_format;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return _cogl_texture_rectangle_object_new (tex_rect);
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
2011-10-14 04:25:12 -04:00
|
|
|
CoglTextureRectangle *
|
|
|
|
cogl_texture_rectangle_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect;
|
|
|
|
|
|
|
|
/* Since no data, we need some internal format */
|
|
|
|
if (internal_format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect =_cogl_texture_rectangle_create_base (ctx,
|
|
|
|
width, height,
|
|
|
|
internal_format);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
/* XXX: This api has been changed for Cogl 2.0 on the master branch
|
|
|
|
* to not take a CoglError to allow the storage to be allocated
|
|
|
|
* lazily but since Mutter uses this api we are currently
|
|
|
|
* maintaining the semantics of immediately allocating the storage
|
|
|
|
*/
|
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (tex_rect), error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (tex_rect);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return tex_rect;
|
|
|
|
}
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
static CoglBool
|
|
|
|
_cogl_texture_rectangle_allocate (CoglTexture *tex,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
GLenum gl_error;
|
|
|
|
GLenum gl_texture;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!_cogl_texture_rectangle_can_create (ctx,
|
|
|
|
tex->width,
|
|
|
|
tex->height,
|
|
|
|
tex_rect->internal_format,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
tex_rect->internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
|
|
|
|
|
|
|
gl_texture =
|
2012-11-19 12:28:52 -05:00
|
|
|
ctx->texture_driver->gen (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect->internal_format);
|
2011-07-06 16:51:00 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
2012-11-22 18:01:08 -05:00
|
|
|
gl_texture,
|
2011-07-06 16:51:00 -04:00
|
|
|
tex_rect->is_foreign);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Clear any GL errors */
|
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
|
|
|
;
|
|
|
|
|
|
|
|
ctx->glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
|
2012-11-22 18:01:08 -05:00
|
|
|
tex->width, tex->height, 0, gl_format, gl_type, NULL);
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
GE( ctx, glDeleteTextures (1, &gl_texture) );
|
|
|
|
return FALSE;
|
2012-11-08 12:54:10 -05:00
|
|
|
}
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect->gl_texture = gl_texture;
|
|
|
|
tex_rect->gl_format = gl_intformat;
|
|
|
|
|
|
|
|
return TRUE;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
2011-10-14 04:25:12 -04:00
|
|
|
CoglTextureRectangle *
|
2012-04-04 10:10:04 -04:00
|
|
|
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
|
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect;
|
2013-06-07 19:28:14 -04:00
|
|
|
CoglBitmap *upload_bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
CoglContext *ctx;
|
2011-07-07 07:48:24 -04:00
|
|
|
|
2011-10-14 04:25:12 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), NULL);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-04-04 08:57:42 -04:00
|
|
|
ctx = _cogl_bitmap_get_context (bmp);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format =
|
2012-02-25 15:18:05 -05:00
|
|
|
_cogl_texture_determine_internal_format (cogl_bitmap_get_format (bmp),
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
if (!_cogl_texture_rectangle_can_create (ctx,
|
|
|
|
cogl_bitmap_get_width (bmp),
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_height (bmp),
|
2011-10-14 04:25:12 -04:00
|
|
|
internal_format,
|
2012-04-04 10:10:04 -04:00
|
|
|
error))
|
2011-10-14 04:25:12 -04:00
|
|
|
return NULL;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_bmp =
|
|
|
|
_cogl_bitmap_convert_for_upload (bmp,
|
|
|
|
internal_format,
|
|
|
|
FALSE, /* can't convert in place */
|
|
|
|
error);
|
|
|
|
if (upload_bmp == NULL)
|
2011-10-14 04:25:12 -04:00
|
|
|
return NULL;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
cogl_bitmap_get_format (upload_bmp),
|
|
|
|
NULL, /* internal format */
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
tex_rect = _cogl_texture_rectangle_create_base (ctx,
|
|
|
|
cogl_bitmap_get_width (bmp),
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_height (bmp),
|
2010-06-10 10:33:34 -04:00
|
|
|
internal_format);
|
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
tex_rect->gl_texture =
|
|
|
|
ctx->texture_driver->gen (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
internal_format);
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!ctx->texture_driver->upload_to_gl (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_rect->gl_texture,
|
|
|
|
FALSE,
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
gl_intformat,
|
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
error))
|
|
|
|
{
|
2013-06-07 19:28:14 -04:00
|
|
|
cogl_object_unref (upload_bmp);
|
2012-11-08 12:54:10 -05:00
|
|
|
cogl_object_unref (tex_rect);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
tex_rect->gl_format = gl_intformat;
|
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
cogl_object_unref (upload_bmp);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect), TRUE);
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return tex_rect;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
2011-10-14 04:25:12 -04:00
|
|
|
CoglTextureRectangle *
|
2012-08-31 21:16:53 -04:00
|
|
|
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
|
|
|
|
unsigned int gl_handle,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2010-10-04 10:27:38 -04:00
|
|
|
{
|
|
|
|
/* NOTE: width, height and internal format are not queriable
|
|
|
|
* in GLES, hence such a function prototype.
|
|
|
|
*/
|
|
|
|
|
2012-08-31 21:16:53 -04:00
|
|
|
GLenum gl_error = 0;
|
|
|
|
GLint gl_compressed = GL_FALSE;
|
|
|
|
GLenum gl_int_format = 0;
|
2010-10-04 10:27:38 -04:00
|
|
|
CoglTextureRectangle *tex_rect;
|
|
|
|
|
2012-08-31 21:16:53 -04:00
|
|
|
/* Assert that it is a valid GL texture object */
|
|
|
|
g_return_val_if_fail (ctx->glIsTexture (gl_handle), NULL);
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB))
|
2012-08-31 21:16:53 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Foreign GL_TEXTURE_RECTANGLE textures are not "
|
|
|
|
"supported by your system");
|
2012-08-31 21:16:53 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Make sure binding succeeds */
|
2011-07-06 16:51:00 -04:00
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
2010-10-04 10:27:38 -04:00
|
|
|
;
|
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, gl_handle, TRUE);
|
2011-07-06 16:51:00 -04:00
|
|
|
if (ctx->glGetError () != GL_NO_ERROR)
|
2012-08-31 21:16:53 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Failed to bind foreign GL_TEXTURE_RECTANGLE texture");
|
2012-08-31 21:16:53 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Obtain texture parameters */
|
|
|
|
|
2013-01-24 06:40:19 -05:00
|
|
|
#ifdef HAVE_COGL_GL
|
2013-01-24 06:51:06 -05:00
|
|
|
if ((ctx->private_feature_flags &
|
|
|
|
COGL_PRIVATE_FEATURE_QUERY_TEXTURE_PARAMETERS))
|
2011-07-07 15:44:56 -04:00
|
|
|
{
|
|
|
|
GLint val;
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
|
|
|
|
GL_TEXTURE_COMPRESSED,
|
|
|
|
&gl_compressed) );
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
|
|
|
|
GL_TEXTURE_INTERNAL_FORMAT,
|
|
|
|
&val) );
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
gl_int_format = val;
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
/* If we can query GL for the actual pixel format then we'll ignore
|
|
|
|
the passed in format and use that. */
|
2012-03-22 12:32:56 -04:00
|
|
|
if (!ctx->driver_vtable->pixel_format_from_gl_internal (ctx,
|
|
|
|
gl_int_format,
|
|
|
|
&format))
|
2012-08-31 21:16:53 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Unsupported internal format for foreign texture");
|
2012-08-31 21:16:53 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-07 15:44:56 -04:00
|
|
|
}
|
|
|
|
else
|
2010-10-04 10:27:38 -04:00
|
|
|
#endif
|
2011-07-07 15:44:56 -04:00
|
|
|
{
|
|
|
|
/* Otherwise we'll assume we can derive the GL format from the
|
|
|
|
passed in format */
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
&gl_int_format,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-07-07 15:44:56 -04:00
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Note: We always trust the given width and height without querying
|
|
|
|
* the texture object because the user may be creating a Cogl
|
|
|
|
* texture for a texture_from_pixmap object where glTexImage2D may
|
|
|
|
* not have been called and the texture_from_pixmap spec doesn't
|
|
|
|
* clarify that it is reliable to query back the size from OpenGL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Validate width and height */
|
2012-08-31 21:16:53 -04:00
|
|
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Compressed texture images not supported */
|
|
|
|
if (gl_compressed == GL_TRUE)
|
2012-08-31 21:16:53 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Compressed foreign textures aren't currently supported");
|
2012-08-31 21:16:53 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Create new texture */
|
2012-09-07 10:26:34 -04:00
|
|
|
tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height, format);
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Setup bitmap info */
|
|
|
|
tex_rect->is_foreign = TRUE;
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect->internal_format = format;
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
tex_rect->gl_texture = gl_handle;
|
|
|
|
tex_rect->gl_format = gl_int_format;
|
|
|
|
|
|
|
|
/* Unknown filter */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_rect->gl_legacy_texobj_min_filter = GL_FALSE;
|
|
|
|
tex_rect->gl_legacy_texobj_mag_filter = GL_FALSE;
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect), TRUE);
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return tex_rect;
|
2010-10-04 10:27:38 -04:00
|
|
|
}
|
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
static int
|
|
|
|
_cogl_texture_rectangle_get_max_waste (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_is_sliced (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_can_hardware_repeat (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_rectangle_transform_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
2012-11-22 16:46:54 -05:00
|
|
|
*s *= tex->width;
|
|
|
|
*t *= tex->height;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static CoglTransformResult
|
|
|
|
_cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *coords)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool need_repeat = FALSE;
|
2010-06-10 10:33:34 -04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (coords[i] < 0.0f || coords[i] > 1.0f)
|
|
|
|
need_repeat = TRUE;
|
2012-11-22 16:46:54 -05:00
|
|
|
coords[i] *= (i & 1) ? tex->height : tex->width;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (need_repeat ? COGL_TRANSFORM_SOFTWARE_REPEAT
|
|
|
|
: COGL_TRANSFORM_NO_REPEAT);
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_get_gl_texture (CoglTexture *tex,
|
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
|
|
|
|
|
|
|
if (out_gl_handle)
|
|
|
|
*out_gl_handle = tex_rect->gl_texture;
|
|
|
|
|
|
|
|
if (out_gl_target)
|
|
|
|
*out_gl_target = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_filters (CoglTexture *tex,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
if (min_filter == tex_rect->gl_legacy_texobj_min_filter
|
|
|
|
&& mag_filter == tex_rect->gl_legacy_texobj_mag_filter)
|
2010-06-10 10:33:34 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Rectangle textures don't support mipmapping */
|
|
|
|
g_assert (min_filter == GL_LINEAR || min_filter == GL_NEAREST);
|
|
|
|
|
|
|
|
/* Store new values */
|
2012-09-10 15:35:39 -04:00
|
|
|
tex_rect->gl_legacy_texobj_min_filter = min_filter;
|
|
|
|
tex_rect->gl_legacy_texobj_mag_filter = mag_filter;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
/* Apply new filters to the texture */
|
2011-07-06 16:51:00 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_rect->gl_texture,
|
|
|
|
tex_rect->is_foreign);
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
|
|
|
|
mag_filter) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
|
|
|
|
min_filter) );
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_rectangle_pre_paint (CoglTexture *tex,
|
|
|
|
CoglTexturePrePaintFlags flags)
|
|
|
|
{
|
|
|
|
/* Rectangle textures don't support mipmaps */
|
|
|
|
g_assert ((flags & COGL_TEXTURE_NEEDS_MIPMAP) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_rectangle_ensure_non_quad_rendering (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
/* Nothing needs to be done */
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_texture_rectangle_set_region (CoglTexture *tex,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int dst_width,
|
|
|
|
int dst_height,
|
2012-11-09 12:55:54 -05:00
|
|
|
int level,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBitmap *bmp,
|
|
|
|
CoglError **error)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
2013-06-07 19:28:14 -04:00
|
|
|
CoglBitmap *upload_bmp;
|
2012-09-07 10:26:34 -04:00
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
CoglContext *ctx = tex->context;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBool status;
|
2011-07-07 07:48:24 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_bmp =
|
|
|
|
_cogl_bitmap_convert_for_upload (bmp,
|
|
|
|
cogl_texture_get_format (tex),
|
|
|
|
FALSE, /* can't convert in place */
|
|
|
|
error);
|
|
|
|
if (upload_bmp == NULL)
|
2012-11-08 12:54:10 -05:00
|
|
|
return FALSE;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
cogl_bitmap_get_format (upload_bmp),
|
|
|
|
NULL, /* internal format */
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
/* Send data to GL */
|
2012-11-08 12:54:10 -05:00
|
|
|
status =
|
|
|
|
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
2012-11-09 12:55:54 -05:00
|
|
|
tex,
|
2012-11-08 12:54:10 -05:00
|
|
|
FALSE,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_width, dst_height,
|
2012-11-09 12:55:54 -05:00
|
|
|
level,
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
error);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
cogl_object_unref (upload_bmp);
|
2011-08-31 12:22:20 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return status;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
|
|
|
_cogl_texture_rectangle_get_data (CoglTexture *tex,
|
|
|
|
CoglPixelFormat format,
|
2012-09-26 12:05:01 -04:00
|
|
|
int rowstride,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *data)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
2010-07-08 08:54:37 -04:00
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
int bpp;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
NULL, /* internal format */
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-03-22 07:40:16 -04:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
|
|
|
rowstride,
|
2012-11-22 16:46:54 -05:00
|
|
|
tex->width,
|
2012-03-22 07:40:16 -04:00
|
|
|
bpp);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_rect->gl_texture,
|
|
|
|
tex_rect->is_foreign);
|
2012-03-22 13:04:47 -04:00
|
|
|
return ctx->texture_driver->gl_get_tex_image (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
2010-07-08 08:54:37 -04:00
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
data);
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_rectangle_get_format (CoglTexture *tex)
|
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
return COGL_TEXTURE_RECTANGLE (tex)->internal_format;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_cogl_texture_rectangle_get_gl_format (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_RECTANGLE (tex)->gl_format;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-10-04 10:27:38 -04:00
|
|
|
_cogl_texture_rectangle_is_foreign (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_RECTANGLE (tex)->is_foreign;
|
|
|
|
}
|
|
|
|
|
2012-02-09 06:19:04 -05:00
|
|
|
static CoglTextureType
|
|
|
|
_cogl_texture_rectangle_get_type (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_TYPE_RECTANGLE;
|
|
|
|
}
|
|
|
|
|
2010-06-10 10:33:34 -04:00
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_texture_rectangle_vtable =
|
|
|
|
{
|
2012-04-04 10:09:43 -04:00
|
|
|
TRUE, /* primitive */
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_texture_rectangle_allocate,
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_set_region,
|
|
|
|
_cogl_texture_rectangle_get_data,
|
2011-10-08 09:13:03 -04:00
|
|
|
NULL, /* foreach_sub_texture_in_region */
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_get_max_waste,
|
|
|
|
_cogl_texture_rectangle_is_sliced,
|
|
|
|
_cogl_texture_rectangle_can_hardware_repeat,
|
|
|
|
_cogl_texture_rectangle_transform_coords_to_gl,
|
|
|
|
_cogl_texture_rectangle_transform_quad_coords_to_gl,
|
|
|
|
_cogl_texture_rectangle_get_gl_texture,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_filters,
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_pre_paint,
|
|
|
|
_cogl_texture_rectangle_ensure_non_quad_rendering,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes,
|
2010-06-10 10:33:34 -04:00
|
|
|
_cogl_texture_rectangle_get_format,
|
|
|
|
_cogl_texture_rectangle_get_gl_format,
|
2012-02-09 06:19:04 -05:00
|
|
|
_cogl_texture_rectangle_get_type,
|
2012-04-04 10:09:43 -04:00
|
|
|
_cogl_texture_rectangle_is_foreign,
|
|
|
|
_cogl_texture_rectangle_set_auto_mipmap
|
2010-06-10 10:33:34 -04:00
|
|
|
};
|