2010-06-10 14:33:34 +00: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 23:02:04 +00:00
|
|
|
#include "cogl-private.h"
|
2010-06-10 14:33:34 +00:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-rectangle-private.h"
|
|
|
|
#include "cogl-texture-driver.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"
|
2010-06-10 14:33:34 +00:00
|
|
|
#include "cogl-journal-private.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2012-08-31 18:28:27 +00:00
|
|
|
#include "cogl-error-private.h"
|
2012-11-08 17:54:10 +00:00
|
|
|
#include "cogl-util-gl-private.h"
|
2010-06-10 14:33:34 +00: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 08:25:12 +00:00
|
|
|
COGL_TEXTURE_DEFINE (TextureRectangle, texture_rectangle);
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-06-10 14:33:34 +00: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 19:35:39 +00: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 14:33:34 +00:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
2012-09-07 14:26:34 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 20:51:00 +00:00
|
|
|
|
2010-06-10 14:33:34 +00: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 19:35:39 +00: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 14:33:34 +00:00
|
|
|
{
|
|
|
|
g_assert (can_use_wrap_mode (wrap_mode_s));
|
|
|
|
g_assert (can_use_wrap_mode (wrap_mode_t));
|
|
|
|
|
2011-07-06 20:51:00 +00: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 14:33:34 +00:00
|
|
|
|
2012-09-10 19:35:39 +00: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 14:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_rectangle_free (CoglTextureRectangle *tex_rect)
|
|
|
|
{
|
2012-11-22 23:01:08 +00:00
|
|
|
if (!tex_rect->is_foreign && tex_rect->gl_texture)
|
2010-10-04 14:27:38 +00:00
|
|
|
_cogl_delete_gl_texture (tex_rect->gl_texture);
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-09-07 14:26:34 +00:00
|
|
|
_cogl_texture_rectangle_can_create (CoglContext *ctx,
|
|
|
|
unsigned int width,
|
2010-06-10 14:33:34 +00:00
|
|
|
unsigned int height,
|
2011-10-14 08:25:12 +00:00
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 18:28:27 +00:00
|
|
|
CoglError **error)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
|
|
|
GLenum gl_intformat;
|
2012-05-23 13:47:57 +00:00
|
|
|
GLenum gl_format;
|
2010-06-10 14:33:34 +00:00
|
|
|
GLenum gl_type;
|
|
|
|
|
2011-10-12 21:31:12 +00:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_RECTANGLE))
|
2011-10-14 08:25:12 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_TYPE,
|
|
|
|
"The CoglTextureRectangle feature isn't available");
|
2011-10-14 08:25:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-03-22 16:32:56 +00:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
2012-05-23 13:47:57 +00:00
|
|
|
&gl_format,
|
2012-03-22 16:32:56 +00:00
|
|
|
&gl_type);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
|
|
|
/* Check that the driver can create a texture with that size */
|
2012-03-22 17:04:47 +00:00
|
|
|
if (!ctx->texture_driver->size_supported (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
2010-06-10 14:33:34 +00:00
|
|
|
gl_intformat,
|
2012-05-23 13:47:57 +00:00
|
|
|
gl_format,
|
2010-06-10 14:33:34 +00:00
|
|
|
gl_type,
|
|
|
|
width,
|
|
|
|
height))
|
2011-10-14 08:25:12 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_SIZE,
|
|
|
|
"The requested texture size + format is unsupported");
|
2011-10-14 08:25:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-10 14:33:34 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-04 14:09:43 +00: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 20:56:40 +00:00
|
|
|
CoglBool value)
|
2012-04-04 14:09:43 +00:00
|
|
|
{
|
|
|
|
/* Rectangle textures currently never support mipmapping so there's
|
|
|
|
no point in doing anything here */
|
|
|
|
}
|
|
|
|
|
2010-06-10 14:33:34 +00:00
|
|
|
static CoglTextureRectangle *
|
2012-09-07 14:26:34 +00:00
|
|
|
_cogl_texture_rectangle_create_base (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglTextureLoader *loader)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1);
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_texture_init (tex, ctx, width, height,
|
|
|
|
internal_format, loader,
|
|
|
|
&cogl_texture_rectangle_vtable);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
tex_rect->gl_texture = 0;
|
2013-08-26 20:51:55 +00:00
|
|
|
tex_rect->is_foreign = FALSE;
|
2012-11-22 23:01:08 +00:00
|
|
|
|
2010-06-10 14:33:34 +00:00
|
|
|
/* We default to GL_LINEAR for both filters */
|
2012-09-10 19:35:39 +00:00
|
|
|
tex_rect->gl_legacy_texobj_min_filter = GL_LINEAR;
|
|
|
|
tex_rect->gl_legacy_texobj_mag_filter = GL_LINEAR;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
|
|
|
/* Wrap mode not yet set */
|
2012-09-10 19:35:39 +00:00
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_s = GL_FALSE;
|
|
|
|
tex_rect->gl_legacy_texobj_wrap_mode_t = GL_FALSE;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
return _cogl_texture_rectangle_object_new (tex_rect);
|
2010-06-10 14:33:34 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:25:12 +00:00
|
|
|
CoglTextureRectangle *
|
|
|
|
cogl_texture_rectangle_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 18:28:27 +00:00
|
|
|
CoglError **error)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTextureLoader *loader;
|
2010-06-10 14:33:34 +00: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;
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
|
|
|
|
loader->src.sized.width = width;
|
|
|
|
loader->src.sized.height = height;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height,
|
|
|
|
internal_format, loader);
|
2013-07-02 00:48:54 +00:00
|
|
|
|
2012-11-22 23:01:08 +00: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
|
|
|
|
*/
|
2013-07-02 00:48:54 +00:00
|
|
|
|
|
|
|
/* By default tex->premultiplied is set to TRUE and tex->components
|
|
|
|
* get initialized according to a given source-format in
|
|
|
|
* _cogl_texture_init(). Since this api has an internal-format
|
|
|
|
* argument for compatibility we need to make sure the
|
|
|
|
* ->premultiplied and ->components state are initialized according
|
|
|
|
* to the users given @internal_format. */
|
|
|
|
_cogl_texture_set_internal_format (COGL_TEXTURE (tex_rect), internal_format);
|
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (tex_rect), error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (tex_rect);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-23 15:18:18 +00:00
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
return tex_rect;
|
|
|
|
}
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
static CoglBool
|
2013-06-23 15:18:18 +00:00
|
|
|
allocate_with_size (CoglTextureRectangle *tex_rect,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2012-11-22 23:01:08 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
2012-11-22 23:01:08 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglPixelFormat internal_format;
|
|
|
|
int width = loader->src.sized.width;
|
|
|
|
int height = loader->src.sized.height;
|
2012-11-22 23:01:08 +00:00
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
GLenum gl_error;
|
|
|
|
GLenum gl_texture;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
internal_format =
|
|
|
|
_cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY);
|
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
if (!_cogl_texture_rectangle_can_create (ctx,
|
2013-06-23 15:18:18 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
internal_format,
|
2012-11-22 23:01:08 +00:00
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
2013-06-23 15:18:18 +00:00
|
|
|
internal_format,
|
2012-11-22 23:01:08 +00:00
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
|
|
|
|
|
|
|
gl_texture =
|
2012-11-19 17:28:52 +00:00
|
|
|
ctx->texture_driver->gen (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
2013-06-23 15:18:18 +00:00
|
|
|
internal_format);
|
2011-07-06 20:51:00 +00:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
2012-11-22 23:01:08 +00:00
|
|
|
gl_texture,
|
2011-07-06 20:51:00 +00:00
|
|
|
tex_rect->is_foreign);
|
2010-06-10 14:33:34 +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_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
|
2013-06-23 15:18:18 +00:00
|
|
|
width, height, 0, gl_format, gl_type, NULL);
|
2012-11-08 17:54:10 +00:00
|
|
|
|
|
|
|
if (_cogl_gl_util_catch_out_of_memory (ctx, error))
|
|
|
|
{
|
2012-11-22 23:01:08 +00:00
|
|
|
GE( ctx, glDeleteTextures (1, &gl_texture) );
|
|
|
|
return FALSE;
|
2012-11-08 17:54:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
tex_rect->internal_format = internal_format;
|
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
tex_rect->gl_texture = gl_texture;
|
|
|
|
tex_rect->gl_format = gl_intformat;
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
|
|
|
|
internal_format, width, height);
|
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
return TRUE;
|
2010-06-10 14:33:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
static CoglBool
|
|
|
|
allocate_from_bitmap (CoglTextureRectangle *tex_rect,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
CoglPixelFormat internal_format;
|
|
|
|
CoglBitmap *bmp = loader->src.bitmap.bitmap;
|
|
|
|
int width = cogl_bitmap_get_width (bmp);
|
|
|
|
int height = cogl_bitmap_get_height (bmp);
|
|
|
|
CoglBool can_convert_in_place = loader->src.bitmap.can_convert_in_place;
|
2013-06-07 23:28:14 +00:00
|
|
|
CoglBitmap *upload_bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2012-04-04 12:57:42 +00:00
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
internal_format =
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_texture_determine_internal_format (tex, cogl_bitmap_get_format (bmp));
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-09-07 14:26:34 +00:00
|
|
|
if (!_cogl_texture_rectangle_can_create (ctx,
|
2013-06-23 15:18:18 +00:00
|
|
|
width,
|
|
|
|
height,
|
2011-10-14 08:25:12 +00:00
|
|
|
internal_format,
|
2012-04-04 14:10:04 +00:00
|
|
|
error))
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
upload_bmp = _cogl_bitmap_convert_for_upload (bmp,
|
|
|
|
internal_format,
|
|
|
|
can_convert_in_place,
|
|
|
|
error);
|
2013-06-07 23:28:14 +00:00
|
|
|
if (upload_bmp == NULL)
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-07 23:28:14 +00: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-11-19 17:28:52 +00:00
|
|
|
tex_rect->gl_texture =
|
|
|
|
ctx->texture_driver->gen (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
internal_format);
|
2012-11-08 17:54:10 +00:00
|
|
|
if (!ctx->texture_driver->upload_to_gl (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_rect->gl_texture,
|
|
|
|
FALSE,
|
2013-06-07 23:28:14 +00:00
|
|
|
upload_bmp,
|
2012-11-08 17:54:10 +00:00
|
|
|
gl_intformat,
|
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
error))
|
|
|
|
{
|
2013-06-07 23:28:14 +00:00
|
|
|
cogl_object_unref (upload_bmp);
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2012-11-08 17:54:10 +00:00
|
|
|
}
|
2010-06-10 14:33:34 +00:00
|
|
|
|
|
|
|
tex_rect->gl_format = gl_intformat;
|
2013-06-23 15:18:18 +00:00
|
|
|
tex_rect->internal_format = internal_format;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-07 23:28:14 +00:00
|
|
|
cogl_object_unref (upload_bmp);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
|
|
|
|
internal_format, width, height);
|
2012-11-22 23:01:08 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
return TRUE;
|
2010-06-10 14:33:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
static CoglBool
|
|
|
|
allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2010-10-04 14:27:38 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
CoglPixelFormat format = loader->src.gl_foreign.format;
|
2012-09-01 01:16:53 +00:00
|
|
|
GLenum gl_error = 0;
|
|
|
|
GLint gl_compressed = GL_FALSE;
|
|
|
|
GLenum gl_int_format = 0;
|
2011-07-06 20:51:00 +00:00
|
|
|
|
2012-03-22 17:04:47 +00:00
|
|
|
if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB))
|
2012-09-01 01:16:53 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Foreign GL_TEXTURE_RECTANGLE textures are not "
|
|
|
|
"supported by your system");
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2012-09-01 01:16:53 +00:00
|
|
|
}
|
2010-10-04 14:27:38 +00:00
|
|
|
|
|
|
|
/* Make sure binding succeeds */
|
2011-07-06 20:51:00 +00:00
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
2010-10-04 14:27:38 +00:00
|
|
|
;
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
loader->src.gl_foreign.gl_handle, TRUE);
|
2011-07-06 20:51:00 +00:00
|
|
|
if (ctx->glGetError () != GL_NO_ERROR)
|
2012-09-01 01:16:53 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Failed to bind foreign GL_TEXTURE_RECTANGLE texture");
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2012-09-01 01:16:53 +00:00
|
|
|
}
|
2010-10-04 14:27:38 +00:00
|
|
|
|
|
|
|
/* Obtain texture parameters */
|
|
|
|
|
2013-01-24 11:40:19 +00:00
|
|
|
#ifdef HAVE_COGL_GL
|
2013-11-25 16:11:36 +00:00
|
|
|
if (_cogl_has_private_feature
|
|
|
|
(ctx, COGL_PRIVATE_FEATURE_QUERY_TEXTURE_PARAMETERS))
|
2011-07-07 19:44:56 +00:00
|
|
|
{
|
|
|
|
GLint val;
|
2010-10-04 14:27:38 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
|
|
|
|
GL_TEXTURE_COMPRESSED,
|
|
|
|
&gl_compressed) );
|
2010-10-04 14:27:38 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
|
|
|
|
GL_TEXTURE_INTERNAL_FORMAT,
|
|
|
|
&val) );
|
2010-10-04 14:27:38 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
gl_int_format = val;
|
2010-10-04 14:27:38 +00:00
|
|
|
|
2011-07-07 19:44:56 +00: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 16:32:56 +00:00
|
|
|
if (!ctx->driver_vtable->pixel_format_from_gl_internal (ctx,
|
|
|
|
gl_int_format,
|
|
|
|
&format))
|
2012-09-01 01:16:53 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Unsupported internal format for foreign texture");
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2012-09-01 01:16:53 +00:00
|
|
|
}
|
2011-07-07 19:44:56 +00:00
|
|
|
}
|
|
|
|
else
|
2010-10-04 14:27:38 +00:00
|
|
|
#endif
|
2011-07-07 19:44:56 +00:00
|
|
|
{
|
|
|
|
/* Otherwise we'll assume we can derive the GL format from the
|
|
|
|
passed in format */
|
2012-03-22 16:32:56 +00:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
&gl_int_format,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-07-07 19:44:56 +00:00
|
|
|
}
|
2010-10-04 14:27:38 +00:00
|
|
|
|
|
|
|
/* Compressed texture images not supported */
|
|
|
|
if (gl_compressed == GL_TRUE)
|
2012-09-01 01:16:53 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Compressed foreign textures aren't currently supported");
|
2013-06-23 15:18:18 +00:00
|
|
|
return FALSE;
|
2012-09-01 01:16:53 +00:00
|
|
|
}
|
2010-10-04 14:27:38 +00:00
|
|
|
|
|
|
|
/* Setup bitmap info */
|
|
|
|
tex_rect->is_foreign = TRUE;
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
tex_rect->gl_texture = loader->src.gl_foreign.gl_handle;
|
2010-10-04 14:27:38 +00:00
|
|
|
tex_rect->gl_format = gl_int_format;
|
|
|
|
|
|
|
|
/* Unknown filter */
|
2012-09-10 19:35:39 +00:00
|
|
|
tex_rect->gl_legacy_texobj_min_filter = GL_FALSE;
|
|
|
|
tex_rect->gl_legacy_texobj_mag_filter = GL_FALSE;
|
2010-10-04 14:27:38 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
tex_rect->internal_format = format;
|
2012-11-22 23:01:08 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
|
|
|
|
format,
|
|
|
|
loader->src.gl_foreign.width,
|
|
|
|
loader->src.gl_foreign.height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
_cogl_texture_rectangle_allocate (CoglTexture *tex,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
|
|
|
CoglTextureLoader *loader = tex->loader;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (loader, FALSE);
|
|
|
|
|
|
|
|
switch (loader->src_type)
|
|
|
|
{
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_SIZED:
|
|
|
|
return allocate_with_size (tex_rect, loader, error);
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_BITMAP:
|
|
|
|
return allocate_from_bitmap (tex_rect, loader, error);
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN:
|
|
|
|
return allocate_from_gl_foreign (tex_rect, loader, error);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTextureRectangle *
|
2013-07-02 00:48:54 +00:00
|
|
|
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp)
|
2013-06-23 15:18:18 +00:00
|
|
|
{
|
|
|
|
CoglTextureLoader *loader;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), NULL);
|
|
|
|
|
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_BITMAP;
|
|
|
|
loader->src.bitmap.bitmap = cogl_object_ref (bmp);
|
|
|
|
loader->src.bitmap.can_convert_in_place = FALSE; /* TODO add api for this */
|
|
|
|
|
|
|
|
return _cogl_texture_rectangle_create_base (_cogl_bitmap_get_context (bmp),
|
|
|
|
cogl_bitmap_get_width (bmp),
|
|
|
|
cogl_bitmap_get_height (bmp),
|
2013-07-02 00:48:54 +00:00
|
|
|
cogl_bitmap_get_format (bmp),
|
2013-06-23 15:18:18 +00:00
|
|
|
loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTextureRectangle *
|
|
|
|
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
|
|
|
|
unsigned int gl_handle,
|
|
|
|
int width,
|
|
|
|
int height,
|
2013-07-02 00:48:54 +00:00
|
|
|
CoglPixelFormat format)
|
2013-06-23 15:18:18 +00:00
|
|
|
{
|
|
|
|
CoglTextureLoader *loader;
|
|
|
|
|
|
|
|
/* NOTE: width, height and internal format are not queriable in
|
|
|
|
* GLES, hence such a function prototype. Also in the case of full
|
|
|
|
* opengl 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Assert that it is a valid GL texture object */
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (ctx->glIsTexture (gl_handle), NULL);
|
|
|
|
|
|
|
|
/* Validate width and height */
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (width > 0 && height > 0, NULL);
|
|
|
|
|
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN;
|
|
|
|
loader->src.gl_foreign.gl_handle = gl_handle;
|
|
|
|
loader->src.gl_foreign.width = width;
|
|
|
|
loader->src.gl_foreign.height = height;
|
|
|
|
loader->src.gl_foreign.format = format;
|
|
|
|
|
|
|
|
return _cogl_texture_rectangle_create_base (ctx, width, height,
|
|
|
|
format, loader);
|
2010-10-04 14:27:38 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-06-10 14:33:34 +00: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 21:46:54 +00:00
|
|
|
*s *= tex->width;
|
|
|
|
*t *= tex->height;
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
CoglBool need_repeat = FALSE;
|
2010-06-10 14:33:34 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (coords[i] < 0.0f || coords[i] > 1.0f)
|
|
|
|
need_repeat = TRUE;
|
2012-11-22 21:46:54 +00:00
|
|
|
coords[i] *= (i & 1) ? tex->height : tex->width;
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-06-10 14:33:34 +00: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 19:35:39 +00:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_filters (CoglTexture *tex,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
2012-09-07 14:26:34 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 20:51:00 +00:00
|
|
|
|
2012-09-10 19:35:39 +00:00
|
|
|
if (min_filter == tex_rect->gl_legacy_texobj_min_filter
|
|
|
|
&& mag_filter == tex_rect->gl_legacy_texobj_mag_filter)
|
2010-06-10 14:33:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Rectangle textures don't support mipmapping */
|
|
|
|
g_assert (min_filter == GL_LINEAR || min_filter == GL_NEAREST);
|
|
|
|
|
|
|
|
/* Store new values */
|
2012-09-10 19:35:39 +00:00
|
|
|
tex_rect->gl_legacy_texobj_min_filter = min_filter;
|
|
|
|
tex_rect->gl_legacy_texobj_mag_filter = mag_filter;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
|
|
|
/* Apply new filters to the texture */
|
2011-07-06 20:51:00 +00: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 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-11-08 17:54:10 +00: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 17:55:54 +00:00
|
|
|
int level,
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBitmap *bmp,
|
|
|
|
CoglError **error)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
2013-06-07 23:28:14 +00:00
|
|
|
CoglBitmap *upload_bmp;
|
2012-09-07 14:26:34 +00:00
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
CoglContext *ctx = tex->context;
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBool status;
|
2011-07-07 11:48:24 +00:00
|
|
|
|
2013-06-07 23:28:14 +00:00
|
|
|
upload_bmp =
|
|
|
|
_cogl_bitmap_convert_for_upload (bmp,
|
2013-06-27 17:33:04 +00:00
|
|
|
_cogl_texture_get_format (tex),
|
2013-06-07 23:28:14 +00:00
|
|
|
FALSE, /* can't convert in place */
|
|
|
|
error);
|
|
|
|
if (upload_bmp == NULL)
|
2012-11-08 17:54:10 +00:00
|
|
|
return FALSE;
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-07 23:28:14 +00: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 14:33:34 +00:00
|
|
|
/* Send data to GL */
|
2012-11-08 17:54:10 +00:00
|
|
|
status =
|
|
|
|
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
2012-11-09 17:55:54 +00:00
|
|
|
tex,
|
2012-11-08 17:54:10 +00:00
|
|
|
FALSE,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_width, dst_height,
|
2012-11-09 17:55:54 +00:00
|
|
|
level,
|
2013-06-07 23:28:14 +00:00
|
|
|
upload_bmp,
|
2012-11-08 17:54:10 +00:00
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
error);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2013-06-07 23:28:14 +00:00
|
|
|
cogl_object_unref (upload_bmp);
|
2011-08-31 16:22:20 +00:00
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
return status;
|
2010-06-10 14:33:34 +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
|
|
|
|
_cogl_texture_rectangle_get_data (CoglTexture *tex,
|
|
|
|
CoglPixelFormat format,
|
2012-09-26 16:05:01 +00: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 20:56:40 +00:00
|
|
|
uint8_t *data)
|
2010-06-10 14:33:34 +00:00
|
|
|
{
|
2010-07-08 12:54:37 +00:00
|
|
|
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
|
2012-09-07 14:26:34 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
int bpp;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2011-07-06 20:51:00 +00:00
|
|
|
|
2012-02-13 23:02:04 +00:00
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-03-22 16:32:56 +00:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
NULL, /* internal format */
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2012-03-22 11:40:16 +00:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
|
|
|
rowstride,
|
2012-11-22 21:46:54 +00:00
|
|
|
tex->width,
|
2012-03-22 11:40:16 +00:00
|
|
|
bpp);
|
2010-06-10 14:33:34 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
tex_rect->gl_texture,
|
|
|
|
tex_rect->is_foreign);
|
2012-03-22 17:04:47 +00:00
|
|
|
return ctx->texture_driver->gl_get_tex_image (ctx,
|
|
|
|
GL_TEXTURE_RECTANGLE_ARB,
|
2010-07-08 12:54:37 +00:00
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
data);
|
2010-06-10 14:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_rectangle_get_format (CoglTexture *tex)
|
|
|
|
{
|
2012-11-22 23:01:08 +00:00
|
|
|
return COGL_TEXTURE_RECTANGLE (tex)->internal_format;
|
2010-06-10 14:33:34 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-10-04 14:27:38 +00:00
|
|
|
_cogl_texture_rectangle_is_foreign (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_RECTANGLE (tex)->is_foreign;
|
|
|
|
}
|
|
|
|
|
2012-02-09 11:19:04 +00:00
|
|
|
static CoglTextureType
|
|
|
|
_cogl_texture_rectangle_get_type (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_TYPE_RECTANGLE;
|
|
|
|
}
|
|
|
|
|
2010-06-10 14:33:34 +00:00
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_texture_rectangle_vtable =
|
|
|
|
{
|
2012-04-04 14:09:43 +00:00
|
|
|
TRUE, /* primitive */
|
2012-11-22 23:01:08 +00:00
|
|
|
_cogl_texture_rectangle_allocate,
|
2010-06-10 14:33:34 +00:00
|
|
|
_cogl_texture_rectangle_set_region,
|
|
|
|
_cogl_texture_rectangle_get_data,
|
2011-10-08 13:13:03 +00:00
|
|
|
NULL, /* foreach_sub_texture_in_region */
|
2010-06-10 14:33:34 +00: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 19:35:39 +00:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_filters,
|
2010-06-10 14:33:34 +00:00
|
|
|
_cogl_texture_rectangle_pre_paint,
|
|
|
|
_cogl_texture_rectangle_ensure_non_quad_rendering,
|
2012-09-10 19:35:39 +00:00
|
|
|
_cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes,
|
2010-06-10 14:33:34 +00:00
|
|
|
_cogl_texture_rectangle_get_format,
|
|
|
|
_cogl_texture_rectangle_get_gl_format,
|
2012-02-09 11:19:04 +00:00
|
|
|
_cogl_texture_rectangle_get_type,
|
2012-04-04 14:09:43 +00:00
|
|
|
_cogl_texture_rectangle_is_foreign,
|
|
|
|
_cogl_texture_rectangle_set_auto_mipmap
|
2010-06-10 14:33:34 +00:00
|
|
|
};
|