From b648d1b1c339dcfdf32548d9595189cd1ef91be9 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 18 Aug 2022 01:38:02 -0700 Subject: [PATCH] move RenderTexture out of Video --- src/Video/Video.cs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Video/Video.cs b/src/Video/Video.cs index 7a5c828..4ca357d 100644 --- a/src/Video/Video.cs +++ b/src/Video/Video.cs @@ -45,7 +45,6 @@ namespace MoonWorks.Video private int currentFrame; private GraphicsDevice GraphicsDevice; - private Texture RenderTexture = null; private Texture yTexture = null; private Texture uTexture = null; private Texture vTexture = null; @@ -115,16 +114,9 @@ namespace MoonWorks.Video InitializeTheoraStream(); + // FIXME: maybe we should store textures on a VideoPlayer to save memory if (Theorafile.tf_hasvideo(Handle) == 1) { - RenderTexture = Texture.CreateTexture2D( - GraphicsDevice, - (uint) yWidth, - (uint) yHeight, - TextureFormat.R8G8B8A8, - TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler - ); - yTexture = Texture.CreateTexture2D( GraphicsDevice, (uint) yWidth, @@ -214,16 +206,23 @@ namespace MoonWorks.Video State = VideoState.Stopped; } - public Texture GetTexture() + public void Render(Texture renderTexture) { - if (RenderTexture == null) + if (renderTexture == null) { throw new InvalidOperationException(); } + #if DEBUG + if (renderTexture.Height != yHeight || renderTexture.Width != yWidth) + { + throw new ArgumentException("Render texture does not match video size!"); + } + #endif + if (State == VideoState.Stopped) { - return RenderTexture; + return; } timeElapsed += (timer.Elapsed.TotalMilliseconds - lastTimestamp) * PlaybackSpeed; @@ -237,7 +236,7 @@ namespace MoonWorks.Video (IntPtr) yuvData, thisFrame - currentFrame ) == 1 || currentFrame == -1) { - UpdateTexture(); + UpdateTexture(renderTexture); } currentFrame = thisFrame; @@ -270,11 +269,9 @@ namespace MoonWorks.Video State = VideoState.Stopped; } } - - return RenderTexture; } - private void UpdateTexture() + private void UpdateTexture(Texture renderTexture) { var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); @@ -287,7 +284,7 @@ namespace MoonWorks.Video ); commandBuffer.BeginRenderPass( - new ColorAttachmentInfo(RenderTexture, Color.Black) + new ColorAttachmentInfo(renderTexture, Color.Black) ); commandBuffer.BindGraphicsPipeline(GraphicsDevice.VideoPipeline); @@ -327,7 +324,6 @@ namespace MoonWorks.Video if (disposing) { // dispose managed state (managed objects) - RenderTexture.Dispose(); yTexture.Dispose(); uTexture.Dispose(); vTexture.Dispose();