move RenderTexture out of Video

pull/22/head
cosmonaut 2022-08-18 01:38:02 -07:00
parent 491eafac76
commit b648d1b1c3
1 changed files with 14 additions and 18 deletions

View File

@ -45,7 +45,6 @@ namespace MoonWorks.Video
private int currentFrame; private int currentFrame;
private GraphicsDevice GraphicsDevice; private GraphicsDevice GraphicsDevice;
private Texture RenderTexture = null;
private Texture yTexture = null; private Texture yTexture = null;
private Texture uTexture = null; private Texture uTexture = null;
private Texture vTexture = null; private Texture vTexture = null;
@ -115,16 +114,9 @@ namespace MoonWorks.Video
InitializeTheoraStream(); InitializeTheoraStream();
// FIXME: maybe we should store textures on a VideoPlayer to save memory
if (Theorafile.tf_hasvideo(Handle) == 1) if (Theorafile.tf_hasvideo(Handle) == 1)
{ {
RenderTexture = Texture.CreateTexture2D(
GraphicsDevice,
(uint) yWidth,
(uint) yHeight,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
yTexture = Texture.CreateTexture2D( yTexture = Texture.CreateTexture2D(
GraphicsDevice, GraphicsDevice,
(uint) yWidth, (uint) yWidth,
@ -214,16 +206,23 @@ namespace MoonWorks.Video
State = VideoState.Stopped; State = VideoState.Stopped;
} }
public Texture GetTexture() public void Render(Texture renderTexture)
{ {
if (RenderTexture == null) if (renderTexture == null)
{ {
throw new InvalidOperationException(); 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) if (State == VideoState.Stopped)
{ {
return RenderTexture; return;
} }
timeElapsed += (timer.Elapsed.TotalMilliseconds - lastTimestamp) * PlaybackSpeed; timeElapsed += (timer.Elapsed.TotalMilliseconds - lastTimestamp) * PlaybackSpeed;
@ -237,7 +236,7 @@ namespace MoonWorks.Video
(IntPtr) yuvData, (IntPtr) yuvData,
thisFrame - currentFrame thisFrame - currentFrame
) == 1 || currentFrame == -1) { ) == 1 || currentFrame == -1) {
UpdateTexture(); UpdateTexture(renderTexture);
} }
currentFrame = thisFrame; currentFrame = thisFrame;
@ -270,11 +269,9 @@ namespace MoonWorks.Video
State = VideoState.Stopped; State = VideoState.Stopped;
} }
} }
return RenderTexture;
} }
private void UpdateTexture() private void UpdateTexture(Texture renderTexture)
{ {
var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
@ -287,7 +284,7 @@ namespace MoonWorks.Video
); );
commandBuffer.BeginRenderPass( commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(RenderTexture, Color.Black) new ColorAttachmentInfo(renderTexture, Color.Black)
); );
commandBuffer.BindGraphicsPipeline(GraphicsDevice.VideoPipeline); commandBuffer.BindGraphicsPipeline(GraphicsDevice.VideoPipeline);
@ -327,7 +324,6 @@ namespace MoonWorks.Video
if (disposing) if (disposing)
{ {
// dispose managed state (managed objects) // dispose managed state (managed objects)
RenderTexture.Dispose();
yTexture.Dispose(); yTexture.Dispose();
uTexture.Dispose(); uTexture.Dispose();
vTexture.Dispose(); vTexture.Dispose();