From ba5418c60d7301fc78190bf7a39f475d868b6126 Mon Sep 17 00:00:00 2001 From: Samuel Iglesias Gonsalvez Date: Fri, 10 Oct 2014 12:46:02 +0200 Subject: [PATCH] mesa/pack: refactor _mesa_pack_rgba_span_float() Use autogenerated format pack functions and take advantage of some macros to reduce source code, facilitating its maintenance. Unfortunately, dstType == GL_UNSIGNED_SHORT cannot simplified like the others, so keep it as it is. Signed-off-by: Samuel Iglesias Gonsalvez Reviewed-by: Jason Ekstrand --- src/mesa/main/pack.c | 1318 +++++--------------------------------- src/mesa/main/pack_tmp.h | 1 + 2 files changed, 153 insertions(+), 1166 deletions(-) diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c index 067a0f5d459..06993d497f9 100644 --- a/src/mesa/main/pack.c +++ b/src/mesa/main/pack.c @@ -531,22 +531,22 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, GLuint n, GLuint rgba[][ { switch(dstType) { case GL_UNSIGNED_INT: - pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_INT: - pack_int_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_int_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_UNSIGNED_SHORT: - pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_SHORT: - pack_short_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_short_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_UNSIGNED_BYTE: - pack_ubyte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_ubyte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_BYTE: - pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_UNSIGNED_BYTE_3_3_2: if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) @@ -722,23 +722,23 @@ _mesa_pack_rgba_span_from_ints(struct gl_context *ctx, GLuint n, GLint rgba[][4] { switch(dstType) { case GL_UNSIGNED_INT: - pack_uint_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_uint_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_INT: /* No conversion necessary. */ - pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, (GLuint (*)[4]) rgba, n); + pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, (GLuint (*)[4]) rgba, NULL, n); break; case GL_UNSIGNED_SHORT: - pack_ushort_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_ushort_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_SHORT: - pack_short_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_short_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_UNSIGNED_BYTE: - pack_ubyte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_ubyte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_BYTE: - pack_byte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n); + pack_byte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n); break; case GL_UNSIGNED_BYTE_3_3_2: if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) @@ -850,6 +850,80 @@ _mesa_pack_rgba_span_from_ints(struct gl_context *ctx, GLuint n, GLint rgba[][4] } } +/* Customization of float packing. + */ +#define SRC_TYPE GLfloat + +#define DST_TYPE GLuint +#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UINT(x) +#define SRC_CONVERT(x) (GLuint) x +#define FN_NAME pack_uint_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#define DST_TYPE GLint +#define FLOAT_SRC_CONVERT(x) FLOAT_TO_INT(x) +#define SRC_CONVERT(x) (GLint) x +#define FN_NAME pack_int_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#define DST_TYPE GLshort +#define FLOAT_SRC_CONVERT(x) FLOAT_TO_SHORT_TEX(x) +#define SRC_CONVERT(x) (GLshort) x +#define FN_NAME pack_short_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#define DST_TYPE GLubyte +#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UBYTE(x) +#define SRC_CONVERT(x) (GLubyte) x +#define FN_NAME pack_ubyte_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#define DST_TYPE GLbyte +#define FLOAT_SRC_CONVERT(x) FLOAT_TO_BYTE_TEX(x) +#define SRC_CONVERT(x) (GLbyte) x +#define FN_NAME pack_byte_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#define DST_TYPE GLfloat +#define FLOAT_SRC_CONVERT(x) x +#define SRC_CONVERT(x) x +#define FN_NAME pack_float_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#define DST_TYPE GLhalfARB +#define FLOAT_SRC_CONVERT(x) _mesa_float_to_half(x) +#define FN_NAME pack_half_float_from_float_rgba +#include "pack_tmp.h" +#undef DST_TYPE +#undef SRC_CONVERT +#undef FLOAT_SRC_CONVERT +#undef FN_NAME + +#undef SRC_TYPE /** * Used to pack an array [][4] of RGBA float colors as specified @@ -935,304 +1009,10 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4], */ switch (dstType) { case GL_UNSIGNED_BYTE: - { - GLubyte *dst = (GLubyte *) dstAddr; - switch (dstFormat) { - case GL_RED: - for (i=0;i