Commit 22264841 authored by NiranV's avatar NiranV

Fixed: Depth Snapshots weirdly zooming in when taking snapshots at unusual screen ratios.

parent f6b12f85
......@@ -4982,43 +4982,62 @@ BOOL LLViewerWindow::rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_hei
F32 scale_factor = 1.0f ;
if (!keep_window_aspect || (image_width > window_width) || (image_height > window_height))
{
//BD - Always update our view rect and aspect ratio to match our desired snapshot resolution.
// Should the snapshot fail our main camera and render loop will automatically return us
// to the proper values again anyway.
mWorldViewRectRaw.set(0, image_height, image_width, 0);
LLViewerCamera::getInstance()->setViewHeightInPixels(mWorldViewRectRaw.getHeight());
LLViewerCamera::getInstance()->setAspect(getWorldViewAspectRatio());
if ((image_width <= gGLManager.mGLMaxTextureSize && image_height <= gGLManager.mGLMaxTextureSize) &&
(image_width > window_width || image_height > window_height) && LLPipeline::sRenderDeferred && !show_ui)
{
U32 color_fmt = type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH ? GL_DEPTH_COMPONENT : GL_RGBA;
if (scratch_space.allocate(image_width, image_height, color_fmt, true, true))
//BD - Don't attempt to allocate scratch space when we take depth shots as it fails to allocate
// the color buffer in llrendertarget.cpp. This leads to depth essentially not getting
// a view rect and aspect ratio update, resulting in the final image being "zoomed in".
// Hence why we pulled the view rect update out of this section and made it always apply.
if (type == LLSnapshotModel::SNAPSHOT_TYPE_COLOR)
{
original_width = gPipeline.mDeferredScreen.getWidth();
original_height = gPipeline.mDeferredScreen.getHeight();
if (gPipeline.allocateScreenBuffer(image_width, image_height))
if (scratch_space.allocate(image_width, image_height, GL_RGBA, true, true))
{
window_width = image_width;
window_height = image_height;
snapshot_width = image_width;
snapshot_height = image_height;
reset_deferred = true;
mWorldViewRectRaw.set(0, image_height, image_width, 0);
LLViewerCamera::getInstance()->setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
LLViewerCamera::getInstance()->setAspect( getWorldViewAspectRatio() );
scratch_space.bindTarget();
original_width = gPipeline.mDeferredScreen.getWidth();
original_height = gPipeline.mDeferredScreen.getHeight();
if (gPipeline.allocateScreenBuffer(image_width, image_height))
{
window_width = image_width;
window_height = image_height;
snapshot_width = image_width;
snapshot_height = image_height;
reset_deferred = true;
scratch_space.bindTarget();
}
else
{
scratch_space.release();
gPipeline.allocateScreenBuffer(original_width, original_height);
}
}
else
{
scratch_space.release();
gPipeline.allocateScreenBuffer(original_width, original_height);
LL_WARNS() << "Failed to allocate scratch space. " << LL_ENDL;
}
}
}
if (!reset_deferred)
//BD - As mentioned above, this is part of the issue that makes depth shots zoomed in.
// Due to the above scratch space allocation failing and thus reset_deferred never
// getting set to true, we end up in here.
// This causes differences between how the final depth shot looks compared to the
// same color snapshot. Make it an option to both depth and color shots can either
// allow cropping or not.
/*if (!reset_deferred &&)
{
// if image cropping or need to enlarge the scene, compute a scale_factor
F32 ratio = llmin( (F32)window_width / image_width , (F32)window_height / image_height) ;
snapshot_width = (S32)(ratio * image_width) ;
snapshot_height = (S32)(ratio * image_height) ;
scale_factor = llmax(1.0f, 1.0f / ratio) ;
}
}*/
}
if (show_ui && scale_factor > 1.f)
......@@ -5222,15 +5241,17 @@ BOOL LLViewerWindow::rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_hei
gPipeline.resetDrawOrders();
}
//BD - We are being incredibly paranoid here, this is absolutely not required to do but we do it
// anyway just to be safer than safe.
mWorldViewRectRaw = window_rect;
LLViewerCamera::getInstance()->setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
LLViewerCamera::getInstance()->setAspect( getWorldViewAspectRatio() );
if (reset_deferred)
{
mWorldViewRectRaw = window_rect;
LLViewerCamera::getInstance()->setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
LLViewerCamera::getInstance()->setAspect( getWorldViewAspectRatio() );
scratch_space.flush();
scratch_space.release();
gPipeline.allocateScreenBuffer(original_width, original_height);
}
if (high_res)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment