X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fformats.c;h=b8fed182570a573ed03504457149064d6cbad8f7;hb=751fe9058bc15f4f8608f0fdc02209542991ff23;hp=d6a1ec81b6c8f83ef9c60384636c594e64f49785;hpb=eb732b1bbb4e4bdd018ee9a1653a62fd8dce2d55;p=mesa.git diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index d6a1ec81b6c..b8fed182570 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -26,8 +26,7 @@ #include "imports.h" #include "formats.h" -#include "config.h" -#include "texstore.h" +#include "mfeatures.h" /** @@ -37,16 +36,20 @@ struct gl_format_info { gl_format Name; + /** text name for debugging */ + const char *StrName; + /** - * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, - * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, - * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL. + * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA, + * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, + * GL_COLOR_INDEX, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, + * GL_DEPTH_STENCIL, GL_DUDV_ATI. */ GLenum BaseFormat; /** * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED, - * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT. + * GL_UNSIGNED_INT, GL_INT, GL_FLOAT. */ GLenum DataType; @@ -77,6 +80,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { { MESA_FORMAT_NONE, /* Name */ + "MESA_FORMAT_NONE", /* StrName */ GL_NONE, /* BaseFormat */ GL_NONE, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -85,6 +89,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA8888, /* Name */ + "MESA_FORMAT_RGBA8888", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ @@ -93,6 +98,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA8888_REV, /* Name */ + "MESA_FORMAT_RGBA8888_REV", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ @@ -101,6 +107,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ARGB8888, /* Name */ + "MESA_FORMAT_ARGB8888", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ @@ -109,6 +116,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ARGB8888_REV, /* Name */ + "MESA_FORMAT_ARGB8888_REV", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ @@ -117,6 +125,16 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_XRGB8888, /* Name */ + "MESA_FORMAT_XRGB8888", /* StrName */ + GL_RGB, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ + 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 4 /* BlockWidth/Height,Bytes */ + }, + { + MESA_FORMAT_XRGB8888_REV, /* Name */ + "MESA_FORMAT_XRGB8888_REV", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ @@ -125,6 +143,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGB888, /* Name */ + "MESA_FORMAT_RGB888", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ @@ -133,6 +152,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_BGR888, /* Name */ + "MESA_FORMAT_BGR888", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ @@ -141,6 +161,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGB565, /* Name */ + "MESA_FORMAT_RGB565", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */ @@ -149,6 +170,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGB565_REV, /* Name */ + "MESA_FORMAT_RGB565_REV", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */ @@ -157,6 +179,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ARGB4444, /* Name */ + "MESA_FORMAT_ARGB4444", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */ @@ -165,6 +188,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ARGB4444_REV, /* Name */ + "MESA_FORMAT_ARGB4444_REV", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */ @@ -173,6 +197,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA5551, /* Name */ + "MESA_FORMAT_RGBA5551", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */ @@ -181,6 +206,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ARGB1555, /* Name */ + "MESA_FORMAT_ARGB1555", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */ @@ -189,14 +215,25 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ARGB1555_REV, /* Name */ + "MESA_FORMAT_ARGB1555_REV", /* StrName */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 2 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_AL44, /* Name */ + "MESA_FORMAT_AL44", /* StrName */ + GL_LUMINANCE_ALPHA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */ + 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 1 /* BlockWidth/Height,Bytes */ + }, { MESA_FORMAT_AL88, /* Name */ + "MESA_FORMAT_AL88", /* StrName */ GL_LUMINANCE_ALPHA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */ @@ -205,14 +242,34 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_AL88_REV, /* Name */ + "MESA_FORMAT_AL88_REV", /* StrName */ GL_LUMINANCE_ALPHA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 2 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_AL1616, /* Name */ + "MESA_FORMAT_AL1616", /* StrName */ + GL_LUMINANCE_ALPHA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */ + 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 4 /* BlockWidth/Height,Bytes */ + }, + { + MESA_FORMAT_AL1616_REV, /* Name */ + "MESA_FORMAT_AL1616_REV", /* StrName */ + GL_LUMINANCE_ALPHA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */ + 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 4 /* BlockWidth/Height,Bytes */ + }, { MESA_FORMAT_RGB332, /* Name */ + "MESA_FORMAT_RGB332", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */ @@ -221,30 +278,61 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_A8, /* Name */ + "MESA_FORMAT_A8", /* StrName */ GL_ALPHA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 1 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_A16, /* Name */ + "MESA_FORMAT_A16", /* StrName */ + GL_ALPHA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */ + 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 2 /* BlockWidth/Height,Bytes */ + }, { MESA_FORMAT_L8, /* Name */ + "MESA_FORMAT_L8", /* StrName */ GL_LUMINANCE, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 1 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_L16, /* Name */ + "MESA_FORMAT_L16", /* StrName */ + GL_LUMINANCE, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ + 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 2 /* BlockWidth/Height,Bytes */ + }, { MESA_FORMAT_I8, /* Name */ + "MESA_FORMAT_I8", /* StrName */ GL_INTENSITY, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 1 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_I16, /* Name */ + "MESA_FORMAT_I16", /* StrName */ + GL_INTENSITY, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED, /* DataType */ + 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ + 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 2 /* BlockWidth/Height,Bytes */ + }, { MESA_FORMAT_CI8, /* Name */ + "MESA_FORMAT_CI8", /* StrName */ GL_COLOR_INDEX, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -253,6 +341,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_YCBCR, /* Name */ + "MESA_FORMAT_YCBCR", /* StrName */ GL_YCBCR_MESA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -261,14 +350,79 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_YCBCR_REV, /* Name */ + "MESA_FORMAT_YCBCR_REV", /* StrName */ GL_YCBCR_MESA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 2 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_R8, + "MESA_FORMAT_R8", + GL_RED, + GL_UNSIGNED_NORMALIZED, + 8, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 1 + }, + { + MESA_FORMAT_RG88, + "MESA_FORMAT_RG88", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_RG88_REV, + "MESA_FORMAT_RG88_REV", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_R16, + "MESA_FORMAT_R16", + GL_RED, + GL_UNSIGNED_NORMALIZED, + 16, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_RG1616, + "MESA_FORMAT_RG1616", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_RG1616_REV, + "MESA_FORMAT_RG1616_REV", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_ARGB2101010, + "MESA_FORMAT_ARGB2101010", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 10, 10, 10, 2, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, { MESA_FORMAT_Z24_S8, /* Name */ + "MESA_FORMAT_Z24_S8", /* StrName */ GL_DEPTH_STENCIL, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -277,6 +431,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_S8_Z24, /* Name */ + "MESA_FORMAT_S8_Z24", /* StrName */ GL_DEPTH_STENCIL, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -285,6 +440,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_Z16, /* Name */ + "MESA_FORMAT_Z16", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -293,6 +449,16 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_X8_Z24, /* Name */ + "MESA_FORMAT_X8_Z24", /* StrName */ + GL_DEPTH_COMPONENT, /* BaseFormat */ + GL_UNSIGNED_INT, /* DataType */ + 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ + 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 4 /* BlockWidth/Height,Bytes */ + }, + { + MESA_FORMAT_Z24_X8, /* Name */ + "MESA_FORMAT_Z24_X8", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -301,6 +467,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_Z32, /* Name */ + "MESA_FORMAT_Z32", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -309,6 +476,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_S8, /* Name */ + "MESA_FORMAT_S8", /* StrName */ GL_STENCIL_INDEX, /* BaseFormat */ GL_UNSIGNED_INT, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ @@ -317,6 +485,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SRGB8, + "MESA_FORMAT_SRGB8", GL_RGB, GL_UNSIGNED_NORMALIZED, 8, 8, 8, 0, @@ -325,6 +494,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SRGBA8, + "MESA_FORMAT_SRGBA8", GL_RGBA, GL_UNSIGNED_NORMALIZED, 8, 8, 8, 8, @@ -333,6 +503,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SARGB8, + "MESA_FORMAT_SARGB8", GL_RGBA, GL_UNSIGNED_NORMALIZED, 8, 8, 8, 8, @@ -341,14 +512,16 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SL8, - GL_LUMINANCE_ALPHA, + "MESA_FORMAT_SL8", + GL_LUMINANCE, GL_UNSIGNED_NORMALIZED, - 0, 0, 0, 8, + 0, 0, 0, 0, 8, 0, 0, 0, 0, - 1, 1, 2 + 1, 1, 1 }, { MESA_FORMAT_SLA8, + "MESA_FORMAT_SLA8", GL_LUMINANCE_ALPHA, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 8, @@ -357,6 +530,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SRGB_DXT1, /* Name */ + "MESA_FORMAT_SRGB_DXT1", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */ @@ -365,6 +539,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SRGBA_DXT1, + "MESA_FORMAT_SRGBA_DXT1", GL_RGBA, GL_UNSIGNED_NORMALIZED, 4, 4, 4, 4, @@ -373,6 +548,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SRGBA_DXT3, + "MESA_FORMAT_SRGBA_DXT3", GL_RGBA, GL_UNSIGNED_NORMALIZED, 4, 4, 4, 4, @@ -381,6 +557,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SRGBA_DXT5, + "MESA_FORMAT_SRGBA_DXT5", GL_RGBA, GL_UNSIGNED_NORMALIZED, 4, 4, 4, 4, @@ -390,23 +567,26 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_RGB_FXT1, + "MESA_FORMAT_RGB_FXT1", GL_RGB, GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 0, + 4, 4, 4, 0, /* approx Red/Green/BlueBits */ 0, 0, 0, 0, 0, 8, 4, 16 /* 16 bytes per 8x4 block */ }, { MESA_FORMAT_RGBA_FXT1, + "MESA_FORMAT_RGBA_FXT1", GL_RGBA, GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 8, + 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */ 0, 0, 0, 0, 0, 8, 4, 16 /* 16 bytes per 8x4 block */ }, { MESA_FORMAT_RGB_DXT1, /* Name */ + "MESA_FORMAT_RGB_DXT1", /* StrName */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED, /* DataType */ 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */ @@ -415,6 +595,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA_DXT1, + "MESA_FORMAT_RGBA_DXT1", GL_RGBA, GL_UNSIGNED_NORMALIZED, 4, 4, 4, 4, @@ -423,6 +604,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA_DXT3, + "MESA_FORMAT_RGBA_DXT3", GL_RGBA, GL_UNSIGNED_NORMALIZED, 4, 4, 4, 4, @@ -431,6 +613,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA_DXT5, + "MESA_FORMAT_RGBA_DXT5", GL_RGBA, GL_UNSIGNED_NORMALIZED, 4, 4, 4, 4, @@ -439,6 +622,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA_FLOAT32, + "MESA_FORMAT_RGBA_FLOAT32", GL_RGBA, GL_FLOAT, 32, 32, 32, 32, @@ -447,6 +631,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGBA_FLOAT16, + "MESA_FORMAT_RGBA_FLOAT16", GL_RGBA, GL_FLOAT, 16, 16, 16, 16, @@ -455,6 +640,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGB_FLOAT32, + "MESA_FORMAT_RGB_FLOAT32", GL_RGB, GL_FLOAT, 32, 32, 32, 0, @@ -463,6 +649,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_RGB_FLOAT16, + "MESA_FORMAT_RGB_FLOAT16", GL_RGB, GL_FLOAT, 16, 16, 16, 0, @@ -471,6 +658,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ALPHA_FLOAT32, + "MESA_FORMAT_ALPHA_FLOAT32", GL_ALPHA, GL_FLOAT, 0, 0, 0, 32, @@ -479,6 +667,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_ALPHA_FLOAT16, + "MESA_FORMAT_ALPHA_FLOAT16", GL_ALPHA, GL_FLOAT, 0, 0, 0, 16, @@ -487,6 +676,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_LUMINANCE_FLOAT32, + "MESA_FORMAT_LUMINANCE_FLOAT32", GL_ALPHA, GL_FLOAT, 0, 0, 0, 0, @@ -495,6 +685,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_LUMINANCE_FLOAT16, + "MESA_FORMAT_LUMINANCE_FLOAT16", GL_ALPHA, GL_FLOAT, 0, 0, 0, 0, @@ -503,6 +694,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, + "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32", GL_LUMINANCE_ALPHA, GL_FLOAT, 0, 0, 0, 32, @@ -511,6 +703,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, + "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16", GL_LUMINANCE_ALPHA, GL_FLOAT, 0, 0, 0, 16, @@ -519,6 +712,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_INTENSITY_FLOAT32, + "MESA_FORMAT_INTENSITY_FLOAT32", GL_INTENSITY, GL_FLOAT, 0, 0, 0, 0, @@ -527,22 +721,114 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_INTENSITY_FLOAT16, + "MESA_FORMAT_INTENSITY_FLOAT16", GL_INTENSITY, GL_FLOAT, 0, 0, 0, 0, 0, 16, 0, 0, 0, 1, 1, 2 }, + + /* unnormalized signed int formats */ + { + MESA_FORMAT_RGBA_INT8, + "MESA_FORMAT_RGBA_INT8", + GL_RGBA, + GL_INT, + 8, 8, 8, 8, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_RGBA_INT16, + "MESA_FORMAT_RGBA_INT16", + GL_RGBA, + GL_INT, + 16, 16, 16, 16, + 0, 0, 0, 0, 0, + 1, 1, 8 + }, + { + MESA_FORMAT_RGBA_INT32, + "MESA_FORMAT_RGBA_INT32", + GL_RGBA, + GL_INT, + 32, 32, 32, 32, + 0, 0, 0, 0, 0, + 1, 1, 16 + }, + + /* unnormalized unsigned int formats */ + { + MESA_FORMAT_RGBA_UINT8, + "MESA_FORMAT_RGBA_UINT8", + GL_RGBA, + GL_UNSIGNED_INT, + 8, 8, 8, 8, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_RGBA_UINT16, + "MESA_FORMAT_RGBA_UINT16", + GL_RGBA, + GL_UNSIGNED_INT, + 16, 16, 16, 16, + 0, 0, 0, 0, 0, + 1, 1, 8 + }, + { + MESA_FORMAT_RGBA_UINT32, + "MESA_FORMAT_RGBA_UINT32", + GL_RGBA, + GL_UNSIGNED_INT, + 32, 32, 32, 32, + 0, 0, 0, 0, 0, + 1, 1, 16 + }, + + { MESA_FORMAT_DUDV8, + "MESA_FORMAT_DUDV8", GL_DUDV_ATI, GL_SIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2 }, + + /* Signed 8 bits / channel */ + { + MESA_FORMAT_SIGNED_R8, /* Name */ + "MESA_FORMAT_SIGNED_R8", /* StrName */ + GL_RED, /* BaseFormat */ + GL_SIGNED_NORMALIZED, /* DataType */ + 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ + 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 1 /* BlockWidth/Height,Bytes */ + }, + { + MESA_FORMAT_SIGNED_RG88, + "MESA_FORMAT_SIGNED_RG88", + GL_RG, + GL_SIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_SIGNED_RGBX8888, + "MESA_FORMAT_SIGNED_RGBX8888", + GL_RGB, + GL_SIGNED_NORMALIZED, + 8, 8, 8, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 /* 4 bpp, but no alpha */ + }, { MESA_FORMAT_SIGNED_RGBA8888, + "MESA_FORMAT_SIGNED_RGBA8888", GL_RGBA, GL_SIGNED_NORMALIZED, 8, 8, 8, 8, @@ -551,19 +837,59 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = }, { MESA_FORMAT_SIGNED_RGBA8888_REV, + "MESA_FORMAT_SIGNED_RGBA8888_REV", GL_RGBA, GL_SIGNED_NORMALIZED, 8, 8, 8, 8, 0, 0, 0, 0, 0, 1, 1, 4 }, + + /* Signed 16 bits / channel */ + { + MESA_FORMAT_SIGNED_R_16, + "MESA_FORMAT_SIGNED_R_16", + GL_RED, + GL_SIGNED_NORMALIZED, + 16, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_SIGNED_RG_16, + "MESA_FORMAT_SIGNED_RG_16", + GL_RG, + GL_SIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_SIGNED_RGB_16, + "MESA_FORMAT_SIGNED_RGB_16", + GL_RGB, + GL_SIGNED_NORMALIZED, + 16, 16, 16, 0, + 0, 0, 0, 0, 0, + 1, 1, 6 + }, { MESA_FORMAT_SIGNED_RGBA_16, + "MESA_FORMAT_SIGNED_RGBA_16", GL_RGBA, GL_SIGNED_NORMALIZED, 16, 16, 16, 16, 0, 0, 0, 0, 0, 1, 1, 8 + }, + { + MESA_FORMAT_RGBA_16, + "MESA_FORMAT_RGBA_16", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 16, 16, 16, 16, + 0, 0, 0, 0, 0, + 1, 1, 8 } }; @@ -578,6 +904,16 @@ _mesa_get_format_info(gl_format format) } +/** Return string name of format (for debugging) */ +const char * +_mesa_get_format_name(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + return info->StrName; +} + + + /** * Return bytes needed to store a block of pixels in the given format. * Normally, a block is 1x1 (a single pixel). But for compressed formats @@ -654,6 +990,7 @@ _mesa_get_format_bits(gl_format format, GLenum pname) * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1] * GL_SIGNED_NORMALIZED = signed int representing [-1, 1] * GL_UNSIGNED_INT = an ordinary unsigned integer + * GL_INT = an ordinary signed integer * GL_FLOAT = an ordinary float */ GLenum @@ -678,6 +1015,22 @@ _mesa_get_format_base_format(gl_format format) } +/** + * Return the block size (in pixels) for the given format. Normally + * the block size is 1x1. But compressed formats will have block sizes + * of 4x4 or 8x4 pixels, etc. + * \param bw returns block width in pixels + * \param bh returns block height in pixels + */ +void +_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + *bw = info->BlockWidth; + *bh = info->BlockHeight; +} + + /** Is the given format a compressed format? */ GLboolean _mesa_is_format_compressed(gl_format format) @@ -687,6 +1040,32 @@ _mesa_is_format_compressed(gl_format format) } +/** + * Determine if the given format represents a packed depth/stencil buffer. + */ +GLboolean +_mesa_is_format_packed_depth_stencil(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + + return info->BaseFormat == GL_DEPTH_STENCIL; +} + + +/** + * Is the given format a signed/unsigned integer color format? + */ +GLboolean +_mesa_is_format_integer_color(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) && + info->BaseFormat != GL_DEPTH_COMPONENT && + info->BaseFormat != GL_DEPTH_STENCIL && + info->BaseFormat != GL_STENCIL_INDEX; +} + + /** * Return color encoding for given format. * \return GL_LINEAR or GL_SRGB @@ -712,6 +1091,48 @@ _mesa_get_format_color_encoding(gl_format format) } +/** + * For an sRGB format, return the corresponding linear color space format. + * For non-sRGB formats, return the format as-is. + */ +gl_format +_mesa_get_srgb_format_linear(gl_format format) +{ + switch (format) { + case MESA_FORMAT_SRGB8: + format = MESA_FORMAT_RGB888; + break; + case MESA_FORMAT_SRGBA8: + format = MESA_FORMAT_RGBA8888; + break; + case MESA_FORMAT_SARGB8: + format = MESA_FORMAT_ARGB8888; + break; + case MESA_FORMAT_SL8: + format = MESA_FORMAT_L8; + break; + case MESA_FORMAT_SLA8: + format = MESA_FORMAT_AL88; + break; + case MESA_FORMAT_SRGB_DXT1: + format = MESA_FORMAT_RGB_DXT1; + break; + case MESA_FORMAT_SRGBA_DXT1: + format = MESA_FORMAT_RGBA_DXT1; + break; + case MESA_FORMAT_SRGBA_DXT3: + format = MESA_FORMAT_RGBA_DXT3; + break; + case MESA_FORMAT_SRGBA_DXT5: + format = MESA_FORMAT_RGBA_DXT5; + break; + default: + break; + } + return format; +} + + /** * Return number of bytes needed to store an image of the given size * in the given format. @@ -723,11 +1144,12 @@ _mesa_format_image_size(gl_format format, GLsizei width, const struct gl_format_info *info = _mesa_get_format_info(format); /* Strictly speaking, a conditional isn't needed here */ if (info->BlockWidth > 1 || info->BlockHeight > 1) { - /* compressed format */ + /* compressed format (2D only for now) */ const GLuint bw = info->BlockWidth, bh = info->BlockHeight; const GLuint wblocks = (width + bw - 1) / bw; const GLuint hblocks = (height + bh - 1) / bh; const GLuint sz = wblocks * hblocks * info->BytesPerBlock; + assert(depth == 1); return sz; } else { @@ -738,6 +1160,36 @@ _mesa_format_image_size(gl_format format, GLsizei width, } +/** + * Same as _mesa_format_image_size() but returns a 64-bit value to + * accomodate very large textures. + */ +uint64_t +_mesa_format_image_size64(gl_format format, GLsizei width, + GLsizei height, GLsizei depth) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + /* Strictly speaking, a conditional isn't needed here */ + if (info->BlockWidth > 1 || info->BlockHeight > 1) { + /* compressed format (2D only for now) */ + const uint64_t bw = info->BlockWidth, bh = info->BlockHeight; + const uint64_t wblocks = (width + bw - 1) / bw; + const uint64_t hblocks = (height + bh - 1) / bh; + const uint64_t sz = wblocks * hblocks * info->BytesPerBlock; + assert(depth == 1); + return sz; + } + else { + /* non-compressed */ + const uint64_t sz = ((uint64_t) width * + (uint64_t) height * + (uint64_t) depth * + info->BytesPerBlock); + return sz; + } +} + + GLint _mesa_format_row_stride(gl_format format, GLsizei width) @@ -758,6 +1210,27 @@ _mesa_format_row_stride(gl_format format, GLsizei width) } +/** + * Debug/test: check that all formats are handled in the + * _mesa_format_to_type_and_comps() function. When new pixel formats + * are added to Mesa, that function needs to be updated. + * This is a no-op after the first call. + */ +static void +check_format_to_type_and_comps(void) +{ + gl_format f; + + for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) { + GLenum datatype = 0; + GLuint comps = 0; + /* This function will emit a problem/warning if the format is + * not handled. + */ + _mesa_format_to_type_and_comps(f, &datatype, &comps); + } +} + /** * Do sanity checking of the format info table. @@ -782,13 +1255,15 @@ _mesa_test_formats(void) if (info->RedBits > 0) { GLuint t = info->RedBits + info->GreenBits + info->BlueBits + info->AlphaBits; - assert(t / 8 == info->BytesPerBlock); + assert(t / 8 <= info->BytesPerBlock); + (void) t; } } assert(info->DataType == GL_UNSIGNED_NORMALIZED || info->DataType == GL_SIGNED_NORMALIZED || info->DataType == GL_UNSIGNED_INT || + info->DataType == GL_INT || info->DataType == GL_FLOAT); if (info->BaseFormat == GL_RGB) { @@ -807,6 +1282,22 @@ _mesa_test_formats(void) assert(info->LuminanceBits == 0); assert(info->IntensityBits == 0); } + else if (info->BaseFormat == GL_RG) { + assert(info->RedBits > 0); + assert(info->GreenBits > 0); + assert(info->BlueBits == 0); + assert(info->AlphaBits == 0); + assert(info->LuminanceBits == 0); + assert(info->IntensityBits == 0); + } + else if (info->BaseFormat == GL_RED) { + assert(info->RedBits > 0); + assert(info->GreenBits == 0); + assert(info->BlueBits == 0); + assert(info->AlphaBits == 0); + assert(info->LuminanceBits == 0); + assert(info->IntensityBits == 0); + } else if (info->BaseFormat == GL_LUMINANCE) { assert(info->RedBits == 0); assert(info->GreenBits == 0); @@ -823,8 +1314,9 @@ _mesa_test_formats(void) assert(info->LuminanceBits == 0); assert(info->IntensityBits > 0); } - } + + check_format_to_type_and_comps(); } @@ -843,6 +1335,7 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_ARGB8888: case MESA_FORMAT_ARGB8888_REV: case MESA_FORMAT_XRGB8888: + case MESA_FORMAT_XRGB8888_REV: *datatype = GL_UNSIGNED_BYTE; *comps = 4; return; @@ -869,11 +1362,41 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 4; return; + case MESA_FORMAT_ARGB2101010: + *datatype = GL_UNSIGNED_INT_2_10_10_10_REV; + *comps = 4; + return; + + case MESA_FORMAT_RGBA5551: + *datatype = GL_UNSIGNED_SHORT_5_5_5_1; + *comps = 4; + return; + + case MESA_FORMAT_AL44: /* XXX this isn't plain GL_UNSIGNED_BYTE */ case MESA_FORMAT_AL88: case MESA_FORMAT_AL88_REV: + case MESA_FORMAT_RG88: + case MESA_FORMAT_RG88_REV: *datatype = GL_UNSIGNED_BYTE; *comps = 2; return; + + case MESA_FORMAT_AL1616: + case MESA_FORMAT_AL1616_REV: + case MESA_FORMAT_RG1616: + case MESA_FORMAT_RG1616_REV: + *datatype = GL_UNSIGNED_SHORT; + *comps = 2; + return; + + case MESA_FORMAT_R16: + case MESA_FORMAT_A16: + case MESA_FORMAT_L16: + case MESA_FORMAT_I16: + *datatype = GL_UNSIGNED_SHORT; + *comps = 1; + return; + case MESA_FORMAT_RGB332: *datatype = GL_UNSIGNED_BYTE_3_3_2; *comps = 3; @@ -883,6 +1406,8 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_L8: case MESA_FORMAT_I8: case MESA_FORMAT_CI8: + case MESA_FORMAT_R8: + case MESA_FORMAT_S8: *datatype = GL_UNSIGNED_BYTE; *comps = 1; return; @@ -913,6 +1438,11 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 1; return; + case MESA_FORMAT_Z24_X8: + *datatype = GL_UNSIGNED_INT; + *comps = 1; + return; + case MESA_FORMAT_Z32: *datatype = GL_UNSIGNED_INT; *comps = 1; @@ -923,11 +1453,38 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 2; return; + case MESA_FORMAT_SIGNED_R8: + *datatype = GL_BYTE; + *comps = 1; + return; + case MESA_FORMAT_SIGNED_RG88: + *datatype = GL_BYTE; + *comps = 2; + return; case MESA_FORMAT_SIGNED_RGBA8888: case MESA_FORMAT_SIGNED_RGBA8888_REV: + case MESA_FORMAT_SIGNED_RGBX8888: *datatype = GL_BYTE; *comps = 4; return; + + case MESA_FORMAT_RGBA_16: + *datatype = GL_UNSIGNED_SHORT; + *comps = 4; + return; + + case MESA_FORMAT_SIGNED_R_16: + *datatype = GL_SHORT; + *comps = 1; + return; + case MESA_FORMAT_SIGNED_RG_16: + *datatype = GL_SHORT; + *comps = 2; + return; + case MESA_FORMAT_SIGNED_RGB_16: + *datatype = GL_SHORT; + *comps = 3; + return; case MESA_FORMAT_SIGNED_RGBA_16: *datatype = GL_SHORT; *comps = 4; @@ -967,12 +1524,12 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_SRGBA_DXT1: case MESA_FORMAT_SRGBA_DXT3: case MESA_FORMAT_SRGBA_DXT5: +#endif #endif /* XXX generate error instead? */ *datatype = GL_UNSIGNED_BYTE; *comps = 0; return; -#endif case MESA_FORMAT_RGBA_FLOAT32: *datatype = GL_FLOAT; @@ -1011,8 +1568,46 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 1; return; + case MESA_FORMAT_RGBA_INT8: + *datatype = GL_BYTE; + *comps = 4; + return; + case MESA_FORMAT_RGBA_INT16: + *datatype = GL_SHORT; + *comps = 4; + return; + case MESA_FORMAT_RGBA_INT32: + *datatype = GL_INT; + *comps = 4; + return; + + /** + * \name Non-normalized unsigned integer formats. + */ + case MESA_FORMAT_RGBA_UINT8: + *datatype = GL_UNSIGNED_BYTE; + *comps = 4; + return; + case MESA_FORMAT_RGBA_UINT16: + *datatype = GL_UNSIGNED_SHORT; + *comps = 4; + return; + case MESA_FORMAT_RGBA_UINT32: + *datatype = GL_UNSIGNED_INT; + *comps = 4; + return; + + case MESA_FORMAT_COUNT: + assert(0); + return; + + case MESA_FORMAT_NONE: + /* For debug builds, warn if any formats are not handled */ +#ifdef DEBUG default: - _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps"); +#endif + _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps", + _mesa_get_format_name(format)); *datatype = 0; *comps = 1; }