rsx: Fix XBGR vs XRGB screenshots

This commit is contained in:
kd-11 2020-08-11 20:35:50 +03:00 committed by kd-11
parent 7e1b24224d
commit fd2607ad52
5 changed files with 21 additions and 10 deletions

View File

@ -220,14 +220,14 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info)
pack_settings.apply(); pack_settings.apply();
if (gl::get_driver_caps().ARB_dsa_supported) if (gl::get_driver_caps().ARB_dsa_supported)
glGetTextureImage(image_to_flip, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer_height * buffer_width * 4, sshot_frame.data()); glGetTextureImage(image_to_flip, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer_height * buffer_width * 4, sshot_frame.data());
else else
glGetTextureImageEXT(image_to_flip, GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, sshot_frame.data()); glGetTextureImageEXT(image_to_flip, GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, sshot_frame.data());
if (GLenum err; (err = glGetError()) != GL_NO_ERROR) if (GLenum err; (err = glGetError()) != GL_NO_ERROR)
screenshot.error("Failed to capture image: 0x%x", err); screenshot.error("Failed to capture image: 0x%x", err);
else else
m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height); m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height, false);
} }
const areai screen_area = coordi({}, { static_cast<int>(buffer_width), static_cast<int>(buffer_height) }); const areai screen_area = coordi({}, { static_cast<int>(buffer_width), static_cast<int>(buffer_height) });

View File

@ -90,7 +90,7 @@ public:
virtual display_handle_t handle() const = 0; virtual display_handle_t handle() const = 0;
std::atomic<bool> screenshot_toggle = false; std::atomic<bool> screenshot_toggle = false;
virtual void take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height) = 0; virtual void take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height, bool is_bgra) = 0;
}; };
class GSRender : public rsx::thread class GSRender : public rsx::thread

View File

@ -659,7 +659,8 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info)
memcpy(sshot_frame.data(), src, sshot_size); memcpy(sshot_frame.data(), src, sshot_size);
sshot_vkbuf.unmap(); sshot_vkbuf.unmap();
m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height); const bool is_bgra = image_to_flip->format() == VK_FORMAT_B8G8R8A8_UNORM;
m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height, is_bgra);
} }
} }

View File

@ -335,10 +335,10 @@ void gs_frame::flip(draw_context_t, bool /*skip_frame*/)
} }
} }
void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height) void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height, bool is_bgra)
{ {
std::thread( std::thread(
[sshot_width, sshot_height](const std::vector<u8> sshot_data) [sshot_width, sshot_height, is_bgra](const std::vector<u8> sshot_data)
{ {
std::string screen_path = fs::get_config_dir() + "screenshots/"; std::string screen_path = fs::get_config_dir() + "screenshots/";
@ -361,9 +361,19 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
const u32* sshot_ptr = reinterpret_cast<const u32*>(sshot_data.data()); const u32* sshot_ptr = reinterpret_cast<const u32*>(sshot_data.data());
u32* alpha_ptr = reinterpret_cast<u32*>(sshot_data_alpha.data()); u32* alpha_ptr = reinterpret_cast<u32*>(sshot_data_alpha.data());
for (size_t index = 0; index < sshot_data.size() / sizeof(u32); index++) if (is_bgra) [[likely]]
{ {
alpha_ptr[index] = ((sshot_ptr[index] & 0xFF) << 16) | (sshot_ptr[index] & 0xFF00) | ((sshot_ptr[index] & 0xFF0000) >> 16) | 0xFF000000; for (size_t index = 0; index < sshot_data.size() / sizeof(u32); index++)
{
alpha_ptr[index] = ((sshot_ptr[index] & 0xFF) << 16) | (sshot_ptr[index] & 0xFF00) | ((sshot_ptr[index] & 0xFF0000) >> 16) | 0xFF000000;
}
}
else
{
for (size_t index = 0; index < sshot_data.size() / sizeof(u32); index++)
{
alpha_ptr[index] = sshot_ptr[index] | 0xFF000000;
}
} }
std::vector<u8> encoded_png; std::vector<u8> encoded_png;

View File

@ -50,7 +50,7 @@ public:
void progress_increment(int delta); void progress_increment(int delta);
void progress_set_limit(int limit); void progress_set_limit(int limit);
void take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height) override; void take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height, bool is_bgra) override;
protected: protected:
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);