X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fformats.c;h=b8fed182570a573ed03504457149064d6cbad8f7;hb=751fe9058bc15f4f8608f0fdc02209542991ff23;hp=cd9eb81852fbae6526e6cf7cf115dd5357c8e75f;hpb=74c324fdbaebb7accaee668f2bc54af4699d0025;p=mesa.git diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index cd9eb81852f..b8fed182570 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -40,9 +40,10 @@ struct gl_format_info 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; @@ -221,6 +222,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 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 */ @@ -275,6 +285,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 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 */ @@ -284,6 +303,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 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 */ @@ -293,6 +321,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 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 */ @@ -374,6 +411,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 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 */ @@ -756,7 +802,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_SIGNED_R8, /* Name */ "MESA_FORMAT_SIGNED_R8", /* StrName */ - GL_RGBA, /* BaseFormat */ + 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 */ @@ -765,7 +811,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_SIGNED_RG88, "MESA_FORMAT_SIGNED_RG88", - GL_RGBA, + GL_RG, GL_SIGNED_NORMALIZED, 8, 8, 0, 0, 0, 0, 0, 0, 0, @@ -774,7 +820,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_SIGNED_RGBX8888, "MESA_FORMAT_SIGNED_RGBX8888", - GL_RGBA, + GL_RGB, GL_SIGNED_NORMALIZED, 8, 8, 8, 0, 0, 0, 0, 0, 0, @@ -803,7 +849,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_SIGNED_R_16, "MESA_FORMAT_SIGNED_R_16", - GL_RGBA, + GL_RED, GL_SIGNED_NORMALIZED, 16, 0, 0, 0, 0, 0, 0, 0, 0, @@ -812,7 +858,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_SIGNED_RG_16, "MESA_FORMAT_SIGNED_RG_16", - GL_RGBA, + GL_RG, GL_SIGNED_NORMALIZED, 16, 16, 0, 0, 0, 0, 0, 0, 0, @@ -821,7 +867,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = { MESA_FORMAT_SIGNED_RGB_16, "MESA_FORMAT_SIGNED_RGB_16", - GL_RGBA, + GL_RGB, GL_SIGNED_NORMALIZED, 16, 16, 16, 0, 0, 0, 0, 0, 0, @@ -863,7 +909,6 @@ const char * _mesa_get_format_name(gl_format format) { const struct gl_format_info *info = _mesa_get_format_info(format); - ASSERT(info->BytesPerBlock); return info->StrName; } @@ -1046,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. @@ -1123,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. @@ -1147,7 +1255,7 @@ _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; } } @@ -1155,6 +1263,7 @@ _mesa_test_formats(void) 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) { @@ -1205,8 +1314,9 @@ _mesa_test_formats(void) assert(info->LuminanceBits == 0); assert(info->IntensityBits > 0); } - } + + check_format_to_type_and_comps(); } @@ -1252,11 +1362,17 @@ _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: @@ -1274,6 +1390,9 @@ _mesa_format_to_type_and_comps(gl_format format, return; case MESA_FORMAT_R16: + case MESA_FORMAT_A16: + case MESA_FORMAT_L16: + case MESA_FORMAT_I16: *datatype = GL_UNSIGNED_SHORT; *comps = 1; return; @@ -1478,10 +1597,13 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 4; return; - case MESA_FORMAT_NONE: case MESA_FORMAT_COUNT: + assert(0); + return; + + case MESA_FORMAT_NONE: /* For debug builds, warn if any formats are not handled */ -#ifndef DEBUG +#ifdef DEBUG default: #endif _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",