diff options
author | Brian Paul <[email protected]> | 2018-02-06 09:55:13 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2018-02-06 15:23:26 -0700 |
commit | b38196b4522efef9cb2b0f5266af9960547046b9 (patch) | |
tree | 22361e0d831fefb6830d25f947d7961bd5bff39f /src | |
parent | d919ff0f279b6007809220dc43af26fc25435356 (diff) |
mesa: simplify _mesa_get_compressed_formats()
Instead of testing for formats==NULL everywhere, just point formats at
a dummy array which will be discarded.
Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/texcompress.c | 200 |
1 files changed, 83 insertions, 117 deletions
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index 15970a75c05..1cc13a50ce1 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -263,27 +263,23 @@ _mesa_gl_compressed_format_base_format(GLenum format) GLuint _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) { + GLint discard_formats[100]; GLuint n = 0; + + if (!formats) { + formats = discard_formats; + } + if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.TDFX_texture_compression_FXT1) { - if (formats) { - formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX; - formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX; - } - else { - n += 2; - } + formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX; + formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX; } if (ctx->Extensions.EXT_texture_compression_s3tc) { - if (formats) { - formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - } - else { - n += 3; - } + formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; /* The ES and desktop GL specs diverge here. * @@ -315,11 +311,7 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) * Note that the addition is only to the OpenGL ES specification! */ if (_mesa_is_gles(ctx)) { - if (formats) { - formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - } else { - n += 1; - } + formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; } } @@ -332,54 +324,36 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) */ if (_mesa_is_gles(ctx) && ctx->Extensions.OES_compressed_ETC1_RGB8_texture) { - if (formats) { - formats[n++] = GL_ETC1_RGB8_OES; - } - else { - n += 1; - } + formats[n++] = GL_ETC1_RGB8_OES; } if (ctx->API == API_OPENGLES) { - if (formats) { - formats[n++] = GL_PALETTE4_RGB8_OES; - formats[n++] = GL_PALETTE4_RGBA8_OES; - formats[n++] = GL_PALETTE4_R5_G6_B5_OES; - formats[n++] = GL_PALETTE4_RGBA4_OES; - formats[n++] = GL_PALETTE4_RGB5_A1_OES; - formats[n++] = GL_PALETTE8_RGB8_OES; - formats[n++] = GL_PALETTE8_RGBA8_OES; - formats[n++] = GL_PALETTE8_R5_G6_B5_OES; - formats[n++] = GL_PALETTE8_RGBA4_OES; - formats[n++] = GL_PALETTE8_RGB5_A1_OES; - } - else { - n += 10; - } + formats[n++] = GL_PALETTE4_RGB8_OES; + formats[n++] = GL_PALETTE4_RGBA8_OES; + formats[n++] = GL_PALETTE4_R5_G6_B5_OES; + formats[n++] = GL_PALETTE4_RGBA4_OES; + formats[n++] = GL_PALETTE4_RGB5_A1_OES; + formats[n++] = GL_PALETTE8_RGB8_OES; + formats[n++] = GL_PALETTE8_RGBA8_OES; + formats[n++] = GL_PALETTE8_R5_G6_B5_OES; + formats[n++] = GL_PALETTE8_RGBA4_OES; + formats[n++] = GL_PALETTE8_RGB5_A1_OES; } if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility) { - if (formats) { - formats[n++] = GL_COMPRESSED_RGB8_ETC2; - formats[n++] = GL_COMPRESSED_RGBA8_ETC2_EAC; - formats[n++] = GL_COMPRESSED_R11_EAC; - formats[n++] = GL_COMPRESSED_RG11_EAC; - formats[n++] = GL_COMPRESSED_SIGNED_R11_EAC; - formats[n++] = GL_COMPRESSED_SIGNED_RG11_EAC; - formats[n++] = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; - } else { - n += 7; - } + formats[n++] = GL_COMPRESSED_RGB8_ETC2; + formats[n++] = GL_COMPRESSED_RGBA8_ETC2_EAC; + formats[n++] = GL_COMPRESSED_R11_EAC; + formats[n++] = GL_COMPRESSED_RG11_EAC; + formats[n++] = GL_COMPRESSED_SIGNED_R11_EAC; + formats[n++] = GL_COMPRESSED_SIGNED_RG11_EAC; + formats[n++] = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; } if (_mesa_is_gles3(ctx)) { - if (formats) { - formats[n++] = GL_COMPRESSED_SRGB8_ETC2; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; - formats[n++] = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; - } else { - n += 3; - } + formats[n++] = GL_COMPRESSED_SRGB8_ETC2; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + formats[n++] = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; } /* The KHR_texture_compression_astc_hdr spec says: @@ -409,70 +383,62 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) */ if (ctx->API == API_OPENGLES2 && ctx->Extensions.KHR_texture_compression_astc_ldr) { - if (formats) { - formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x5_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x6_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x8_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x5_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x6_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x8_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x10_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x10_KHR; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x12_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; - } - else { - n += 28; - } + formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x5_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x6_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x8_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x5_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x6_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x8_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x10_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x10_KHR; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x12_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; } if (_mesa_is_gles3(ctx) && ctx->Extensions.OES_texture_compression_astc) { - if (formats) { - formats[n++] = GL_COMPRESSED_RGBA_ASTC_3x3x3_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x3x3_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x3_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x4_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4x4_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x4_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x5_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5x5_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x5_OES; - formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x6_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES; - formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES; - } - else { - n += 20; - } + formats[n++] = GL_COMPRESSED_RGBA_ASTC_3x3x3_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x3x3_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x3_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x4_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4x4_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x4_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x5_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5x5_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x5_OES; + formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x6_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES; } + assert(n <= ARRAY_SIZE(discard_formats)); + return n; } |