[Cogl] [PATCH 1/5] Use ffs to calculate the GL_{UN, }PACK_ALIGNMENT
Robert Bragg
robert at sixbynine.org
Tue Apr 3 08:36:46 PDT 2012
Reviewed-by: Robert Bragg <robert at linux.intel.com>
On Tue, Mar 27, 2012 at 5:56 PM, Neil Roberts <neil at linux.intel.com> wrote:
> Instead of having a series of if-statements this adds an inline
> function to calculate the alignment directly using ffs which is
> probably slightly faster. Admittedly this is a pointless
> micro-optimisation but I think it makes the code looks a bit neater
> anyway.
> ---
> cogl/cogl-texture.c | 28 ++++++++++++----------------
> 1 files changed, 12 insertions(+), 16 deletions(-)
>
> diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
> index ab07f91..df4fdcc 100644
> --- a/cogl/cogl-texture.c
> +++ b/cogl/cogl-texture.c
> @@ -255,19 +255,21 @@ _cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
> return dst_bmp;
> }
>
> +static inline int
> +calculate_alignment (int rowstride)
> +{
> + int alignment = 1 << (_cogl_util_ffs (rowstride) - 1);
> +
> + return MIN (alignment, 8);
> +}
> +
> void
> _cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride)
> {
> _COGL_GET_CONTEXT (ctx, NO_RETVAL);
>
> - if (!(pixels_rowstride & 0x7))
> - GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 8) );
> - else if (!(pixels_rowstride & 0x3))
> - GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 4) );
> - else if (!(pixels_rowstride & 0x1))
> - GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 2) );
> - else
> - GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 1) );
> + GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT,
> + calculate_alignment (pixels_rowstride)) );
> }
>
> void
> @@ -275,14 +277,8 @@ _cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride)
> {
> _COGL_GET_CONTEXT (ctx, NO_RETVAL);
>
> - if (!(pixels_rowstride & 0x7))
> - GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 8) );
> - else if (!(pixels_rowstride & 0x3))
> - GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 4) );
> - else if (!(pixels_rowstride & 0x1))
> - GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 2) );
> - else
> - GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 1) );
> + GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT,
> + calculate_alignment (pixels_rowstride)) );
> }
>
> /* FIXME: wrap modes should be set on pipelines not textures */
> --
> 1.7.3.16.g9464b
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl
More information about the Cogl
mailing list