summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/formats.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-08-23 10:45:00 -0700
committerIago Toral Quiroga <[email protected]>2015-01-12 11:20:28 +0100
commit3da735cc4c478b0ab2ecc2164899cf9d77dc671a (patch)
tree4158684e428ad25b4708a51556d409b2f0b94a02 /src/mesa/main/formats.c
parent382d097e546cb7568bef4fa552dcd84535271845 (diff)
main: Add a concept of an array format
An array format is a 32-bit integer format identifier that can represent any format that can be represented as an array of standard GL datatypes. Whie the MESA_FORMAT enums provide several of these, they don't account for all of them. v2 by Iago Toral Quiroga <[email protected]>: - Implement mesa_array_format as a plain bitfiled uint32_t type instead of using a struct inside a union to access the various components packed in it. This is necessary to support bigendian properly, as pointed out by Ian. - Squashed: Make float types normalized v3 by Iago Toral Quiroga <[email protected]>: - Include compiler.h in formats.h, which is necessary to build in MSVC as indicated by Brian Paul. Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/mesa/main/formats.c')
-rw-r--r--src/mesa/main/formats.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 676ac2781ae..125989254aa 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -71,6 +71,7 @@ struct gl_format_info
GLubyte BytesPerBlock;
uint8_t Swizzle[4];
+ mesa_array_format ArrayFormat;
};
#include "format_info.c"
@@ -269,6 +270,62 @@ _mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4])
memcpy(swizzle_out, info->Swizzle, sizeof(info->Swizzle));
}
+mesa_array_format
+_mesa_array_format_flip_channels(mesa_array_format format)
+{
+ int num_channels;
+ uint8_t swizzle[4];
+
+ num_channels = _mesa_array_format_get_num_channels(format);
+ _mesa_array_format_get_swizzle(format, swizzle);
+
+ if (num_channels == 1)
+ return format;
+
+ if (num_channels == 2) {
+ _mesa_array_format_set_swizzle(&format, swizzle[1], swizzle[0],
+ swizzle[2], swizzle[3]);
+ return format;
+ }
+
+ if (num_channels == 4) {
+ _mesa_array_format_set_swizzle(&format, swizzle[3], swizzle[2],
+ swizzle[1], swizzle[0]);
+ return format;
+ }
+
+ unreachable("Invalid array format");
+}
+
+uint32_t
+_mesa_format_to_array_format(mesa_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ if (_mesa_little_endian())
+ return info->ArrayFormat;
+ else
+ return _mesa_array_format_flip_channels(info->ArrayFormat);
+}
+
+mesa_format
+_mesa_format_from_array_format(uint32_t array_format)
+{
+ mesa_array_format af;
+ unsigned f;
+
+ assert(_mesa_format_is_mesa_array_format(array_format));
+
+ if (_mesa_little_endian())
+ af = array_format;
+ else
+ af = _mesa_array_format_flip_channels(array_format);
+
+ for (f = 1; f < MESA_FORMAT_COUNT; ++f)
+ if (_mesa_get_format_info(f)->ArrayFormat == af)
+ return f;
+
+ return MESA_FORMAT_NONE;
+}
/** Is the given format a compressed format? */
GLboolean