Split the wrap mode of _cogl_texture_set_wrap_mode into three

GL supports setting different wrap modes for the s, t and r
coordinates so we should design the backend interface to support that
also. The r coordinate is not currently used by any of the backends
but we might as well have it to make life easier if we ever add
support for 3D textures.

http://bugzilla.openedhand.com/show_bug.cgi?id=2063
This commit is contained in:
Neil Roberts 2010-03-25 17:29:22 +00:00
parent 774f5e0bdf
commit 463ebc8220
9 changed files with 87 additions and 42 deletions

View File

@ -229,13 +229,18 @@ _cogl_atlas_texture_foreach_sub_texture_in_region (
} }
static void static void
_cogl_atlas_texture_set_wrap_mode_parameter (CoglTexture *tex, _cogl_atlas_texture_set_wrap_mode_parameters (CoglTexture *tex,
GLenum wrap_mode) GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r)
{ {
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex); CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
/* Forward on to the sub texture */ /* Forward on to the sub texture */
_cogl_texture_set_wrap_mode_parameter (atlas_tex->sub_texture, wrap_mode); _cogl_texture_set_wrap_mode_parameters (atlas_tex->sub_texture,
wrap_mode_s,
wrap_mode_t,
wrap_mode_r);
} }
static void static void
@ -1068,7 +1073,7 @@ cogl_atlas_texture_vtable =
_cogl_atlas_texture_set_filters, _cogl_atlas_texture_set_filters,
_cogl_atlas_texture_ensure_mipmaps, _cogl_atlas_texture_ensure_mipmaps,
_cogl_atlas_texture_ensure_non_quad_rendering, _cogl_atlas_texture_ensure_non_quad_rendering,
_cogl_atlas_texture_set_wrap_mode_parameter, _cogl_atlas_texture_set_wrap_mode_parameters,
_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_width,

View File

@ -157,7 +157,10 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
/* We can't use hardware repeat so we need to set clamp to edge /* We can't use hardware repeat so we need to set clamp to edge
otherwise it might pull in edge pixels from the other side */ otherwise it might pull in edge pixels from the other side */
/* FIXME: wrap modes should be part of the material! */ /* FIXME: wrap modes should be part of the material! */
_cogl_texture_set_wrap_mode_parameter (tex_handle, GL_CLAMP_TO_EDGE); _cogl_texture_set_wrap_mode_parameters (tex_handle,
GL_CLAMP_TO_EDGE,
GL_CLAMP_TO_EDGE,
GL_CLAMP_TO_EDGE);
state.material = material; state.material = material;
@ -329,7 +332,10 @@ _cogl_multitexture_quad_single_primitive (const float *position,
else else
wrap_mode = GL_CLAMP_TO_EDGE; wrap_mode = GL_CLAMP_TO_EDGE;
_cogl_texture_set_wrap_mode_parameter (tex_handle, wrap_mode); _cogl_texture_set_wrap_mode_parameters (tex_handle,
wrap_mode,
wrap_mode,
wrap_mode);
} }
_cogl_journal_log_quad (position, _cogl_journal_log_quad (position,
@ -920,7 +926,9 @@ cogl_polygon (const CoglTextureVertex *vertices,
* a transparent border * a transparent border
* XXX: it's doesn't look like we save/restore this, like * XXX: it's doesn't look like we save/restore this, like
* the comment implies? */ * the comment implies? */
_cogl_texture_set_wrap_mode_parameter (tex_handle, _cogl_texture_set_wrap_mode_parameters (tex_handle,
GL_CLAMP_TO_BORDER,
GL_CLAMP_TO_BORDER,
GL_CLAMP_TO_BORDER); GL_CLAMP_TO_BORDER);
} }
#endif #endif

View File

@ -224,12 +224,17 @@ _cogl_sub_texture_foreach_sub_texture_in_region (
} }
static void static void
_cogl_sub_texture_set_wrap_mode_parameter (CoglTexture *tex, _cogl_sub_texture_set_wrap_mode_parameters (CoglTexture *tex,
GLenum wrap_mode) GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r)
{ {
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex); CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
_cogl_texture_set_wrap_mode_parameter (sub_tex->full_texture, wrap_mode); _cogl_texture_set_wrap_mode_parameters (sub_tex->full_texture,
wrap_mode_s,
wrap_mode_t,
wrap_mode_r);
} }
static void static void
@ -547,7 +552,7 @@ cogl_sub_texture_vtable =
_cogl_sub_texture_set_filters, _cogl_sub_texture_set_filters,
_cogl_sub_texture_ensure_mipmaps, _cogl_sub_texture_ensure_mipmaps,
_cogl_sub_texture_ensure_non_quad_rendering, _cogl_sub_texture_ensure_non_quad_rendering,
_cogl_sub_texture_set_wrap_mode_parameter, _cogl_sub_texture_set_wrap_mode_parameters,
_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_width,

View File

@ -47,7 +47,8 @@ struct _CoglTexture2D
int height; int height;
GLenum min_filter; GLenum min_filter;
GLenum mag_filter; GLenum mag_filter;
GLint wrap_mode; GLint wrap_mode_s;
GLint wrap_mode_t;
gboolean auto_mipmap; gboolean auto_mipmap;
gboolean mipmaps_dirty; gboolean mipmaps_dirty;
}; };

View File

@ -65,7 +65,8 @@ struct _CoglTexture2DSliced
GLenum min_filter; GLenum min_filter;
GLenum mag_filter; GLenum mag_filter;
gboolean is_foreign; gboolean is_foreign;
GLint wrap_mode; GLenum wrap_mode_s;
GLenum wrap_mode_t;
gboolean auto_mipmap; gboolean auto_mipmap;
gboolean mipmaps_dirty; gboolean mipmaps_dirty;

View File

@ -661,14 +661,18 @@ _cogl_pot_slices_for_size (int size_to_fill,
} }
static void static void
_cogl_texture_2d_sliced_set_wrap_mode_parameter (CoglTexture *tex, _cogl_texture_2d_sliced_set_wrap_mode_parameters (CoglTexture *tex,
GLenum wrap_mode) GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r)
{ {
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
/* Only set the wrap mode if it's different from the current /* Only set the wrap mode if it's different from the current value
value to avoid too many GL calls */ to avoid too many GL calls. Texture 2D doesn't make use of the r
if (tex_2ds->wrap_mode != wrap_mode) coordinate so we can ignore its wrap mode */
if (tex_2ds->wrap_mode_s != wrap_mode_s ||
tex_2ds->wrap_mode_t != wrap_mode_t)
{ {
int i; int i;
@ -681,11 +685,14 @@ _cogl_texture_2d_sliced_set_wrap_mode_parameter (CoglTexture *tex,
GLuint texnum = g_array_index (tex_2ds->slice_gl_handles, GLuint, i); GLuint texnum = g_array_index (tex_2ds->slice_gl_handles, GLuint, i);
GE( glBindTexture (tex_2ds->gl_target, texnum) ); GE( glBindTexture (tex_2ds->gl_target, texnum) );
GE( glTexParameteri (tex_2ds->gl_target, GL_TEXTURE_WRAP_S, wrap_mode) ); GE( glTexParameteri (tex_2ds->gl_target,
GE( glTexParameteri (tex_2ds->gl_target, GL_TEXTURE_WRAP_T, wrap_mode) ); GL_TEXTURE_WRAP_S, wrap_mode_s) );
GE( glTexParameteri (tex_2ds->gl_target,
GL_TEXTURE_WRAP_T, wrap_mode_t) );
} }
tex_2ds->wrap_mode = wrap_mode; tex_2ds->wrap_mode_s = wrap_mode_s;
tex_2ds->wrap_mode_t = wrap_mode_t;
} }
} }
@ -827,7 +834,8 @@ _cogl_texture_2d_sliced_slices_create (CoglTexture2DSliced *tex_2ds,
tex_2ds->first_pixels = g_new (CoglTexturePixel, n_slices); tex_2ds->first_pixels = g_new (CoglTexturePixel, n_slices);
/* Wrap mode not yet set */ /* Wrap mode not yet set */
tex_2ds->wrap_mode = GL_FALSE; tex_2ds->wrap_mode_s = GL_FALSE;
tex_2ds->wrap_mode_t = GL_FALSE;
/* Generate a "working set" of GL texture objects /* Generate a "working set" of GL texture objects
* (some implementations might supported faster * (some implementations might supported faster
@ -1188,7 +1196,8 @@ _cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle,
tex_2ds->max_waste = 0; tex_2ds->max_waste = 0;
/* Wrap mode not yet set */ /* Wrap mode not yet set */
tex_2ds->wrap_mode = GL_FALSE; tex_2ds->wrap_mode_s = GL_FALSE;
tex_2ds->wrap_mode_t = GL_FALSE;
/* Create slice arrays */ /* Create slice arrays */
tex_2ds->slice_x_spans = tex_2ds->slice_x_spans =
@ -1728,7 +1737,7 @@ cogl_texture_2d_sliced_vtable =
_cogl_texture_2d_sliced_set_filters, _cogl_texture_2d_sliced_set_filters,
_cogl_texture_2d_sliced_ensure_mipmaps, _cogl_texture_2d_sliced_ensure_mipmaps,
_cogl_texture_2d_sliced_ensure_non_quad_rendering, _cogl_texture_2d_sliced_ensure_non_quad_rendering,
_cogl_texture_2d_sliced_set_wrap_mode_parameter, _cogl_texture_2d_sliced_set_wrap_mode_parameters,
_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_width,

View File

@ -124,24 +124,29 @@ _cogl_texture_2d_foreach_sub_texture_in_region (
} }
static void static void
_cogl_texture_2d_set_wrap_mode_parameter (CoglTexture *tex, _cogl_texture_2d_set_wrap_mode_parameters (CoglTexture *tex,
GLenum wrap_mode) GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r)
{ {
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
/* Only set the wrap mode if it's different from the current /* Only set the wrap mode if it's different from the current value
value to avoid too many GL calls */ to avoid too many GL calls. Texture 2D doesn't make use of the r
if (tex_2d->wrap_mode != wrap_mode) coordinate so we can ignore its wrap mode */
if (tex_2d->wrap_mode_s != wrap_mode_s ||
tex_2d->wrap_mode_t != wrap_mode_t)
{ {
/* Any queued texture rectangles may be depending on the /* Any queued texture rectangles may be depending on the
* previous wrap mode... */ * previous wrap mode... */
_cogl_journal_flush (); _cogl_journal_flush ();
GE( glBindTexture (GL_TEXTURE_2D, tex_2d->gl_texture) ); GE( glBindTexture (GL_TEXTURE_2D, tex_2d->gl_texture) );
GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode) ); GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode_s) );
GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode) ); GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode_t) );
tex_2d->wrap_mode = wrap_mode; tex_2d->wrap_mode_s = wrap_mode_s;
tex_2d->wrap_mode_t = wrap_mode_t;
} }
} }
@ -231,7 +236,8 @@ _cogl_texture_2d_create_base (unsigned int width,
tex_2d->mag_filter = GL_LINEAR; tex_2d->mag_filter = GL_LINEAR;
/* Wrap mode not yet set */ /* Wrap mode not yet set */
tex_2d->wrap_mode = GL_FALSE; tex_2d->wrap_mode_s = GL_FALSE;
tex_2d->wrap_mode_t = GL_FALSE;
tex_2d->format = internal_format; tex_2d->format = internal_format;
@ -643,7 +649,7 @@ cogl_texture_2d_vtable =
_cogl_texture_2d_set_filters, _cogl_texture_2d_set_filters,
_cogl_texture_2d_ensure_mipmaps, _cogl_texture_2d_ensure_mipmaps,
_cogl_texture_2d_ensure_non_quad_rendering, _cogl_texture_2d_ensure_non_quad_rendering,
_cogl_texture_2d_set_wrap_mode_parameter, _cogl_texture_2d_set_wrap_mode_parameters,
_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_width,

View File

@ -109,8 +109,10 @@ struct _CoglTextureVtable
void (* ensure_mipmaps) (CoglTexture *tex); void (* ensure_mipmaps) (CoglTexture *tex);
void (* ensure_non_quad_rendering) (CoglTexture *tex); void (* ensure_non_quad_rendering) (CoglTexture *tex);
void (* set_wrap_mode_parameter) (CoglTexture *tex, void (* set_wrap_mode_parameters) (CoglTexture *tex,
GLenum wrap_mode); GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r);
CoglPixelFormat (* get_format) (CoglTexture *tex); CoglPixelFormat (* get_format) (CoglTexture *tex);
GLenum (* get_gl_format) (CoglTexture *tex); GLenum (* get_gl_format) (CoglTexture *tex);
@ -148,8 +150,11 @@ GLenum
_cogl_texture_get_gl_format (CoglHandle handle); _cogl_texture_get_gl_format (CoglHandle handle);
void void
_cogl_texture_set_wrap_mode_parameter (CoglHandle handle, _cogl_texture_set_wrap_mode_parameters (CoglHandle handle,
GLenum wrap_mode); GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r);
void void
_cogl_texture_set_filters (CoglHandle handle, _cogl_texture_set_filters (CoglHandle handle,

View File

@ -212,12 +212,17 @@ _cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride)
/* FIXME: wrap modes should be set on materials not textures */ /* FIXME: wrap modes should be set on materials not textures */
void void
_cogl_texture_set_wrap_mode_parameter (CoglHandle handle, _cogl_texture_set_wrap_mode_parameters (CoglHandle handle,
GLenum wrap_mode) GLenum wrap_mode_s,
GLenum wrap_mode_t,
GLenum wrap_mode_r)
{ {
CoglTexture *tex = COGL_TEXTURE (handle); CoglTexture *tex = COGL_TEXTURE (handle);
tex->vtable->set_wrap_mode_parameter (tex, wrap_mode); tex->vtable->set_wrap_mode_parameters (tex,
wrap_mode_s,
wrap_mode_t,
wrap_mode_r);
} }
/* This is like CoglSpanIter except it deals with floats and it /* This is like CoglSpanIter except it deals with floats and it