mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
mesa/main: factor out format/type enum checking
Checking if the format and type enums are valid while checking that the combinations are valid makes the code hard to modify when there's complex conditions at play. Let's factor these checks out so we can stricten up this code in a more maintainable way. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29528>
This commit is contained in:
parent
227c6627cb
commit
d2817013ba
1 changed files with 36 additions and 10 deletions
|
|
@ -1725,6 +1725,37 @@ _mesa_get_linear_internalformat(GLenum format)
|
|||
}
|
||||
|
||||
|
||||
static bool
|
||||
valid_texture_format_enum(const struct gl_context *ctx, GLenum format)
|
||||
{
|
||||
switch (format) {
|
||||
case GL_RG:
|
||||
return _mesa_has_rg_textures(ctx);
|
||||
|
||||
case GL_YCBCR_MESA:
|
||||
return _mesa_has_MESA_ycbcr_texture(ctx);
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
valid_texture_type_enum(const struct gl_context *ctx, GLenum type)
|
||||
{
|
||||
switch (type) {
|
||||
case GL_UNSIGNED_INT_10F_11F_11F_REV:
|
||||
return _mesa_has_packed_float(ctx);
|
||||
|
||||
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
|
||||
return _mesa_has_float_depth_buffer(ctx);
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do error checking of format/type combinations for glReadPixels,
|
||||
* glDrawPixels and glTex[Sub]Image. Note that depending on the format
|
||||
|
|
@ -1740,6 +1771,11 @@ GLenum
|
|||
_mesa_error_check_format_and_type(const struct gl_context *ctx,
|
||||
GLenum format, GLenum type)
|
||||
{
|
||||
|
||||
if (!valid_texture_format_enum(ctx, format) ||
|
||||
!valid_texture_type_enum(ctx, type))
|
||||
return GL_INVALID_ENUM;
|
||||
|
||||
/* From OpenGL 3.3 spec, page 220:
|
||||
* "If the format is DEPTH_STENCIL, then values are taken from
|
||||
* both the depth buffer and the stencil buffer. If there is no
|
||||
|
|
@ -1825,18 +1861,12 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
|
|||
return GL_NO_ERROR;
|
||||
|
||||
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
|
||||
if (!_mesa_has_float_depth_buffer(ctx)) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
if (format != GL_DEPTH_STENCIL) {
|
||||
return GL_INVALID_OPERATION;
|
||||
}
|
||||
return GL_NO_ERROR;
|
||||
|
||||
case GL_UNSIGNED_INT_10F_11F_11F_REV:
|
||||
if (!_mesa_has_packed_float(ctx)) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
if (format != GL_RGB) {
|
||||
return GL_INVALID_OPERATION;
|
||||
}
|
||||
|
|
@ -1907,8 +1937,6 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
|
|||
}
|
||||
|
||||
case GL_RG:
|
||||
if (!_mesa_has_rg_textures(ctx))
|
||||
return GL_INVALID_ENUM;
|
||||
switch (type) {
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
|
|
@ -2013,8 +2041,6 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
|
|||
}
|
||||
|
||||
case GL_YCBCR_MESA:
|
||||
if (!_mesa_has_MESA_ycbcr_texture(ctx))
|
||||
return GL_INVALID_ENUM;
|
||||
if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
|
||||
type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
|
||||
return GL_NO_ERROR;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue