/**************************************************************************
- *
+ *
* Copyright 2007 VMware, Inc.
* Copyright (c) 2008-2010 VMware, Inc.
* All Rights Reserved.
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
- *
+ *
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
+ *
**************************************************************************/
* \author Brian Paul
*/
-#include "main/imports.h"
+
#include "main/context.h"
#include "main/enums.h"
#include "main/formats.h"
}
}
- if (_mesa_is_format_astc_2d(mesaFormat) && !st->has_astc_2d_ldr) {
+ if (st_astc_format_fallback(st, mesaFormat)) {
if (_mesa_is_format_srgb(mesaFormat))
return PIPE_FORMAT_R8G8B8A8_SRGB;
else
},
{
{ GL_R3_G3_B2, 0 },
- { PIPE_FORMAT_B2G3R3_UNORM, PIPE_FORMAT_B5G6R5_UNORM,
- PIPE_FORMAT_B5G5R5A1_UNORM, DEFAULT_RGB_FORMATS }
+ { PIPE_FORMAT_B2G3R3_UNORM, PIPE_FORMAT_R3G3B2_UNORM,
+ PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_B5G5R5A1_UNORM,
+ DEFAULT_RGB_FORMATS }
},
{
{ GL_RGB4 },
{ PIPE_FORMAT_DXT5_RGBA, 0 }
},
-#if 0
{
{ GL_COMPRESSED_RGB_FXT1_3DFX, 0 },
- { PIPE_FORMAT_RGB_FXT1, 0 }
+ { PIPE_FORMAT_FXT1_RGB, 0 }
},
{
{ GL_COMPRESSED_RGBA_FXT1_3DFX, 0 },
- { PIPE_FORMAT_RGBA_FXT1, 0 }
+ { PIPE_FORMAT_FXT1_RGBA, 0 }
},
-#endif
/* Depth formats */
{
return PIPE_FORMAT_NONE;
}
-
-struct exact_format_mapping
-{
- GLenum format;
- GLenum type;
- enum pipe_format pformat;
-};
-
-static const struct exact_format_mapping rgba8888_tbl[] =
-{
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_ABGR8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_ABGR8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_RGBA8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_RGBA8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_ARGB8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_BGRA8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_BYTE, PIPE_FORMAT_R8G8B8A8_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_BYTE, PIPE_FORMAT_A8B8G8R8_UNORM },
- { GL_BGRA, GL_UNSIGNED_BYTE, PIPE_FORMAT_B8G8R8A8_UNORM },
- { 0, 0, 0 }
-};
-
-static const struct exact_format_mapping rgbx8888_tbl[] =
-{
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_XBGR8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_XBGR8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_RGBX8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_RGBX8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_XRGB8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_BGRX8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_BYTE, PIPE_FORMAT_R8G8B8X8_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_BYTE, PIPE_FORMAT_X8B8G8R8_UNORM },
- { GL_BGRA, GL_UNSIGNED_BYTE, PIPE_FORMAT_B8G8R8X8_UNORM },
- { 0, 0, 0 }
-};
-
-
-/**
- * For unsized/base internal formats, we may choose a convenient effective
- * internal format for {format, type}. If one exists, return that, otherwise
- * return PIPE_FORMAT_NONE.
- */
-static enum pipe_format
-find_exact_format(GLint internalFormat, GLenum format, GLenum type)
-{
- uint i;
- const struct exact_format_mapping* tbl;
-
- if (format == GL_NONE || type == GL_NONE)
- return PIPE_FORMAT_NONE;
-
- switch (internalFormat) {
- case 4:
- case GL_RGBA:
- tbl = rgba8888_tbl;
- break;
- case 3:
- case GL_RGB:
- tbl = rgbx8888_tbl;
- break;
- default:
- return PIPE_FORMAT_NONE;
- }
-
- for (i = 0; tbl[i].format; i++)
- if (tbl[i].format == format && tbl[i].type == type)
- return tbl[i].pformat;
-
- return PIPE_FORMAT_NONE;
-}
-
-
/**
* Given an OpenGL internalFormat value for a texture or surface, return
* the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
GLenum format, GLenum type,
enum pipe_texture_target target, unsigned sample_count,
unsigned storage_sample_count,
- unsigned bindings, boolean allow_dxt)
+ unsigned bindings, bool swap_bytes, bool allow_dxt)
{
struct pipe_screen *screen = st->pipe->screen;
unsigned i;
return PIPE_FORMAT_NONE;
}
- /* search for exact matches */
- pf = find_exact_format(internalFormat, format, type);
- if (pf != PIPE_FORMAT_NONE &&
- screen->is_format_supported(screen, pf, target, sample_count,
- storage_sample_count, bindings)) {
- goto success;
+ /* If we have an unsized internalFormat, and the driver supports a format
+ * that exactly matches format/type such that we can just memcpy, pick that
+ * (unless the format wouldn't still be unorm, which is the expectation for
+ * unsized formats).
+ */
+ if (_mesa_is_enum_format_unsized(internalFormat) && format != 0 &&
+ _mesa_is_type_unsigned(type)) {
+ pf = st_choose_matching_format(st, bindings, format, type,
+ swap_bytes);
+
+ if (pf != PIPE_FORMAT_NONE &&
+ screen->is_format_supported(screen, pf, target, sample_count,
+ storage_sample_count, bindings) &&
+ _mesa_get_format_base_format(st_pipe_format_to_mesa_format(pf)) ==
+ internalFormat) {
+ goto success;
+ }
}
/* For an unsized GL_RGB but a 2_10_10_10 type, try to pick one of the
bindings = PIPE_BIND_RENDER_TARGET;
return st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
PIPE_TEXTURE_2D, sample_count,
- storage_sample_count, bindings, FALSE);
+ storage_sample_count, bindings,
+ false, false);
}
}
pFormat = st_choose_format(st, internalFormat, format, type,
- pTarget, 0, 0, bindings, GL_TRUE);
+ pTarget, 0, 0, bindings,
+ ctx->Unpack.SwapBytes, true);
if (pFormat == PIPE_FORMAT_NONE && !is_renderbuffer) {
/* try choosing format again, this time without render target bindings */
pFormat = st_choose_format(st, internalFormat, format, type,
pTarget, 0, 0, PIPE_BIND_SAMPLER_VIEW,
- GL_TRUE);
+ ctx->Unpack.SwapBytes, true);
}
if (pFormat == PIPE_FORMAT_NONE) {
/* Set sample counts in descending order. */
for (i = 16; i > 1; i--) {
format = st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
- PIPE_TEXTURE_2D, i, i, bind, FALSE);
+ PIPE_TEXTURE_2D, i, i, bind,
+ false, false);
if (format != PIPE_FORMAT_NONE) {
samples[num_sample_counts++] = i;
GL_NONE,
GL_NONE,
PIPE_TEXTURE_2D, 0, 0,
- bindings, FALSE);
+ bindings,
+ false, false);
if (pformat)
params[0] = internalFormat;
break;