diff --git a/CopyMoonlibs.targets b/CopyMoonlibs.targets index 3694e83..93a3508 100644 --- a/CopyMoonlibs.targets +++ b/CopyMoonlibs.targets @@ -36,7 +36,7 @@ %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always diff --git a/Examples/VideoPlayerExample.cs b/Examples/VideoPlayerExample.cs new file mode 100644 index 0000000..a9df789 --- /dev/null +++ b/Examples/VideoPlayerExample.cs @@ -0,0 +1,53 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Video; +using MoonWorks.Input; + +namespace MoonWorksGraphicsTests; + +class VideoPlayerExample : Example +{ + private VideoAV1 Video; + private VideoPlayer VideoPlayer; + + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + + Window.SetTitle("VideoPlayer"); + + // Load the video + Video = new VideoAV1(GraphicsDevice, TestUtils.GetVideoPath("hello.obu"), 25); + + // Play the video + VideoPlayer = new VideoPlayer(GraphicsDevice); + VideoPlayer.Load(Video); + VideoPlayer.Loop = true; + VideoPlayer.Play(); + } + + public override void Update(System.TimeSpan delta) + { + VideoPlayer.Render(); + } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + cmdbuf.Blit(VideoPlayer.RenderTexture, swapchainTexture, Filter.Linear, false); + } + GraphicsDevice.Submit(cmdbuf); + } + + public override void Destroy() + { + VideoPlayer.Stop(); + VideoPlayer.Unload(); + VideoPlayer.Dispose(); + Video.Dispose(); + } +} diff --git a/Examples/VideoPlayerGame.cs b/Examples/VideoPlayerGame.cs deleted file mode 100644 index 38fc2a9..0000000 --- a/Examples/VideoPlayerGame.cs +++ /dev/null @@ -1,98 +0,0 @@ -using MoonWorks.Math.Float; -using MoonWorks.Graphics; -using MoonWorks.Video; - -namespace MoonWorks.Test -{ - class VideoPlayerGame : Game - { - private GraphicsPipeline pipeline; - private Sampler sampler; - private GpuBuffer vertexBuffer; - private GpuBuffer indexBuffer; - - private Video.VideoAV1 video; - private VideoPlayer videoPlayer; - - public VideoPlayerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) - { - // Load the shaders - ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert")); - ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag")); - - // Create the graphics pipeline - GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( - MainWindow.SwapchainFormat, - vertShaderModule, - fragShaderModule - ); - pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); - pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1; - pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); - - // Create the sampler - sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearClamp); - - // Create and populate the GPU resources - var resourceUploader = new ResourceUploader(GraphicsDevice); - - vertexBuffer = resourceUploader.CreateBuffer( - [ - new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), - new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), - new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), - new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)), - ], - BufferUsageFlags.Vertex - ); - - indexBuffer = resourceUploader.CreateBuffer( - [ - 0, 1, 2, - 0, 2, 3, - ], - BufferUsageFlags.Index - ); - - resourceUploader.Upload(); - resourceUploader.Dispose(); - - // Load the video - video = new VideoAV1(GraphicsDevice, TestUtils.GetVideoPath("hello.obu"), 25); - - // Play the video - videoPlayer = new VideoPlayer(GraphicsDevice); - videoPlayer.Load(video); - videoPlayer.Loop = true; - videoPlayer.Play(); - } - - protected override void Update(System.TimeSpan delta) - { - videoPlayer.Render(); - } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue)); - cmdbuf.BindGraphicsPipeline(pipeline); - cmdbuf.BindVertexBuffers(vertexBuffer); - cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); - cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(videoPlayer.RenderTexture, sampler)); - cmdbuf.DrawIndexedPrimitives(0, 0, 2); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - public static void Main(string[] args) - { - VideoPlayerGame game = new VideoPlayerGame(); - game.Run(); - } - } -} diff --git a/MoonWorksGraphicsTests.csproj b/MoonWorksGraphicsTests.csproj index fefc2d7..dab7714 100644 --- a/MoonWorksGraphicsTests.csproj +++ b/MoonWorksGraphicsTests.csproj @@ -52,6 +52,7 @@ + diff --git a/Program.cs b/Program.cs index 2faf4d4..41fee29 100644 --- a/Program.cs +++ b/Program.cs @@ -35,7 +35,8 @@ class Program : Game new TexturedQuadExample(), new TextureMipmapsExample(), new TriangleVertexBufferExample(), - new VertexSamplerExample() + new VertexSamplerExample(), + new VideoPlayerExample() ]; int ExampleIndex = 0;