2010-06-10 10:33:34 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-06-10 10:33:34 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2010-06-10 10:33:34 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2010-06-10 10:33:34 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-06-10 10:33:34 -04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2016-05-05 10:21:51 -04:00
|
|
|
#include "cogl-config.h"
|
2010-06-10 10:33:34 -04:00
|
|
|
#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"
|
2013-09-02 11:02:42 -04:00
|
|
|
#include "cogl-gtype-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);
|
2013-09-02 11:02:42 -04:00
|
|
|
COGL_GTYPE_DEFINE_CLASS (TextureRectangle, texture_rectangle,
|
|
|
|
COGL_GTYPE_IMPLEMENT_INTERFACE (texture));
|
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,
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglTextureLoader *loader)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
|
|
|
CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1);
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_init (tex, ctx, width, height,
|
|
|
|
internal_format, loader,
|
|
|
|
&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-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,
|
2014-01-13 12:16:09 -05:00
|
|
|
int height)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
2014-01-13 12:16:09 -05:00
|
|
|
CoglTextureLoader *loader = _cogl_texture_create_loader ();
|
2013-06-23 11:18:18 -04:00
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
|
|
|
|
loader->src.sized.width = width;
|
|
|
|
loader->src.sized.height = height;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2014-01-13 12:16:09 -05:00
|
|
|
return _cogl_texture_rectangle_create_base (ctx, width, height,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
loader);
|
2012-11-22 18:01:08 -05:00
|
|
|
}
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
static CoglBool
|
2013-06-23 11:18:18 -04:00
|
|
|
allocate_with_size (CoglTextureRectangle *tex_rect,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2012-11-22 18:01:08 -05:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglContext *ctx = tex->context;
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglPixelFormat internal_format;
|
|
|
|
int width = loader->src.sized.width;
|
|
|
|
int height = loader->src.sized.height;
|
2012-11-22 18:01:08 -05:00
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
GLenum gl_texture;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
internal_format =
|
|
|
|
_cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY);
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!_cogl_texture_rectangle_can_create (ctx,
|
2013-06-23 11:18:18 -04:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
internal_format,
|
2012-11-22 18:01:08 -05:00
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
2013-06-23 11:18:18 -04:00
|
|
|
internal_format,
|
2012-11-22 18:01:08 -05:00
|
|
|
&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,
|
2013-06-23 11:18:18 -04:00
|
|
|
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 */
|
2016-05-24 13:37:02 -04:00
|
|
|
_cogl_gl_util_clear_gl_errors (ctx);
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
ctx->glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
|
2013-06-23 11:18:18 -04:00
|
|
|
width, 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
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_rect->internal_format = internal_format;
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
tex_rect->gl_texture = gl_texture;
|
|
|
|
tex_rect->gl_format = gl_intformat;
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
|
|
|
|
internal_format, width, height);
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
return TRUE;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static CoglBool
|
|
|
|
allocate_from_bitmap (CoglTextureRectangle *tex_rect,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2010-06-10 10:33:34 -04:00
|
|
|
{
|
2013-06-23 11:18:18 -04: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 19:28:14 -04:00
|
|
|
CoglBitmap *upload_bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2012-04-04 08:57:42 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format =
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_determine_internal_format (tex, cogl_bitmap_get_format (bmp));
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
if (!_cogl_texture_rectangle_can_create (ctx,
|
2013-06-23 11:18:18 -04:00
|
|
|
width,
|
|
|
|
height,
|
2011-10-14 04:25:12 -04:00
|
|
|
internal_format,
|
2012-04-04 10:10:04 -04:00
|
|
|
error))
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
upload_bmp = _cogl_bitmap_convert_for_upload (bmp,
|
|
|
|
internal_format,
|
|
|
|
can_convert_in_place,
|
|
|
|
error);
|
2013-06-07 19:28:14 -04:00
|
|
|
if (upload_bmp == NULL)
|
2013-06-23 11:18:18 -04: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);
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
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);
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2012-11-08 12:54:10 -05:00
|
|
|
}
|
2010-06-10 10:33:34 -04:00
|
|
|
|
|
|
|
tex_rect->gl_format = gl_intformat;
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_rect->internal_format = internal_format;
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
cogl_object_unref (upload_bmp);
|
2010-06-10 10:33:34 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_rect),
|
|
|
|
internal_format, width, height);
|
2012-11-22 18:01:08 -05:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
return TRUE;
|
2010-06-10 10:33:34 -04:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static CoglBool
|
|
|
|
allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
2010-10-04 10:27:38 -04:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_rect);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
CoglPixelFormat format = loader->src.gl_foreign.format;
|
2012-08-31 21:16:53 -04:00
|
|
|
GLint gl_compressed = GL_FALSE;
|
|
|
|
GLenum gl_int_format = 0;
|
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");
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2012-08-31 21:16:53 -04:00
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Make sure binding succeeds */
|
2016-05-24 13:37:02 -04:00
|
|
|
_cogl_gl_util_clear_gl_errors (ctx);
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
loader->src.gl_foreign.gl_handle, TRUE);
|
2016-05-24 13:37:02 -04:00
|
|
|
if (_cogl_gl_util_get_error (ctx) != 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");
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2012-08-31 21:16:53 -04:00
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Obtain texture parameters */
|
|
|
|
|
2013-01-24 06:40:19 -05:00
|
|
|
#ifdef HAVE_COGL_GL
|
2013-11-25 11:11:36 -05:00
|
|
|
if (_cogl_has_private_feature
|
|
|
|
(ctx, 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");
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2012-08-31 21:16:53 -04:00
|
|
|
}
|
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
|
|
|
|
|
|
|
/* 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");
|
2013-06-23 11:18:18 -04:00
|
|
|
return FALSE;
|
2012-08-31 21:16:53 -04:00
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Setup bitmap info */
|
|
|
|
tex_rect->is_foreign = TRUE;
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_rect->gl_texture = loader->src.gl_foreign.gl_handle;
|
2010-10-04 10:27:38 -04:00
|
|
|
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
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_rect->internal_format = format;
|
2012-11-22 18:01:08 -05:00
|
|
|
|
2013-06-23 11:18:18 -04: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-01 20:48:54 -04:00
|
|
|
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp)
|
2013-06-23 11:18:18 -04: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-01 20:48:54 -04:00
|
|
|
cogl_bitmap_get_format (bmp),
|
2013-06-23 11:18:18 -04:00
|
|
|
loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTextureRectangle *
|
|
|
|
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
|
|
|
|
unsigned int gl_handle,
|
|
|
|
int width,
|
|
|
|
int height,
|
2013-07-01 20:48:54 -04:00
|
|
|
CoglPixelFormat format)
|
2013-06-23 11:18:18 -04: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 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,
|
2013-06-27 13:33:04 -04:00
|
|
|
_cogl_texture_get_format (tex),
|
2013-06-07 19:28:14 -04:00
|
|
|
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,
|
2018-12-19 05:46:45 -05:00
|
|
|
_cogl_texture_rectangle_set_auto_mipmap,
|
|
|
|
NULL /* is_get_data_supported */
|
2010-06-10 10:33:34 -04:00
|
|
|
};
|