HostDisplay: Add method to render screenshots at window size

This commit is contained in:
Connor McLaughlin
2021-03-06 02:11:17 +10:00
parent 757bef7b6d
commit 2aea58d056
8 changed files with 279 additions and 33 deletions

View File

@ -749,7 +749,6 @@ bool OpenGLHostDisplay::Render()
return false;
}
glDisable(GL_SCISSOR_TEST);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
@ -765,6 +764,46 @@ bool OpenGLHostDisplay::Render()
return true;
}
bool OpenGLHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector<u32>* out_pixels, u32* out_stride,
HostDisplayPixelFormat* out_format)
{
GL::Texture texture;
if (!texture.Create(width, height, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, nullptr) || !texture.CreateFramebuffer())
return false;
texture.BindFramebuffer(GL_FRAMEBUFFER);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
if (HasDisplayTexture())
{
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height, 0);
if (!m_post_processing_chain.IsEmpty())
{
ApplyPostProcessingChain(texture.GetGLFramebufferID(), left, height - top - draw_height, draw_width, draw_height,
m_display_texture_handle, m_display_texture_width, m_display_texture_height,
m_display_texture_view_x, m_display_texture_view_y, m_display_texture_view_width,
m_display_texture_view_height, width, height);
}
else
{
RenderDisplay(left, height - top - draw_height, draw_width, draw_height, m_display_texture_handle,
m_display_texture_width, m_display_texture_height, m_display_texture_view_x,
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
m_display_linear_filtering);
}
}
out_pixels->resize(width * height);
*out_stride = sizeof(u32) * width;
*out_format = HostDisplayPixelFormat::RGBA8;
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, out_pixels->data());
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return true;
}
void OpenGLHostDisplay::RenderImGui()
{
ImGui::Render();
@ -783,7 +822,8 @@ void OpenGLHostDisplay::RenderDisplay()
{
ApplyPostProcessingChain(0, left, GetWindowHeight() - top - height, width, height, m_display_texture_handle,
m_display_texture_width, m_display_texture_height, m_display_texture_view_x,
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height);
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
GetWindowWidth(), GetWindowHeight());
return;
}
@ -995,11 +1035,12 @@ bool OpenGLHostDisplay::CheckPostProcessingRenderTargets(u32 target_width, u32 t
void OpenGLHostDisplay::ApplyPostProcessingChain(GLuint final_target, s32 final_left, s32 final_top, s32 final_width,
s32 final_height, void* texture_handle, u32 texture_width,
s32 texture_height, s32 texture_view_x, s32 texture_view_y,
s32 texture_view_width, s32 texture_view_height)
s32 texture_view_width, s32 texture_view_height, u32 target_width,
u32 target_height)
{
if (!CheckPostProcessingRenderTargets(GetWindowWidth(), GetWindowHeight()))
if (!CheckPostProcessingRenderTargets(target_width, target_height))
{
RenderDisplay(final_left, GetWindowHeight() - final_top - final_height, final_width, final_height, texture_handle,
RenderDisplay(final_left, target_height - final_top - final_height, final_width, final_height, texture_handle,
texture_width, texture_height, texture_view_x, texture_view_y, texture_view_width,
texture_view_height, m_display_linear_filtering);
return;
@ -1008,7 +1049,7 @@ void OpenGLHostDisplay::ApplyPostProcessingChain(GLuint final_target, s32 final_
// downsample/upsample - use same viewport for remainder
m_post_processing_input_texture.BindFramebuffer(GL_DRAW_FRAMEBUFFER);
glClear(GL_COLOR_BUFFER_BIT);
RenderDisplay(final_left, GetWindowHeight() - final_top - final_height, final_width, final_height, texture_handle,
RenderDisplay(final_left, target_height - final_top - final_height, final_width, final_height, texture_handle,
texture_width, texture_height, texture_view_x, texture_view_y, texture_view_width, texture_view_height,
m_display_linear_filtering);