diff --git a/rpcs3/Emu/RSX/GL/GLHelpers.h b/rpcs3/Emu/RSX/GL/GLHelpers.h index e5e4c93d20..551984405b 100644 --- a/rpcs3/Emu/RSX/GL/GLHelpers.h +++ b/rpcs3/Emu/RSX/GL/GLHelpers.h @@ -1441,7 +1441,8 @@ namespace gl //Sized internal formats, see opengl spec document on glTexImage2D, table 3 rgba8 = GL_RGBA8, - r5g6b5 = GL_RGB565, + rgb565 = GL_RGB565, + rgb5a1 = GL_RGB5_A1, rgba4 = GL_RGBA4, r8 = GL_R8, r16 = GL_R16, diff --git a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp index f0bac5e41f..9734698f5b 100644 --- a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp +++ b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp @@ -8,63 +8,61 @@ color_format rsx::internals::surface_color_format_to_gl(rsx::surface_color_forma switch (color_format) { case rsx::surface_color_format::r5g6b5: - return{ ::gl::texture::type::ushort_5_6_5, ::gl::texture::format::rgb, false, 3, 2 }; + return{ ::gl::texture::type::ushort_5_6_5, ::gl::texture::format::rgb, ::gl::texture::internal_format::rgb565, true }; case rsx::surface_color_format::a8r8g8b8: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1 }; + return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, ::gl::texture::internal_format::rgba8, false }; //These formats discard their alpha component, forced to 0 or 1 //All XBGR formats will have remapping before they can be read back in shaders as DRGB8 //Prefix o = 1, z = 0 case rsx::surface_color_format::x1r5g5b5_o1r5g5b5: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::ushort_5_5_5_1, ::gl::texture::format::rgb, ::gl::texture::internal_format::rgb5a1, true, { ::gl::texture::channel::one, ::gl::texture::channel::r, ::gl::texture::channel::g, ::gl::texture::channel::b } }; case rsx::surface_color_format::x1r5g5b5_z1r5g5b5: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::ushort_5_5_5_1, ::gl::texture::format::rgb, ::gl::texture::internal_format::rgb5a1, true, { ::gl::texture::channel::zero, ::gl::texture::channel::r, ::gl::texture::channel::g, ::gl::texture::channel::b } }; case rsx::surface_color_format::x8r8g8b8_z8r8g8b8: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, ::gl::texture::internal_format::rgba8, false, { ::gl::texture::channel::zero, ::gl::texture::channel::r, ::gl::texture::channel::g, ::gl::texture::channel::b } }; case rsx::surface_color_format::x8b8g8r8_o8b8g8r8: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::rgba, ::gl::texture::internal_format::rgba8, false, { ::gl::texture::channel::one, ::gl::texture::channel::b, ::gl::texture::channel::g, ::gl::texture::channel::r } }; case rsx::surface_color_format::x8b8g8r8_z8b8g8r8: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::rgba, ::gl::texture::internal_format::rgba8, false, { ::gl::texture::channel::zero, ::gl::texture::channel::b, ::gl::texture::channel::g, ::gl::texture::channel::r } }; case rsx::surface_color_format::x8r8g8b8_o8r8g8b8: - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, ::gl::texture::internal_format::rgba8, false, { ::gl::texture::channel::one, ::gl::texture::channel::r, ::gl::texture::channel::g, ::gl::texture::channel::b } }; case rsx::surface_color_format::w16z16y16x16: - return{ ::gl::texture::type::f16, ::gl::texture::format::rgba, true, 4, 2 }; + return{ ::gl::texture::type::f16, ::gl::texture::format::rgba, ::gl::texture::internal_format::rgba16f, true}; case rsx::surface_color_format::w32z32y32x32: - return{ ::gl::texture::type::f32, ::gl::texture::format::rgba, true, 4, 4 }; + return{ ::gl::texture::type::f32, ::gl::texture::format::rgba, ::gl::texture::internal_format::rgba32f, true}; case rsx::surface_color_format::b8: - return{ ::gl::texture::type::ubyte, ::gl::texture::format::r, false, 1, 1, + return{ ::gl::texture::type::ubyte, ::gl::texture::format::r, ::gl::texture::internal_format::r8, false, { ::gl::texture::channel::one, ::gl::texture::channel::r, ::gl::texture::channel::r, ::gl::texture::channel::r } }; case rsx::surface_color_format::g8b8: - return{ ::gl::texture::type::ubyte, ::gl::texture::format::rg, false, 2, 1, + return{ ::gl::texture::type::ubyte, ::gl::texture::format::rg, ::gl::texture::internal_format::rg8, false, { ::gl::texture::channel::g, ::gl::texture::channel::r, ::gl::texture::channel::g, ::gl::texture::channel::r } }; case rsx::surface_color_format::x32: - return{ ::gl::texture::type::f32, ::gl::texture::format::r, true, 1, 4 }; + return{ ::gl::texture::type::f32, ::gl::texture::format::r, ::gl::texture::internal_format::r32f, true}; case rsx::surface_color_format::a8b8g8r8: - //NOTE: To sample this surface as ARGB8 (ABGR8 does not exist), swizzle will be applied by the application - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1, + return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::rgba, ::gl::texture::internal_format::rgba8, false, { ::gl::texture::channel::a, ::gl::texture::channel::b, ::gl::texture::channel::g, ::gl::texture::channel::r } }; default: - LOG_ERROR(RSX, "Surface color buffer: Unsupported surface color format (0x%x)", (u32)color_format); - return{ ::gl::texture::type::uint_8_8_8_8, ::gl::texture::format::bgra, false, 4, 1 }; + fmt::throw_exception("Unsupported surface color format 0x%x" HERE, (u32)color_format); } } @@ -75,13 +73,14 @@ depth_format rsx::internals::surface_depth_format_to_gl(rsx::surface_depth_forma case rsx::surface_depth_format::z16: return{ ::gl::texture::type::ushort, ::gl::texture::format::depth, ::gl::texture::internal_format::depth16 }; - default: - LOG_ERROR(RSX, "Surface depth buffer: Unsupported surface depth format (0x%x)", (u32)depth_format); case rsx::surface_depth_format::z24s8: if (g_cfg.video.force_high_precision_z_buffer && ::gl::get_driver_caps().ARB_depth_buffer_float_supported) return{ ::gl::texture::type::uint_24_8, ::gl::texture::format::depth_stencil, ::gl::texture::internal_format::depth32f_stencil8 }; else return{ ::gl::texture::type::uint_24_8, ::gl::texture::format::depth_stencil, ::gl::texture::internal_format::depth24_stencil8 }; + + default: + fmt::throw_exception("Unsupported depth format 0x%x" HERE, (u32)depth_format); } } @@ -95,48 +94,6 @@ u8 rsx::internals::get_pixel_size(rsx::surface_depth_format format) fmt::throw_exception("Unknown depth format" HERE); } -::gl::texture::internal_format rsx::internals::sized_internal_format(rsx::surface_color_format color_format) -{ - switch (color_format) - { - case rsx::surface_color_format::r5g6b5: - return ::gl::texture::internal_format::r5g6b5; - - case rsx::surface_color_format::a8r8g8b8: - return ::gl::texture::internal_format::rgba8; - - case rsx::surface_color_format::x1r5g5b5_o1r5g5b5: - case rsx::surface_color_format::x1r5g5b5_z1r5g5b5: - case rsx::surface_color_format::x8r8g8b8_z8r8g8b8: - case rsx::surface_color_format::x8b8g8r8_o8b8g8r8: - case rsx::surface_color_format::x8b8g8r8_z8b8g8r8: - case rsx::surface_color_format::x8r8g8b8_o8r8g8b8: - return ::gl::texture::internal_format::rgba8; - - case rsx::surface_color_format::w16z16y16x16: - return ::gl::texture::internal_format::rgba16f; - - case rsx::surface_color_format::w32z32y32x32: - return ::gl::texture::internal_format::rgba32f; - - case rsx::surface_color_format::b8: - return ::gl::texture::internal_format::r8; - - case rsx::surface_color_format::g8b8: - return ::gl::texture::internal_format::rg8; - - case rsx::surface_color_format::x32: - return ::gl::texture::internal_format::r32f; - - case rsx::surface_color_format::a8b8g8r8: - return ::gl::texture::internal_format::rgba8; - - default: - LOG_ERROR(RSX, "Surface color buffer: Unsupported surface color format (0x%x)", (u32)color_format); - return ::gl::texture::internal_format::rgba8; - } -} - namespace { std::array get_offsets() diff --git a/rpcs3/Emu/RSX/GL/GLRenderTargets.h b/rpcs3/Emu/RSX/GL/GLRenderTargets.h index dbb59c2852..22a3306cdc 100644 --- a/rpcs3/Emu/RSX/GL/GLRenderTargets.h +++ b/rpcs3/Emu/RSX/GL/GLRenderTargets.h @@ -21,9 +21,8 @@ struct color_format { gl::texture::type type; gl::texture::format format; + gl::texture::internal_format internal_format; bool swap_bytes; - int channel_count; - int channel_size; color_swizzle swizzle; }; @@ -38,7 +37,6 @@ namespace rsx { namespace internals { - ::gl::texture::internal_format sized_internal_format(rsx::surface_color_format color_format); color_format surface_color_format_to_gl(rsx::surface_color_format color_format); depth_format surface_depth_format_to_gl(rsx::surface_depth_format depth_format); u8 get_pixel_size(rsx::surface_depth_format format); @@ -142,13 +140,12 @@ struct gl_render_target_traits ) { auto format = rsx::internals::surface_color_format_to_gl(surface_color_format); - auto internal_fmt = rsx::internals::sized_internal_format(surface_color_format); std::unique_ptr result(new gl::render_target(rsx::apply_resolution_scale((u16)width, true), - rsx::apply_resolution_scale((u16)height, true), (GLenum)internal_fmt)); + rsx::apply_resolution_scale((u16)height, true), (GLenum)format.internal_format)); result->set_aa_mode(antialias); - result->set_native_pitch((u16)width * format.channel_count * format.channel_size * result->samples_x); + result->set_native_pitch((u16)width * get_format_block_size_in_bytes(surface_color_format) * result->samples_x); result->set_surface_dimensions((u16)width, (u16)height, (u16)pitch); result->set_format(surface_color_format); @@ -327,7 +324,7 @@ struct gl_render_target_traits rsx::surface_antialiasing antialias, bool check_refs=false) { - const auto internal_fmt = rsx::internals::sized_internal_format(format); + const auto internal_fmt = rsx::internals::surface_color_format_to_gl(format).internal_format; return int_surface_matches_properties(surface, internal_fmt, width, height, antialias, check_refs); } diff --git a/rpcs3/Emu/RSX/GL/GLTexture.cpp b/rpcs3/Emu/RSX/GL/GLTexture.cpp index 049d194be6..f068e2ca56 100644 --- a/rpcs3/Emu/RSX/GL/GLTexture.cpp +++ b/rpcs3/Emu/RSX/GL/GLTexture.cpp @@ -104,14 +104,16 @@ namespace gl return std::make_tuple(GL_RED, GL_UNSIGNED_SHORT, true); case texture::internal_format::r32f: return std::make_tuple(GL_RED, GL_FLOAT, true); - case texture::internal_format::r5g6b5: - return std::make_tuple(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, true); case texture::internal_format::rg8: return std::make_tuple(GL_RG, GL_UNSIGNED_BYTE, false); case texture::internal_format::rg16: return std::make_tuple(GL_RG, GL_UNSIGNED_SHORT, true); case texture::internal_format::rg16f: return std::make_tuple(GL_RG, GL_HALF_FLOAT, true); + case texture::internal_format::rgb565: + return std::make_tuple(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, true); + case texture::internal_format::rgb5a1: + return std::make_tuple(GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, true); case texture::internal_format::rgba4: return std::make_tuple(GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4, false); case texture::internal_format::rgba8: diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.h b/rpcs3/Emu/RSX/GL/GLTextureCache.h index 564d7a29cb..1a0f053950 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.h +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.h @@ -915,7 +915,7 @@ namespace gl case CELL_GCM_TEXTURE_X32_FLOAT: return (ifmt == gl::texture::internal_format::r32f); case CELL_GCM_TEXTURE_R5G6B5: - return (ifmt == gl::texture::internal_format::r5g6b5); + return (ifmt == gl::texture::internal_format::rgb565); case CELL_GCM_TEXTURE_A8R8G8B8: return (ifmt == gl::texture::internal_format::rgba8 || ifmt == gl::texture::internal_format::depth24_stencil8 ||