Skip to content

Commit

Permalink
- apply present shader on screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed May 20, 2019
1 parent 61ead74 commit 2a15f65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
23 changes: 17 additions & 6 deletions src/rendering/vulkan/renderer/vk_postprocess.cpp
Expand Up @@ -169,7 +169,7 @@ void VkPostprocess::BlitCurrentToImage(VkTextureImage *dstimage, VkImageLayout f
imageTransition1.execute(cmdbuffer);
}

void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders)
void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool screenshot)
{
auto fb = GetVulkanFrameBuffer();

Expand All @@ -193,10 +193,19 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool
uniforms.GrayFormula = static_cast<int>(gl_satformula);
}
uniforms.ColorScale = (gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1);
uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), -screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() };
uniforms.Offset = { 0.0f, 1.0f };

if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT)
if (screenshot)
{
uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() };
uniforms.Offset = { 0.0f, 0.0f };
}
else
{
uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), -screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() };
uniforms.Offset = { 0.0f, 1.0f };
}

if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT && !screenshot)
{
uniforms.HdrMode = 1;
}
Expand All @@ -211,9 +220,11 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool
renderstate.Viewport = box;
renderstate.SetInputCurrent(0, ViewportLinearScale() ? PPFilterMode::Linear : PPFilterMode::Nearest);
renderstate.SetInputTexture(1, &hw_postprocess.present.Dither, PPFilterMode::Nearest, PPWrapMode::Repeat);
renderstate.SetOutputSwapChain();
if (screenshot)
renderstate.SetOutputNext();
else
renderstate.SetOutputSwapChain();
renderstate.SetNoBlend();
//if (clearBorders) renderstate.SetClearBorders();
renderstate.Draw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/vulkan/renderer/vk_postprocess.h
Expand Up @@ -56,7 +56,7 @@ class VkPostprocess

void BlitSceneToPostprocess();
void BlitCurrentToImage(VkTextureImage *image, VkImageLayout finallayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
void DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders);
void DrawPresentTexture(const IntRect &box, bool applyGamma, bool screenshot);

private:
void NextEye(int eyeCount);
Expand Down
9 changes: 8 additions & 1 deletion src/rendering/vulkan/system/vk_framebuffer.cpp
Expand Up @@ -272,7 +272,7 @@ void VulkanFrameBuffer::WaitForCommands(bool finish)

presentImageIndex = swapChain->AcquireImage(GetClientWidth(), GetClientHeight(), mSwapChainImageAvailableSemaphore.get());
if (presentImageIndex != 0xffffffff)
mPostprocess->DrawPresentTexture(mOutputLetterbox, true, true);
mPostprocess->DrawPresentTexture(mOutputLetterbox, true, false);
}

FlushCommands(finish, true);
Expand Down Expand Up @@ -787,6 +787,13 @@ TArray<uint8_t> VulkanFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &colo
int w = SCREENWIDTH;
int h = SCREENHEIGHT;

IntRect box;
box.left = 0;
box.top = 0;
box.width = w;
box.height = h;
mPostprocess->DrawPresentTexture(box, true, true);

TArray<uint8_t> ScreenshotBuffer(w * h * 3, true);
CopyScreenToBuffer(w, h, ScreenshotBuffer.Data());

Expand Down

0 comments on commit 2a15f65

Please sign in to comment.