Videos no longer use more vram then required.

This commit is contained in:
IceReaper
2023-05-14 14:18:17 +02:00
committed by Matthias Mailänder
parent 49c837e7d0
commit 41669d246f

View File

@@ -37,7 +37,8 @@ namespace OpenRA.Mods.Common.Widgets
float2 overlayOrigin, overlaySize; float2 overlayOrigin, overlaySize;
float overlayScale; float overlayScale;
bool stopped; bool stopped;
int textureSize; int textureWidth;
int textureHeight;
Action onComplete; Action onComplete;
@@ -120,12 +121,12 @@ namespace OpenRA.Mods.Common.Widgets
invLength = video.Framerate * 1f / video.FrameCount; invLength = video.Framerate * 1f / video.FrameCount;
var size = Math.Max(video.Width, video.Height); textureWidth = Exts.NextPowerOf2(video.Width);
textureSize = Exts.NextPowerOf2(size); textureHeight = Exts.NextPowerOf2(video.Height);
var videoSheet = new Sheet(SheetType.BGRA, new Size(textureSize, textureSize)); var videoSheet = new Sheet(SheetType.BGRA, new Size(textureWidth, textureHeight));
videoSheet.GetTexture().ScaleFilter = TextureScaleFilter.Linear; videoSheet.GetTexture().ScaleFilter = TextureScaleFilter.Linear;
videoSheet.GetTexture().SetData(video.CurrentFrameData, textureSize, textureSize); videoSheet.GetTexture().SetData(video.CurrentFrameData, textureWidth, textureHeight);
videoSprite = new Sprite(videoSheet, videoSprite = new Sprite(videoSheet,
new Rectangle( new Rectangle(
@@ -168,7 +169,7 @@ namespace OpenRA.Mods.Common.Widgets
while (nextFrame > Video.CurrentFrameIndex) while (nextFrame > Video.CurrentFrameIndex)
{ {
Video.AdvanceFrame(); Video.AdvanceFrame();
videoSprite.Sheet.GetTexture().SetData(Video.CurrentFrameData, textureSize, textureSize); videoSprite.Sheet.GetTexture().SetData(Video.CurrentFrameData, textureWidth, textureHeight);
skippedFrames++; skippedFrames++;
} }
@@ -283,7 +284,7 @@ namespace OpenRA.Mods.Common.Widgets
Paused = true; Paused = true;
Game.Sound.StopVideo(); Game.Sound.StopVideo();
Video.Reset(); Video.Reset();
videoSprite.Sheet.GetTexture().SetData(Video.CurrentFrameData, textureSize, textureSize); videoSprite.Sheet.GetTexture().SetData(Video.CurrentFrameData, textureWidth, textureHeight);
Game.RunAfterTick(() => Game.RunAfterTick(() =>
{ {
if (onComplete != null) if (onComplete != null)