From b060767bd8fb2327e0fd5d17ca5f29a2f0d344b7 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 17 Jan 2021 14:36:14 +0100 Subject: [PATCH] glgsg: slight refactor of get_internal_image_format() --- .../glstuff/glGraphicsStateGuardian_src.cxx | 82 ++++++++++--------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 2ee90887c7..45eac22e9e 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -9648,8 +9648,10 @@ get_internal_image_format(Texture *tex, bool force_sized) const { // no compression for render targets compression = Texture::CM_off; } - bool is_3d = (tex->get_texture_type() == Texture::TT_3d_texture || - tex->get_texture_type() == Texture::TT_2d_texture_array); + Texture::ComponentType component_type = tex->get_component_type(); + Texture::TextureType texture_type = tex->get_texture_type(); + bool is_3d = (texture_type == Texture::TT_3d_texture || + texture_type == Texture::TT_2d_texture_array); if (get_supports_compressed_texture_format(compression)) { switch (compression) { @@ -9789,7 +9791,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { } #endif if (get_supports_compressed_texture_format(Texture::CM_eac) && !is_3d) { - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_COMPRESSED_R11_EAC; } else { return GL_COMPRESSED_SIGNED_R11_EAC; @@ -9815,7 +9817,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { } #endif if (get_supports_compressed_texture_format(Texture::CM_eac) && !is_3d) { - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_COMPRESSED_RG11_EAC; } else { return GL_COMPRESSED_SIGNED_RG11_EAC; @@ -9993,7 +9995,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { break; case Texture::CM_eac: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { if (tex->get_num_components() == 1) { return GL_COMPRESSED_R11_EAC; } else { @@ -10026,7 +10028,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_depth_stencil: if (_supports_depth_stencil) { #ifndef OPENGLES - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_DEPTH32F_STENCIL8; } else #endif @@ -10038,7 +10040,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_depth_component: #ifndef OPENGLES - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_DEPTH_COMPONENT32F; } else #endif @@ -10073,7 +10075,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return GL_DEPTH_COMPONENT16_OES; } #else - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_DEPTH_COMPONENT32F; } else { return GL_DEPTH_COMPONENT32; @@ -10083,7 +10085,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_rgba: case Texture::F_rgbm: #ifndef OPENGLES_1 - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_RGBA16F; } else #endif @@ -10093,11 +10095,11 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return _supports_bgr ? GL_BGRA : GL_RGBA; } #else - if (tex->get_component_type() == Texture::T_unsigned_short) { + if (component_type == Texture::T_unsigned_short) { return GL_RGBA16; - } else if (tex->get_component_type() == Texture::T_short) { + } else if (component_type == Texture::T_short) { return GL_RGBA16_SNORM; - } else if (tex->get_component_type() == Texture::T_byte) { + } else if (component_type == Texture::T_byte) { return GL_RGBA8_SNORM; } else { return force_sized ? GL_RGBA8 : GL_RGBA; @@ -10114,32 +10116,32 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return _supports_bgr ? GL_BGRA : (force_sized ? GL_RGBA8 : GL_RGBA); #else case Texture::F_rgba8: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGBA8; } else { return GL_RGBA8_SNORM; } case Texture::F_r8i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_R8UI; } else { return GL_R8I; } case Texture::F_rg8i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RG8UI; } else { return GL_RG8I; } case Texture::F_rgb8i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGB8UI; } else { return GL_RGB8I; } case Texture::F_rgba8i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGBA8UI; } else { return GL_RGBA8I; @@ -10149,9 +10151,9 @@ get_internal_image_format(Texture *tex, bool force_sized) const { #endif // OPENGLES #ifndef OPENGLES case Texture::F_rgba16: - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_RGBA16F; - } else if (Texture::is_unsigned(tex->get_component_type())) { + } else if (Texture::is_unsigned(component_type)) { return GL_RGBA16; } else { return GL_RGBA16_SNORM; @@ -10161,7 +10163,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { #endif // OPENGLES case Texture::F_rgb: - switch (tex->get_component_type()) { + switch (component_type) { case Texture::T_float: return GL_RGB16F; #ifndef OPENGLES case Texture::T_unsigned_short: return GL_RGB16; @@ -10191,7 +10193,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return GL_RGB16F; #else case Texture::F_rgb8: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGB8; } else { return GL_RGB8_SNORM; @@ -10199,9 +10201,9 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_rgb12: return GL_RGB12; case Texture::F_rgb16: - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_RGB16F; - } else if (Texture::is_unsigned(tex->get_component_type())) { + } else if (Texture::is_unsigned(component_type)) { return GL_RGB16; } else { return GL_RGB16_SNORM; @@ -10222,41 +10224,41 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return GL_RG16F_EXT; #elif !defined(OPENGLES_1) case Texture::F_r16: - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_R16F; - } else if (Texture::is_unsigned(tex->get_component_type())) { + } else if (Texture::is_unsigned(component_type)) { return GL_R16; } else { return GL_R16_SNORM; } case Texture::F_rg16: - if (tex->get_component_type() == Texture::T_float) { + if (component_type == Texture::T_float) { return GL_RG16F; - } else if (Texture::is_unsigned(tex->get_component_type())) { + } else if (Texture::is_unsigned(component_type)) { return GL_RG16; } else { return GL_RG16_SNORM; } case Texture::F_r16i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_R16UI; } else { return GL_R16I; } case Texture::F_rg16i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RG16UI; } else { return GL_RG16I; } case Texture::F_rgb16i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGB16UI; } else { return GL_RGB16I; } case Texture::F_rgba16i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGBA16UI; } else { return GL_RGBA16I; @@ -10273,7 +10275,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_green: case Texture::F_blue: #ifndef OPENGLES - if (!Texture::is_unsigned(tex->get_component_type())) { + if (!Texture::is_unsigned(component_type)) { return GL_R8_SNORM; } else #endif @@ -10298,7 +10300,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return force_sized ? GL_LUMINANCE8 : GL_LUMINANCE; #else if (_supports_luminance_texture) { - switch (tex->get_component_type()) { + switch (component_type) { case Texture::T_float: case Texture::T_half_float: return GL_LUMINANCE16F_ARB; @@ -10310,7 +10312,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return force_sized ? GL_LUMINANCE8 : GL_LUMINANCE; } } else { - switch (tex->get_component_type()) { + switch (component_type) { case Texture::T_float: case Texture::T_half_float: return GL_R16F; @@ -10329,7 +10331,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return force_sized ? GL_LUMINANCE8_ALPHA8 : GL_LUMINANCE_ALPHA; #else if (_supports_luminance_texture) { - switch (tex->get_component_type()) { + switch (component_type) { case Texture::T_float: case Texture::T_half_float: return GL_LUMINANCE_ALPHA16F_ARB; @@ -10341,7 +10343,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return force_sized ? GL_LUMINANCE8_ALPHA8 : GL_LUMINANCE_ALPHA; } } else { - switch (tex->get_component_type()) { + switch (component_type) { case Texture::T_float: case Texture::T_half_float: return GL_RG16F; @@ -10375,25 +10377,25 @@ get_internal_image_format(Texture *tex, bool force_sized) const { #ifndef OPENGLES_1 case Texture::F_r32i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_R32UI; } else { return GL_R32I; } case Texture::F_rg32i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RG32UI; } else { return GL_RG32I; } case Texture::F_rgb32i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGB32UI; } else { return GL_RGB32I; } case Texture::F_rgba32i: - if (Texture::is_unsigned(tex->get_component_type())) { + if (Texture::is_unsigned(component_type)) { return GL_RGBA32UI; } else { return GL_RGBA32I;