VideoPlayerExample
parent
2cfc8fa512
commit
486b55527f
|
@ -36,7 +36,7 @@
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="..\moonlibs\windows\libdav1dfile.*">
|
<Content Include="..\moonlibs\lib64\libdav1dfile.*">
|
||||||
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<PositionTextureVertex>();
|
|
||||||
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<ushort>(
|
|
||||||
[
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -52,6 +52,7 @@
|
||||||
<Compile Include="Examples\TextureMipmapsExample.cs" />
|
<Compile Include="Examples\TextureMipmapsExample.cs" />
|
||||||
<Compile Include="Examples\TriangleVertexBufferExample.cs" />
|
<Compile Include="Examples\TriangleVertexBufferExample.cs" />
|
||||||
<Compile Include="Examples\VertexSamplerExample.cs" />
|
<Compile Include="Examples\VertexSamplerExample.cs" />
|
||||||
|
<Compile Include="Examples\VideoPlayerExample.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project=".\CopyMoonlibs.targets" />
|
<Import Project=".\CopyMoonlibs.targets" />
|
||||||
|
|
|
@ -35,7 +35,8 @@ class Program : Game
|
||||||
new TexturedQuadExample(),
|
new TexturedQuadExample(),
|
||||||
new TextureMipmapsExample(),
|
new TextureMipmapsExample(),
|
||||||
new TriangleVertexBufferExample(),
|
new TriangleVertexBufferExample(),
|
||||||
new VertexSamplerExample()
|
new VertexSamplerExample(),
|
||||||
|
new VideoPlayerExample()
|
||||||
];
|
];
|
||||||
|
|
||||||
int ExampleIndex = 0;
|
int ExampleIndex = 0;
|
||||||
|
|
Loading…
Reference in New Issue