texture: add width/height members to base CoglTexture

There was a lot of redundancy in how we tracked the width and height of
different texture types which is greatly simplified by adding width and
height members to CoglTexture directly and removing the get_width and
get_height vfuncs from CoglTextureVtable

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 3236e47723e4287d5e0023f29083521aeffc75dd)
This commit is contained in:
Robert Bragg 2012-11-22 21:46:54 +00:00
parent 0850eea162
commit 5a814e386a
18 changed files with 104 additions and 228 deletions

View File

@ -632,24 +632,6 @@ _cogl_atlas_texture_get_gl_format (CoglTexture *tex)
return _cogl_texture_gl_get_format (atlas_tex->sub_texture); return _cogl_texture_gl_get_format (atlas_tex->sub_texture);
} }
static int
_cogl_atlas_texture_get_width (CoglTexture *tex)
{
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
/* Forward on to the sub texture */
return cogl_texture_get_width (atlas_tex->sub_texture);
}
static int
_cogl_atlas_texture_get_height (CoglTexture *tex)
{
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
/* Forward on to the sub texture */
return cogl_texture_get_height (atlas_tex->sub_texture);
}
static CoglBool static CoglBool
_cogl_atlas_texture_can_use_format (CoglPixelFormat format) _cogl_atlas_texture_can_use_format (CoglPixelFormat format)
{ {
@ -716,6 +698,7 @@ _cogl_atlas_texture_new_with_size (CoglContext *ctx,
_cogl_texture_init (COGL_TEXTURE (atlas_tex), _cogl_texture_init (COGL_TEXTURE (atlas_tex),
ctx, ctx,
width, height,
&cogl_atlas_texture_vtable); &cogl_atlas_texture_vtable);
atlas_tex->sub_texture = NULL; atlas_tex->sub_texture = NULL;
@ -871,8 +854,6 @@ cogl_atlas_texture_vtable =
_cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes, _cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes,
_cogl_atlas_texture_get_format, _cogl_atlas_texture_get_format,
_cogl_atlas_texture_get_gl_format, _cogl_atlas_texture_get_gl_format,
_cogl_atlas_texture_get_width,
_cogl_atlas_texture_get_height,
_cogl_atlas_texture_get_type, _cogl_atlas_texture_get_type,
NULL, /* is_foreign */ NULL, /* is_foreign */
NULL /* set_auto_mipmap */ NULL /* set_auto_mipmap */

View File

@ -44,14 +44,12 @@ struct _CoglSubTexture
is created */ is created */
CoglTexture *full_texture; CoglTexture *full_texture;
/* The region represented by this sub-texture. This is the region of /* The offset of the region represented by this sub-texture. This is
full_texture which won't necessarily be the same as the region * the offset in full_texture which won't necessarily be the same as
passed to _cogl_sub_texture_new if next_texture is actually * the offset passed to _cogl_sub_texture_new if next_texture is
already a sub texture */ * actually already a sub texture */
int sub_x; int sub_x;
int sub_y; int sub_y;
int sub_width;
int sub_height;
}; };
#endif /* __COGL_SUB_TEXTURE_PRIVATE_H */ #endif /* __COGL_SUB_TEXTURE_PRIVATE_H */

View File

@ -52,6 +52,8 @@ static void
_cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex, _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
float *coords) float *coords)
{ {
CoglTexture *tex = COGL_TEXTURE (sub_tex);
/* NB: coords[] come in as non-normalized if sub_tex->full_texture /* NB: coords[] come in as non-normalized if sub_tex->full_texture
* is a CoglTextureRectangle otherwhise they are normalized. The * is a CoglTextureRectangle otherwhise they are normalized. The
* coordinates we write out though must always be normalized. * coordinates we write out though must always be normalized.
@ -61,19 +63,19 @@ _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
*/ */
if (cogl_is_texture_rectangle (sub_tex->full_texture)) if (cogl_is_texture_rectangle (sub_tex->full_texture))
{ {
coords[0] = (coords[0] - sub_tex->sub_x) / sub_tex->sub_width; coords[0] = (coords[0] - sub_tex->sub_x) / tex->width;
coords[1] = (coords[1] - sub_tex->sub_y) / sub_tex->sub_height; coords[1] = (coords[1] - sub_tex->sub_y) / tex->height;
coords[2] = (coords[2] - sub_tex->sub_x) / sub_tex->sub_width; coords[2] = (coords[2] - sub_tex->sub_x) / tex->width;
coords[3] = (coords[3] - sub_tex->sub_y) / sub_tex->sub_height; coords[3] = (coords[3] - sub_tex->sub_y) / tex->height;
} }
else else
{ {
float width = cogl_texture_get_width (sub_tex->full_texture); float width = cogl_texture_get_width (sub_tex->full_texture);
float height = cogl_texture_get_height (sub_tex->full_texture); float height = cogl_texture_get_height (sub_tex->full_texture);
coords[0] = (coords[0] * width - sub_tex->sub_x) / sub_tex->sub_width; coords[0] = (coords[0] * width - sub_tex->sub_x) / tex->width;
coords[1] = (coords[1] * height - sub_tex->sub_y) / sub_tex->sub_height; coords[1] = (coords[1] * height - sub_tex->sub_y) / tex->height;
coords[2] = (coords[2] * width - sub_tex->sub_x) / sub_tex->sub_width; coords[2] = (coords[2] * width - sub_tex->sub_x) / tex->width;
coords[3] = (coords[3] * height - sub_tex->sub_y) / sub_tex->sub_height; coords[3] = (coords[3] * height - sub_tex->sub_y) / tex->height;
} }
} }
@ -81,6 +83,8 @@ static void
_cogl_sub_texture_map_quad (CoglSubTexture *sub_tex, _cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
float *coords) float *coords)
{ {
CoglTexture *tex = COGL_TEXTURE (sub_tex);
/* NB: coords[] always come in as normalized coordinates but may go /* NB: coords[] always come in as normalized coordinates but may go
* out as non-normalized if sub_tex->full_texture is a * out as non-normalized if sub_tex->full_texture is a
* CoglTextureRectangle. * CoglTextureRectangle.
@ -91,19 +95,19 @@ _cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
if (cogl_is_texture_rectangle (sub_tex->full_texture)) if (cogl_is_texture_rectangle (sub_tex->full_texture))
{ {
coords[0] = coords[0] * sub_tex->sub_width + sub_tex->sub_x; coords[0] = coords[0] * tex->width + sub_tex->sub_x;
coords[1] = coords[1] * sub_tex->sub_height + sub_tex->sub_y; coords[1] = coords[1] * tex->height + sub_tex->sub_y;
coords[2] = coords[2] * sub_tex->sub_width + sub_tex->sub_x; coords[2] = coords[2] * tex->width + sub_tex->sub_x;
coords[3] = coords[3] * sub_tex->sub_height + sub_tex->sub_y; coords[3] = coords[3] * tex->height + sub_tex->sub_y;
} }
else else
{ {
float width = cogl_texture_get_width (sub_tex->full_texture); float width = cogl_texture_get_width (sub_tex->full_texture);
float height = cogl_texture_get_height (sub_tex->full_texture); float height = cogl_texture_get_height (sub_tex->full_texture);
coords[0] = (coords[0] * sub_tex->sub_width + sub_tex->sub_x) / width; coords[0] = (coords[0] * tex->width + sub_tex->sub_x) / width;
coords[1] = (coords[1] * sub_tex->sub_height + sub_tex->sub_y) / height; coords[1] = (coords[1] * tex->height + sub_tex->sub_y) / height;
coords[2] = (coords[2] * sub_tex->sub_width + sub_tex->sub_x) / width; coords[2] = (coords[2] * tex->width + sub_tex->sub_x) / width;
coords[3] = (coords[3] * sub_tex->sub_height + sub_tex->sub_y) / height; coords[3] = (coords[3] * tex->height + sub_tex->sub_y) / height;
} }
} }
@ -230,7 +234,8 @@ cogl_sub_texture_new (CoglContext *ctx,
tex = COGL_TEXTURE (sub_tex); tex = COGL_TEXTURE (sub_tex);
_cogl_texture_init (tex, ctx, &cogl_sub_texture_vtable); _cogl_texture_init (tex, ctx, sub_width, sub_height,
&cogl_sub_texture_vtable);
/* If the next texture is also a sub texture we can avoid one level /* If the next texture is also a sub texture we can avoid one level
of indirection by referencing the full texture of that texture of indirection by referencing the full texture of that texture
@ -250,8 +255,6 @@ cogl_sub_texture_new (CoglContext *ctx,
sub_tex->sub_x = sub_x; sub_tex->sub_x = sub_x;
sub_tex->sub_y = sub_y; sub_tex->sub_y = sub_y;
sub_tex->sub_width = sub_width;
sub_tex->sub_height = sub_height;
return _cogl_sub_texture_object_new (sub_tex); return _cogl_sub_texture_object_new (sub_tex);
} }
@ -285,9 +288,9 @@ _cogl_sub_texture_can_hardware_repeat (CoglTexture *tex)
/* We can hardware repeat if the subtexture actually represents all of the /* We can hardware repeat if the subtexture actually represents all of the
of the full texture */ of the full texture */
return (sub_tex->sub_width == return (tex->width ==
cogl_texture_get_width (sub_tex->full_texture) && cogl_texture_get_width (sub_tex->full_texture) &&
sub_tex->sub_height == tex->height ==
cogl_texture_get_height (sub_tex->full_texture) && cogl_texture_get_height (sub_tex->full_texture) &&
_cogl_texture_can_hardware_repeat (sub_tex->full_texture)); _cogl_texture_can_hardware_repeat (sub_tex->full_texture));
} }
@ -301,9 +304,9 @@ _cogl_sub_texture_transform_coords_to_gl (CoglTexture *tex,
/* This won't work if the sub texture is not the size of the full /* This won't work if the sub texture is not the size of the full
texture and the coordinates are outside the range [0,1] */ texture and the coordinates are outside the range [0,1] */
*s = ((*s * sub_tex->sub_width + sub_tex->sub_x) / *s = ((*s * tex->width + sub_tex->sub_x) /
cogl_texture_get_width (sub_tex->full_texture)); cogl_texture_get_width (sub_tex->full_texture));
*t = ((*t * sub_tex->sub_height + sub_tex->sub_y) / *t = ((*t * tex->height + sub_tex->sub_y) /
cogl_texture_get_height (sub_tex->full_texture)); cogl_texture_get_height (sub_tex->full_texture));
_cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t); _cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t);
@ -418,22 +421,6 @@ _cogl_sub_texture_get_gl_format (CoglTexture *tex)
return _cogl_texture_gl_get_format (sub_tex->full_texture); return _cogl_texture_gl_get_format (sub_tex->full_texture);
} }
static int
_cogl_sub_texture_get_width (CoglTexture *tex)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
return sub_tex->sub_width;
}
static int
_cogl_sub_texture_get_height (CoglTexture *tex)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
return sub_tex->sub_height;
}
static CoglTextureType static CoglTextureType
_cogl_sub_texture_get_type (CoglTexture *tex) _cogl_sub_texture_get_type (CoglTexture *tex)
{ {
@ -461,8 +448,6 @@ cogl_sub_texture_vtable =
_cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes, _cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes,
_cogl_sub_texture_get_format, _cogl_sub_texture_get_format,
_cogl_sub_texture_get_gl_format, _cogl_sub_texture_get_gl_format,
_cogl_sub_texture_get_width,
_cogl_sub_texture_get_height,
_cogl_sub_texture_get_type, _cogl_sub_texture_get_type,
NULL, /* is_foreign */ NULL, /* is_foreign */
NULL /* set_auto_mipmap */ NULL /* set_auto_mipmap */

View File

@ -40,8 +40,6 @@ struct _CoglTexture2D
/* The internal format of the GL texture represented as a /* The internal format of the GL texture represented as a
CoglPixelFormat */ CoglPixelFormat */
CoglPixelFormat format; CoglPixelFormat format;
int width;
int height;
CoglBool auto_mipmap; CoglBool auto_mipmap;
CoglBool mipmaps_dirty; CoglBool mipmaps_dirty;

View File

@ -38,9 +38,6 @@ struct _CoglTexture2DSliced
GArray *slice_y_spans; GArray *slice_y_spans;
GArray *slice_textures; GArray *slice_textures;
int max_waste; int max_waste;
int width;
int height;
}; };
CoglTexture2DSliced * CoglTexture2DSliced *

