Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
vontell committed Nov 25, 2024
1 parent 8b4df1c commit 23cce36
Showing 1 changed file with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ private IEnumerator UpdateGPUData(int frame, Action<(byte[], int, int)?> onCompl
var screenWidth = Screen.width;
var screenHeight = Screen.height;

if (_screenShotTexture == null || _screenShotTexture.width != screenWidth ||
_screenShotTexture.height != screenHeight)
if (_screenShotTexture == null || _screenShotTexture.width != screenWidth || _screenShotTexture.height != screenHeight)
{
if (_screenShotTexture != null)
{
Expand All @@ -326,8 +325,7 @@ private IEnumerator UpdateGPUData(int frame, Action<(byte[], int, int)?> onCompl
{
// why Metal defaults to B8G8R8A8_SRGB and thus flips the colors.. who knows..
// this setting stops it from spamming log errors
_screenShotTexture = new RenderTexture(screenWidth, screenHeight, 0,
GraphicsFormat.R8G8B8A8_SRGB);
_screenShotTexture = new RenderTexture(screenWidth, screenHeight, 0, GraphicsFormat.R8G8B8A8_SRGB);
}
else
{
Expand All @@ -340,15 +338,12 @@ private IEnumerator UpdateGPUData(int frame, Action<(byte[], int, int)?> onCompl
try
{
ScreenCapture.CaptureScreenshotIntoRenderTexture(_screenShotTexture);
var readbackRequest = AsyncGPUReadback.Request(_screenShotTexture, 0,
GraphicsFormat.R8G8B8A8_SRGB, request =>
var readbackRequest = AsyncGPUReadback.Request(_screenShotTexture, 0, GraphicsFormat.R8G8B8A8_SRGB, request =>
{
if (!request.hasError)
{
var pixels = request.GetData<Color32>();
var copyBuffer =
_copyBuffer
.Value; // uses a threadlocal to avoid re-allocating this on every readback
var copyBuffer = _copyBuffer.Value; // uses a threadlocal to avoid re-allocating this on every readback
if (SystemInfo.graphicsUVStartsAtTop)
{
// the pixels from the GPU are upside down, we need to reverse this for it to be right side up
Expand All @@ -357,30 +352,24 @@ private IEnumerator UpdateGPUData(int frame, Action<(byte[], int, int)?> onCompl
{
// swap rows
// bottom row to buffer
NativeArray<Color32>.Copy(pixels, i * screenWidth, copyBuffer, 0,
screenWidth);
NativeArray<Color32>.Copy(pixels, i * screenWidth, copyBuffer, 0, screenWidth);
// top row to bottom
NativeArray<Color32>.Copy(pixels, (screenHeight - i - 1) * screenWidth,
pixels, i * screenWidth, screenWidth);
NativeArray<Color32>.Copy(pixels, (screenHeight - i - 1) * screenWidth, pixels, i * screenWidth, screenWidth);
// buffer to top row
NativeArray<Color32>.Copy(copyBuffer, 0, pixels,
(screenHeight - i - 1) * screenWidth, screenWidth);
NativeArray<Color32>.Copy(copyBuffer, 0, pixels, (screenHeight - i - 1) * screenWidth, screenWidth);
}
} //else.. we're fine

var imageOutput = ImageConversion.EncodeNativeArrayToJPG(pixels, theGraphicsFormat,
(uint)screenWidth, (uint)screenHeight);
var imageOutput = ImageConversion.EncodeNativeArrayToJPG(pixels, theGraphicsFormat, (uint)screenWidth, (uint)screenHeight);

RGDebug.LogDebug($"ScreenshotCapture - Captured screenshot for frame # {frame}");
AddFrame(frame, (imageOutput.ToArray(), screenWidth, screenHeight));
}
else
{
RGDebug.LogWarning(
$"ScreenshotCapture - Error capturing screenshot for frame # {frame}");
RGDebug.LogWarning($"ScreenshotCapture - Error capturing screenshot for frame # {frame}");
AddFrame(frame, null);
}

HandleCompletedActionCallbacks();
});
// update from null to the real request
Expand All @@ -389,8 +378,7 @@ private IEnumerator UpdateGPUData(int frame, Action<(byte[], int, int)?> onCompl
}
catch (Exception e)
{
RGDebug.LogWarning(
$"ScreenshotCapture - Exception starting to capture screenshot for frame # {frame} - {e.Message}");
RGDebug.LogWarning($"ScreenshotCapture - Exception starting to capture screenshot for frame # {frame} - {e.Message}");
}

}
Expand Down

0 comments on commit 23cce36

Please sign in to comment.