#include "errors.h"
-#include "imports.h"
+
#include "formats.h"
#include "macros.h"
#include "glformats.h"
{
const struct mesa_format_info *info = &format_info[format];
STATIC_ASSERT(ARRAY_SIZE(format_info) == MESA_FORMAT_COUNT);
+
+ /* The MESA_FORMAT_* enums are sparse, don't return a format info
+ * for empty entries.
+ */
+ if (info->Name == MESA_FORMAT_NONE && format != MESA_FORMAT_NONE)
+ return NULL;
+
assert(info->Name == format);
return info;
}
_mesa_get_format_name(mesa_format format)
{
const struct mesa_format_info *info = _mesa_get_format_info(format);
+ if (!info)
+ return NULL;
return info->StrName;
}
num_channels = _mesa_array_format_get_num_channels(format);
_mesa_array_format_get_swizzle(format, swizzle);
- if (num_channels == 1)
+ if (num_channels == 1 || num_channels == 3)
return format;
if (num_channels == 2) {
for (f = 1; f < MESA_FORMAT_COUNT; ++f) {
info = _mesa_get_format_info(f);
- if (!info->ArrayFormat)
+ if (!info || !info->ArrayFormat)
+ continue;
+
+ /* All sRGB formats should have an equivalent UNORM format, and that's
+ * the one we want in the table.
+ */
+ if (_mesa_is_format_srgb(f))
continue;
#if UTIL_ARCH_LITTLE_ENDIAN
array_format = _mesa_array_format_flip_channels(info->ArrayFormat);
#endif
- /* This can happen and does for some of the BGR formats. Let's take
- * the first one in the list.
- */
- if (_mesa_hash_table_search_pre_hashed(format_array_format_table,
- array_format,
- (void *)(intptr_t)array_format))
- continue;
-
_mesa_hash_table_insert_pre_hashed(format_array_format_table,
array_format,
(void *)(intptr_t)array_format,
bool
_mesa_is_format_signed(mesa_format format)
{
- if (format == MESA_FORMAT_R11G11B10_FLOAT ||
+ if (format == MESA_FORMAT_R11G11B10_FLOAT ||
format == MESA_FORMAT_R9G9B9E5_FLOAT) {
/* these packed float formats only store unsigned values */
return false;
*datatype = GL_UNSIGNED_BYTE;
*comps = 3;
return;
- case MESA_FORMAT_RGBA_UINT8:
- *datatype = GL_UNSIGNED_BYTE;
- *comps = 4;
- return;
case MESA_FORMAT_R_UINT16:
*datatype = GL_UNSIGNED_SHORT;
*comps = 1;
case MESA_FORMAT_COUNT:
assert(0);
return;
- default:
+ default: {
+ const char *name = _mesa_get_format_name(format);
/* Warn if any formats are not handled */
_mesa_problem(NULL, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
- _mesa_get_format_name(format));
+ name ? name : "???");
assert(format == MESA_FORMAT_NONE ||
_mesa_is_format_compressed(format));
*datatype = 0;
*comps = 1;
}
+ }
}
/**