View File

@ -112,8 +112,8 @@ _cogl_texture_2d_sliced_foreach_sub_texture_in_region (
data.callback = callback; data.callback = callback;
data.user_data = user_data; data.user_data = user_data;
data.x_normalize_factor = 1.0f / tex_2ds->width; data.x_normalize_factor = 1.0f / tex->width;
data.y_normalize_factor = 1.0f / tex_2ds->height; data.y_normalize_factor = 1.0f / tex->height;
un_normalized_coords[0] = virtual_tx_1 * data.x_normalize_factor; un_normalized_coords[0] = virtual_tx_1 * data.x_normalize_factor;
un_normalized_coords[1] = virtual_ty_1 * data.y_normalize_factor; un_normalized_coords[1] = virtual_ty_1 * data.y_normalize_factor;
@ -428,6 +428,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
GLuint source_gl_type, GLuint source_gl_type,
CoglError **error) CoglError **error)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2ds);
CoglSpan *x_span; CoglSpan *x_span;
CoglSpan *y_span; CoglSpan *y_span;
CoglSpanIter x_iter; CoglSpanIter x_iter;
@ -449,7 +450,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
_cogl_span_iter_begin (&y_iter, _cogl_span_iter_begin (&y_iter,
(CoglSpan *)tex_2ds->slice_y_spans->data, (CoglSpan *)tex_2ds->slice_y_spans->data,
tex_2ds->slice_y_spans->len, tex_2ds->slice_y_spans->len,
tex_2ds->height, tex->height,
dst_y, dst_y,
dst_y + height, dst_y + height,
COGL_PIPELINE_WRAP_MODE_REPEAT); COGL_PIPELINE_WRAP_MODE_REPEAT);
@ -467,7 +468,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
_cogl_span_iter_begin (&x_iter, _cogl_span_iter_begin (&x_iter,
(CoglSpan *)tex_2ds->slice_x_spans->data, (CoglSpan *)tex_2ds->slice_x_spans->data,
tex_2ds->slice_x_spans->len, tex_2ds->slice_x_spans->len,
tex_2ds->width, tex->width,
dst_x, dst_x,
dst_x + width, dst_x + width,
COGL_PIPELINE_WRAP_MODE_REPEAT); COGL_PIPELINE_WRAP_MODE_REPEAT);
@ -866,7 +867,7 @@ _cogl_texture_2d_sliced_init_base (CoglContext *ctx,
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2ds); CoglTexture *tex = COGL_TEXTURE (tex_2ds);
_cogl_texture_init (tex, ctx, &cogl_texture_2d_sliced_vtable); _cogl_texture_init (tex, ctx, width, height, &cogl_texture_2d_sliced_vtable);
tex_2ds->slice_x_spans = NULL; tex_2ds->slice_x_spans = NULL;
tex_2ds->slice_y_spans = NULL; tex_2ds->slice_y_spans = NULL;
@ -880,9 +881,6 @@ _cogl_texture_2d_sliced_init_base (CoglContext *ctx,
internal_format)) internal_format))
return FALSE; return FALSE;
tex_2ds->width = width;
tex_2ds->height = height;
return TRUE; return TRUE;
} }
@ -1052,10 +1050,9 @@ _cogl_texture_2d_sliced_new_from_foreign (CoglContext *ctx,
tex_2ds = g_new0 (CoglTexture2DSliced, 1); tex_2ds = g_new0 (CoglTexture2DSliced, 1);
tex = COGL_TEXTURE (tex_2ds); tex = COGL_TEXTURE (tex_2ds);
tex->vtable = &cogl_texture_2d_sliced_vtable; _cogl_texture_init (tex, ctx, gl_width, gl_height,
&cogl_texture_2d_sliced_vtable);
tex_2ds->width = gl_width - x_pot_waste;
tex_2ds->height = gl_height - y_pot_waste;
tex_2ds->max_waste = 0; tex_2ds->max_waste = 0;
/* Create slice arrays */ /* Create slice arrays */
@ -1163,8 +1160,8 @@ _cogl_texture_2d_sliced_transform_coords_to_gl (CoglTexture *tex,
x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0); x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0);
y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0); y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0);
*s *= tex_2ds->width / (float)x_span->size; *s *= tex->width / (float)x_span->size;
*t *= tex_2ds->height / (float)y_span->size; *t *= tex->height / (float)y_span->size;
/* Let the child texture further transform the coords */ /* Let the child texture further transform the coords */
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0); slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
@ -1356,18 +1353,6 @@ _cogl_texture_2d_sliced_get_gl_format (CoglTexture *tex)
return _cogl_texture_gl_get_format (COGL_TEXTURE (slice_tex)); return _cogl_texture_gl_get_format (COGL_TEXTURE (slice_tex));
} }
static int
_cogl_texture_2d_sliced_get_width (CoglTexture *tex)
{
return COGL_TEXTURE_2D_SLICED (tex)->width;
}
static int
_cogl_texture_2d_sliced_get_height (CoglTexture *tex)
{
return COGL_TEXTURE_2D_SLICED (tex)->height;
}
static CoglTextureType static CoglTextureType
_cogl_texture_2d_sliced_get_type (CoglTexture *tex) _cogl_texture_2d_sliced_get_type (CoglTexture *tex)
{ {
@ -1393,8 +1378,6 @@ cogl_texture_2d_sliced_vtable =
_cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes, _cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_2d_sliced_get_format, _cogl_texture_2d_sliced_get_format,
_cogl_texture_2d_sliced_get_gl_format, _cogl_texture_2d_sliced_get_gl_format,
_cogl_texture_2d_sliced_get_width,
_cogl_texture_2d_sliced_get_height,
_cogl_texture_2d_sliced_get_type, _cogl_texture_2d_sliced_get_type,
_cogl_texture_2d_sliced_is_foreign, _cogl_texture_2d_sliced_is_foreign,
NULL /* set_auto_mipmap */ NULL /* set_auto_mipmap */

View File

@ -112,10 +112,8 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1); CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1);
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
_cogl_texture_init (tex, ctx, &cogl_texture_2d_vtable); _cogl_texture_init (tex, ctx, width, height, &cogl_texture_2d_vtable);
tex_2d->width = width;
tex_2d->height = height;
tex_2d->mipmaps_dirty = TRUE; tex_2d->mipmaps_dirty = TRUE;
tex_2d->auto_mipmap = TRUE; tex_2d->auto_mipmap = TRUE;
@ -382,12 +380,11 @@ _cogl_texture_2d_is_sliced (CoglTexture *tex)
static CoglBool static CoglBool
_cogl_texture_2d_can_hardware_repeat (CoglTexture *tex) _cogl_texture_2d_can_hardware_repeat (CoglTexture *tex)
{ {
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
CoglContext *ctx = tex->context; CoglContext *ctx = tex->context;
if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT) || if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT) ||
(_cogl_util_is_pot (tex_2d->width) && (_cogl_util_is_pot (tex->width) &&
_cogl_util_is_pot (tex_2d->height))) _cogl_util_is_pot (tex->height)))
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -537,18 +534,6 @@ _cogl_texture_2d_get_gl_format (CoglTexture *tex)
return COGL_TEXTURE_2D (tex)->gl_internal_format; return COGL_TEXTURE_2D (tex)->gl_internal_format;
} }
static int
_cogl_texture_2d_get_width (CoglTexture *tex)
{
return COGL_TEXTURE_2D (tex)->width;
}
static int
_cogl_texture_2d_get_height (CoglTexture *tex)
{
return COGL_TEXTURE_2D (tex)->height;
}
static CoglBool static CoglBool
_cogl_texture_2d_is_foreign (CoglTexture *tex) _cogl_texture_2d_is_foreign (CoglTexture *tex)
{ {
@ -580,8 +565,6 @@ cogl_texture_2d_vtable =
_cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes, _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_2d_get_format, _cogl_texture_2d_get_format,
_cogl_texture_2d_get_gl_format, _cogl_texture_2d_get_gl_format,
_cogl_texture_2d_get_width,
_cogl_texture_2d_get_height,
_cogl_texture_2d_get_type, _cogl_texture_2d_get_type,
_cogl_texture_2d_is_foreign, _cogl_texture_2d_is_foreign,
_cogl_texture_2d_set_auto_mipmap _cogl_texture_2d_set_auto_mipmap

View File

@ -37,8 +37,6 @@ struct _CoglTexture3D
/* The internal format of the texture represented as a /* The internal format of the texture represented as a
CoglPixelFormat */ CoglPixelFormat */
CoglPixelFormat format; CoglPixelFormat format;
int width;
int height;
int depth; int depth;
CoglBool auto_mipmap; CoglBool auto_mipmap;
CoglBool mipmaps_dirty; CoglBool mipmaps_dirty;

View File

@ -120,10 +120,8 @@ _cogl_texture_3d_create_base (CoglContext *ctx,
CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1); CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1);
CoglTexture *tex = COGL_TEXTURE (tex_3d); CoglTexture *tex = COGL_TEXTURE (tex_3d);
_cogl_texture_init (tex, ctx, &cogl_texture_3d_vtable); _cogl_texture_init (tex, ctx, width, height, &cogl_texture_3d_vtable);
tex_3d->width = width;
tex_3d->height = height;
tex_3d->depth = depth; tex_3d->depth = depth;
tex_3d->mipmaps_dirty = TRUE; tex_3d->mipmaps_dirty = TRUE;
tex_3d->auto_mipmap = TRUE; tex_3d->auto_mipmap = TRUE;
@ -639,18 +637,6 @@ _cogl_texture_3d_get_gl_format (CoglTexture *tex)
return COGL_TEXTURE_3D (tex)->gl_format; return COGL_TEXTURE_3D (tex)->gl_format;
} }
static int
_cogl_texture_3d_get_width (CoglTexture *tex)
{
return COGL_TEXTURE_3D (tex)->width;
}
static int
_cogl_texture_3d_get_height (CoglTexture *tex)
{
return COGL_TEXTURE_3D (tex)->height;
}
static CoglTextureType static CoglTextureType
_cogl_texture_3d_get_type (CoglTexture *tex) _cogl_texture_3d_get_type (CoglTexture *tex)
{ {
@ -676,8 +662,6 @@ cogl_texture_3d_vtable =
_cogl_texture_3d_gl_flush_legacy_texobj_wrap_modes, _cogl_texture_3d_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_3d_get_format, _cogl_texture_3d_get_format,
_cogl_texture_3d_get_gl_format, _cogl_texture_3d_get_gl_format,
_cogl_texture_3d_get_width,
_cogl_texture_3d_get_height,
_cogl_texture_3d_get_type, _cogl_texture_3d_get_type,
NULL, /* is_foreign */ NULL, /* is_foreign */
_cogl_texture_3d_set_auto_mipmap _cogl_texture_3d_set_auto_mipmap

View File

@ -126,8 +126,6 @@ struct _CoglTextureVtable
CoglPixelFormat (* get_format) (CoglTexture *tex); CoglPixelFormat (* get_format) (CoglTexture *tex);
GLenum (* get_gl_format) (CoglTexture *tex); GLenum (* get_gl_format) (CoglTexture *tex);
int (* get_width) (CoglTexture *tex);
int (* get_height) (CoglTexture *tex);
CoglTextureType (* get_type) (CoglTexture *tex); CoglTextureType (* get_type) (CoglTexture *tex);
@ -144,6 +142,8 @@ struct _CoglTexture
CoglContext *context; CoglContext *context;
GList *framebuffers; GList *framebuffers;
int max_level; int max_level;
int width;
int height;
const CoglTextureVtable *vtable; const CoglTextureVtable *vtable;
}; };
@ -177,6 +177,8 @@ struct _CoglTexturePixel
void void
_cogl_texture_init (CoglTexture *texture, _cogl_texture_init (CoglTexture *texture,
CoglContext *ctx, CoglContext *ctx,
int width,
int height,
const CoglTextureVtable *vtable); const CoglTextureVtable *vtable);
void void

