Add a strong CoglTexture type to replace CoglHandle

As part of the on going, incremental effort to purge the non type safe
CoglHandle type from the Cogl API this patch tackles most of the
CoglHandle uses relating to textures.

We'd postponed making this change for quite a while because we wanted to
have a clearer understanding of how we wanted to evolve the texture APIs
towards Cogl 2.0 before exposing type safety here which would be
difficult to change later since it would imply breaking APIs.

The basic idea that we are steering towards now is that CoglTexture
can be considered to be the most primitive interface we have for any
object representing a texture. The texture interface would provide
roughly these methods:

  cogl_texture_get_width
  cogl_texture_get_height
  cogl_texture_can_repeat
  cogl_texture_can_mipmap
  cogl_texture_generate_mipmap;
  cogl_texture_get_format
  cogl_texture_set_region
  cogl_texture_get_region

Besides the texture interface we will then start to expose types
corresponding to specific texture types: CoglTexture2D,
CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and
CoglTexturePixmapX11.

We will then also expose an interface for the high-level texture types
we have (such as CoglTexture2DSlice, CoglSubTexture and
CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an
additional interface that lets you iterate a virtual region of a meta
texture and get mappings of primitive textures to sub-regions of that
virtual region. Internally we already have this kind of abstraction for
dealing with sliced texture, sub-textures and atlas textures in a
consistent way, so this will just make that abstraction public. The aim
here is to clarify that there is a difference between primitive textures
(CoglTexture2D/3D) and some of the other high-level textures, and also
enable developers to implement primitives that can support meta textures
since they can only be used with the cogl_rectangle API currently.

The thing that's not so clean-cut with this are the texture constructors
we have currently; such as cogl_texture_new_from_file which no longer
make sense when CoglTexture is considered to be an interface.  These
will basically just become convenient factory functions and it's just a
bit unusual that they are within the cogl_texture namespace.  It's worth
noting here that all the texture type APIs will also have their own type
specific constructors so these functions will only be used for the
convenience of being able to create a texture without really wanting to
know the details of what type of texture you need.  Longer term for 2.0
we may come up with replacement names for these factory functions or the
other thing we are considering is designing some asynchronous factory
functions instead since it's so often detrimental to application
performance to be blocked waiting for a texture to be uploaded to the
GPU.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-08-24 21:30:34 +01:00
parent dfb7c76567
commit 4c3dadd35e
32 changed files with 382 additions and 501 deletions

View File

@ -72,7 +72,7 @@ struct _CoglPangoDisplayListNode
struct
{
/* The texture to render these coords from */
CoglHandle texture;
CoglTexture *texture;
/* Array of rectangles in the format expected by
cogl_rectangles_with_texture_coords */
GArray *rectangles;
@ -134,7 +134,7 @@ _cogl_pango_display_list_remove_color_override (CoglPangoDisplayList *dl)
void
_cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
CoglHandle texture,
CoglTexture *texture,
float x_1, float y_1,
float x_2, float y_2,
float tx_1, float ty_1,
@ -168,7 +168,7 @@ _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
node->color_override = dl->color_override;
node->color = dl->color;
node->pipeline = NULL;
node->d.texture.texture = cogl_handle_ref (texture);
node->d.texture.texture = cogl_object_ref (texture);
node->d.texture.rectangles
= g_array_new (FALSE, FALSE, sizeof (CoglPangoDisplayListRectangle));
node->d.texture.primitive = NULL;
@ -465,8 +465,8 @@ _cogl_pango_display_list_node_free (CoglPangoDisplayListNode *node)
if (node->type == COGL_PANGO_DISPLAY_LIST_TEXTURE)
{
g_array_free (node->d.texture.rectangles, TRUE);
if (node->d.texture.texture != COGL_INVALID_HANDLE)
cogl_handle_unref (node->d.texture.texture);
if (node->d.texture.texture != NULL)
cogl_object_unref (node->d.texture.texture);
if (node->d.texture.primitive != NULL)
cogl_object_unref (node->d.texture.primitive);
}

View File

@ -39,7 +39,7 @@ void _cogl_pango_display_list_set_color_override (CoglPangoDisplayList *dl,
void _cogl_pango_display_list_remove_color_override (CoglPangoDisplayList *dl);
void _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
CoglHandle texture,
CoglTexture *texture,
float x_1, float y_1,
float x_2, float y_2,
float tx_1, float ty_1,

View File

@ -71,7 +71,7 @@ static void
cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value)
{
if (value->texture)
cogl_handle_unref (value->texture);
cogl_object_unref (value->texture);
g_slice_free (CoglPangoGlyphCacheValue, value);
}
@ -178,8 +178,8 @@ cogl_pango_glyph_cache_update_position_cb (void *user_data,
float tex_width, tex_height;
if (value->texture)
cogl_handle_unref (value->texture);
value->texture = cogl_handle_ref (new_texture);
cogl_object_unref (value->texture);
value->texture = cogl_object_ref (new_texture);
tex_width = cogl_texture_get_width (new_texture);
tex_height = cogl_texture_get_height (new_texture);
@ -202,7 +202,7 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
PangoGlyph glyph,
CoglPangoGlyphCacheValue *value)
{
CoglHandle texture;
CoglTexture *texture;
if (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SHARED_ATLAS))
return FALSE;
@ -217,7 +217,7 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
COGL_TEXTURE_NONE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
if (texture == COGL_INVALID_HANDLE)
if (texture == NULL)
return FALSE;
value->texture = texture;
@ -310,7 +310,7 @@ cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache,
PangoRectangle ink_rect;
value = g_slice_new (CoglPangoGlyphCacheValue);
value->texture = COGL_INVALID_HANDLE;
value->texture = NULL;
pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
pango_extents_to_pixels (&ink_rect, NULL);

View File

@ -35,20 +35,20 @@ typedef struct _CoglPangoGlyphCacheValue CoglPangoGlyphCacheValue;
struct _CoglPangoGlyphCacheValue
{
CoglHandle texture;
CoglTexture *texture;
float tx1;
float ty1;
float tx2;
float ty2;
float tx1;
float ty1;
float tx2;
float ty2;
int tx_pixel;
int ty_pixel;
int tx_pixel;
int ty_pixel;
int draw_x;
int draw_y;
int draw_width;
int draw_height;
int draw_x;
int draw_y;
int draw_width;
int draw_height;
/* This will be set to TRUE when the glyph atlas is reorganized
which means the glyph will need to be redrawn */

View File

@ -49,7 +49,7 @@ struct _CoglPangoPipelineCacheEntry
{
/* This will take a reference or it can be NULL to represent the
pipeline used to render colors */
CoglHandle texture;
CoglTexture *texture;
/* This will only take a weak reference */
CoglHandle pipeline;
@ -155,7 +155,7 @@ get_base_texture_alpha_pipeline (CoglPangoPipelineCache *cache)
typedef struct
{
CoglPangoPipelineCache *cache;
CoglHandle texture;
CoglTexture *texture;
} PipelineDestroyNotifyData;
static void
@ -188,7 +188,7 @@ _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache,
{
CoglPipeline *base;
entry->texture = cogl_handle_ref (texture);
entry->texture = cogl_object_ref (texture);
if (cogl_texture_get_format (entry->texture) == COGL_PIXEL_FORMAT_A_8)
base = get_base_texture_alpha_pipeline (cache);
@ -216,7 +216,7 @@ _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache,
pipeline_destroy_notify_cb);
g_hash_table_insert (cache->hash_table,
texture ? cogl_handle_ref (texture) : NULL,
texture ? cogl_object_ref (texture) : NULL,
entry);
/* This doesn't take a reference on the pipeline so that it will use

View File

@ -94,7 +94,7 @@ typedef struct
} CoglPangoRendererSliceCbData;
void
cogl_pango_renderer_slice_cb (CoglHandle handle,
cogl_pango_renderer_slice_cb (CoglTexture *texture,
const float *slice_coords,
const float *virtual_coords,
void *user_data)
@ -106,7 +106,7 @@ cogl_pango_renderer_slice_cb (CoglHandle handle,
coordinates based on the virtual_coords */
_cogl_pango_display_list_add_texture (data->display_list,
handle,
texture,
data->x1,
data->y1,
data->x2,
@ -486,7 +486,7 @@ cogl_pango_renderer_set_dirty_glyph (PangoFont *font,
/* Glyphs that don't take up any space will end up without a
texture. These should never become dirty so they shouldn't end up
here */
g_return_if_fail (value->texture != COGL_INVALID_HANDLE);
g_return_if_fail (value->texture != NULL);
if (cogl_texture_get_format (value->texture) == COGL_PIXEL_FORMAT_A_8)
{

View File

@ -384,7 +384,7 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
/* Notify cogl-pipeline.c that the texture's underlying GL texture
* storage is changing so it knows it may need to bind a new texture
* if the CoglTexture is reused with the same texture unit. */
_cogl_pipeline_texture_storage_change_notify (atlas_tex);
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (atlas_tex));
/* We need to unref the sub texture after doing the copy because
the copy can involve rendering which might cause the texture

View File

@ -339,14 +339,14 @@ validate_layer_cb (CoglPipeline *pipeline,
int layer_index,
void *user_data)
{
CoglHandle texture =
CoglTexture *texture =
_cogl_pipeline_get_layer_texture (pipeline, layer_index);
ValidateLayerState *state = user_data;
gboolean status = TRUE;
/* invalid textures will be handled correctly in
* _cogl_pipeline_flush_layers_gl_state */
if (texture == COGL_INVALID_HANDLE)
if (texture == NULL)
goto validated;
_cogl_texture_flush_journal_rendering (texture);

View File

@ -243,8 +243,8 @@ cogl_context_new (CoglDisplay *display,
context->legacy_state_set = 0;
context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE;
context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE;
context->default_gl_texture_2d_tex = NULL;
context->default_gl_texture_rect_tex = NULL;
context->framebuffers = NULL;
@ -410,9 +410,9 @@ _cogl_context_free (CoglContext *context)
cogl_handle_unref (context->current_path);
if (context->default_gl_texture_2d_tex)
cogl_handle_unref (context->default_gl_texture_2d_tex);
cogl_object_unref (context->default_gl_texture_2d_tex);
if (context->default_gl_texture_rect_tex)
cogl_handle_unref (context->default_gl_texture_rect_tex);
cogl_object_unref (context->default_gl_texture_rect_tex);
if (context->opaque_color_pipeline)
cogl_handle_unref (context->opaque_color_pipeline);

View File

@ -108,7 +108,7 @@ typedef struct _CoglOffscreen
CoglFramebuffer _parent;
GLuint fbo_handle;
GSList *renderbuffers;
CoglHandle texture;
CoglTexture *texture;
} CoglOffscreen;
/* Flags to pass to _cogl_offscreen_new_to_texture_full */
@ -244,7 +244,7 @@ _cogl_free_framebuffer_stack (GSList *stack);
/*
* _cogl_offscreen_new_to_texture_full:
* @texhandle: A handle to the texture to target
* @texture: A #CoglTexture pointer
* @create_flags: Flags specifying how to create the FBO
* @level: The mipmap level within the texture to target
*
@ -256,7 +256,7 @@ _cogl_free_framebuffer_stack (GSList *stack);
* Return value: the new CoglOffscreen object.
*/
CoglHandle
_cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
_cogl_offscreen_new_to_texture_full (CoglTexture *texture,
CoglOffscreenFlags create_flags,
unsigned int level);

View File

@ -682,7 +682,7 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
typedef struct
{
CoglHandle texture;
CoglTexture *texture;
unsigned int level;
unsigned int level_width;
unsigned int level_height;
@ -808,7 +808,7 @@ try_creating_fbo (CoglOffscreen *offscreen,
}
CoglHandle
_cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
_cogl_offscreen_new_to_texture_full (CoglTexture *texture,
CoglOffscreenFlags create_flags,
unsigned int level)
{
@ -824,21 +824,21 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN))
return COGL_INVALID_HANDLE;
/* Make texhandle is a valid texture object */
if (!cogl_is_texture (texhandle))
/* Make texture is a valid texture object */
if (!cogl_is_texture (texture))
return COGL_INVALID_HANDLE;
/* The texture must not be sliced */
if (cogl_texture_is_sliced (texhandle))
if (cogl_texture_is_sliced (texture))
return COGL_INVALID_HANDLE;
data.texture = texhandle;
data.texture = texture;
data.level = level;
/* Calculate the size of the texture at this mipmap level to ensure
that it's a valid level */
data.level_width = cogl_texture_get_width (texhandle);
data.level_height = cogl_texture_get_height (texhandle);
data.level_width = cogl_texture_get_width (texture);
data.level_height = cogl_texture_get_height (texture);
for (i = 0; i < level; i++)
{
@ -863,10 +863,10 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
* the texture is actually used for rendering according to the filters set on
* the corresponding CoglPipeline.
*/
_cogl_texture_set_filters (texhandle, GL_NEAREST, GL_NEAREST);
_cogl_texture_set_filters (texture, GL_NEAREST, GL_NEAREST);
offscreen = g_new0 (CoglOffscreen, 1);
offscreen->texture = texhandle;
offscreen->texture = texture;
if ((create_flags & COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL))
fbo_created = try_creating_fbo (offscreen, 0, &data);
@ -903,15 +903,14 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
_cogl_framebuffer_init (fb,
ctx,
COGL_FRAMEBUFFER_TYPE_OFFSCREEN,
cogl_texture_get_format (texhandle),
cogl_texture_get_format (texture),
data.level_width,
data.level_height);
/* take a reference on the texture */
cogl_handle_ref (offscreen->texture);
cogl_object_ref (offscreen->texture);
ret = _cogl_offscreen_object_new (offscreen);
_cogl_texture_associate_framebuffer (texhandle, COGL_FRAMEBUFFER (ret));
_cogl_texture_associate_framebuffer (texture, COGL_FRAMEBUFFER (ret));
fb->allocated = TRUE;
@ -928,9 +927,9 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle,
}
CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle)
cogl_offscreen_new_to_texture (CoglTexture *texture)
{
return _cogl_offscreen_new_to_texture_full (texhandle, 0, 0);
return _cogl_offscreen_new_to_texture_full (texture, 0, 0);
}
static void
@ -953,7 +952,7 @@ _cogl_offscreen_free (CoglOffscreen *offscreen)
GE (ctx, glDeleteFramebuffers (1, &offscreen->fbo_handle));
if (offscreen->texture != COGL_INVALID_HANDLE)
cogl_handle_unref (offscreen->texture);
cogl_object_unref (offscreen->texture);
g_free (offscreen);
}

View File

@ -76,7 +76,7 @@ _cogl_journal_log_quad (CoglJournal *journal,
const float *position,
CoglPipeline *pipeline,
int n_layers,
CoglHandle layer0_override_texture,
CoglTexture *layer0_override_texture,
const float *tex_coords,
unsigned int tex_coords_len);

View File

@ -1449,7 +1449,7 @@ static gboolean
add_framebuffer_deps_cb (CoglPipelineLayer *layer, void *user_data)
{
CoglFramebuffer *framebuffer = user_data;
CoglHandle texture = _cogl_pipeline_layer_get_texture_real (layer);
CoglTexture *texture = _cogl_pipeline_layer_get_texture_real (layer);
const GList *l;
if (!texture)
@ -1466,7 +1466,7 @@ _cogl_journal_log_quad (CoglJournal *journal,
const float *position,
CoglPipeline *pipeline,
int n_layers,
CoglHandle layer0_override_texture,
CoglTexture *layer0_override_texture,
const float *tex_coords,
unsigned int tex_coords_len)
{

View File

@ -29,6 +29,7 @@
#define __COGL_OFFSCREEN_H__
#include <cogl/cogl-types.h>
#include <cogl/cogl-texture.h>
G_BEGIN_DECLS
@ -44,14 +45,14 @@ G_BEGIN_DECLS
/**
* cogl_offscreen_new_to_texture:
* @handle: A CoglHandle for a Cogl texture
* @texture: A #CoglTexture pointer
*
* This creates an offscreen buffer object using the given texture as the
* This creates an offscreen buffer object using the given @texture as the
* primary color buffer. It doesn't just initialize the contents of the
* offscreen buffer with the texture; they are tightly bound so that
* offscreen buffer with the @texture; they are tightly bound so that
* drawing to the offscreen buffer effectivly updates the contents of the
* given texture. You don't need to destroy the offscreen buffer before
* you can use the texture again.
* you can use the @texture again.
*
* Note: This does not work with sliced Cogl textures.
*
@ -59,7 +60,7 @@ G_BEGIN_DECLS
* buffer or %COGL_INVALID_HANDLE if it wasn't possible to create the
* buffer.
*/
CoglHandle cogl_offscreen_new_to_texture (CoglHandle handle);
CoglHandle cogl_offscreen_new_to_texture (CoglTexture *texture);
/**
* cogl_is_offscreen:

View File

@ -366,7 +366,7 @@ ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
texture = _cogl_pipeline_layer_get_texture (layer);
if (texture == COGL_INVALID_HANDLE)
if (texture == NULL)
{
target_string = "2D";
tex_coord_swizzle = "st";

View File

@ -108,7 +108,7 @@ _cogl_pipeline_set_layer_unit (CoglPipeline *required_owner,
return layer;
}
CoglHandle
CoglTexture *
_cogl_pipeline_layer_get_texture_real (CoglPipelineLayer *layer)
{
CoglPipelineLayer *authority =
@ -118,7 +118,7 @@ _cogl_pipeline_layer_get_texture_real (CoglPipelineLayer *layer)
return authority->texture;
}
CoglHandle
CoglTexture *
_cogl_pipeline_get_layer_texture (CoglPipeline *pipeline,
int layer_index)
{
@ -201,7 +201,7 @@ changed:
static void
_cogl_pipeline_set_layer_texture_data (CoglPipeline *pipeline,
int layer_index,
CoglHandle texture)
CoglTexture *texture)
{
CoglPipelineLayerState change = COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA;
CoglPipelineLayer *layer;
@ -282,7 +282,7 @@ changed:
* with no associated CoglTexture will have a texture target of 0.
*/
static GLenum
get_texture_target (CoglHandle texture)
get_texture_target (CoglTexture *texture)
{
GLuint ignore_handle;
GLenum gl_target;
@ -297,7 +297,7 @@ get_texture_target (CoglHandle texture)
void
cogl_pipeline_set_layer_texture (CoglPipeline *pipeline,
int layer_index,
CoglHandle texture)
CoglTexture *texture)
{
/* For the convenience of fragend code we separate texture state
* into the "target" and the "data", and setting a layer texture
@ -1305,7 +1305,7 @@ cogl_pipeline_set_layer_matrix (CoglPipeline *pipeline,
/* FIXME: deprecate and replace with
* cogl_pipeline_get_layer_texture() instead. */
CoglHandle
CoglTexture *
_cogl_pipeline_layer_get_texture (CoglPipelineLayer *layer)
{
g_return_val_if_fail (_cogl_is_pipeline_layer (layer), NULL);

View File

@ -121,7 +121,7 @@ typedef enum {
* cogl_pipeline_set_layer:
* @pipeline: A #CoglPipeline object
* @layer_index: the index of the layer
* @texture: a #CoglHandle for the layer object
* @texture: a #CoglTexture for the layer object
*
* In addition to the standard OpenGL lighting model a Cogl pipeline may have
* one or more layers comprised of textures that can be blended together in
@ -139,7 +139,7 @@ typedef enum {
void
cogl_pipeline_set_layer_texture (CoglPipeline *pipeline,
int layer_index,
CoglHandle texture);
CoglTexture *texture);
#define cogl_pipeline_remove_layer cogl_pipeline_remove_layer_EXP
/**

View File

@ -217,7 +217,7 @@ _cogl_delete_gl_texture (GLuint gl_texture)
* if it is reused again with the same texture unit.
*/
void
_cogl_pipeline_texture_storage_change_notify (CoglHandle texture)
_cogl_pipeline_texture_storage_change_notify (CoglTexture *texture)
{
int i;
@ -781,11 +781,11 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
unsigned long state = COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA;
CoglPipelineLayer *authority =
_cogl_pipeline_layer_get_authority (layer, state);
CoglHandle texture;
GLuint gl_texture;
GLenum gl_target;
CoglTexture *texture;
GLuint gl_texture;
GLenum gl_target;
texture = (authority->texture == COGL_INVALID_HANDLE ?
texture = (authority->texture == NULL ?
ctx->default_gl_texture_2d_tex :
authority->texture);
@ -897,12 +897,12 @@ _cogl_pipeline_flush_common_gl_state (CoglPipeline *pipeline,
*/
static void
_cogl_pipeline_layer_forward_wrap_modes (CoglPipelineLayer *layer,
CoglHandle texture)
CoglTexture *texture)
{
CoglPipelineWrapModeInternal wrap_mode_s, wrap_mode_t, wrap_mode_p;
GLenum gl_wrap_mode_s, gl_wrap_mode_t, gl_wrap_mode_p;
if (texture == COGL_INVALID_HANDLE)
if (texture == NULL)
return;
_cogl_pipeline_layer_get_wrap_modes (layer,
@ -964,9 +964,9 @@ foreach_texture_unit_update_filter_and_wrap_modes (void)
if (unit->layer)
{
CoglHandle texture = _cogl_pipeline_layer_get_texture (unit->layer);
CoglTexture *texture = _cogl_pipeline_layer_get_texture (unit->layer);
if (texture != COGL_INVALID_HANDLE)
if (texture != NULL)
{
CoglPipelineFilter min;
CoglPipelineFilter mag;

View File

@ -387,9 +387,9 @@ struct _CoglPipelineLayer
/* Each layer is directly associated with a single texture unit */
int unit_index;
/* The texture for this layer, or COGL_INVALID_HANDLE for an empty
/* The texture for this layer, or NULL for an empty
* layer */
CoglHandle texture;
CoglTexture *texture;
GLenum target;
CoglPipelineFilter mag_filter;
@ -1006,7 +1006,7 @@ typedef struct _CoglPipelineFlushOptions
guint32 fallback_layers;
guint32 disable_layers;
CoglHandle layer0_override_texture;
CoglTexture *layer0_override_texture;
} CoglPipelineFlushOptions;
void
@ -1194,7 +1194,7 @@ _cogl_pipeline_get_layer_matrix (CoglPipeline *pipeline,
int layer_index);
void
_cogl_pipeline_texture_storage_change_notify (CoglHandle texture);
_cogl_pipeline_texture_storage_change_notify (CoglTexture *texture);
void
_cogl_pipeline_apply_legacy_state (CoglPipeline *pipeline);
@ -1229,7 +1229,7 @@ _cogl_pipeline_find_equivalent_parent (CoglPipeline *pipeline,
CoglPipelineState pipeline_state,
CoglPipelineLayerState layer_state);
CoglHandle
CoglTexture *
_cogl_pipeline_get_layer_texture (CoglPipeline *pipeline,
int layer_index);
@ -1273,10 +1273,10 @@ typedef enum {
CoglPipelineLayerType
_cogl_pipeline_layer_get_type (CoglPipelineLayer *layer);
CoglHandle
CoglTexture *
_cogl_pipeline_layer_get_texture (CoglPipelineLayer *layer);
CoglHandle
CoglTexture *
_cogl_pipeline_layer_get_texture_real (CoglPipelineLayer *layer);
CoglPipelineFilter
@ -1302,7 +1302,7 @@ CoglPipelineLayer *
_cogl_pipeline_layer_get_authority (CoglPipelineLayer *layer,
unsigned long difference);
CoglHandle
CoglTexture *
_cogl_pipeline_layer_get_texture (CoglPipelineLayer *layer);
typedef gboolean (*CoglPipelineInternalLayerCallback) (CoglPipelineLayer *layer,

View File

@ -2149,7 +2149,7 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data)
COGL_COUNTER_INC (_cogl_uprof_context, layer_fallback_counter);
if (G_LIKELY (texture != COGL_INVALID_HANDLE))
if (G_LIKELY (texture != NULL))
cogl_texture_get_gl_texture (texture, NULL, &gl_target);
else
gl_target = GL_TEXTURE_2D;
@ -3161,7 +3161,7 @@ _cogl_pipeline_layer_pre_paint (CoglPipelineLayer *layer)
_cogl_pipeline_layer_get_authority (layer,
COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA);
if (texture_authority->texture != COGL_INVALID_HANDLE)
if (texture_authority->texture != NULL)
{
CoglTexturePrePaintFlags flags = 0;
CoglPipelineFilter min_filter;

View File

@ -46,7 +46,7 @@
typedef struct _TextureSlicedQuadState
{
CoglPipeline *pipeline;
CoglHandle main_texture;
CoglTexture *main_texture;
float tex_virtual_origin_x;
float tex_virtual_origin_y;
float quad_origin_x;
@ -68,14 +68,14 @@ typedef struct _TextureSlicedPolygonState
} TextureSlicedPolygonState;
static void
log_quad_sub_textures_cb (CoglHandle texture_handle,
log_quad_sub_textures_cb (CoglTexture *texture,
const float *subtexture_coords,
const float *virtual_coords,
void *user_data)
{
TextureSlicedQuadState *state = user_data;
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
CoglHandle texture_override;
CoglTexture *texture_override;
float quad_coords[4];
#define TEX_VIRTUAL_TO_QUAD(V, Q, AXIS) \
@ -112,10 +112,10 @@ log_quad_sub_textures_cb (CoglHandle texture_handle,
/* We only need to override the texture if it's different from the
main texture */
if (texture_handle == state->main_texture)
texture_override = COGL_INVALID_HANDLE;
if (texture == state->main_texture)
texture_override = NULL;
else
texture_override = texture_handle;
texture_override = texture;
_cogl_journal_log_quad (framebuffer->journal,
quad_coords,
@ -180,7 +180,7 @@ validate_first_layer_cb (CoglPipeline *pipeline,
*/
/* TODO: support multitexturing */
static void
_cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
_cogl_texture_quad_multiple_primitives (CoglTexture *texture,
CoglPipeline *pipeline,
gboolean clamp_s,
gboolean clamp_t,
@ -220,7 +220,7 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
(position[2] - position[0]) *
(tx_1 - old_tx_1) / (old_tx_2 - old_tx_1)),
position[3] };
_cogl_texture_quad_multiple_primitives (tex_handle, pipeline,
_cogl_texture_quad_multiple_primitives (texture, pipeline,
FALSE, clamp_t,
tmp_position,
tx_1, ty_1, tx_1, ty_2);
@ -235,7 +235,7 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
(position[2] - position[0]) *
(tx_2 - old_tx_1) / (old_tx_2 - old_tx_1)),
position[1], position[2], position[3] };
_cogl_texture_quad_multiple_primitives (tex_handle, pipeline,
_cogl_texture_quad_multiple_primitives (texture, pipeline,
FALSE, clamp_t,
tmp_position,
tx_2, ty_1, tx_2, ty_2);
@ -267,7 +267,7 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
(position[1] +
(position[3] - position[1]) *
(ty_1 - old_ty_1) / (old_ty_2 - old_ty_1)) };
_cogl_texture_quad_multiple_primitives (tex_handle, pipeline,
_cogl_texture_quad_multiple_primitives (texture, pipeline,
clamp_s, FALSE,
tmp_position,
tx_1, ty_1, tx_2, ty_1);
@ -283,7 +283,7 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
(position[3] - position[1]) *
(ty_2 - old_ty_1) / (old_ty_2 - old_ty_1)),
position[2], position[3] };
_cogl_texture_quad_multiple_primitives (tex_handle, pipeline,
_cogl_texture_quad_multiple_primitives (texture, pipeline,
clamp_s, FALSE,
tmp_position,
tx_1, ty_2, tx_2, ty_2);
@ -302,7 +302,7 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
validate_first_layer_cb,
&validate_first_layer_state);
state.main_texture = tex_handle;
state.main_texture = texture;
if (validate_first_layer_state.override_pipeline)
state.pipeline = validate_first_layer_state.override_pipeline;
@ -350,7 +350,7 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
state.v_to_q_scale_x = fabs (state.quad_len_x / (tx_2 - tx_1));
state.v_to_q_scale_y = fabs (state.quad_len_y / (ty_2 - ty_1));
_cogl_texture_foreach_sub_texture_in_region (tex_handle,
_cogl_texture_foreach_sub_texture_in_region (texture,
tx_1, ty_1, tx_2, ty_2,
log_quad_sub_textures_cb,
&state);
@ -379,7 +379,7 @@ validate_tex_coords_cb (CoglPipeline *pipeline,
void *user_data)
{
ValidateTexCoordsState *state = user_data;
CoglHandle texture;
CoglTexture *texture;
const float *in_tex_coords;
float *out_tex_coords;
float default_tex_coords[4] = {0.0, 0.0, 1.0, 1.0};
@ -457,7 +457,7 @@ validate_tex_coords_cb (CoglPipeline *pipeline,
"supported with multi-texturing.", state->i);
warning_seen = TRUE;
cogl_pipeline_set_layer_texture (texture, layer_index, NULL);
cogl_pipeline_set_layer_texture (pipeline, layer_index, NULL);
}
}
@ -543,7 +543,7 @@ _cogl_multitexture_quad_single_primitive (const float *position,
position,
pipeline,
n_layers,
COGL_INVALID_HANDLE, /* no texture override */
NULL, /* no texture override */
final_tex_coords,
n_layers * 4);
@ -567,7 +567,7 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
void *user_data)
{
ValidateLayerState *state = user_data;
CoglHandle texture;
CoglTexture *texture;
state->i++;
@ -615,9 +615,9 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
texture = _cogl_pipeline_get_layer_texture (pipeline, layer_index);
/* COGL_INVALID_HANDLE textures are handled by
/* NULL textures are handled by
* _cogl_pipeline_flush_gl_state */
if (texture == COGL_INVALID_HANDLE)
if (texture == NULL)
return TRUE;
if (state->i == 0)
@ -753,7 +753,7 @@ _cogl_rectangles_with_multitexture_coords (
for (i = 0; i < n_rects; i++)
{
CoglHandle texture;
CoglTexture *texture;
const float default_tex_coords[4] = {0.0, 0.0, 1.0, 1.0};
const float *tex_coords;
gboolean clamp_s, clamp_t;
@ -981,19 +981,19 @@ append_tex_coord_attributes_cb (CoglPipeline *pipeline,
void *user_data)
{
AppendTexCoordsState *state = user_data;
CoglHandle tex_handle;
CoglTexture *texture;
float tx, ty;
float *t;
tx = state->vertices_in[state->vertex].tx;
ty = state->vertices_in[state->vertex].ty;
/* COGL_INVALID_HANDLE textures will be handled in
/* NULL textures will be handled in
* _cogl_pipeline_flush_layers_gl_state but there is no need to worry
* about scaling texture coordinates in this case */
tex_handle = _cogl_pipeline_get_layer_texture (pipeline, layer_index);
if (tex_handle != COGL_INVALID_HANDLE)
_cogl_texture_transform_coords_to_gl (tex_handle, &tx, &ty);
texture = _cogl_pipeline_get_layer_texture (pipeline, layer_index);
if (texture != NULL)
_cogl_texture_transform_coords_to_gl (texture, &tx, &ty);
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
t = state->vertices_out + 3 + 2 * state->layer;

View File

@ -155,7 +155,7 @@ typedef struct _CoglSubTextureForeachData
} CoglSubTextureForeachData;
static void
_cogl_sub_texture_foreach_cb (CoglHandle handle,
_cogl_sub_texture_foreach_cb (CoglTexture *texture,
const float *slice_coords,
const float *full_virtual_coords,
void *user_data)
@ -173,7 +173,7 @@ _cogl_sub_texture_foreach_cb (CoglHandle handle,
&virtual_coords[2],
&virtual_coords[3]);
data->callback (handle,
data->callback (texture,
slice_coords, virtual_coords,
data->user_data);
}

View File

@ -67,7 +67,7 @@ typedef struct
} ForeachData;
static void
_cogl_texture_2d_sliced_foreach_cb (CoglHandle handle,
_cogl_texture_2d_sliced_foreach_cb (CoglTexture *texture,
const float *slice_coords,
const float *virtual_coords_in,
void *user_data)
@ -86,7 +86,7 @@ _cogl_texture_2d_sliced_foreach_cb (CoglHandle handle,
virtual_coords_out[3] = (virtual_coords_in[3] * data->y_span->size +
data->y_span->start) / data->tex->height;
data->callback (handle,
data->callback (texture,
slice_coords,
virtual_coords_out,
data->user_data);

View File

@ -28,12 +28,9 @@
#include "cogl-handle.h"
#include "cogl-pipeline-private.h"
#define COGL_TEXTURE(tex) ((CoglTexture *)(tex))
typedef struct _CoglTexture CoglTexture;
typedef struct _CoglTextureVtable CoglTextureVtable;
typedef void (*CoglTextureSliceCallback) (CoglHandle handle,
typedef void (*CoglTextureSliceCallback) (CoglTexture *texture,
const float *slice_coords,
const float *virtual_coords,
void *user_data);
@ -136,7 +133,7 @@ struct _CoglTextureVtable
struct _CoglTexture
{
CoglHandleObject _parent;
CoglObject _parent;
GList *framebuffers;
const CoglTextureVtable *vtable;
};
@ -193,7 +190,7 @@ _cogl_texture_register_texture_type (GQuark type);
## type_name ## _get_type ()))
void
_cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
_cogl_texture_foreach_sub_texture_in_region (CoglTexture *texture,
float virtual_tx_1,
float virtual_ty_1,
float virtual_tx_2,
@ -202,36 +199,36 @@ _cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
void *user_data);
gboolean
_cogl_texture_can_hardware_repeat (CoglHandle handle);
_cogl_texture_can_hardware_repeat (CoglTexture *texture);
void
_cogl_texture_transform_coords_to_gl (CoglHandle handle,
_cogl_texture_transform_coords_to_gl (CoglTexture *texture,
float *s,
float *t);
CoglTransformResult
_cogl_texture_transform_quad_coords_to_gl (CoglHandle handle,
_cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture,
float *coords);
GLenum
_cogl_texture_get_gl_format (CoglHandle handle);
_cogl_texture_get_gl_format (CoglTexture *texture);
void
_cogl_texture_set_wrap_mode_parameters (CoglHandle handle,
_cogl_texture_set_wrap_mode_parameters (CoglTexture *texture,
GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_p);
void
_cogl_texture_set_filters (CoglHandle handle,
_cogl_texture_set_filters (CoglTexture *texture,
GLenum min_filter,
GLenum mag_filter);
void
_cogl_texture_pre_paint (CoglHandle handle, CoglTexturePrePaintFlags flags);
_cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags);
void
_cogl_texture_ensure_non_quad_rendering (CoglHandle handle);
_cogl_texture_ensure_non_quad_rendering (CoglTexture *texture);
/* Utility function to determine which pixel format to use when
dst_format is COGL_PIXEL_FORMAT_ANY. If dst_format is not ANY then
@ -274,22 +271,22 @@ _cogl_texture_iterate_manual_repeats (CoglTextureManualRepeatCallback callback,
texture via the framebuffer */
gboolean
_cogl_texture_draw_and_read (CoglHandle handle,
_cogl_texture_draw_and_read (CoglTexture *texture,
CoglBitmap *target_bmp,
GLuint target_gl_format,
GLuint target_gl_type);
gboolean
_cogl_texture_is_foreign (CoglHandle handle);
_cogl_texture_is_foreign (CoglTexture *texture);
void
_cogl_texture_associate_framebuffer (CoglHandle handle,
_cogl_texture_associate_framebuffer (CoglTexture *texture,
CoglFramebuffer *framebuffer);
const GList *
_cogl_texture_get_associated_framebuffers (CoglHandle handle);
_cogl_texture_get_associated_framebuffers (CoglTexture *texture);
void
_cogl_texture_flush_journal_rendering (CoglHandle handle);
_cogl_texture_flush_journal_rendering (CoglTexture *texture);
#endif /* __COGL_TEXTURE_PRIVATE_H */

View File

@ -79,14 +79,14 @@ _cogl_texture_register_texture_type (GQuark type)
}
gboolean
cogl_is_texture (CoglHandle handle)
cogl_is_texture (void *object)
{
CoglHandleObject *obj = (CoglHandleObject *)handle;
CoglObject *obj = (CoglObject *)object;
GSList *l;
_COGL_GET_CONTEXT (ctxt, FALSE);
if (handle == COGL_INVALID_HANDLE)
if (object == NULL)
return FALSE;
for (l = ctxt->texture_types; l; l = l->next)
@ -96,33 +96,33 @@ cogl_is_texture (CoglHandle handle)
return FALSE;
}
CoglHandle
cogl_texture_ref (CoglHandle handle)
void *
cogl_texture_ref (void *object)
{
if (!cogl_is_texture (handle))
return COGL_INVALID_HANDLE;
if (!cogl_is_texture (object))
return NULL;
_COGL_HANDLE_DEBUG_REF (CoglTexture, handle);
_COGL_OBJECT_DEBUG_REF (CoglTexture, object);
cogl_handle_ref (handle);
cogl_object_ref (object);
return handle;
return object;
}
void
cogl_texture_unref (CoglHandle handle)
cogl_texture_unref (void *object)
{
if (!cogl_is_texture (handle))
if (!cogl_is_texture (object))
{
g_warning (G_STRINGIFY (cogl_texture_unref)
": Ignoring unref of Cogl handle "
": Ignoring unref of CoglObject "
"due to type mismatch");
return;
}
_COGL_HANDLE_DEBUG_UNREF (CoglTexture, handle);
_COGL_OBJECT_DEBUG_UNREF (CoglTexture, object);
cogl_handle_unref (handle);
cogl_object_unref (object);
}
void
@ -281,17 +281,15 @@ _cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride)
/* FIXME: wrap modes should be set on pipelines not textures */
void
_cogl_texture_set_wrap_mode_parameters (CoglHandle handle,
_cogl_texture_set_wrap_mode_parameters (CoglTexture *texture,
GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_p)
{
CoglTexture *tex = COGL_TEXTURE (handle);
tex->vtable->set_wrap_mode_parameters (tex,
wrap_mode_s,
wrap_mode_t,
wrap_mode_p);
texture->vtable->set_wrap_mode_parameters (texture,
wrap_mode_s,
wrap_mode_t,
wrap_mode_p);
}
/* This is like CoglSpanIter except it deals with floats and it
@ -389,32 +387,33 @@ _cogl_texture_iterate_manual_repeats (CoglTextureManualRepeatCallback callback,
}
}
CoglHandle
CoglTexture *
cogl_texture_new_with_size (unsigned int width,
unsigned int height,
CoglTextureFlags flags,
CoglPixelFormat internal_format)
{
CoglHandle tex;
CoglTexture *tex;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
/* First try creating a fast-path non-sliced texture */
tex = cogl_texture_2d_new_with_size (ctx,
width, height, internal_format,
NULL);
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height,
internal_format,
NULL));
/* If it fails resort to sliced textures */
if (tex == COGL_INVALID_HANDLE)
tex = _cogl_texture_2d_sliced_new_with_size (width,
height,
flags,
internal_format);
if (tex == NULL)
tex = COGL_TEXTURE (_cogl_texture_2d_sliced_new_with_size (width,
height,
flags,
internal_format));
return tex;
}
CoglHandle
CoglTexture *
cogl_texture_new_from_data (unsigned int width,
unsigned int height,
CoglTextureFlags flags,
@ -424,13 +423,13 @@ cogl_texture_new_from_data (unsigned int width,
const guint8 *data)
{
CoglBitmap *bmp;
CoglHandle tex;
CoglTexture *tex;
if (format == COGL_PIXEL_FORMAT_ANY)
return COGL_INVALID_HANDLE;
return NULL;
if (data == NULL)
return COGL_INVALID_HANDLE;
return NULL;
/* Rowstride from width if not given */
if (rowstride == 0)
@ -451,47 +450,47 @@ cogl_texture_new_from_data (unsigned int width,
return tex;
}
CoglHandle
cogl_texture_new_from_bitmap (CoglHandle bmp_handle,
CoglTexture *
cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
CoglTextureFlags flags,
CoglPixelFormat internal_format)
{
CoglHandle tex;
CoglTexture *tex;
/* First try putting the texture in the atlas */
if ((tex = _cogl_atlas_texture_new_from_bitmap (bmp_handle,
if ((tex = _cogl_atlas_texture_new_from_bitmap (bitmap,
flags,
internal_format)))
return tex;
/* If that doesn't work try a fast path 2D texture */
if ((tex = _cogl_texture_2d_new_from_bitmap (bmp_handle,
if ((tex = _cogl_texture_2d_new_from_bitmap (bitmap,
flags,
internal_format,
NULL)))
return tex;
/* Otherwise create a sliced texture */
return _cogl_texture_2d_sliced_new_from_bitmap (bmp_handle,
return _cogl_texture_2d_sliced_new_from_bitmap (bitmap,
flags,
internal_format);
}
CoglHandle
CoglTexture *
cogl_texture_new_from_file (const char *filename,
CoglTextureFlags flags,
CoglPixelFormat internal_format,
GError **error)
{
CoglBitmap *bmp;
CoglHandle handle = COGL_INVALID_HANDLE;
CoglTexture *texture = NULL;
CoglPixelFormat src_format;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
bmp = cogl_bitmap_new_from_file (filename, error);
if (bmp == NULL)
return COGL_INVALID_HANDLE;
return NULL;
src_format = _cogl_bitmap_get_format (bmp);
@ -503,14 +502,14 @@ cogl_texture_new_from_file (const char *filename,
_cogl_texture_determine_internal_format (src_format, internal_format);
if (!_cogl_texture_needs_premult_conversion (src_format, internal_format) ||
_cogl_bitmap_convert_premult_status (bmp, src_format ^ COGL_PREMULT_BIT))
handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
texture = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
cogl_object_unref (bmp);
return handle;
return texture;
}
CoglHandle
CoglTexture *
cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target,
GLuint width,
@ -549,43 +548,37 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
else
{
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
return cogl_texture_2d_new_from_foreign (ctx,
gl_handle,
width,
height,
format,
NULL);
return COGL_TEXTURE (cogl_texture_2d_new_from_foreign (ctx,
gl_handle,
width,
height,
format,
NULL));
}
}
gboolean
_cogl_texture_is_foreign (CoglHandle handle)
_cogl_texture_is_foreign (CoglTexture *texture)
{
CoglTexture *tex;
g_return_val_if_fail (cogl_is_texture (handle), FALSE);
tex = COGL_TEXTURE (handle);
if (tex->vtable->is_foreign)
return tex->vtable->is_foreign (tex);
if (texture->vtable->is_foreign)
return texture->vtable->is_foreign (texture);
else
return FALSE;
}
CoglHandle
cogl_texture_new_from_sub_texture (CoglHandle full_texture,
int sub_x,
int sub_y,
int sub_width,
int sub_height)
CoglTexture *
cogl_texture_new_from_sub_texture (CoglTexture *full_texture,
int sub_x,
int sub_y,
int sub_width,
int sub_height)
{
return _cogl_sub_texture_new (full_texture, sub_x, sub_y,
sub_width, sub_height);
}
CoglHandle
cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
CoglTexture *
cogl_texture_new_from_buffer_EXP (CoglPixelBuffer *buffer,
unsigned int width,
unsigned int height,
CoglTextureFlags flags,
@ -594,15 +587,15 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
unsigned int rowstride,
const unsigned int offset)
{
CoglHandle texture;
CoglTexture *texture;
CoglBuffer *cogl_buffer;
CoglPixelBuffer *pixel_buffer;
CoglBitmap *bmp;
g_return_val_if_fail (cogl_is_buffer (buffer), COGL_INVALID_HANDLE);
g_return_val_if_fail (cogl_is_buffer (buffer), NULL);
if (format == COGL_PIXEL_FORMAT_ANY)
return COGL_INVALID_HANDLE;
return NULL;
cogl_buffer = COGL_BUFFER (buffer);
pixel_buffer = COGL_PIXEL_BUFFER (buffer);
@ -623,7 +616,7 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
/* no width or height specified, neither at creation time (because the
* array was created by cogl_pixel_buffer_new()) nor when calling this
* function */
return COGL_INVALID_HANDLE;
return NULL;
}
/* Wrap the buffer into a bitmap */
@ -641,87 +634,45 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
}
unsigned int
cogl_texture_get_width (CoglHandle handle)
cogl_texture_get_width (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return 0;
tex = COGL_TEXTURE (handle);
return tex->vtable->get_width (tex);
return texture->vtable->get_width (texture);
}
unsigned int
cogl_texture_get_height (CoglHandle handle)
cogl_texture_get_height (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return 0;
tex = COGL_TEXTURE (handle);
return tex->vtable->get_height (tex);
return texture->vtable->get_height (texture);
}
CoglPixelFormat
cogl_texture_get_format (CoglHandle handle)
cogl_texture_get_format (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return COGL_PIXEL_FORMAT_ANY;
tex = COGL_TEXTURE (handle);
return tex->vtable->get_format (tex);
return texture->vtable->get_format (texture);
}
unsigned int
cogl_texture_get_rowstride (CoglHandle handle)
cogl_texture_get_rowstride (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return 0;
/* FIXME: This function should go away. It previously just returned
the rowstride that was used to upload the data as far as I can
tell. This is not helpful */
tex = COGL_TEXTURE (handle);
/* Just guess at a suitable rowstride */
return (_cogl_get_format_bpp (cogl_texture_get_format (tex))
* cogl_texture_get_width (tex));
return (_cogl_get_format_bpp (cogl_texture_get_format (texture))
* cogl_texture_get_width (texture));
}
int
cogl_texture_get_max_waste (CoglHandle handle)
cogl_texture_get_max_waste (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return 0;
tex = COGL_TEXTURE (handle);
return tex->vtable->get_max_waste (tex);
return texture->vtable->get_max_waste (texture);
}
gboolean
cogl_texture_is_sliced (CoglHandle handle)
cogl_texture_is_sliced (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return FALSE;
tex = COGL_TEXTURE (handle);
return tex->vtable->is_sliced (tex);
return texture->vtable->is_sliced (texture);
}
/* Some CoglTextures, notably sliced textures or atlas textures when repeating
@ -734,7 +685,7 @@ cogl_texture_is_sliced (CoglHandle handle)
* region specified in texture coordinates.
*/
void
_cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
_cogl_texture_foreach_sub_texture_in_region (CoglTexture *texture,
float virtual_tx_1,
float virtual_ty_1,
float virtual_tx_2,
@ -742,15 +693,13 @@ _cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
CoglTextureSliceCallback callback,
void *user_data)
{
CoglTexture *tex = COGL_TEXTURE (handle);
tex->vtable->foreach_sub_texture_in_region (tex,
virtual_tx_1,
virtual_ty_1,
virtual_tx_2,
virtual_ty_2,
callback,
user_data);
texture->vtable->foreach_sub_texture_in_region (texture,
virtual_tx_1,
virtual_ty_1,
virtual_tx_2,
virtual_ty_2,
callback,
user_data);
}
/* If this returns FALSE, that implies _foreach_sub_texture_in_region
@ -758,101 +707,66 @@ _cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
* texture coordinates extend out of the range [0,1]
*/
gboolean
_cogl_texture_can_hardware_repeat (CoglHandle handle)
_cogl_texture_can_hardware_repeat (CoglTexture *texture)
{
CoglTexture *tex = (CoglTexture *)handle;
return tex->vtable->can_hardware_repeat (tex);
return texture->vtable->can_hardware_repeat (texture);
}
/* NB: You can't use this with textures comprised of multiple sub textures (use
* cogl_texture_is_sliced() to check) since coordinate transformation for such
* textures will be different for each slice. */
void
_cogl_texture_transform_coords_to_gl (CoglHandle handle,
_cogl_texture_transform_coords_to_gl (CoglTexture *texture,
float *s,
float *t)
{
CoglTexture *tex = COGL_TEXTURE (handle);
tex->vtable->transform_coords_to_gl (tex, s, t);
texture->vtable->transform_coords_to_gl (texture, s, t);
}
CoglTransformResult
_cogl_texture_transform_quad_coords_to_gl (CoglHandle handle,
_cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture,
float *coords)
{
CoglTexture *tex = COGL_TEXTURE (handle);
return tex->vtable->transform_quad_coords_to_gl (tex, coords);
return texture->vtable->transform_quad_coords_to_gl (texture, coords);
}
GLenum
_cogl_texture_get_gl_format (CoglHandle handle)
_cogl_texture_get_gl_format (CoglTexture *texture)
{
CoglTexture *tex = COGL_TEXTURE (handle);
return tex->vtable->get_gl_format (tex);
return texture->vtable->get_gl_format (texture);
}
gboolean
cogl_texture_get_gl_texture (CoglHandle handle,
cogl_texture_get_gl_texture (CoglTexture *texture,
GLuint *out_gl_handle,
GLenum *out_gl_target)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return FALSE;
tex = COGL_TEXTURE (handle);
return tex->vtable->get_gl_texture (tex, out_gl_handle, out_gl_target);
return texture->vtable->get_gl_texture (texture,
out_gl_handle, out_gl_target);
}
void
_cogl_texture_set_filters (CoglHandle handle,
_cogl_texture_set_filters (CoglTexture *texture,
GLenum min_filter,
GLenum mag_filter)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return;
tex = COGL_TEXTURE (handle);
tex->vtable->set_filters (tex, min_filter, mag_filter);
texture->vtable->set_filters (texture, min_filter, mag_filter);
}
void
_cogl_texture_pre_paint (CoglHandle handle, CoglTexturePrePaintFlags flags)
_cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return;
tex = COGL_TEXTURE (handle);
tex->vtable->pre_paint (tex, flags);
texture->vtable->pre_paint (texture, flags);
}
void
_cogl_texture_ensure_non_quad_rendering (CoglHandle handle)
_cogl_texture_ensure_non_quad_rendering (CoglTexture *texture)
{
CoglTexture *tex;
if (!cogl_is_texture (handle))
return;
tex = COGL_TEXTURE (handle);
tex->vtable->ensure_non_quad_rendering (tex);
texture->vtable->ensure_non_quad_rendering (texture);
}
gboolean
cogl_texture_set_region_from_bitmap (CoglHandle handle,
cogl_texture_set_region_from_bitmap (CoglTexture *texture,
int src_x,
int src_y,
int dst_x,
@ -861,8 +775,7 @@ cogl_texture_set_region_from_bitmap (CoglHandle handle,
unsigned int dst_height,
CoglBitmap *bmp)
{
CoglTexture *tex = COGL_TEXTURE (handle);
gboolean ret;
gboolean ret;
/* Shortcut out early if the image is empty */
if (dst_width == 0 || dst_height == 0)
@ -875,17 +788,17 @@ cogl_texture_set_region_from_bitmap (CoglHandle handle,
always stored in an RGBA texture even if the texture format is
advertised as RGB. */
ret = tex->vtable->set_region (handle,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
bmp);
ret = texture->vtable->set_region (texture,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
bmp);
return ret;
}
gboolean
cogl_texture_set_region (CoglHandle handle,
cogl_texture_set_region (CoglTexture *texture,
int src_x,
int src_y,
int dst_x,
@ -918,7 +831,7 @@ cogl_texture_set_region (CoglHandle handle,
NULL, /* destroy_fn */
NULL); /* destroy_fn_data */
ret = cogl_texture_set_region_from_bitmap (handle,
ret = cogl_texture_set_region_from_bitmap (texture,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
@ -943,7 +856,7 @@ cogl_texture_set_region (CoglHandle handle,
* glGetTexImage, but may be used as a fallback in some circumstances.
*/
static void
do_texture_draw_and_read (CoglHandle handle,
do_texture_draw_and_read (CoglTexture *texture,
CoglBitmap *target_bmp,
float *viewport)
{
@ -958,8 +871,8 @@ do_texture_draw_and_read (CoglHandle handle,
bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
tex_width = cogl_texture_get_width (handle);
tex_height = cogl_texture_get_height (handle);
tex_width = cogl_texture_get_width (texture);
tex_height = cogl_texture_get_height (texture);
ry2 = 0;
ty2 = 0;
@ -1045,7 +958,7 @@ do_texture_draw_and_read (CoglHandle handle,
* glGetTexImage, but may be used as a fallback in some circumstances.
*/
gboolean
_cogl_texture_draw_and_read (CoglHandle handle,
_cogl_texture_draw_and_read (CoglTexture *texture,
CoglBitmap *target_bmp,
GLuint target_gl_format,
GLuint target_gl_type)
@ -1091,7 +1004,7 @@ _cogl_texture_draw_and_read (CoglHandle handle,
/* Direct copy operation */
if (ctx->texture_download_pipeline == COGL_INVALID_HANDLE)
if (ctx->texture_download_pipeline == NULL)
{
ctx->texture_download_pipeline = cogl_pipeline_new ();
cogl_pipeline_set_blend (ctx->texture_download_pipeline,
@ -1101,7 +1014,7 @@ _cogl_texture_draw_and_read (CoglHandle handle,
_cogl_push_source (ctx->texture_download_pipeline, FALSE);
cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, handle);
cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, texture);
cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
0, /* layer */
@ -1112,7 +1025,7 @@ _cogl_texture_draw_and_read (CoglHandle handle,
COGL_PIPELINE_FILTER_NEAREST,
COGL_PIPELINE_FILTER_NEAREST);
do_texture_draw_and_read (handle, target_bmp, viewport);
do_texture_draw_and_read (texture, target_bmp, viewport);
/* Check whether texture has alpha and framebuffer not */
/* FIXME: For some reason even if ALPHA_BITS is 8, the framebuffer
@ -1127,7 +1040,7 @@ _cogl_texture_draw_and_read (CoglHandle handle,
printf ("G bits: %d\n", g_bits);
printf ("B bits: %d\n", b_bits);
printf ("A bits: %d\n", a_bits); */
if ((cogl_texture_get_format (handle) & COGL_A_BIT)/* && a_bits == 0*/)
if ((cogl_texture_get_format (texture) & COGL_A_BIT)/* && a_bits == 0*/)
{
guint8 *srcdata;
guint8 *dstdata;
@ -1157,7 +1070,7 @@ _cogl_texture_draw_and_read (CoglHandle handle,
"RGBA = REPLACE (TEXTURE[A])",
NULL);
do_texture_draw_and_read (handle, alpha_bmp, viewport);
do_texture_draw_and_read (texture, alpha_bmp, viewport);
/* Copy temp R to target A */
@ -1189,7 +1102,7 @@ _cogl_texture_draw_and_read (CoglHandle handle,
}
static gboolean
get_texture_bits_via_offscreen (CoglHandle texture_handle,
get_texture_bits_via_offscreen (CoglTexture *texture,
int x,
int y,
int width,
@ -1206,7 +1119,7 @@ get_texture_bits_via_offscreen (CoglHandle texture_handle,
return FALSE;
framebuffer = _cogl_offscreen_new_to_texture_full
(texture_handle,
(texture,
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
0);
@ -1227,7 +1140,7 @@ get_texture_bits_via_offscreen (CoglHandle texture_handle,
}
static gboolean
get_texture_bits_via_copy (CoglHandle texture_handle,
get_texture_bits_via_copy (CoglTexture *texture,
int x,
int y,
int width,
@ -1236,25 +1149,24 @@ get_texture_bits_via_copy (CoglHandle texture_handle,
unsigned int dst_rowstride,
CoglPixelFormat dst_format)
{
CoglTexture *tex = COGL_TEXTURE (texture_handle);
unsigned int full_rowstride;
guint8 *full_bits;
gboolean ret = TRUE;
int bpp;
int full_tex_width, full_tex_height;
full_tex_width = cogl_texture_get_width (texture_handle);
full_tex_height = cogl_texture_get_height (texture_handle);
full_tex_width = cogl_texture_get_width (texture);
full_tex_height = cogl_texture_get_height (texture);
bpp = _cogl_get_format_bpp (dst_format);
full_rowstride = bpp * full_tex_width;
full_bits = g_malloc (full_rowstride * full_tex_height);
if (tex->vtable->get_data (tex,
dst_format,
full_rowstride,
full_bits))
if (texture->vtable->get_data (texture,
dst_format,
full_rowstride,
full_bits))
{
guint8 *dst = dst_bits;
guint8 *src = full_bits + x * bpp + y * full_rowstride;
@ -1285,18 +1197,17 @@ typedef struct
} CoglTextureGetData;
static void
texture_get_cb (CoglHandle texture_handle,
texture_get_cb (CoglTexture *texture,
const float *subtexture_coords,
const float *virtual_coords,
void *user_data)
{
CoglTexture *tex = COGL_TEXTURE (texture_handle);
CoglTextureGetData *tg_data = user_data;
CoglPixelFormat format = _cogl_bitmap_get_format (tg_data->target_bmp);
int bpp = _cogl_get_format_bpp (format);
unsigned int rowstride = _cogl_bitmap_get_rowstride (tg_data->target_bmp);
int subtexture_width = cogl_texture_get_width (texture_handle);
int subtexture_height = cogl_texture_get_height (texture_handle);
int subtexture_width = cogl_texture_get_width (texture);
int subtexture_height = cogl_texture_get_height (texture);
int x_in_subtexture = (int) (0.5 + subtexture_width * subtexture_coords[0]);
int y_in_subtexture = (int) (0.5 + subtexture_height * subtexture_coords[1]);
@ -1321,15 +1232,15 @@ texture_get_cb (CoglHandle texture_handle,
if (x_in_subtexture == 0 && y_in_subtexture == 0 &&
width == subtexture_width && height == subtexture_height)
{
if (tex->vtable->get_data (tex,
format,
rowstride,
dst_bits))
if (texture->vtable->get_data (texture,
format,
rowstride,
dst_bits))
return;
}
/* Next best option is a FBO and glReadPixels */
if (get_texture_bits_via_offscreen (texture_handle,
if (get_texture_bits_via_offscreen (texture,
x_in_subtexture, y_in_subtexture,
width, height,
dst_bits,
@ -1338,7 +1249,7 @@ texture_get_cb (CoglHandle texture_handle,
return;
/* Getting ugly: read the entire texture, copy out the part we want */
if (get_texture_bits_via_copy (texture_handle,
if (get_texture_bits_via_copy (texture,
x_in_subtexture, y_in_subtexture,
width, height,
dst_bits,
@ -1352,12 +1263,11 @@ texture_get_cb (CoglHandle texture_handle,
}
int
cogl_texture_get_data (CoglHandle handle,
cogl_texture_get_data (CoglTexture *texture,
CoglPixelFormat format,
unsigned int rowstride,
guint8 *data)
{
CoglTexture *tex;
int bpp;
int byte_size;
CoglPixelFormat closest_format;
@ -1376,17 +1286,12 @@ cogl_texture_get_data (CoglHandle handle,
_COGL_GET_CONTEXT (ctx, 0);
if (!cogl_is_texture (handle))
return 0;
tex = COGL_TEXTURE (handle);
/* Default to internal format if none specified */
if (format == COGL_PIXEL_FORMAT_ANY)
format = cogl_texture_get_format (handle);
format = cogl_texture_get_format (texture);
tex_width = cogl_texture_get_width (handle);
tex_height = cogl_texture_get_height (handle);
tex_width = cogl_texture_get_width (texture);
tex_height = cogl_texture_get_height (texture);
/* Rowstride from texture width if none specified */
bpp = _cogl_get_format_bpp (format);
@ -1442,7 +1347,7 @@ cogl_texture_get_data (CoglHandle handle,
* the data for a sliced texture, and allows us to do the
* read-from-framebuffer logic here in a simple fashion rather than
* passing offsets down through the code. */
_cogl_texture_foreach_sub_texture_in_region (handle,
_cogl_texture_foreach_sub_texture_in_region (texture,
0, 0, 1, 1,
texture_get_cb,
&tg_data);
@ -1454,7 +1359,7 @@ cogl_texture_get_data (CoglHandle handle,
* support glGetTexImage, so here we fallback to drawing the
* texture and reading the pixels from the framebuffer. */
if (!tg_data.success)
_cogl_texture_draw_and_read (tex, target_bmp,
_cogl_texture_draw_and_read (texture, target_bmp,
closest_gl_format,
closest_gl_type);
@ -1512,40 +1417,37 @@ _cogl_texture_framebuffer_destroy_cb (void *user_data,
}
void
_cogl_texture_associate_framebuffer (CoglHandle handle,
_cogl_texture_associate_framebuffer (CoglTexture *texture,
CoglFramebuffer *framebuffer)
{
CoglTexture *tex = COGL_TEXTURE (handle);
static CoglUserDataKey framebuffer_destroy_notify_key;
/* Note: we don't take a reference on the framebuffer here because
* that would introduce a circular reference. */
tex->framebuffers = g_list_prepend (tex->framebuffers, framebuffer);
texture->framebuffers = g_list_prepend (texture->framebuffers, framebuffer);
/* Since we haven't taken a reference on the framebuffer we setup
* some private data so we will be notified if it is destroyed... */
* some private data so we will be notified if it is destroyed... */
_cogl_object_set_user_data (COGL_OBJECT (framebuffer),
&framebuffer_destroy_notify_key,
tex,
texture,
_cogl_texture_framebuffer_destroy_cb);
}
const GList *
_cogl_texture_get_associated_framebuffers (CoglHandle handle)
_cogl_texture_get_associated_framebuffers (CoglTexture *texture)
{
CoglTexture *tex = COGL_TEXTURE (handle);
return tex->framebuffers;
return texture->framebuffers;
}
void
_cogl_texture_flush_journal_rendering (CoglHandle handle)
_cogl_texture_flush_journal_rendering (CoglTexture *texture)
{
CoglTexture *tex = COGL_TEXTURE (handle);
GList *l;
/* It could be that a referenced texture is part of a framebuffer
* which has an associated journal that must be flushed before it
* can be sampled from by the current primitive... */
for (l = tex->framebuffers; l; l = l->next)
for (l = texture->framebuffers; l; l = l->next)
_cogl_framebuffer_flush_journal (l->data);
}

View File

@ -30,6 +30,9 @@
#include <cogl/cogl-types.h>
#include <cogl/cogl-defines.h>
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
#include <cogl/cogl-pixel-buffer.h>
#endif
G_BEGIN_DECLS
@ -37,11 +40,14 @@ G_BEGIN_DECLS
* SECTION:cogl-texture
* @short_description: Fuctions for creating and manipulating textures
*
* COGL allows creating and manipulating GL textures using a uniform
* Cogl allows creating and manipulating textures using a uniform
* API that tries to hide all the various complexities of creating,
* loading and manipulating textures.
*/
typedef struct _CoglTexture CoglTexture;
#define COGL_TEXTURE(X) ((CoglTexture *)X)
#define COGL_TEXTURE_MAX_WASTE 127
/**
@ -80,14 +86,13 @@ GQuark cogl_texture_error_quark (void);
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture.
*
* Creates a new COGL texture with the specified dimensions and pixel format.
* Creates a new #CoglTexture with the specified dimensions and pixel format.
*
* Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure
* Return value: A newly created #CoglTexture or %NULL on failure
*
* Since: 0.8
*/
CoglHandle
CoglTexture *
cogl_texture_new_with_size (unsigned int width,
unsigned int height,
CoglTextureFlags flags,
@ -107,14 +112,13 @@ cogl_texture_new_with_size (unsigned int width,
* other than straight blending.
* @error: return location for a #GError or %NULL
*
* Creates a COGL texture from an image file.
* Creates a #CoglTexture from an image file.
*
* Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure
* Return value: A newly created #CoglTexture or %NULL on failure
*
* Since: 0.8
*/
CoglHandle
CoglTexture *
cogl_texture_new_from_file (const char *filename,
CoglTextureFlags flags,
CoglPixelFormat internal_format,
@ -138,14 +142,13 @@ cogl_texture_new_from_file (const char *filename,
* scanlines in @data
* @data: pointer the memory region where the source buffer resides
*
* Creates a new COGL texture based on data residing in memory.
* Creates a new #CoglTexture based on data residing in memory.
*
* Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure
* Return value: A newly created #CoglTexture or %NULL on failure
*
* Since: 0.8
*/
CoglHandle
CoglTexture *
cogl_texture_new_from_data (unsigned int width,
unsigned int height,
CoglTextureFlags flags,
@ -164,7 +167,7 @@ cogl_texture_new_from_data (unsigned int width,
* @y_pot_waste: vertical waste on the bottom edge of the texture.
* @format: format of the foreign texture.
*
* Creates a COGL texture based on an existing OpenGL texture; the
* Creates a #CoglTexture based on an existing OpenGL texture; the
* width, height and format are passed along since it is not always
* possible to query these from OpenGL.
*
@ -175,12 +178,11 @@ cogl_texture_new_from_data (unsigned int width,
* the waste arguments to tell Cogl which region should be mapped to
* the texture coordinate range [0:1].
*
* Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure
* Return value: A newly created #CoglTexture or %NULL on failure
*
* Since: 0.8
*/
CoglHandle
CoglTexture *
cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target,
GLuint width,
@ -191,83 +193,82 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
/**
* cogl_texture_new_from_bitmap:
* @bmp_handle: A CoglBitmap handle
* @bitmap: A #CoglBitmap pointer
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture
*
* Creates a COGL texture from a CoglBitmap.
* Creates a #CoglTexture from a #CoglBitmap.
*
* Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure
* Return value: A newly created #CoglTexture or %NULL on failure
*
* Since: 1.0
*/
CoglHandle
cogl_texture_new_from_bitmap (CoglHandle bmp_handle,
CoglTexture *
cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
CoglTextureFlags flags,
CoglPixelFormat internal_format);
CoglPixelFormat internal_format);
/**
* cogl_is_texture:
* @handle: A CoglHandle
* @object: A #CoglObject pointer
*
* Gets whether the given handle references an existing texture object.
* Gets whether the given object references a texture object.
*
* Return value: %TRUE if the handle references a texture, and
* %FALSE otherwise
*/
gboolean
cogl_is_texture (CoglHandle handle);
cogl_is_texture (void *object);
/**
* cogl_texture_get_width:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
*
* Queries the width of a cogl texture.
*
* Return value: the width of the GPU side texture in pixels
*/
unsigned int
cogl_texture_get_width (CoglHandle handle);
cogl_texture_get_width (CoglTexture *texture);
/**
* cogl_texture_get_height:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
*
* Queries the height of a cogl texture.
*
* Return value: the height of the GPU side texture in pixels
*/
unsigned int
cogl_texture_get_height (CoglHandle handle);
cogl_texture_get_height (CoglTexture *texture);
/**
* cogl_texture_get_format:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
*
* Queries the #CoglPixelFormat of a cogl texture.
*
* Return value: the #CoglPixelFormat of the GPU side texture
*/
CoglPixelFormat
cogl_texture_get_format (CoglHandle handle);
cogl_texture_get_format (CoglTexture *texture);
/**
* cogl_texture_get_rowstride:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
*
* Queries the rowstride of a cogl texture.
*
* Return value: the offset in bytes between each consequetive row of pixels
*/
unsigned int
cogl_texture_get_rowstride (CoglHandle handle);
cogl_texture_get_rowstride (CoglTexture *texture);
/**
* cogl_texture_get_max_waste:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
*
* Queries the maximum wasted (unused) pixels in one dimension of a GPU side
* texture.
@ -275,11 +276,11 @@ cogl_texture_get_rowstride (CoglHandle handle);
* Return value: the maximum waste
*/
int
cogl_texture_get_max_waste (CoglHandle handle);
cogl_texture_get_max_waste (CoglTexture *texture);
/**
* cogl_texture_is_sliced:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
*
* Queries if a texture is sliced (stored as multiple GPU side tecture
* objects).
@ -288,17 +289,17 @@ cogl_texture_get_max_waste (CoglHandle handle);
* is stored as a single GPU texture
*/
gboolean
cogl_texture_is_sliced (CoglHandle handle);
cogl_texture_is_sliced (CoglTexture *texture);
/**
* cogl_texture_get_gl_texture:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
* @out_gl_handle: (out) (allow-none): pointer to return location for the
* textures GL handle, or %NULL.
* @out_gl_target: (out) (allow-none): pointer to return location for the
* GL target type, or %NULL.
*
* Queries the GL handles for a GPU side texture through its #CoglHandle.
* Queries the GL handles for a GPU side texture through its #CoglTexture.
*
* If the texture is spliced the data for the first sub texture will be
* queried.
@ -307,13 +308,13 @@ cogl_texture_is_sliced (CoglHandle handle);
* if the handle was invalid
*/
gboolean
cogl_texture_get_gl_texture (CoglHandle handle,
cogl_texture_get_gl_texture (CoglTexture *texture,
GLuint *out_gl_handle,
GLenum *out_gl_target);
/**
* cogl_texture_get_data:
* @handle: a #CoglHandle for a texture.
* @texture a #CoglTexture pointer.
* @format: the #CoglPixelFormat to store the texture as.
* @rowstride: the rowstride of @data or retrieved from texture if none is
* specified.
@ -326,14 +327,14 @@ cogl_texture_get_gl_texture (CoglHandle handle,
* is not valid
*/
int
cogl_texture_get_data (CoglHandle handle,
CoglPixelFormat format,
unsigned int rowstride,
guint8 *data);
cogl_texture_get_data (CoglTexture *texture,
CoglPixelFormat format,
unsigned int rowstride,
guint8 *data);
/**
* cogl_texture_set_region:
* @handle: a #CoglHandle.
* @texture a #CoglTexture.
* @src_x: upper left coordinate to use from source data.
* @src_y: upper left coordinate to use from source data.
* @dst_x: upper left destination horizontal coordinate.
@ -354,7 +355,7 @@ cogl_texture_get_data (CoglHandle handle,
* %FALSE otherwise
*/
gboolean
cogl_texture_set_region (CoglHandle handle,
cogl_texture_set_region (CoglTexture *texture,
int src_x,
int src_y,
int dst_x,
@ -373,7 +374,7 @@ cogl_texture_set_region (CoglHandle handle,
cogl_texture_set_region_from_bitmap_EXP
/**
* cogl_texture_set_region_from_bitmap:
* @handle: a #CoglHandle for a texture
* @texture a #CoglTexture pointer
* @src_x: upper left coordinate to use from the source bitmap.
* @src_y: upper left coordinate to use from the source bitmap
* @dst_x: upper left destination horizontal coordinate.
@ -392,7 +393,7 @@ cogl_texture_set_region (CoglHandle handle,
* Stability: unstable
*/
gboolean
cogl_texture_set_region_from_bitmap (CoglHandle handle,
cogl_texture_set_region_from_bitmap (CoglTexture *texture,
int src_x,
int src_y,
int dst_x,
@ -404,7 +405,7 @@ cogl_texture_set_region_from_bitmap (CoglHandle handle,
/**
* cogl_texture_new_from_sub_texture:
* @full_texture: a #CoglHandle to an existing texture
* @full_texture: a #CoglTexture pointer
* @sub_x: X coordinate of the top-left of the subregion
* @sub_y: Y coordinate of the top-left of the subregion
* @sub_width: Width in pixels of the subregion
@ -422,22 +423,22 @@ cogl_texture_set_region_from_bitmap (CoglHandle handle,
* not need to keep one separately if you only want to use the sub
* texture.
*
* Return value: a #CoglHandle to the new texture.
*
* Return value: A newly created #CoglTexture or %NULL on failure
* Since: 1.2
*/
CoglHandle
cogl_texture_new_from_sub_texture (CoglHandle full_texture,
int sub_x,
int sub_y,
int sub_width,
int sub_height);
CoglTexture *
cogl_texture_new_from_sub_texture (CoglTexture *full_texture,
int sub_x,
int sub_y,
int sub_width,
int sub_height);
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
#define cogl_texture_new_from_buffer cogl_texture_new_from_buffer_EXP
/**
* cogl_texture_new_from_buffer:
* @buffer: the #CoglHandle of a pixel buffer
* @buffer: A #CoglPixelBuffer pointer
* @width: width of texture in pixels or 0
* @height: height of texture in pixels or 0
* @flags: optional flags for the texture, or %COGL_TEXTURE_NONE
@ -459,14 +460,13 @@ cogl_texture_new_from_sub_texture (CoglHandle full_texture,
* has been created using cogl_pixel_buffer_new_for_size() it's possible to omit
* the height and width values already specified at creation time.
*
* Return value: a #CoglHandle to the new texture or %COGL_INVALID_HANDLE on
* failure
* Return value: A newly created #CoglTexture or %NULL on failure
*
* Since: 1.2
* Stability: Unstable
*/
CoglHandle
cogl_texture_new_from_buffer (CoglHandle buffer,
CoglTexture *
cogl_texture_new_from_buffer (CoglPixelBuffer *buffer,
unsigned int width,
unsigned int height,
CoglTextureFlags flags,
@ -474,51 +474,33 @@ cogl_texture_new_from_buffer (CoglHandle buffer,
CoglPixelFormat internal_format,
unsigned int rowstride,
unsigned int offset);
/* the function above is experimental, the actual symbol is suffixed by _EXP so
* we can ensure ABI compatibility and leave the cogl_buffer namespace free for
* future use. A bunch of defines translates the symbols documented above into
* the real symbols */
CoglHandle
cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
unsigned int width,
unsigned int height,
CoglTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
unsigned int rowstride,
unsigned int offset);
#define cogl_texture_new_from_buffer cogl_texture_new_from_buffer_EXP
#endif
#ifndef COGL_DISABLE_DEPRECATED
/**
* cogl_texture_ref:
* @handle: a @CoglHandle.
* @texture: a #CoglTexture.
*
* Increment the reference count for a cogl texture.
*
* Deprecated: 1.2: Use cogl_handle_ref() instead
* Deprecated: 1.2: Use cogl_object_ref() instead
*
* Return value: the @handle.
* Return value: the @texture pointer.
*/
CoglHandle
cogl_texture_ref (CoglHandle handle) G_GNUC_DEPRECATED;
void *
cogl_texture_ref (void *texture) G_GNUC_DEPRECATED;
/**
* cogl_texture_unref:
* @handle: a @CoglHandle.
* @texture: a #CoglTexture.
*
* Decrement the reference count for a cogl texture.
*
* Deprecated: 1.2: Use cogl_handle_unref() instead
* Deprecated: 1.2: Use cogl_object_unref() instead
*/
void
cogl_texture_unref (CoglHandle handle) G_GNUC_DEPRECATED;
cogl_texture_unref (void *texture) G_GNUC_DEPRECATED;
#endif /* COGL_DISABLE_DEPRECATED */

View File

@ -1004,13 +1004,13 @@ cogl_set_source (void *material_or_pipeline)
}
void
cogl_set_source_texture (CoglHandle texture_handle)
cogl_set_source_texture (CoglTexture *texture)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
g_return_if_fail (texture_handle != NULL);
g_return_if_fail (texture != NULL);
cogl_pipeline_set_layer_texture (ctx->texture_pipeline, 0, texture_handle);
cogl_pipeline_set_layer_texture (ctx->texture_pipeline, 0, texture);
cogl_set_source (ctx->texture_pipeline);
}

View File

@ -693,10 +693,10 @@ cogl_set_source_color4f (float red,
/**
* cogl_set_source_texture:
* @texture_handle: The Cogl texture you want as your source
* @texture: The #CoglTexture you want as your source
*
* This is a convenience function for creating a material with the first
* layer set to #texture_handle and setting that material as the source with
* layer set to @texture and setting that material as the source with
* cogl_set_source.
*
* Note: There is no interaction between calls to cogl_set_source_color
@ -712,7 +712,7 @@ cogl_set_source_color4f (float red,
* Since: 1.0
*/
void
cogl_set_source_texture (CoglHandle texture_handle);
cogl_set_source_texture (CoglTexture *texture);
/**
* SECTION:cogl-clipping

View File

@ -307,9 +307,9 @@ _cogl_path_fill_nodes (CoglPath *path)
for (l = _cogl_pipeline_get_layers (cogl_get_source ()); l; l = l->next)
{
CoglHandle layer = l->data;
CoglHandle texture = _cogl_pipeline_layer_get_texture (layer);
CoglTexture *texture = _cogl_pipeline_layer_get_texture (layer);
if (texture != COGL_INVALID_HANDLE &&
if (texture != NULL &&
(cogl_texture_is_sliced (texture) ||
!_cogl_texture_can_hardware_repeat (texture)))
{

View File

@ -637,7 +637,7 @@ _cogl_texture_pixmap_x11_set_use_winsys_texture (CoglTexturePixmapX11 *tex_pixma
/* Notify cogl-pipeline.c that the texture's underlying GL texture
* storage is changing so it knows it may need to bind a new texture
* if the CoglTexture is reused with the same texture unit. */
_cogl_pipeline_texture_storage_change_notify (tex_pixmap);
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (tex_pixmap));
tex_pixmap->use_winsys_texture = new_value;
}

View File

@ -176,7 +176,7 @@ typedef struct _CoglOnscreenEGL
typedef struct _CoglTexturePixmapEGL
{
EGLImageKHR image;
CoglHandle texture;
CoglTexture *texture;
} CoglTexturePixmapEGL;
#endif
@ -1667,13 +1667,13 @@ _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
COGL_PIXEL_FORMAT_RGBA_8888_PRE :
COGL_PIXEL_FORMAT_RGB_888);
egl_tex_pixmap->texture =
egl_tex_pixmap->texture = COGL_TEXTURE (
_cogl_egl_texture_2d_new_from_image (ctx,
tex_pixmap->width,
tex_pixmap->height,
texture_format,
egl_tex_pixmap->image,
NULL);
NULL));
tex_pixmap->winsys = egl_tex_pixmap;
@ -1695,7 +1695,7 @@ _cogl_winsys_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap)
egl_tex_pixmap = tex_pixmap->winsys;
if (egl_tex_pixmap->texture)
cogl_handle_unref (egl_tex_pixmap->texture);
cogl_object_unref (egl_tex_pixmap->texture);
if (egl_tex_pixmap->image != EGL_NO_IMAGE_KHR)
_cogl_egl_destroy_image (ctx, egl_tex_pixmap->image);

View File

@ -10,7 +10,7 @@ typedef struct _Data
CoglMatrix view;
CoglPrimitive *prim;
CoglHandle texture;
CoglTexture *texture;
CoglPipeline *crate_pipeline;
/* The cube continually rotates around each axis. */