X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ftexformat.c;h=2542cea856b65154e1b15504bc523b1b65b2b7f0;hb=d9e591391d490c83ce301aa568a2e0afe4cc3c0a;hp=dae98bcc6f7d39c9f6af1a08a4585948e720f7f3;hpb=a608257a02d2ba4e8119be462bbd40ed238b184a;p=mesa.git diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c index dae98bcc6f7..2542cea856b 100644 --- a/src/mesa/main/texformat.c +++ b/src/mesa/main/texformat.c @@ -1,9 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5.1 + * Version: 7.7 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * Copyright (c) 2008 VMware, Inc. + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (c) 2008-2009 VMware, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,996 +29,20 @@ * Texture formats. * * \author Gareth Hughes + * \author Brian Paul */ -#include "colormac.h" #include "context.h" +#include "mfeatures.h" +#include "mtypes.h" #include "texcompress.h" -#include "texcompress_fxt1.h" -#include "texcompress_s3tc.h" #include "texformat.h" -#include "texstore.h" - - -#if FEATURE_EXT_texture_sRGB - -/** - * Convert an 8-bit sRGB value from non-linear space to a - * linear RGB value in [0, 1]. - * Implemented with a 256-entry lookup table. - */ -static INLINE GLfloat -nonlinear_to_linear(GLubyte cs8) -{ - static GLfloat table[256]; - static GLboolean tableReady = GL_FALSE; - if (!tableReady) { - /* compute lookup table now */ - GLuint i; - for (i = 0; i < 256; i++) { - const GLfloat cs = UBYTE_TO_FLOAT(i); - if (cs <= 0.04045) { - table[i] = cs / 12.92f; - } - else { - table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4); - } - } - tableReady = GL_TRUE; - } - return table[cs8]; -} - - -#endif /* FEATURE_EXT_texture_sRGB */ - - -/* Texel fetch routines for all supported formats - */ -#define DIM 1 -#include "texformat_tmp.h" - -#define DIM 2 -#include "texformat_tmp.h" - -#define DIM 3 -#include "texformat_tmp.h" - -/** - * Null texel fetch function. - * - * Have to have this so the FetchTexel function pointer is never NULL. - */ -static void fetch_null_texelf( const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel ) -{ - (void) texImage; (void) i; (void) j; (void) k; - texel[RCOMP] = 0.0; - texel[GCOMP] = 0.0; - texel[BCOMP] = 0.0; - texel[ACOMP] = 0.0; - _mesa_warning(NULL, "fetch_null_texelf() called!"); -} - -static void store_null_texel(struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, const void *texel) -{ - (void) texImage; - (void) i; - (void) j; - (void) k; - (void) texel; - /* no-op */ -} - - -/** - * Notes about the predefined gl_texture_formats: - * - * 1. There are 1D, 2D and 3D functions for fetching texels from texture - * images, returning both GLchan values and GLfloat values. (six - * functions in total) - * You don't have to provide both the GLchan and GLfloat functions; - * just one or the other is OK. Mesa will use an "adaptor" to convert - * between GLchan/GLfloat when needed. - * Since the adaptors have small performance penalty, we provide both - * GLchan and GLfloat functions for some common formats like RGB, RGBA. - */ - - -/***************************************************************/ -/** \name Default GLchan-based formats */ -/*@{*/ - -const struct gl_texture_format _mesa_texformat_rgba = { - MESA_FORMAT_RGBA, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - CHAN_BITS, /* RedBits */ - CHAN_BITS, /* GreenBits */ - CHAN_BITS, /* BlueBits */ - CHAN_BITS, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4 * sizeof(GLchan), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb = { - MESA_FORMAT_RGB, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - CHAN_BITS, /* RedBits */ - CHAN_BITS, /* GreenBits */ - CHAN_BITS, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 3 * sizeof(GLchan), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_alpha = { - MESA_FORMAT_ALPHA, /* MesaFormat */ - GL_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - CHAN_BITS, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - sizeof(GLchan), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_luminance = { - MESA_FORMAT_LUMINANCE, /* MesaFormat */ - GL_LUMINANCE, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - CHAN_BITS, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - sizeof(GLchan), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_luminance_alpha = { - MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - CHAN_BITS, /* AlphaBits */ - CHAN_BITS, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2 * sizeof(GLchan), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_intensity = { - MESA_FORMAT_INTENSITY, /* MesaFormat */ - GL_INTENSITY, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - CHAN_BITS, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - sizeof(GLchan), /* TexelBytes */ -}; - - -#if FEATURE_EXT_texture_sRGB - -const struct gl_texture_format _mesa_texformat_srgb8 = { - MESA_FORMAT_SRGB8, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 3, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_srgba8 = { - MESA_FORMAT_SRGBA8, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_sargb8 = { - MESA_FORMAT_SARGB8, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_sl8 = { - MESA_FORMAT_SL8, /* MesaFormat */ - GL_LUMINANCE, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 8, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1, /* TexelBytes */ -}; - -/* Note: this format name looks like a misnomer, make it sal8? */ -const struct gl_texture_format _mesa_texformat_sla8 = { - MESA_FORMAT_SLA8, /* MesaFormat */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8, /* AlphaBits */ - 8, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -#endif /* FEATURE_EXT_texture_sRGB */ - -const struct gl_texture_format _mesa_texformat_rgba_float32 = { - MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 8 * sizeof(GLfloat), /* RedBits */ - 8 * sizeof(GLfloat), /* GreenBits */ - 8 * sizeof(GLfloat), /* BlueBits */ - 8 * sizeof(GLfloat), /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4 * sizeof(GLfloat), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgba_float16 = { - MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 8 * sizeof(GLhalfARB), /* RedBits */ - 8 * sizeof(GLhalfARB), /* GreenBits */ - 8 * sizeof(GLhalfARB), /* BlueBits */ - 8 * sizeof(GLhalfARB), /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4 * sizeof(GLhalfARB), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb_float32 = { - MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 8 * sizeof(GLfloat), /* RedBits */ - 8 * sizeof(GLfloat), /* GreenBits */ - 8 * sizeof(GLfloat), /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 3 * sizeof(GLfloat), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb_float16 = { - MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 8 * sizeof(GLhalfARB), /* RedBits */ - 8 * sizeof(GLhalfARB), /* GreenBits */ - 8 * sizeof(GLhalfARB), /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 3 * sizeof(GLhalfARB), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_alpha_float32 = { - MESA_FORMAT_ALPHA_FLOAT32, /* MesaFormat */ - GL_ALPHA, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8 * sizeof(GLfloat), /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1 * sizeof(GLfloat), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_alpha_float16 = { - MESA_FORMAT_ALPHA_FLOAT16, /* MesaFormat */ - GL_ALPHA, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8 * sizeof(GLhalfARB), /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1 * sizeof(GLhalfARB), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_luminance_float32 = { - MESA_FORMAT_LUMINANCE_FLOAT32, /* MesaFormat */ - GL_LUMINANCE, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 8 * sizeof(GLfloat), /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1 * sizeof(GLfloat), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_luminance_float16 = { - MESA_FORMAT_LUMINANCE_FLOAT16, /* MesaFormat */ - GL_LUMINANCE, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 8 * sizeof(GLhalfARB), /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1 * sizeof(GLhalfARB), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_luminance_alpha_float32 = { - MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, /* MesaFormat */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8 * sizeof(GLfloat), /* AlphaBits */ - 8 * sizeof(GLfloat), /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2 * sizeof(GLfloat), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_luminance_alpha_float16 = { - MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, /* MesaFormat */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8 * sizeof(GLhalfARB), /* AlphaBits */ - 8 * sizeof(GLhalfARB), /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2 * sizeof(GLhalfARB), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_intensity_float32 = { - MESA_FORMAT_INTENSITY_FLOAT32, /* MesaFormat */ - GL_INTENSITY, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 8 * sizeof(GLfloat), /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1 * sizeof(GLfloat), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_intensity_float16 = { - MESA_FORMAT_INTENSITY_FLOAT16, /* MesaFormat */ - GL_INTENSITY, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 8 * sizeof(GLhalfARB), /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1 * sizeof(GLhalfARB), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_dudv8 = { - MESA_FORMAT_DUDV8, /* MesaFormat */ - GL_DUDV_ATI, /* BaseFormat */ - GL_SIGNED_NORMALIZED, /* DataType */ - /* maybe should add dudvBits field, but spec seems to be - lacking the ability to query with GetTexLevelParameter anyway */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_signed_rgba8888 = { - MESA_FORMAT_SIGNED_RGBA8888, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_SIGNED_NORMALIZED, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_signed_rgba8888_rev = { - MESA_FORMAT_SIGNED_RGBA8888_REV, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_SIGNED_NORMALIZED, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -/*@}*/ - - -/***************************************************************/ -/** \name Hardware formats */ -/*@{*/ - -const struct gl_texture_format _mesa_texformat_rgba8888 = { - MESA_FORMAT_RGBA8888, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgba8888_rev = { - MESA_FORMAT_RGBA8888_REV, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_argb8888 = { - MESA_FORMAT_ARGB8888, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_argb8888_rev = { - MESA_FORMAT_ARGB8888_REV, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb888 = { - MESA_FORMAT_RGB888, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 3, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_bgr888 = { - MESA_FORMAT_BGR888, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 8, /* RedBits */ - 8, /* GreenBits */ - 8, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 3, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb565 = { - MESA_FORMAT_RGB565, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 6, /* GreenBits */ - 5, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb565_rev = { - MESA_FORMAT_RGB565_REV, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 6, /* GreenBits */ - 5, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgba4444 = { - MESA_FORMAT_RGBA4444, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 4, /* RedBits */ - 4, /* GreenBits */ - 4, /* BlueBits */ - 4, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_argb4444 = { - MESA_FORMAT_ARGB4444, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 4, /* RedBits */ - 4, /* GreenBits */ - 4, /* BlueBits */ - 4, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_argb4444_rev = { - MESA_FORMAT_ARGB4444_REV, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 4, /* RedBits */ - 4, /* GreenBits */ - 4, /* BlueBits */ - 4, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgba5551 = { - MESA_FORMAT_RGBA5551, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 5, /* GreenBits */ - 5, /* BlueBits */ - 1, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_argb1555 = { - MESA_FORMAT_ARGB1555, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 5, /* GreenBits */ - 5, /* BlueBits */ - 1, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_argb1555_rev = { - MESA_FORMAT_ARGB1555_REV, /* MesaFormat */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 5, /* RedBits */ - 5, /* GreenBits */ - 5, /* BlueBits */ - 1, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_al88 = { - MESA_FORMAT_AL88, /* MesaFormat */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8, /* AlphaBits */ - 8, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_al88_rev = { - MESA_FORMAT_AL88_REV, /* MesaFormat */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8, /* AlphaBits */ - 8, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_rgb332 = { - MESA_FORMAT_RGB332, /* MesaFormat */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 3, /* RedBits */ - 3, /* GreenBits */ - 2, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_a8 = { - MESA_FORMAT_A8, /* MesaFormat */ - GL_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 8, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_l8 = { - MESA_FORMAT_L8, /* MesaFormat */ - GL_LUMINANCE, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 8, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_i8 = { - MESA_FORMAT_I8, /* MesaFormat */ - GL_INTENSITY, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 8, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_ci8 = { - MESA_FORMAT_CI8, /* MesaFormat */ - GL_COLOR_INDEX, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 8, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 1, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_ycbcr = { - MESA_FORMAT_YCBCR, /* MesaFormat */ - GL_YCBCR_MESA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_ycbcr_rev = { - MESA_FORMAT_YCBCR_REV, /* MesaFormat */ - GL_YCBCR_MESA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 2, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_z24_s8 = { - MESA_FORMAT_Z24_S8, /* MesaFormat */ - GL_DEPTH_STENCIL_EXT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 24, /* DepthBits */ - 8, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_s8_z24 = { - MESA_FORMAT_S8_Z24, /* MesaFormat */ - GL_DEPTH_STENCIL_EXT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 24, /* DepthBits */ - 8, /* StencilBits */ - 4, /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_z16 = { - MESA_FORMAT_Z16, /* MesaFormat */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - sizeof(GLushort) * 8, /* DepthBits */ - 0, /* StencilBits */ - sizeof(GLushort), /* TexelBytes */ -}; - -const struct gl_texture_format _mesa_texformat_z32 = { - MESA_FORMAT_Z32, /* MesaFormat */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - sizeof(GLuint) * 8, /* DepthBits */ - 0, /* StencilBits */ - sizeof(GLuint), /* TexelBytes */ -}; - -/*@}*/ - - -/***************************************************************/ -/** \name Null format (useful for proxy textures) */ -/*@{*/ - -const struct gl_texture_format _mesa_null_texformat = { - -1, /* MesaFormat */ - 0, /* BaseFormat */ - GL_NONE, /* DataType */ - 0, /* RedBits */ - 0, /* GreenBits */ - 0, /* BlueBits */ - 0, /* AlphaBits */ - 0, /* LuminanceBits */ - 0, /* IntensityBits */ - 0, /* IndexBits */ - 0, /* DepthBits */ - 0, /* StencilBits */ - 0, /* TexelBytes */ -}; - -/*@}*/ +#define RETURN_IF_SUPPORTED(f) do { \ + if (ctx->TextureFormatSupported[f]) \ + return f; \ +} while (0) /** * Choose an appropriate texture format given the format, type and @@ -1035,84 +59,143 @@ const struct gl_texture_format _mesa_null_texformat = { * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers * will typically override this function with a specialized version. */ -const struct gl_texture_format * -_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, +gl_format +_mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, GLenum format, GLenum type ) { (void) format; (void) type; switch (internalFormat) { - /* RGBA formats */ + /* shallow RGBA formats */ case 4: case GL_RGBA: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return &_mesa_texformat_rgba; + if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444); + } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555); + } + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; + case GL_RGBA8: - return &_mesa_texformat_rgba8888; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; case GL_RGB5_A1: - return &_mesa_texformat_argb1555; + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555); + break; case GL_RGBA2: - return &_mesa_texformat_argb4444_rev; /* just to test another format*/ + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444_REV); /* just to test another format*/ + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444); + break; case GL_RGBA4: - return &_mesa_texformat_argb4444; + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444); + break; - /* RGB formats */ + /* deep RGBA formats */ + case GL_RGB10_A2: + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; + case GL_RGBA12: + case GL_RGBA16: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; + + /* shallow RGB formats */ case 3: case GL_RGB: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return &_mesa_texformat_rgb; case GL_RGB8: - return &_mesa_texformat_rgb888; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888); + RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; case GL_R3_G3_B2: - return &_mesa_texformat_rgb332; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB332); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888); + RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; case GL_RGB4: - return &_mesa_texformat_rgb565_rev; /* just to test another format */ + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV); /* just to test another format */ + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565); + break; case GL_RGB5: - return &_mesa_texformat_rgb565; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565); + break; + + /* deep RGB formats */ + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16); + RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; /* Alpha formats */ case GL_ALPHA: case GL_ALPHA4: + case GL_ALPHA8: + RETURN_IF_SUPPORTED(MESA_FORMAT_A8); + break; + case GL_ALPHA12: case GL_ALPHA16: - return &_mesa_texformat_alpha; - case GL_ALPHA8: - return &_mesa_texformat_a8; + RETURN_IF_SUPPORTED(MESA_FORMAT_A16); + RETURN_IF_SUPPORTED(MESA_FORMAT_A8); + break; /* Luminance formats */ case 1: case GL_LUMINANCE: case GL_LUMINANCE4: + case GL_LUMINANCE8: + RETURN_IF_SUPPORTED(MESA_FORMAT_L8); + break; + case GL_LUMINANCE12: case GL_LUMINANCE16: - return &_mesa_texformat_luminance; - case GL_LUMINANCE8: - return &_mesa_texformat_l8; + RETURN_IF_SUPPORTED(MESA_FORMAT_L16); + RETURN_IF_SUPPORTED(MESA_FORMAT_L8); + break; /* Luminance/Alpha formats */ + case GL_LUMINANCE4_ALPHA4: + RETURN_IF_SUPPORTED(MESA_FORMAT_AL44); + RETURN_IF_SUPPORTED(MESA_FORMAT_AL88); + break; + case 2: case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + RETURN_IF_SUPPORTED(MESA_FORMAT_AL88); + break; + case GL_LUMINANCE12_ALPHA4: case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: - return &_mesa_texformat_luminance_alpha; - case GL_LUMINANCE8_ALPHA8: - return &_mesa_texformat_al88; + RETURN_IF_SUPPORTED(MESA_FORMAT_AL1616); + RETURN_IF_SUPPORTED(MESA_FORMAT_AL88); + break; case GL_INTENSITY: case GL_INTENSITY4: + case GL_INTENSITY8: + RETURN_IF_SUPPORTED(MESA_FORMAT_I8); + break; + case GL_INTENSITY12: case GL_INTENSITY16: - return &_mesa_texformat_intensity; - case GL_INTENSITY8: - return &_mesa_texformat_i8; + RETURN_IF_SUPPORTED(MESA_FORMAT_I16); + RETURN_IF_SUPPORTED(MESA_FORMAT_I8); + break; case GL_COLOR_INDEX: case GL_COLOR_INDEX1_EXT: @@ -1121,7 +204,8 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, case GL_COLOR_INDEX12_EXT: case GL_COLOR_INDEX16_EXT: case GL_COLOR_INDEX8_EXT: - return &_mesa_texformat_ci8; + RETURN_IF_SUPPORTED(MESA_FORMAT_CI8); + break; default: ; /* fallthrough */ @@ -1132,9 +216,12 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT32: - return &_mesa_texformat_z32; + RETURN_IF_SUPPORTED(MESA_FORMAT_Z32); + RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24); + break; case GL_DEPTH_COMPONENT16: - return &_mesa_texformat_z16; + RETURN_IF_SUPPORTED(MESA_FORMAT_Z16); + RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24); default: ; /* fallthrough */ } @@ -1142,35 +229,36 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, switch (internalFormat) { case GL_COMPRESSED_ALPHA_ARB: - return &_mesa_texformat_alpha; + RETURN_IF_SUPPORTED(MESA_FORMAT_A8); + break; case GL_COMPRESSED_LUMINANCE_ARB: - return &_mesa_texformat_luminance; + RETURN_IF_SUPPORTED(MESA_FORMAT_L8); + break; case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: - return &_mesa_texformat_luminance_alpha; + RETURN_IF_SUPPORTED(MESA_FORMAT_AL88); + break; case GL_COMPRESSED_INTENSITY_ARB: - return &_mesa_texformat_intensity; + RETURN_IF_SUPPORTED(MESA_FORMAT_I8); + break; case GL_COMPRESSED_RGB_ARB: -#if FEATURE_texture_fxt1 - if (ctx->Extensions.TDFX_texture_compression_FXT1) - return &_mesa_texformat_rgb_fxt1; -#endif -#if FEATURE_texture_s3tc if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc) - return &_mesa_texformat_rgb_dxt1; -#endif - return &_mesa_texformat_rgb; - case GL_COMPRESSED_RGBA_ARB: -#if FEATURE_texture_fxt1 + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1); if (ctx->Extensions.TDFX_texture_compression_FXT1) - return &_mesa_texformat_rgba_fxt1; -#endif -#if FEATURE_texture_s3tc + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888); + RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; + case GL_COMPRESSED_RGBA_ARB: if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc) - return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */ -#endif - return &_mesa_texformat_rgba; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */ + if (ctx->Extensions.TDFX_texture_compression_FXT1) + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; default: ; /* fallthrough */ } @@ -1178,9 +266,9 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, if (ctx->Extensions.MESA_ycbcr_texture) { if (internalFormat == GL_YCBCR_MESA) { if (type == GL_UNSIGNED_SHORT_8_8_MESA) - return &_mesa_texformat_ycbcr; + RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR); else - return &_mesa_texformat_ycbcr_rev; + RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV); } } @@ -1188,9 +276,11 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, if (ctx->Extensions.TDFX_texture_compression_FXT1) { switch (internalFormat) { case GL_COMPRESSED_RGB_FXT1_3DFX: - return &_mesa_texformat_rgb_fxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1); + break; case GL_COMPRESSED_RGBA_FXT1_3DFX: - return &_mesa_texformat_rgba_fxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1); + break; default: ; /* fallthrough */ } @@ -1201,13 +291,17 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, if (ctx->Extensions.EXT_texture_compression_s3tc) { switch (internalFormat) { case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - return &_mesa_texformat_rgb_dxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1); + break; case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - return &_mesa_texformat_rgba_dxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT1); + break; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - return &_mesa_texformat_rgba_dxt3; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); + break; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - return &_mesa_texformat_rgba_dxt5; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT5); + break; default: ; /* fallthrough */ } @@ -1217,10 +311,12 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, switch (internalFormat) { case GL_RGB_S3TC: case GL_RGB4_S3TC: - return &_mesa_texformat_rgb_dxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1); + break; case GL_RGBA_S3TC: case GL_RGBA4_S3TC: - return &_mesa_texformat_rgba_dxt3; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); + break; default: ; /* fallthrough */ } @@ -1230,29 +326,41 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, if (ctx->Extensions.ARB_texture_float) { switch (internalFormat) { case GL_ALPHA16F_ARB: - return &_mesa_texformat_alpha_float16; + RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16); + break; case GL_ALPHA32F_ARB: - return &_mesa_texformat_alpha_float32; + RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32); + break; case GL_LUMINANCE16F_ARB: - return &_mesa_texformat_luminance_float16; + RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16); + break; case GL_LUMINANCE32F_ARB: - return &_mesa_texformat_luminance_float32; + RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32); + break; case GL_LUMINANCE_ALPHA16F_ARB: - return &_mesa_texformat_luminance_alpha_float16; + RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16); + break; case GL_LUMINANCE_ALPHA32F_ARB: - return &_mesa_texformat_luminance_alpha_float32; + RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32); + break; case GL_INTENSITY16F_ARB: - return &_mesa_texformat_intensity_float16; + RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16); + break; case GL_INTENSITY32F_ARB: - return &_mesa_texformat_intensity_float32; + RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32); + break; case GL_RGB16F_ARB: - return &_mesa_texformat_rgb_float16; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16); + break; case GL_RGB32F_ARB: - return &_mesa_texformat_rgb_float32; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32); + break; case GL_RGBA16F_ARB: - return &_mesa_texformat_rgba_float16; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); + break; case GL_RGBA32F_ARB: - return &_mesa_texformat_rgba_float32; + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + break; default: ; /* fallthrough */ } @@ -1262,7 +370,9 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, switch (internalFormat) { case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - return &_mesa_texformat_z24_s8; + RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_S8); + RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24); + break; default: ; /* fallthrough */ } @@ -1272,7 +382,8 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, switch (internalFormat) { case GL_DUDV_ATI: case GL_DU8DV8_ATI: - return &_mesa_texformat_dudv8; + RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8); + break; default: ; /* fallthrough */ } @@ -1282,60 +393,116 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, switch (internalFormat) { case GL_RGBA_SNORM: case GL_RGBA8_SNORM: - return &_mesa_texformat_signed_rgba8888; + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888); + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV); + break; default: ; /* fallthrough */ } } + if (ctx->VersionMajor * 10 + ctx->VersionMinor >= 31) { + switch (internalFormat) { + case GL_RED_SNORM: + case GL_R8_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8); + break; + case GL_RG_SNORM: + case GL_RG8_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG88); + break; + case GL_RGB_SNORM: + case GL_RGB8_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888); + break; + case GL_RGBA_SNORM: + case GL_RGBA8_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888); + break; + case GL_R16_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R_16); + break; + case GL_RG16_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_16); + break; + case GL_RGB16_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16); + break; + case GL_RGBA16_SNORM: + RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16); + break; + default: + ; /* fall-through */ + } + } #if FEATURE_EXT_texture_sRGB if (ctx->Extensions.EXT_texture_sRGB) { switch (internalFormat) { case GL_SRGB_EXT: case GL_SRGB8_EXT: - return &_mesa_texformat_srgb8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_SRGB_ALPHA_EXT: case GL_SRGB8_ALPHA8_EXT: - return &_mesa_texformat_srgba8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_SLUMINANCE_EXT: case GL_SLUMINANCE8_EXT: - return &_mesa_texformat_sl8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SL8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_SLUMINANCE_ALPHA_EXT: case GL_SLUMINANCE8_ALPHA8_EXT: - return &_mesa_texformat_sla8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_COMPRESSED_SLUMINANCE_EXT: - return &_mesa_texformat_sl8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SL8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: - return &_mesa_texformat_sla8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_COMPRESSED_SRGB_EXT: #if FEATURE_texture_s3tc if (ctx->Extensions.EXT_texture_compression_s3tc) - return &_mesa_texformat_srgb_dxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1); #endif - return &_mesa_texformat_srgb8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; case GL_COMPRESSED_SRGB_ALPHA_EXT: #if FEATURE_texture_s3tc if (ctx->Extensions.EXT_texture_compression_s3tc) - return &_mesa_texformat_srgba_dxt3; /* Not srgba_dxt1, see spec */ + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */ #endif - return &_mesa_texformat_srgba8; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); + break; #if FEATURE_texture_s3tc case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: if (ctx->Extensions.EXT_texture_compression_s3tc) - return &_mesa_texformat_srgb_dxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); break; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: if (ctx->Extensions.EXT_texture_compression_s3tc) - return &_mesa_texformat_srgba_dxt1; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT1); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); break; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: if (ctx->Extensions.EXT_texture_compression_s3tc) - return &_mesa_texformat_srgba_dxt3; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); break; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: if (ctx->Extensions.EXT_texture_compression_s3tc) - return &_mesa_texformat_srgba_dxt5; + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT5); + RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8); break; #endif default: @@ -1344,709 +511,98 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, } #endif /* FEATURE_EXT_texture_sRGB */ - _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()"); - return NULL; -} - - - -/** - * Return datatype and number of components per texel for the - * given gl_texture_format. - */ -void -_mesa_format_to_type_and_comps(const struct gl_texture_format *format, - GLenum *datatype, GLuint *comps) -{ - switch (format->MesaFormat) { - case MESA_FORMAT_RGBA8888: - case MESA_FORMAT_RGBA8888_REV: - case MESA_FORMAT_ARGB8888: - case MESA_FORMAT_ARGB8888_REV: - *datatype = CHAN_TYPE; - *comps = 4; - return; - case MESA_FORMAT_RGB888: - case MESA_FORMAT_BGR888: - *datatype = GL_UNSIGNED_BYTE; - *comps = 3; - return; - case MESA_FORMAT_RGB565: - case MESA_FORMAT_RGB565_REV: - *datatype = GL_UNSIGNED_SHORT_5_6_5; - *comps = 3; - return; - - case MESA_FORMAT_ARGB4444: - case MESA_FORMAT_ARGB4444_REV: - *datatype = GL_UNSIGNED_SHORT_4_4_4_4; - *comps = 4; - return; - - case MESA_FORMAT_ARGB1555: - case MESA_FORMAT_ARGB1555_REV: - *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV; - *comps = 4; - return; - - case MESA_FORMAT_AL88: - case MESA_FORMAT_AL88_REV: - *datatype = GL_UNSIGNED_BYTE; - *comps = 2; - return; - case MESA_FORMAT_RGB332: - *datatype = GL_UNSIGNED_BYTE_3_3_2; - *comps = 3; - return; - - case MESA_FORMAT_A8: - case MESA_FORMAT_L8: - case MESA_FORMAT_I8: - case MESA_FORMAT_CI8: - *datatype = GL_UNSIGNED_BYTE; - *comps = 1; - return; - - case MESA_FORMAT_YCBCR: - case MESA_FORMAT_YCBCR_REV: - *datatype = GL_UNSIGNED_SHORT; - *comps = 2; - return; - - case MESA_FORMAT_Z24_S8: - *datatype = GL_UNSIGNED_INT; - *comps = 1; /* XXX OK? */ - return; - - case MESA_FORMAT_S8_Z24: - *datatype = GL_UNSIGNED_INT; - *comps = 1; /* XXX OK? */ - return; - - case MESA_FORMAT_Z16: - *datatype = GL_UNSIGNED_SHORT; - *comps = 1; - return; - - case MESA_FORMAT_Z32: - *datatype = GL_UNSIGNED_INT; - *comps = 1; - return; - - case MESA_FORMAT_DUDV8: - *datatype = GL_BYTE; - *comps = 2; - return; - - case MESA_FORMAT_SIGNED_RGBA8888: - case MESA_FORMAT_SIGNED_RGBA8888_REV: - *datatype = GL_BYTE; - *comps = 4; - return; - -#if FEATURE_EXT_texture_sRGB - case MESA_FORMAT_SRGB8: - *datatype = GL_UNSIGNED_BYTE; - *comps = 3; - return; - case MESA_FORMAT_SRGBA8: - case MESA_FORMAT_SARGB8: - *datatype = GL_UNSIGNED_BYTE; - *comps = 4; - return; - case MESA_FORMAT_SL8: - *datatype = GL_UNSIGNED_BYTE; - *comps = 1; - return; - case MESA_FORMAT_SLA8: - *datatype = GL_UNSIGNED_BYTE; - *comps = 2; - return; -#endif - -#if FEATURE_texture_fxt1 - case MESA_FORMAT_RGB_FXT1: - case MESA_FORMAT_RGBA_FXT1: -#endif -#if FEATURE_texture_s3tc - case MESA_FORMAT_RGB_DXT1: - case MESA_FORMAT_RGBA_DXT1: - case MESA_FORMAT_RGBA_DXT3: - case MESA_FORMAT_RGBA_DXT5: -#if FEATURE_EXT_texture_sRGB - case MESA_FORMAT_SRGB_DXT1: - case MESA_FORMAT_SRGBA_DXT1: - case MESA_FORMAT_SRGBA_DXT3: - case MESA_FORMAT_SRGBA_DXT5: -#endif - /* XXX generate error instead? */ - *datatype = GL_UNSIGNED_BYTE; - *comps = 0; - return; -#endif - - case MESA_FORMAT_RGBA: - *datatype = CHAN_TYPE; - *comps = 4; - return; - case MESA_FORMAT_RGB: - *datatype = CHAN_TYPE; - *comps = 3; - return; - case MESA_FORMAT_LUMINANCE_ALPHA: - *datatype = CHAN_TYPE; - *comps = 2; - return; - case MESA_FORMAT_ALPHA: - case MESA_FORMAT_LUMINANCE: - case MESA_FORMAT_INTENSITY: - *datatype = CHAN_TYPE; - *comps = 1; - return; - - case MESA_FORMAT_RGBA_FLOAT32: - *datatype = GL_FLOAT; - *comps = 4; - return; - case MESA_FORMAT_RGBA_FLOAT16: - *datatype = GL_HALF_FLOAT_ARB; - *comps = 4; - return; - case MESA_FORMAT_RGB_FLOAT32: - *datatype = GL_FLOAT; - *comps = 3; - return; - case MESA_FORMAT_RGB_FLOAT16: - *datatype = GL_HALF_FLOAT_ARB; - *comps = 3; - return; - case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32: - *datatype = GL_FLOAT; - *comps = 2; - return; - case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16: - *datatype = GL_HALF_FLOAT_ARB; - *comps = 2; - return; - case MESA_FORMAT_ALPHA_FLOAT32: - case MESA_FORMAT_LUMINANCE_FLOAT32: - case MESA_FORMAT_INTENSITY_FLOAT32: - *datatype = GL_FLOAT; - *comps = 1; - return; - case MESA_FORMAT_ALPHA_FLOAT16: - case MESA_FORMAT_LUMINANCE_FLOAT16: - case MESA_FORMAT_INTENSITY_FLOAT16: - *datatype = GL_HALF_FLOAT_ARB; - *comps = 1; - return; - - default: - _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps"); - *datatype = 0; - *comps = 1; - } -} - - - -/** - * Table to map MESA_FORMAT_ to texel fetch/store funcs. - * XXX this is somewhat temporary. - */ -static struct { - GLuint Name; - FetchTexelFuncF Fetch1D; - FetchTexelFuncF Fetch2D; - FetchTexelFuncF Fetch3D; - StoreTexelFunc StoreTexel; -} -texfetch_funcs[MESA_FORMAT_COUNT] = -{ - { - MESA_FORMAT_RGBA, - fetch_texel_1d_f_rgba, - fetch_texel_2d_f_rgba, - fetch_texel_3d_f_rgba, - store_texel_rgba - }, - { - MESA_FORMAT_RGB, - fetch_texel_1d_f_rgb, - fetch_texel_2d_f_rgb, - fetch_texel_3d_f_rgb, - store_texel_rgb - }, - { - MESA_FORMAT_ALPHA, - fetch_texel_1d_f_alpha, - fetch_texel_2d_f_alpha, - fetch_texel_3d_f_alpha, - store_texel_alpha - }, - { - MESA_FORMAT_LUMINANCE, - fetch_texel_1d_f_luminance, - fetch_texel_2d_f_luminance, - fetch_texel_3d_f_luminance, - store_texel_luminance - }, - { - MESA_FORMAT_LUMINANCE_ALPHA, - fetch_texel_1d_f_luminance_alpha, - fetch_texel_2d_f_luminance_alpha, - fetch_texel_3d_f_luminance_alpha, - store_texel_luminance_alpha - }, - { - MESA_FORMAT_INTENSITY, - fetch_texel_1d_f_intensity, - fetch_texel_2d_f_intensity, - fetch_texel_3d_f_intensity, - store_texel_intensity - }, - { - MESA_FORMAT_SRGB8, - fetch_texel_1d_srgb8, - fetch_texel_2d_srgb8, - fetch_texel_3d_srgb8, - store_texel_srgb8 - }, - { - MESA_FORMAT_SRGBA8, - fetch_texel_1d_srgba8, - fetch_texel_2d_srgba8, - fetch_texel_3d_srgba8, - store_texel_srgba8 - }, - { - MESA_FORMAT_SARGB8, - fetch_texel_1d_sargb8, - fetch_texel_2d_sargb8, - fetch_texel_3d_sargb8, - store_texel_sargb8 - }, - { - MESA_FORMAT_SL8, - fetch_texel_1d_sl8, - fetch_texel_2d_sl8, - fetch_texel_3d_sl8, - store_texel_sl8 - }, - { - MESA_FORMAT_SLA8, - fetch_texel_1d_sla8, - fetch_texel_2d_sla8, - fetch_texel_3d_sla8, - store_texel_sla8 - }, - { - MESA_FORMAT_RGB_FXT1, - NULL, - _mesa_fetch_texel_2d_f_rgb_fxt1, - NULL, - NULL - }, - { - MESA_FORMAT_RGBA_FXT1, - NULL, - _mesa_fetch_texel_2d_f_rgba_fxt1, - NULL, - NULL - }, - { - MESA_FORMAT_RGB_DXT1, - NULL, - _mesa_fetch_texel_2d_f_rgb_dxt1, - NULL, - NULL - }, - { - MESA_FORMAT_RGBA_DXT1, - NULL, - _mesa_fetch_texel_2d_f_rgba_dxt1, - NULL, - NULL - }, - { - MESA_FORMAT_RGBA_DXT3, - NULL, - _mesa_fetch_texel_2d_f_rgba_dxt3, - NULL, - NULL - }, - { - MESA_FORMAT_RGBA_DXT5, - NULL, - _mesa_fetch_texel_2d_f_rgba_dxt5, - NULL, - NULL - }, - { - MESA_FORMAT_SRGB_DXT1, - NULL, - _mesa_fetch_texel_2d_f_srgb_dxt1, - NULL, - NULL - }, - { - MESA_FORMAT_SRGBA_DXT1, - NULL, - _mesa_fetch_texel_2d_f_srgba_dxt1, - NULL, - NULL - }, - { - MESA_FORMAT_SRGBA_DXT3, - NULL, - _mesa_fetch_texel_2d_f_srgba_dxt3, - NULL, - NULL - }, - { - MESA_FORMAT_SRGBA_DXT5, - NULL, - _mesa_fetch_texel_2d_f_srgba_dxt5, - NULL, - NULL - }, - { - MESA_FORMAT_RGBA_FLOAT32, - fetch_texel_1d_f_rgba_f32, - fetch_texel_2d_f_rgba_f32, - fetch_texel_3d_f_rgba_f32, - store_texel_rgba_f32 - }, - { - MESA_FORMAT_RGBA_FLOAT16, - fetch_texel_1d_f_rgba_f16, - fetch_texel_2d_f_rgba_f16, - fetch_texel_3d_f_rgba_f16, - store_texel_rgba_f16 - }, - { - MESA_FORMAT_RGB_FLOAT32, - fetch_texel_1d_f_rgb_f32, - fetch_texel_2d_f_rgb_f32, - fetch_texel_3d_f_rgb_f32, - store_texel_rgb_f32 - }, - { - MESA_FORMAT_RGB_FLOAT16, - fetch_texel_1d_f_rgb_f16, - fetch_texel_2d_f_rgb_f16, - fetch_texel_3d_f_rgb_f16, - store_texel_rgb_f16 - }, - { - MESA_FORMAT_ALPHA_FLOAT32, - fetch_texel_1d_f_alpha_f32, - fetch_texel_2d_f_alpha_f32, - fetch_texel_3d_f_alpha_f32, - store_texel_alpha_f32 - }, - { - MESA_FORMAT_ALPHA_FLOAT16, - fetch_texel_1d_f_alpha_f16, - fetch_texel_2d_f_alpha_f16, - fetch_texel_3d_f_alpha_f16, - store_texel_alpha_f16 - }, - { - MESA_FORMAT_LUMINANCE_FLOAT32, - fetch_texel_1d_f_luminance_f32, - fetch_texel_2d_f_luminance_f32, - fetch_texel_3d_f_luminance_f32, - store_texel_luminance_f32 - }, - { - MESA_FORMAT_LUMINANCE_FLOAT16, - fetch_texel_1d_f_luminance_f16, - fetch_texel_2d_f_luminance_f16, - fetch_texel_3d_f_luminance_f16, - store_texel_luminance_f16 - }, - { - MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, - fetch_texel_1d_f_luminance_alpha_f32, - fetch_texel_2d_f_luminance_alpha_f32, - fetch_texel_3d_f_luminance_alpha_f32, - store_texel_luminance_alpha_f32 - }, - { - MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, - fetch_texel_1d_f_luminance_alpha_f16, - fetch_texel_2d_f_luminance_alpha_f16, - fetch_texel_3d_f_luminance_alpha_f16, - store_texel_luminance_alpha_f16 - }, - { - MESA_FORMAT_INTENSITY_FLOAT32, - fetch_texel_1d_f_intensity_f32, - fetch_texel_2d_f_intensity_f32, - fetch_texel_3d_f_intensity_f32, - store_texel_intensity_f32 - }, - { - MESA_FORMAT_INTENSITY_FLOAT16, - fetch_texel_1d_f_intensity_f16, - fetch_texel_2d_f_intensity_f16, - fetch_texel_3d_f_intensity_f16, - store_texel_intensity_f16 - }, - { - MESA_FORMAT_DUDV8, - fetch_texel_1d_dudv8, - fetch_texel_2d_dudv8, - fetch_texel_3d_dudv8, - NULL - }, - { - MESA_FORMAT_SIGNED_RGBA8888, - fetch_texel_1d_signed_rgba8888, - fetch_texel_2d_signed_rgba8888, - fetch_texel_3d_signed_rgba8888, - store_texel_signed_rgba8888 - }, - { - MESA_FORMAT_SIGNED_RGBA8888_REV, - fetch_texel_1d_signed_rgba8888_rev, - fetch_texel_2d_signed_rgba8888_rev, - fetch_texel_3d_signed_rgba8888_rev, - store_texel_signed_rgba8888_rev - }, - { - MESA_FORMAT_RGBA8888, - fetch_texel_1d_f_rgba8888, - fetch_texel_2d_f_rgba8888, - fetch_texel_3d_f_rgba8888, - store_texel_rgba8888 - }, - { - MESA_FORMAT_RGBA8888_REV, - fetch_texel_1d_f_rgba8888_rev, - fetch_texel_2d_f_rgba8888_rev, - fetch_texel_3d_f_rgba8888_rev, - store_texel_rgba8888_rev - }, - { - MESA_FORMAT_ARGB8888, - fetch_texel_1d_f_argb8888, - fetch_texel_2d_f_argb8888, - fetch_texel_3d_f_argb8888, - store_texel_argb8888 - }, - { - MESA_FORMAT_ARGB8888_REV, - fetch_texel_1d_f_argb8888_rev, - fetch_texel_2d_f_argb8888_rev, - fetch_texel_3d_f_argb8888_rev, - store_texel_argb8888_rev - }, - { - MESA_FORMAT_RGB888, - fetch_texel_1d_f_rgb888, - fetch_texel_2d_f_rgb888, - fetch_texel_3d_f_rgb888, - store_texel_rgb888 - }, - { - MESA_FORMAT_BGR888, - fetch_texel_1d_f_bgr888, - fetch_texel_2d_f_bgr888, - fetch_texel_3d_f_bgr888, - store_texel_bgr888 - }, - { - MESA_FORMAT_RGB565, - fetch_texel_1d_f_rgb565, - fetch_texel_2d_f_rgb565, - fetch_texel_3d_f_rgb565, - store_texel_rgb565 - }, - { - MESA_FORMAT_RGB565_REV, - fetch_texel_1d_f_rgb565_rev, - fetch_texel_2d_f_rgb565_rev, - fetch_texel_3d_f_rgb565_rev, - store_texel_rgb565_rev - }, - { - MESA_FORMAT_RGBA4444, - fetch_texel_1d_f_rgba4444, - fetch_texel_2d_f_rgba4444, - fetch_texel_3d_f_rgba4444, - store_texel_rgba4444 - }, - { - MESA_FORMAT_ARGB4444, - fetch_texel_1d_f_argb4444, - fetch_texel_2d_f_argb4444, - fetch_texel_3d_f_argb4444, - store_texel_argb4444 - }, - { - MESA_FORMAT_ARGB4444_REV, - fetch_texel_1d_f_argb4444_rev, - fetch_texel_2d_f_argb4444_rev, - fetch_texel_3d_f_argb4444_rev, - store_texel_argb4444_rev - }, - { - MESA_FORMAT_RGBA5551, - fetch_texel_1d_f_rgba5551, - fetch_texel_2d_f_rgba5551, - fetch_texel_3d_f_rgba5551, - store_texel_rgba5551 - }, - { - MESA_FORMAT_ARGB1555, - fetch_texel_1d_f_argb1555, - fetch_texel_2d_f_argb1555, - fetch_texel_3d_f_argb1555, - store_texel_argb1555 - }, - { - MESA_FORMAT_ARGB1555_REV, - fetch_texel_1d_f_argb1555_rev, - fetch_texel_2d_f_argb1555_rev, - fetch_texel_3d_f_argb1555_rev, - store_texel_argb1555_rev - }, - { - MESA_FORMAT_AL88, - fetch_texel_1d_f_al88, - fetch_texel_2d_f_al88, - fetch_texel_3d_f_al88, - store_texel_al88 - }, - { - MESA_FORMAT_AL88_REV, - fetch_texel_1d_f_al88_rev, - fetch_texel_2d_f_al88_rev, - fetch_texel_3d_f_al88_rev, - store_texel_al88_rev - }, - { - MESA_FORMAT_RGB332, - fetch_texel_1d_f_rgb332, - fetch_texel_2d_f_rgb332, - fetch_texel_3d_f_rgb332, - store_texel_rgb332 - }, - { - MESA_FORMAT_A8, - fetch_texel_1d_f_a8, - fetch_texel_2d_f_a8, - fetch_texel_3d_f_a8, - store_texel_a8 - }, - { - MESA_FORMAT_L8, - fetch_texel_1d_f_l8, - fetch_texel_2d_f_l8, - fetch_texel_3d_f_l8, - store_texel_l8 - }, - { - MESA_FORMAT_I8, - fetch_texel_1d_f_i8, - fetch_texel_2d_f_i8, - fetch_texel_3d_f_i8, - store_texel_i8 - }, - { - MESA_FORMAT_CI8, - fetch_texel_1d_f_ci8, - fetch_texel_2d_f_ci8, - fetch_texel_3d_f_ci8, - store_texel_ci8 - }, - { - MESA_FORMAT_YCBCR, - fetch_texel_1d_f_ycbcr, - fetch_texel_2d_f_ycbcr, - fetch_texel_3d_f_ycbcr, - store_texel_ycbcr - }, - { - MESA_FORMAT_YCBCR_REV, - fetch_texel_1d_f_ycbcr_rev, - fetch_texel_2d_f_ycbcr_rev, - fetch_texel_3d_f_ycbcr_rev, - store_texel_ycbcr_rev - }, - { - MESA_FORMAT_Z24_S8, - fetch_texel_1d_f_z24_s8, - fetch_texel_2d_f_z24_s8, - fetch_texel_3d_f_z24_s8, - store_texel_z24_s8 - }, - { - MESA_FORMAT_S8_Z24, - fetch_texel_1d_f_s8_z24, - fetch_texel_2d_f_s8_z24, - fetch_texel_3d_f_s8_z24, - store_texel_s8_z24 - }, - { - MESA_FORMAT_Z16, - fetch_texel_1d_f_z16, - fetch_texel_2d_f_z16, - fetch_texel_3d_f_z16, - store_texel_z16 - }, - { - MESA_FORMAT_Z32, - fetch_texel_1d_f_z32, - fetch_texel_2d_f_z32, - fetch_texel_3d_f_z32, - store_texel_z32 + if (ctx->Extensions.EXT_texture_integer) { + switch (internalFormat) { + case GL_RGBA32UI_EXT: + case GL_RGB32UI_EXT: + case GL_ALPHA32UI_EXT: + case GL_INTENSITY32UI_EXT: + case GL_LUMINANCE32UI_EXT: + case GL_LUMINANCE_ALPHA32UI_EXT: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); + break; + case GL_RGBA16UI_EXT: + case GL_RGB16UI_EXT: + case GL_ALPHA16UI_EXT: + case GL_INTENSITY16UI_EXT: + case GL_LUMINANCE16UI_EXT: + case GL_LUMINANCE_ALPHA16UI_EXT: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); + break; + case GL_RGBA8UI_EXT: + case GL_RGB8UI_EXT: + case GL_ALPHA8UI_EXT: + case GL_INTENSITY8UI_EXT: + case GL_LUMINANCE8UI_EXT: + case GL_LUMINANCE_ALPHA8UI_EXT: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); + break; + case GL_RGBA32I_EXT: + case GL_RGB32I_EXT: + case GL_ALPHA32I_EXT: + case GL_INTENSITY32I_EXT: + case GL_LUMINANCE32I_EXT: + case GL_LUMINANCE_ALPHA32I_EXT: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32); + break; + case GL_RGBA16I_EXT: + case GL_RGB16I_EXT: + case GL_ALPHA16I_EXT: + case GL_INTENSITY16I_EXT: + case GL_LUMINANCE16I_EXT: + case GL_LUMINANCE_ALPHA16I_EXT: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16); + break; + case GL_RGBA8I_EXT: + case GL_RGB8I_EXT: + case GL_ALPHA8I_EXT: + case GL_INTENSITY8I_EXT: + case GL_LUMINANCE8I_EXT: + case GL_LUMINANCE_ALPHA8I_EXT: + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8); + break; + } } -}; + if (ctx->Extensions.ARB_texture_rg) { + switch (internalFormat) { + case GL_R8: + case GL_RED: + case GL_COMPRESSED_RED: + RETURN_IF_SUPPORTED(MESA_FORMAT_R8); + break; + + case GL_R16: + RETURN_IF_SUPPORTED(MESA_FORMAT_R16); + break; + + case GL_RG: + case GL_RG8: + case GL_COMPRESSED_RG: + RETURN_IF_SUPPORTED(MESA_FORMAT_RG88); + break; + + case GL_RG16: + RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616); + break; -FetchTexelFuncF -_mesa_get_texel_fetch_func(GLuint format, GLuint dims) -{ - FetchTexelFuncF f; - GLuint i; - /* XXX replace loop with direct table lookup */ - for (i = 0; i < MESA_FORMAT_COUNT; i++) { - if (texfetch_funcs[i].Name == format) { - switch (dims) { - case 1: - f = texfetch_funcs[i].Fetch1D; - break; - case 2: - f = texfetch_funcs[i].Fetch2D; - break; - case 3: - f = texfetch_funcs[i].Fetch3D; - break; - } - if (!f) - f = fetch_null_texelf; - return f; + default: + ; /* fallthrough */ } } - return NULL; -} + if (ctx->Extensions.EXT_texture_format_BGRA8888) { + switch (internalFormat) { + case GL_BGRA: + RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); + break; -StoreTexelFunc -_mesa_get_texel_store_func(GLuint format) -{ - GLuint i; - /* XXX replace loop with direct table lookup */ - for (i = 0; i < MESA_FORMAT_COUNT; i++) { - if (texfetch_funcs[i].Name == format) { - if (texfetch_funcs[i].StoreTexel) - return texfetch_funcs[i].StoreTexel; - else - return store_null_texel; + default: + ; /* fallthrough */ } } - return NULL; + + _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()"); + return MESA_FORMAT_NONE; } +