[Mesa-dev] [PATCH v2 06/29] mesa: Let _mesa_swizzle_and_convert take array format types instead of GL types
Iago Toral Quiroga
itoral at igalia.com
Mon Dec 1 03:04:59 PST 2014
In the future we would like to have a format conversion library that is
indepdent of GL so we can share it with Gallium. This is a step in that
direction.
---
src/mesa/main/format_utils.c | 263 +++++++++++++++++++++----------------------
src/mesa/main/format_utils.h | 8 +-
2 files changed, 132 insertions(+), 139 deletions(-)
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 8b435f4..c6a60a2 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -76,32 +76,6 @@ invert_swizzle(uint8_t dst[4], const uint8_t src[4])
dst[i] = j;
}
-static GLenum
-gl_type_for_array_format_datatype(enum mesa_array_format_datatype type)
-{
- switch (type) {
- case MESA_ARRAY_FORMAT_TYPE_UBYTE:
- return GL_UNSIGNED_BYTE;
- case MESA_ARRAY_FORMAT_TYPE_USHORT:
- return GL_UNSIGNED_SHORT;
- case MESA_ARRAY_FORMAT_TYPE_UINT:
- return GL_UNSIGNED_INT;
- case MESA_ARRAY_FORMAT_TYPE_BYTE:
- return GL_BYTE;
- case MESA_ARRAY_FORMAT_TYPE_SHORT:
- return GL_SHORT;
- case MESA_ARRAY_FORMAT_TYPE_INT:
- return GL_INT;
- case MESA_ARRAY_FORMAT_TYPE_HALF:
- return GL_HALF_FLOAT;
- case MESA_ARRAY_FORMAT_TYPE_FLOAT:
- return GL_FLOAT;
- default:
- assert(!"Invalid datatype");
- return GL_NONE;
- }
-}
-
enum {
ZERO = 4,
ONE = 5
@@ -460,7 +434,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
mesa_array_format src_array_format, dst_array_format;
uint8_t src2dst[4], src2rgba[4], rgba2dst[4], dst2rgba[4];
uint8_t rebased_src2rgba[4];
- GLenum src_gl_type, dst_gl_type, common_gl_type;
+ enum mesa_array_format_datatype src_type, dst_type, common_type;
+ int src_num_channels, dst_num_channels;
bool normalized, dst_integer, src_integer, is_signed;
uint8_t (*tmp_ubyte)[4];
float (*tmp_float)[4];
@@ -561,7 +536,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
/* Handle conversions between array formats */
normalized = false;
if (src_array_format.as_uint) {
- src_gl_type = gl_type_for_array_format_datatype(src_array_format.type);
+ src_type = src_array_format.type;
+ src_num_channels = src_array_format.num_channels;
src2rgba[0] = src_array_format.swizzle_x;
src2rgba[1] = src_array_format.swizzle_y;
@@ -572,7 +548,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
}
if (dst_array_format.as_uint) {
- dst_gl_type = gl_type_for_array_format_datatype(dst_array_format.type);
+ dst_type = dst_array_format.type;
+ dst_num_channels = dst_array_format.num_channels;
dst2rgba[0] = dst_array_format.swizzle_x;
dst2rgba[1] = dst_array_format.swizzle_y;
@@ -589,8 +566,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
compute_src2dst_component_mapping(src2rgba, rgba2dst, rebase_swizzle,
src2dst);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_gl_type, dst_array_format.num_channels,
- src, src_gl_type, src_array_format.num_channels,
+ _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+ src, src_type, src_num_channels,
src2dst, normalized, width);
src += src_stride;
dst += dst_stride;
@@ -671,14 +648,14 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
* _mesa_swizzle_and_convert for signed formats, which is aware of the
* truncation problem.
*/
- common_gl_type = is_signed ? GL_INT : GL_UNSIGNED_INT;
+ common_type = is_signed ? MESA_ARRAY_FORMAT_TYPE_INT :
+ MESA_ARRAY_FORMAT_TYPE_UINT;
if (src_array_format.as_uint) {
compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
rebased_src2rgba);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(tmp_uint + row * width, common_gl_type, 4,
- src, src_gl_type,
- src_array_format.num_channels,
+ _mesa_swizzle_and_convert(tmp_uint + row * width, common_type, 4,
+ src, src_type, src_num_channels,
rebased_src2rgba, normalized, width);
src += src_stride;
}
@@ -687,8 +664,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
_mesa_unpack_uint_rgba_row(src_format, width,
src, tmp_uint + row * width);
if (rebase_swizzle)
- _mesa_swizzle_and_convert(tmp_uint + row * width, common_gl_type, 4,
- tmp_uint + row * width, common_gl_type, 4,
+ _mesa_swizzle_and_convert(tmp_uint + row * width, common_type, 4,
+ tmp_uint + row * width, common_type, 4,
rebase_swizzle, false, width);
src += src_stride;
}
@@ -700,9 +677,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
*/
if (dst_format & MESA_ARRAY_FORMAT_BIT) {
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_gl_type,
- dst_array_format.num_channels,
- tmp_uint + row * width, common_gl_type, 4,
+ _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+ tmp_uint + row * width, common_type, 4,
rgba2dst, normalized, width);
dst += dst_stride;
}
@@ -722,9 +698,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
rebased_src2rgba);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(tmp_float + row * width, GL_FLOAT, 4,
- src, src_gl_type,
- src_array_format.num_channels,
+ _mesa_swizzle_and_convert(tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+ src, src_type, src_num_channels,
rebased_src2rgba, normalized, width);
src += src_stride;
}
@@ -733,8 +709,10 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
_mesa_unpack_rgba_row(src_format, width,
src, tmp_float + row * width);
if (rebase_swizzle)
- _mesa_swizzle_and_convert(tmp_float + row * width, GL_FLOAT, 4,
- tmp_float + row * width, GL_FLOAT, 4,
+ _mesa_swizzle_and_convert(tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+ tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
rebase_swizzle, false, width);
src += src_stride;
}
@@ -742,9 +720,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
if (dst_format & MESA_ARRAY_FORMAT_BIT) {
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_gl_type,
- dst_array_format.num_channels,
- tmp_float + row * width, GL_FLOAT, 4,
+ _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+ tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
rgba2dst, normalized, width);
dst += dst_stride;
}
@@ -764,9 +742,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
rebased_src2rgba);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
- src, src_gl_type,
- src_array_format.num_channels,
+ _mesa_swizzle_and_convert(tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+ src, src_type, src_num_channels,
rebased_src2rgba, normalized, width);
src += src_stride;
}
@@ -775,8 +753,10 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
_mesa_unpack_ubyte_rgba_row(src_format, width,
src, tmp_ubyte + row * width);
if (rebase_swizzle)
- _mesa_swizzle_and_convert(tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
- tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
+ _mesa_swizzle_and_convert(tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+ tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
rebase_swizzle, false, width);
src += src_stride;
}
@@ -784,9 +764,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
if (dst_format & MESA_ARRAY_FORMAT_BIT) {
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_gl_type,
- dst_array_format.num_channels,
- tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
+ _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+ tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
rgba2dst, normalized, width);
dst += dst_stride;
}
@@ -940,8 +920,12 @@ half_to_uint(uint16_t x)
* operation with memcpy, false otherwise
*/
static bool
-swizzle_convert_try_memcpy(void *dst, GLenum dst_type, int num_dst_channels,
- const void *src, GLenum src_type, int num_src_channels,
+swizzle_convert_try_memcpy(void *dst,
+ enum mesa_array_format_datatype dst_type,
+ int num_dst_channels,
+ const void *src,
+ enum mesa_array_format_datatype src_type,
+ int num_src_channels,
const uint8_t swizzle[4], bool normalized, int count)
{
int i;
@@ -955,7 +939,8 @@ swizzle_convert_try_memcpy(void *dst, GLenum dst_type, int num_dst_channels,
if (swizzle[i] != i && swizzle[i] != MESA_FORMAT_SWIZZLE_NONE)
return false;
- memcpy(dst, src, count * num_src_channels * _mesa_sizeof_type(src_type));
+ memcpy(dst, src, count * num_src_channels *
+ _mesa_array_format_datatype_size(src_type));
return true;
}
@@ -1111,48 +1096,48 @@ convert_float(void *void_dst, int num_dst_channels,
const float one = 1.0f;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
SWIZZLE_CONVERT(float, float, src);
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
SWIZZLE_CONVERT(float, uint16_t, _mesa_half_to_float(src));
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(float, uint8_t, _mesa_unorm_to_float(src, 8));
} else {
SWIZZLE_CONVERT(float, uint8_t, src);
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(float, int8_t, _mesa_snorm_to_float(src, 8));
} else {
SWIZZLE_CONVERT(float, int8_t, src);
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(float, uint16_t, _mesa_unorm_to_float(src, 16));
} else {
SWIZZLE_CONVERT(float, uint16_t, src);
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(float, int16_t, _mesa_snorm_to_float(src, 16));
} else {
SWIZZLE_CONVERT(float, int16_t, src);
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(float, uint32_t, _mesa_unorm_to_float(src, 32));
} else {
SWIZZLE_CONVERT(float, uint32_t, src);
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(float, int32_t, _mesa_snorm_to_float(src, 32));
} else {
@@ -1173,48 +1158,48 @@ convert_half_float(void *void_dst, int num_dst_channels,
const uint16_t one = _mesa_float_to_half(1.0f);
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_half(src));
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
SWIZZLE_CONVERT(uint16_t, uint16_t, src);
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_unorm_to_half(src, 8));
} else {
SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_float_to_half(src));
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_snorm_to_half(src, 8));
} else {
SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_float_to_half(src));
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_unorm_to_half(src, 16));
} else {
SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_float_to_half(src));
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_snorm_to_half(src, 16));
} else {
SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_float_to_half(src));
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_unorm_to_half(src, 32));
} else {
SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_float_to_half(src));
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, int32_t, _mesa_snorm_to_half(src, 32));
} else {
@@ -1234,52 +1219,52 @@ convert_ubyte(void *void_dst, int num_dst_channels,
const uint8_t one = normalized ? UINT8_MAX : 1;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, float, _mesa_float_to_unorm(src, 8));
} else {
SWIZZLE_CONVERT(uint8_t, float, (src < 0) ? 0 : src);
}
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_unorm(src, 8));
} else {
SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_unsigned_to_unsigned(half_to_uint(src), 8));
}
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
SWIZZLE_CONVERT(uint8_t, uint8_t, src);
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, int8_t, _mesa_snorm_to_unorm(src, 8, 8));
} else {
SWIZZLE_CONVERT(uint8_t, int8_t, _mesa_signed_to_unsigned(src, 8));
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_unorm_to_unorm(src, 16, 8));
} else {
SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_unsigned_to_unsigned(src, 8));
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, int16_t, _mesa_snorm_to_unorm(src, 16, 8));
} else {
SWIZZLE_CONVERT(uint8_t, int16_t, _mesa_signed_to_unsigned(src, 8));
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, uint32_t, _mesa_unorm_to_unorm(src, 32, 8));
} else {
SWIZZLE_CONVERT(uint8_t, uint32_t, _mesa_unsigned_to_unsigned(src, 8));
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, int32_t, _mesa_snorm_to_unorm(src, 32, 8));
} else {
@@ -1300,52 +1285,52 @@ convert_byte(void *void_dst, int num_dst_channels,
const int8_t one = normalized ? INT8_MAX : 1;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, float, _mesa_float_to_snorm(src, 8));
} else {
SWIZZLE_CONVERT(uint8_t, float, src);
}
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
if (normalized) {
SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_snorm(src, 8));
} else {
SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_float(src));
}
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(int8_t, uint8_t, _mesa_unorm_to_snorm(src, 8, 8));
} else {
SWIZZLE_CONVERT(int8_t, uint8_t, _mesa_unsigned_to_signed(src, 8));
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
SWIZZLE_CONVERT(int8_t, int8_t, src);
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(int8_t, uint16_t, _mesa_unorm_to_snorm(src, 16, 8));
} else {
SWIZZLE_CONVERT(int8_t, uint16_t, _mesa_unsigned_to_signed(src, 8));
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(int8_t, int16_t, _mesa_snorm_to_snorm(src, 16, 8));
} else {
SWIZZLE_CONVERT(int8_t, int16_t, _mesa_signed_to_signed(src, 8));
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(int8_t, uint32_t, _mesa_unorm_to_snorm(src, 32, 8));
} else {
SWIZZLE_CONVERT(int8_t, uint32_t, _mesa_unsigned_to_signed(src, 8));
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(int8_t, int32_t, _mesa_snorm_to_snorm(src, 32, 8));
} else {
@@ -1366,52 +1351,52 @@ convert_ushort(void *void_dst, int num_dst_channels,
const uint16_t one = normalized ? UINT16_MAX : 1;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_unorm(src, 16));
} else {
SWIZZLE_CONVERT(uint16_t, float, (src < 0) ? 0 : src);
}
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_unorm(src, 16));
} else {
SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_uint(src));
}
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_unorm_to_unorm(src, 8, 16));
} else {
SWIZZLE_CONVERT(uint16_t, uint8_t, src);
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_snorm_to_unorm(src, 8, 16));
} else {
SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_signed_to_unsigned(src, 16));
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
SWIZZLE_CONVERT(uint16_t, uint16_t, src);
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_snorm_to_unorm(src, 16, 16));
} else {
SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_signed_to_unsigned(src, 16));
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_unorm_to_unorm(src, 32, 16));
} else {
SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_unsigned_to_unsigned(src, 16));
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, int32_t, _mesa_snorm_to_unorm(src, 32, 16));
} else {
@@ -1432,52 +1417,52 @@ convert_short(void *void_dst, int num_dst_channels,
const int16_t one = normalized ? INT16_MAX : 1;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_snorm(src, 16));
} else {
SWIZZLE_CONVERT(uint16_t, float, src);
}
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
if (normalized) {
SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_snorm(src, 16));
} else {
SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_float(src));
}
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(int16_t, uint8_t, _mesa_unorm_to_snorm(src, 8, 16));
} else {
SWIZZLE_CONVERT(int16_t, uint8_t, src);
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(int16_t, int8_t, _mesa_snorm_to_snorm(src, 8, 16));
} else {
SWIZZLE_CONVERT(int16_t, int8_t, src);
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(int16_t, uint16_t, _mesa_unorm_to_snorm(src, 16, 16));
} else {
SWIZZLE_CONVERT(int16_t, uint16_t, _mesa_unsigned_to_signed(src, 16));
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
SWIZZLE_CONVERT(int16_t, int16_t, src);
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(int16_t, uint32_t, _mesa_unorm_to_snorm(src, 32, 16));
} else {
SWIZZLE_CONVERT(int16_t, uint32_t, _mesa_unsigned_to_signed(src, 16));
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(int16_t, int32_t, _mesa_snorm_to_snorm(src, 32, 16));
} else {
@@ -1497,52 +1482,52 @@ convert_uint(void *void_dst, int num_dst_channels,
const uint32_t one = normalized ? UINT32_MAX : 1;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, float, _mesa_float_to_unorm(src, 32));
} else {
SWIZZLE_CONVERT(uint32_t, float, (src < 0) ? 0 : src);
}
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_unorm(src, 32));
} else {
SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_uint(src));
}
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, uint8_t, _mesa_unorm_to_unorm(src, 8, 32));
} else {
SWIZZLE_CONVERT(uint32_t, uint8_t, src);
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, int8_t, _mesa_snorm_to_unorm(src, 8, 32));
} else {
SWIZZLE_CONVERT(uint32_t, int8_t, _mesa_signed_to_unsigned(src, 32));
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_unorm_to_unorm(src, 16, 32));
} else {
SWIZZLE_CONVERT(uint32_t, uint16_t, src);
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, int16_t, _mesa_snorm_to_unorm(src, 16, 32));
} else {
SWIZZLE_CONVERT(uint32_t, int16_t, _mesa_signed_to_unsigned(src, 32));
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
SWIZZLE_CONVERT(uint32_t, uint32_t, src);
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, int32_t, _mesa_snorm_to_unorm(src, 32, 32));
} else {
@@ -1563,56 +1548,56 @@ convert_int(void *void_dst, int num_dst_channels,
const int32_t one = normalized ? INT32_MAX : 1;
switch (src_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, float, _mesa_float_to_snorm(src, 32));
} else {
SWIZZLE_CONVERT(uint32_t, float, src);
}
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
if (normalized) {
SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_snorm(src, 32));
} else {
SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_float(src));
}
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
if (normalized) {
SWIZZLE_CONVERT(int32_t, uint8_t, _mesa_unorm_to_snorm(src, 8, 32));
} else {
SWIZZLE_CONVERT(int32_t, uint8_t, src);
}
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
if (normalized) {
SWIZZLE_CONVERT(int32_t, int8_t, _mesa_snorm_to_snorm(src, 8, 32));
} else {
SWIZZLE_CONVERT(int32_t, int8_t, src);
}
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
if (normalized) {
SWIZZLE_CONVERT(int32_t, uint16_t, _mesa_unorm_to_snorm(src, 16, 32));
} else {
SWIZZLE_CONVERT(int32_t, uint16_t, src);
}
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
if (normalized) {
SWIZZLE_CONVERT(int32_t, int16_t, _mesa_snorm_to_snorm(src, 16, 32));
} else {
SWIZZLE_CONVERT(int32_t, int16_t, src);
}
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
if (normalized) {
SWIZZLE_CONVERT(int32_t, uint32_t, _mesa_unorm_to_snorm(src, 32, 32));
} else {
SWIZZLE_CONVERT(int32_t, uint32_t, _mesa_unsigned_to_signed(src, 32));
}
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
SWIZZLE_CONVERT(int32_t, int32_t, src);
break;
default:
@@ -1645,16 +1630,16 @@ convert_int(void *void_dst, int num_dst_channels,
* \param[out] dst pointer to where the converted data should
* be stored
*
- * \param[in] dst_type the destination GL type of the converted
- * data (GL_BYTE, etc.)
+ * \param[in] dst_type the mesa_array_format_datatype of the converted
+ * data (MESA_ARRAY_FORMAT_TYPE_BYTE, etc.)
*
* \param[in] num_dst_channels the number of channels in the converted
* data
*
* \param[in] src pointer to the source data
*
- * \param[in] src_type the GL type of the source data (GL_BYTE,
- * etc.)
+ * \param[in] src_type the mesa_array_format_datatype of the source
+ * data (MESA_ARRAY_FORMAT_TYPE_BYTE, etc.)
*
* \param[in] num_src_channels the number of channels in the source data
* (the number of channels total, not just
@@ -1670,8 +1655,12 @@ convert_int(void *void_dst, int num_dst_channels,
* \param[in] count the number of pixels to convert
*/
void
-_mesa_swizzle_and_convert(void *void_dst, GLenum dst_type, int num_dst_channels,
- const void *void_src, GLenum src_type, int num_src_channels,
+_mesa_swizzle_and_convert(void *void_dst,
+ enum mesa_array_format_datatype dst_type,
+ int num_dst_channels,
+ const void *void_src,
+ enum mesa_array_format_datatype src_type,
+ int num_src_channels,
const uint8_t swizzle[4], bool normalized, int count)
{
if (swizzle_convert_try_memcpy(void_dst, dst_type, num_dst_channels,
@@ -1680,35 +1669,35 @@ _mesa_swizzle_and_convert(void *void_dst, GLenum dst_type, int num_dst_channels,
return;
switch (dst_type) {
- case GL_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_FLOAT:
convert_float(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_HALF_FLOAT:
+ case MESA_ARRAY_FORMAT_TYPE_HALF:
convert_half_float(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_UNSIGNED_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_UBYTE:
convert_ubyte(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_BYTE:
+ case MESA_ARRAY_FORMAT_TYPE_BYTE:
convert_byte(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_UNSIGNED_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_USHORT:
convert_ushort(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_SHORT:
+ case MESA_ARRAY_FORMAT_TYPE_SHORT:
convert_short(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_UNSIGNED_INT:
+ case MESA_ARRAY_FORMAT_TYPE_UINT:
convert_uint(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
- case GL_INT:
+ case MESA_ARRAY_FORMAT_TYPE_INT:
convert_int(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
break;
diff --git a/src/mesa/main/format_utils.h b/src/mesa/main/format_utils.h
index 1d3a192..e40a077 100644
--- a/src/mesa/main/format_utils.h
+++ b/src/mesa/main/format_utils.h
@@ -173,8 +173,12 @@ _mesa_format_to_array(mesa_format, GLenum *type, int *num_components,
uint8_t swizzle[4], bool *normalized);
void
-_mesa_swizzle_and_convert(void *dst, GLenum dst_type, int num_dst_channels,
- const void *src, GLenum src_type, int num_src_channels,
+_mesa_swizzle_and_convert(void *dst,
+ enum mesa_array_format_datatype dst_type,
+ int num_dst_channels,
+ const void *src,
+ enum mesa_array_format_datatype src_type,
+ int num_src_channels,
const uint8_t swizzle[4], bool normalized, int count);
void
--
1.9.1
More information about the mesa-dev
mailing list