From: Brian Paul Date: Thu, 22 Apr 2010 16:47:53 +0000 (-0600) Subject: st/mesa: refactor depth/stencil format selection code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e65b11525ada0e80943a92fe659cad986ec8c613;p=mesa.git st/mesa: refactor depth/stencil format selection code --- diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index d7f5b1ea247..b9f0c1fde69 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -420,6 +420,49 @@ default_depth_format(struct pipe_screen *screen, } +static enum pipe_format +default_depth_stencil_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) +{ + static const enum pipe_format zsFormats[] = { + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_S8_USCALED_Z24_UNORM + }; + uint i; + for (i = 0; i < Elements(zsFormats); i++) { + if (screen->is_format_supported( screen, zsFormats[i], target, + tex_usage, geom_flags )) { + return zsFormats[i]; + } + } + return PIPE_FORMAT_NONE; +} + + +static enum pipe_format +default_stencil_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) +{ + static const enum pipe_format sFormats[] = { + PIPE_FORMAT_S8_USCALED, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_S8_USCALED_Z24_UNORM + }; + uint i; + for (i = 0; i < Elements(sFormats); i++) { + if (screen->is_format_supported( screen, sFormats[i], target, + tex_usage, geom_flags )) { + return sFormats[i]; + } + } + return PIPE_FORMAT_NONE; +} + + /** * Given an OpenGL internalFormat value for a texture or surface, return * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match. @@ -577,21 +620,11 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8_USCALED, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8_USCALED; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, target, tex_usage, geom_flags )) - return PIPE_FORMAT_Z24_UNORM_S8_USCALED; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8_USCALED_Z24_UNORM; - return PIPE_FORMAT_NONE; + return default_stencil_format(screen, target, tex_usage, geom_flags); case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, target, tex_usage, geom_flags )) - return PIPE_FORMAT_Z24_UNORM_S8_USCALED; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8_USCALED_Z24_UNORM; - return PIPE_FORMAT_NONE; + return default_depth_stencil_format(screen, target, tex_usage, geom_flags); case GL_SRGB_EXT: case GL_SRGB8_EXT: