summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Justen <[email protected]>2012-06-09 12:14:26 -0700
committerJordan Justen <[email protected]>2012-07-21 16:49:42 -0700
commit749c9060aca85277c388377d15fd6323ba20b78e (patch)
tree56faf569c5a61012b7e3a6824f38f83b761dc951
parent1c8812c244d74dd562a3db7c9226405bd6333735 (diff)
mesa formats: add MESA_FORMAT_ABGR2101010_UINT
Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Brian Paul <[email protected]>
-rw-r--r--src/mesa/main/format_pack.c28
-rw-r--r--src/mesa/main/format_unpack.c34
-rw-r--r--src/mesa/main/formats.c15
-rw-r--r--src/mesa/main/formats.h1
-rw-r--r--src/mesa/main/texformat.c1
-rw-r--r--src/mesa/main/texstore.c68
-rw-r--r--src/mesa/swrast/s_texfetch.c8
7 files changed, 154 insertions, 1 deletions
diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 7f0bda1278d..be6c026e8c2 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -1005,6 +1005,32 @@ pack_float_ARGB2101010(const GLfloat src[4], void *dst)
}
+/* MESA_FORMAT_ABGR2101010_UINT */
+
+static void
+pack_ubyte_ABGR2101010_UINT(const GLubyte src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r = UBYTE_TO_USHORT(src[RCOMP]);
+ GLushort g = UBYTE_TO_USHORT(src[GCOMP]);
+ GLushort b = UBYTE_TO_USHORT(src[BCOMP]);
+ GLushort a = UBYTE_TO_USHORT(src[ACOMP]);
+ *d = PACK_COLOR_2101010_US(a, b, g, r);
+}
+
+static void
+pack_float_ABGR2101010_UINT(const GLfloat src[4], void *dst)
+{
+ GLuint *d = ((GLuint *) dst);
+ GLushort r, g, b, a;
+ UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
+ UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+ *d = PACK_COLOR_2101010_US(a, b, g, r);
+}
+
+
/* MESA_FORMAT_SRGB8 */
static void
@@ -1696,6 +1722,7 @@ _mesa_get_pack_ubyte_rgba_function(gl_format format)
table[MESA_FORMAT_RG1616] = pack_ubyte_RG1616;
table[MESA_FORMAT_RG1616_REV] = pack_ubyte_RG1616_REV;
table[MESA_FORMAT_ARGB2101010] = pack_ubyte_ARGB2101010;
+ table[MESA_FORMAT_ABGR2101010_UINT] = pack_ubyte_ABGR2101010_UINT;
/* should never convert RGBA to these formats */
table[MESA_FORMAT_Z24_S8] = NULL;
@@ -1841,6 +1868,7 @@ _mesa_get_pack_float_rgba_function(gl_format format)
table[MESA_FORMAT_RG1616] = pack_float_RG1616;
table[MESA_FORMAT_RG1616_REV] = pack_float_RG1616_REV;
table[MESA_FORMAT_ARGB2101010] = pack_float_ARGB2101010;
+ table[MESA_FORMAT_ABGR2101010_UINT] = pack_float_ABGR2101010_UINT;
/* should never convert RGBA to these formats */
table[MESA_FORMAT_Z24_S8] = NULL;
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index d1daae59ce1..529c416a8cc 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -610,6 +610,20 @@ unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
static void
+unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
+{
+ const GLuint *s = ((const GLuint *) src);
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i][RCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff);
+ dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
+ dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
+ dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03);
+ }
+}
+
+
+static void
unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
{
/* only return Z, not stencil data */
@@ -1499,6 +1513,7 @@ get_unpack_rgba_function(gl_format format)
table[MESA_FORMAT_RG1616] = unpack_RG1616;
table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
+ table[MESA_FORMAT_ABGR2101010_UINT] = unpack_ABGR2101010_UINT;
table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
table[MESA_FORMAT_Z16] = unpack_Z16;
@@ -2589,6 +2604,20 @@ unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
}
}
+static void
+unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+ unsigned int i;
+
+ for (i = 0; i < n; i++) {
+ GLuint tmp = src[i];
+ dst[i][0] = (tmp >> 0) & 0x3ff;
+ dst[i][1] = (tmp >> 10) & 0x3ff;
+ dst[i][2] = (tmp >> 20) & 0x3ff;
+ dst[i][3] = (tmp >> 30) & 0x3;
+ }
+}
+
void
_mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
const void *src, GLuint dst[][4])
@@ -2759,6 +2788,11 @@ _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
case MESA_FORMAT_ARGB2101010_UINT:
unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
break;
+
+ case MESA_FORMAT_ABGR2101010_UINT:
+ unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
+ break;
+
default:
_mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
_mesa_get_format_name(format));
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 5dd9f085a85..1fa641c92ee 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1520,6 +1520,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
0, 0, 0, 0, 0,
1, 1, 4
},
+ {
+ MESA_FORMAT_ABGR2101010_UINT,
+ "MESA_FORMAT_ABGR2101010_UINT",
+ GL_RGBA,
+ GL_UNSIGNED_INT,
+ 10, 10, 10, 2,
+ 0, 0, 0, 0, 0,
+ 1, 1, 4
+ },
};
@@ -2503,6 +2512,7 @@ _mesa_format_to_type_and_comps(gl_format format,
return;
case MESA_FORMAT_ARGB2101010_UINT:
+ case MESA_FORMAT_ABGR2101010_UINT:
*datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
*comps = 4;
return;
@@ -2928,6 +2938,11 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
type == GL_UNSIGNED_INT_2_10_10_10_REV &&
!swapBytes);
+ case MESA_FORMAT_ABGR2101010_UINT:
+ return (format == GL_RGBA_INTEGER_EXT &&
+ type == GL_UNSIGNED_INT_2_10_10_10_REV &&
+ !swapBytes);
+
case MESA_FORMAT_RGB9_E5_FLOAT:
return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV &&
!swapBytes;
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 176e0fd18f6..1843eb6fc2c 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -276,6 +276,7 @@ typedef enum
MESA_FORMAT_Z32_FLOAT_X24S8,
MESA_FORMAT_ARGB2101010_UINT,
+ MESA_FORMAT_ABGR2101010_UINT,
MESA_FORMAT_COUNT
} gl_format;
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 26bcbc10a66..91897176ef4 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -887,6 +887,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
switch (internalFormat) {
case GL_RGB10_A2UI:
RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010_UINT);
+ RETURN_IF_SUPPORTED(MESA_FORMAT_ABGR2101010_UINT);
break;
default:
break;
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 6721be9e85e..ab9fdf26d3e 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -71,6 +71,7 @@
#include "teximage.h"
#include "texstore.h"
#include "enums.h"
+#include "glformats.h"
#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
@@ -3891,6 +3892,72 @@ _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS)
}
static GLboolean
+_mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS)
+{
+ const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+ ASSERT(dstFormat == MESA_FORMAT_ABGR2101010_UINT);
+ ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
+
+ if (baseInternalFormat == GL_RGBA &&
+ _mesa_format_matches_format_and_type(dstFormat, srcFormat, srcType,
+ srcPacking->SwapBytes)) {
+ /* simple memcpy path */
+ memcpy_texture(ctx, dims,
+ dstFormat,
+ dstRowStride, dstSlices,
+ srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+ srcAddr, srcPacking);
+ }
+ else {
+ /* general path */
+ const GLuint *tempImage = make_temp_uint_image(ctx, dims,
+ baseInternalFormat,
+ baseFormat,
+ srcWidth, srcHeight,
+ srcDepth, srcFormat,
+ srcType, srcAddr,
+ srcPacking);
+ const GLuint *src = tempImage;
+ GLint img, row, col;
+ GLboolean is_unsigned = _mesa_is_type_unsigned(srcType);
+ if (!tempImage)
+ return GL_FALSE;
+ for (img = 0; img < srcDepth; img++) {
+ GLubyte *dstRow = dstSlices[img];
+
+ for (row = 0; row < srcHeight; row++) {
+ GLuint *dstUI = (GLuint *) dstRow;
+ if (is_unsigned) {
+ for (col = 0; col < srcWidth; col++) {
+ GLushort a,r,g,b;
+ r = MIN2(src[RCOMP], 0x3ff);
+ g = MIN2(src[GCOMP], 0x3ff);
+ b = MIN2(src[BCOMP], 0x3ff);
+ a = MIN2(src[ACOMP], 0x003);
+ dstUI[col] = (a << 30) | (b << 20) | (g << 10) | (r);
+ src += 4;
+ }
+ } else {
+ for (col = 0; col < srcWidth; col++) {
+ GLushort a,r,g,b;
+ r = CLAMP((GLint) src[RCOMP], 0, 0x3ff);
+ g = CLAMP((GLint) src[GCOMP], 0, 0x3ff);
+ b = CLAMP((GLint) src[BCOMP], 0, 0x3ff);
+ a = CLAMP((GLint) src[ACOMP], 0, 0x003);
+ dstUI[col] = (a << 30) | (b << 20) | (g << 10) | (r);
+ src += 4;
+ }
+ }
+ dstRow += dstRowStride;
+ }
+ }
+ free((void *) tempImage);
+ }
+ return GL_TRUE;
+}
+
+static GLboolean
_mesa_texstore_null(TEXSTORE_PARAMS)
{
(void) ctx; (void) dims;
@@ -4084,6 +4151,7 @@ _mesa_get_texstore_func(gl_format format)
table[MESA_FORMAT_RGBA_UINT32] = _mesa_texstore_rgba_uint32;
table[MESA_FORMAT_ARGB2101010_UINT] = _mesa_texstore_argb2101010_uint;
+ table[MESA_FORMAT_ABGR2101010_UINT] = _mesa_texstore_abgr2101010_uint;
initialized = GL_TRUE;
}
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index 8529ff08db3..12ee47963d7 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -1104,7 +1104,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
NULL,
NULL,
NULL
- }
+ },
+ {
+ MESA_FORMAT_ABGR2101010_UINT,
+ NULL,
+ NULL,
+ NULL
+ },
};