View File

@ -35,8 +35,6 @@ struct _CoglTextureRectangle
/* The internal format of the texture represented as a /* The internal format of the texture represented as a
CoglPixelFormat */ CoglPixelFormat */
CoglPixelFormat format; CoglPixelFormat format;
int width;
int height;
/* TODO: factor out these OpenGL specific members into some form /* TODO: factor out these OpenGL specific members into some form
* of driver private state. */ * of driver private state. */

View File

@ -171,10 +171,7 @@ _cogl_texture_rectangle_create_base (CoglContext *ctx,
CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1); CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1);
CoglTexture *tex = COGL_TEXTURE (tex_rect); CoglTexture *tex = COGL_TEXTURE (tex_rect);
_cogl_texture_init (tex, ctx, &cogl_texture_rectangle_vtable); _cogl_texture_init (tex, ctx, width, height, &cogl_texture_rectangle_vtable);
tex_rect->width = width;
tex_rect->height = height;
/* We default to GL_LINEAR for both filters */ /* We default to GL_LINEAR for both filters */
tex_rect->gl_legacy_texobj_min_filter = GL_LINEAR; tex_rect->gl_legacy_texobj_min_filter = GL_LINEAR;
@ -462,17 +459,14 @@ _cogl_texture_rectangle_transform_coords_to_gl (CoglTexture *tex,
float *s, float *s,
float *t) float *t)
{ {
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex); *s *= tex->width;
*t *= tex->height;
*s *= tex_rect->width;
*t *= tex_rect->height;
} }
static CoglTransformResult static CoglTransformResult
_cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex, _cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex,
float *coords) float *coords)
{ {
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
CoglBool need_repeat = FALSE; CoglBool need_repeat = FALSE;
int i; int i;
@ -480,7 +474,7 @@ _cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex,
{ {
if (coords[i] < 0.0f || coords[i] > 1.0f) if (coords[i] < 0.0f || coords[i] > 1.0f)
need_repeat = TRUE; need_repeat = TRUE;
coords[i] *= (i & 1) ? tex_rect->height : tex_rect->width; coords[i] *= (i & 1) ? tex->height : tex->width;
} }
return (need_repeat ? COGL_TRANSFORM_SOFTWARE_REPEAT return (need_repeat ? COGL_TRANSFORM_SOFTWARE_REPEAT
@ -614,7 +608,7 @@ _cogl_texture_rectangle_get_data (CoglTexture *tex,
ctx->texture_driver->prep_gl_for_pixels_download (ctx, ctx->texture_driver->prep_gl_for_pixels_download (ctx,
rowstride, rowstride,
tex_rect->width, tex->width,
bpp); bpp);
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
@ -639,18 +633,6 @@ _cogl_texture_rectangle_get_gl_format (CoglTexture *tex)
return COGL_TEXTURE_RECTANGLE (tex)->gl_format; return COGL_TEXTURE_RECTANGLE (tex)->gl_format;
} }
static int
_cogl_texture_rectangle_get_width (CoglTexture *tex)
{
return COGL_TEXTURE_RECTANGLE (tex)->width;
}
static int
_cogl_texture_rectangle_get_height (CoglTexture *tex)
{
return COGL_TEXTURE_RECTANGLE (tex)->height;
}
static CoglBool static CoglBool
_cogl_texture_rectangle_is_foreign (CoglTexture *tex) _cogl_texture_rectangle_is_foreign (CoglTexture *tex)
{ {
@ -682,8 +664,6 @@ cogl_texture_rectangle_vtable =
_cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes, _cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_rectangle_get_format, _cogl_texture_rectangle_get_format,
_cogl_texture_rectangle_get_gl_format, _cogl_texture_rectangle_get_gl_format,
_cogl_texture_rectangle_get_width,
_cogl_texture_rectangle_get_height,
_cogl_texture_rectangle_get_type, _cogl_texture_rectangle_get_type,
_cogl_texture_rectangle_is_foreign, _cogl_texture_rectangle_is_foreign,
_cogl_texture_rectangle_set_auto_mipmap _cogl_texture_rectangle_set_auto_mipmap

View File

@ -131,10 +131,14 @@ cogl_texture_unref (void *object)
void void
_cogl_texture_init (CoglTexture *texture, _cogl_texture_init (CoglTexture *texture,
CoglContext *context, CoglContext *context,
int width,
int height,
const CoglTextureVtable *vtable) const CoglTextureVtable *vtable)
{ {
texture->context = context; texture->context = context;
texture->max_level = 0; texture->max_level = 0;
texture->width = width;
texture->height = height;
texture->vtable = vtable; texture->vtable = vtable;
texture->framebuffers = NULL; texture->framebuffers = NULL;
} }
@ -295,13 +299,13 @@ cogl_texture_new_from_sub_texture (CoglTexture *full_texture,
unsigned int unsigned int
cogl_texture_get_width (CoglTexture *texture) cogl_texture_get_width (CoglTexture *texture)
{ {
return texture->vtable->get_width (texture); return texture->width;
} }
unsigned int unsigned int
cogl_texture_get_height (CoglTexture *texture) cogl_texture_get_height (CoglTexture *texture)
{ {
return texture->vtable->get_height (texture); return texture->height;
} }
CoglPixelFormat CoglPixelFormat

View File

@ -607,6 +607,7 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
{ {
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context; CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
int bpp; int bpp;
int width = COGL_TEXTURE (tex_2d)->width;
GLenum gl_format; GLenum gl_format;
GLenum gl_type; GLenum gl_type;
@ -620,7 +621,7 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
ctx->texture_driver->prep_gl_for_pixels_download (ctx, ctx->texture_driver->prep_gl_for_pixels_download (ctx,
rowstride, rowstride,
tex_2d->width, width,
bpp); bpp);
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D, _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,

View File

@ -57,8 +57,6 @@ struct _CoglTexturePixmapX11
unsigned int depth; unsigned int depth;
Visual *visual; Visual *visual;
unsigned int width;
unsigned int height;
XImage *image; XImage *image;

View File

@ -125,6 +125,7 @@ static void
process_damage_event (CoglTexturePixmapX11 *tex_pixmap, process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
XDamageNotifyEvent *damage_event) XDamageNotifyEvent *damage_event)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
Display *display; Display *display;
enum { DO_NOTHING, NEEDS_SUBTRACT, NEED_BOUNDING_BOX } handle_mode; enum { DO_NOTHING, NEEDS_SUBTRACT, NEED_BOUNDING_BOX } handle_mode;
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
@ -167,8 +168,8 @@ process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
need to request the bounding box of the region because we're need to request the bounding box of the region because we're
going to update the whole texture anyway. */ going to update the whole texture anyway. */
if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect, if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect,
tex_pixmap->width, tex->width,
tex_pixmap->height)) tex->height))
{ {
if (handle_mode != DO_NOTHING) if (handle_mode != DO_NOTHING)
XDamageSubtract (display, tex_pixmap->damage, None, None); XDamageSubtract (display, tex_pixmap->damage, None, None);
@ -283,24 +284,16 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer); Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
Window pixmap_root_window; Window pixmap_root_window;
int pixmap_x, pixmap_y; int pixmap_x, pixmap_y;
unsigned int pixmap_width, pixmap_height;
unsigned int pixmap_border_width; unsigned int pixmap_border_width;
CoglTexture *tex = COGL_TEXTURE (tex_pixmap); CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
XWindowAttributes window_attributes; XWindowAttributes window_attributes;
int damage_base; int damage_base;
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
_cogl_texture_init (tex, ctxt, &cogl_texture_pixmap_x11_vtable);
tex_pixmap->pixmap = pixmap;
tex_pixmap->image = NULL;
tex_pixmap->shm_info.shmid = -1;
tex_pixmap->tex = NULL;
tex_pixmap->damage_owned = FALSE;
tex_pixmap->damage = 0;
if (!XGetGeometry (display, pixmap, &pixmap_root_window, if (!XGetGeometry (display, pixmap, &pixmap_root_window,
&pixmap_x, &pixmap_y, &pixmap_x, &pixmap_y,
&tex_pixmap->width, &tex_pixmap->height, &pixmap_width, &pixmap_height,
&pixmap_border_width, &tex_pixmap->depth)) &pixmap_border_width, &tex_pixmap->depth))
{ {
g_free (tex_pixmap); g_free (tex_pixmap);
@ -311,6 +304,16 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
return NULL; return NULL;
} }
_cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height,
&cogl_texture_pixmap_x11_vtable);
tex_pixmap->pixmap = pixmap;
tex_pixmap->image = NULL;
tex_pixmap->shm_info.shmid = -1;
tex_pixmap->tex = NULL;
tex_pixmap->damage_owned = FALSE;
tex_pixmap->damage = 0;
/* We need a visual to use for shared memory images so we'll query /* We need a visual to use for shared memory images so we'll query
it from the pixmap's root window */ it from the pixmap's root window */
if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes)) if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
@ -342,9 +345,9 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
/* Assume the entire pixmap is damaged to begin with */ /* Assume the entire pixmap is damaged to begin with */
tex_pixmap->damage_rect.x1 = 0; tex_pixmap->damage_rect.x1 = 0;
tex_pixmap->damage_rect.x2 = tex_pixmap->width; tex_pixmap->damage_rect.x2 = tex->width;
tex_pixmap->damage_rect.y1 = 0; tex_pixmap->damage_rect.y1 = 0;
tex_pixmap->damage_rect.y2 = tex_pixmap->height; tex_pixmap->damage_rect.y2 = tex->height;
winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
if (winsys->texture_pixmap_x11_create) if (winsys->texture_pixmap_x11_create)
@ -366,6 +369,7 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
static void static void
try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap) try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
XImage *dummy_image; XImage *dummy_image;
Display *display; Display *display;
@ -392,8 +396,8 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
ZPixmap, ZPixmap,
NULL, NULL,
NULL, /* shminfo, */ NULL, /* shminfo, */
tex_pixmap->width, tex->width,
tex_pixmap->height); tex->height);
if (!dummy_image) if (!dummy_image)
goto failed_image_create; goto failed_image_create;
@ -479,6 +483,7 @@ cogl_texture_pixmap_x11_set_damage_object (CoglTexturePixmapX11 *tex_pixmap,
static void static void
_cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap) _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
Display *display; Display *display;
Visual *visual; Visual *visual;
CoglPixelFormat image_format; CoglPixelFormat image_format;
@ -514,8 +519,8 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
? COGL_PIXEL_FORMAT_RGBA_8888_PRE ? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888); : COGL_PIXEL_FORMAT_RGB_888);
tex_pixmap->tex = cogl_texture_new_with_size (tex_pixmap->width, tex_pixmap->tex = cogl_texture_new_with_size (tex->width,
tex_pixmap->height, tex->height,
COGL_TEXTURE_NONE, COGL_TEXTURE_NONE,
texture_format); texture_format);
} }
@ -540,7 +545,7 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
tex_pixmap->image = XGetImage (display, tex_pixmap->image = XGetImage (display,
tex_pixmap->pixmap, tex_pixmap->pixmap,
0, 0, 0, 0,
tex_pixmap->width, tex_pixmap->height, tex->width, tex->height,
AllPlanes, ZPixmap); AllPlanes, ZPixmap);
image = tex_pixmap->image; image = tex_pixmap->image;
src_x = x; src_x = x;
@ -773,8 +778,8 @@ _cogl_texture_pixmap_x11_foreach_sub_texture_in_region
if (cogl_is_texture_rectangle (child_tex)) if (cogl_is_texture_rectangle (child_tex))
{ {
NormalizeCoordsWrapperData data; NormalizeCoordsWrapperData data;
int width = tex_pixmap->width; int width = tex->width;
int height = tex_pixmap->height; int height = tex->height;
virtual_tx_1 *= width; virtual_tx_1 *= width;
virtual_ty_1 *= height; virtual_ty_1 *= height;
@ -945,22 +950,6 @@ _cogl_texture_pixmap_x11_get_gl_format (CoglTexture *tex)
return _cogl_texture_gl_get_format (child_tex); return _cogl_texture_gl_get_format (child_tex);
} }
static int
_cogl_texture_pixmap_x11_get_width (CoglTexture *tex)
{
CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex);
return tex_pixmap->width;
}
static int
_cogl_texture_pixmap_x11_get_height (CoglTexture *tex)
{
CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex);
return tex_pixmap->height;
}
static CoglTextureType static CoglTextureType
_cogl_texture_pixmap_x11_get_type (CoglTexture *tex) _cogl_texture_pixmap_x11_get_type (CoglTexture *tex)
{ {
@ -1027,8 +1016,6 @@ cogl_texture_pixmap_x11_vtable =
_cogl_texture_pixmap_x11_gl_flush_legacy_texobj_wrap_modes, _cogl_texture_pixmap_x11_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_pixmap_x11_get_format, _cogl_texture_pixmap_x11_get_format,
_cogl_texture_pixmap_x11_get_gl_format, _cogl_texture_pixmap_x11_get_gl_format,
_cogl_texture_pixmap_x11_get_width,
_cogl_texture_pixmap_x11_get_height,
_cogl_texture_pixmap_x11_get_type, _cogl_texture_pixmap_x11_get_type,
NULL, /* is_foreign */ NULL, /* is_foreign */
NULL /* set_auto_mipmap */ NULL /* set_auto_mipmap */

View File

@ -686,15 +686,13 @@ _cogl_winsys_poll_dispatch (CoglContext *context,
static CoglBool static CoglBool
_cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap) _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
CoglContext *ctx = tex->context;
CoglTexturePixmapEGL *egl_tex_pixmap; CoglTexturePixmapEGL *egl_tex_pixmap;
EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
CoglPixelFormat texture_format; CoglPixelFormat texture_format;
CoglRendererEGL *egl_renderer; CoglRendererEGL *egl_renderer;
/* FIXME: It should be possible to get to a CoglContext from any
* CoglTexture pointer. */
_COGL_GET_CONTEXT (ctx, FALSE);
egl_renderer = ctx->display->renderer->winsys; egl_renderer = ctx->display->renderer->winsys;
if (!(egl_renderer->private_features & if (!(egl_renderer->private_features &
@ -725,8 +723,8 @@ _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
egl_tex_pixmap->texture = COGL_TEXTURE ( egl_tex_pixmap->texture = COGL_TEXTURE (
_cogl_egl_texture_2d_new_from_image (ctx, _cogl_egl_texture_2d_new_from_image (ctx,
tex_pixmap->width, tex->width,
tex_pixmap->height, tex->height,
texture_format, texture_format,
egl_tex_pixmap->image, egl_tex_pixmap->image,
NULL)); NULL));

View File

@ -1931,6 +1931,7 @@ static CoglBool
_cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
CoglBool needs_mipmap) CoglBool needs_mipmap)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
CoglContext *ctx = COGL_TEXTURE (tex_pixmap)->context; CoglContext *ctx = COGL_TEXTURE (tex_pixmap)->context;
CoglTexturePixmapGLX *glx_tex_pixmap = tex_pixmap->winsys; CoglTexturePixmapGLX *glx_tex_pixmap = tex_pixmap->winsys;
CoglGLXRenderer *glx_renderer; CoglGLXRenderer *glx_renderer;
@ -1955,8 +1956,8 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
{ {
glx_tex_pixmap->glx_tex = COGL_TEXTURE ( glx_tex_pixmap->glx_tex = COGL_TEXTURE (
cogl_texture_rectangle_new_with_size (ctx, cogl_texture_rectangle_new_with_size (ctx,
tex_pixmap->width, tex->width,
tex_pixmap->height, tex->height,
texture_format, texture_format,
&error)); &error));
@ -1977,8 +1978,8 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
{ {
glx_tex_pixmap->glx_tex = COGL_TEXTURE ( glx_tex_pixmap->glx_tex = COGL_TEXTURE (
cogl_texture_2d_new_with_size (ctx, cogl_texture_2d_new_with_size (ctx,
tex_pixmap->width, tex->width,
tex_pixmap->height, tex->height,
texture_format, texture_format,
NULL)); NULL));