Commit 68cad860 authored by Martin Finkel's avatar Martin Finkel

more wip...

parent 53b16a64
......@@ -20,13 +20,13 @@
libvlc needs to be installed separately. See VideoLAN.LibVLC.* packages.
</Description>
<TargetFrameworks>netstandard2.0;netstandard1.1;net40;net471</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsPlatform('Linux'))">$(TargetFrameworks);MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsPlatform('Linux'))">$(TargetFrameworks);Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(TargetFrameworks);uap10.0;uap10.0.16299</TargetFrameworks>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeAWindow</TargetsForTfmSpecificBuildOutput>
<RootNamespace>LibVLCSharp</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>7.3</LangVersion>
<Version>3.0.1</Version>
<Version>4.0-alpha</Version>
<PackageId>LibVLCSharp</PackageId>
<Authors>VideoLAN</Authors>
<Owners>VideoLAN</Owners>
......
......@@ -4,6 +4,13 @@
<OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
......@@ -23,7 +30,7 @@
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="SharpDX.DXGI" Version="4.2.0" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.6" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="4.0.0-alpha2" />
</ItemGroup>
<ItemGroup>
......
......@@ -171,7 +171,7 @@ namespace LibVLCSharp.D3DCallbacks
{
var desc = new SwapChainDescription
{
BufferCount = 0,
BufferCount = 1,
ModeDescription = new ModeDescription { Format = Format.R8G8B8A8_UNorm, Height = form.ClientSize.Height, Width = form.ClientSize.Width },
Usage = Usage.RenderTargetOutput,
OutputHandle = form.Handle,
......@@ -180,7 +180,13 @@ namespace LibVLCSharp.D3DCallbacks
Flags = SwapChainFlags.AllowModeSwitch
};
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.VideoSupport, desc, out device, out swapChain);
Device.CreateWithSwapChain(DriverType.Hardware,
DeviceCreationFlags.VideoSupport | DeviceCreationFlags.Debug,
new FeatureLevel[] { FeatureLevel.Level_11_0 },
desc,
out device,
out swapChain);
context = device.ImmediateContext;
var multithread = device.QueryInterface<DeviceMultithread>();
......@@ -192,7 +198,7 @@ namespace LibVLCSharp.D3DCallbacks
swapchainRenderTarget = new RenderTargetView(device, backBuffer);
backBuffer.Dispose();
var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "VS", "vs_4_0");
var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "VShader", "vs_4_0");
var vertexShader = new VertexShader(device, vertexShaderByteCode);
var ied = new InputElement[]
{
......@@ -213,39 +219,112 @@ namespace LibVLCSharp.D3DCallbacks
};
shadersInputLayout = new InputLayout(device, vertexShaderByteCode.Bytecode.Data, ied);
float one = 1.0f;
float zero = 0.0f;
float[,] ourverticles = new float[,]
ShaderInput[] OurVerticles = new ShaderInput[]
{
new ShaderInput
{
BORDER_LEFT, BORDER_BOTTOM, zero, zero, one
position = new Position
{
x = BORDER_LEFT,
y = BORDER_BOTTOM,
z = 0.0f
},
texture = new Texture { x = 0.0f, y = 1.0f }
},
new ShaderInput
{
BORDER_RIGHT, BORDER_BOTTOM, zero, one, one
position = new Position
{
x = BORDER_RIGHT,
y = BORDER_BOTTOM,
z = 0.0f
},
texture = new Texture { x = 1.0f, y = 1.0f }
},
new ShaderInput
{
BORDER_RIGHT, BORDER_TOP, zero, one, zero
position = new Position
{
x = BORDER_RIGHT,
y = BORDER_TOP,
z = 0.0f
},
texture = new Texture { x = 1.0f, y = 0.0f }
},
new ShaderInput
{
BORDER_LEFT, BORDER_TOP, zero, zero, zero
position = new Position
{
x = BORDER_LEFT,
y = BORDER_TOP,
z = 0.0f
},
texture = new Texture { x = 0.0f, y = 0.0f }
}
};
var sizeInBytes = Marshal.SizeOf<ShaderInput>() * 4;
var bd = new BufferDescription
{
Usage = ResourceUsage.Dynamic,
SizeInBytes = Marshal.SizeOf(ourverticles),
SizeInBytes = sizeInBytes,
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.Write
};
vertexBuffer = new Buffer(device, bd);
vertexBufferStride = Convert.ToUInt32(Marshal.SizeOf(ourverticles));
vertexBufferStride = Convert.ToUInt32(Marshal.SizeOf(OurVerticles[0]));
var dataBox = context.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard, 0);
long LongPtr = dataBox.DataPointer.ToInt64();
for (int i = 0; i < OurVerticles.Length; i++)
{
IntPtr RectPtr = new IntPtr(LongPtr);
Marshal.StructureToPtr(OurVerticles[i], RectPtr, false);
LongPtr += Marshal.SizeOf(typeof(ShaderInput));
}
context.UnmapSubresource(vertexBuffer, 0);
quadIndexCount = 6;
var quadDescription = new BufferDescription
{
Usage = ResourceUsage.Dynamic,
SizeInBytes = sizeof(ushort) * Convert.ToInt32(quadIndexCount),
BindFlags = BindFlags.IndexBuffer,
CpuAccessFlags = CpuAccessFlags.Write
};
indexBuffer = new Buffer(device, quadDescription);
context.MapSubresource(vertexBuffer, MapMode.WriteDiscard, 0, out var dataStream);
ushort[] trianglePost = new ushort[6];
dataBox = context.MapSubresource(indexBuffer, 0, MapMode.WriteDiscard, 0);
//LongPtr = dataBox.DataPointer.ToInt64();
//for(var i = 0; i < quadIndexCount; i++)
//{
// IntPtr RectPtr = new IntPtr(LongPtr);
// Marshal.StructureToPtr(OurVerticles[i], RectPtr, false);
// LongPtr += Marshal.SizeOf(typeof(ShaderInput));
//}
////dataBox.DataPointer
context.UnmapSubresource(indexBuffer, 0);
var sampDesc = new SamplerStateDescription
{
Filter = Filter.MinMagLinearMipPoint,
AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,
ComparisonFunction = Comparison.Always,
MinimumLod = 0,
MaximumLod = float.MaxValue
};
samplerState = new SamplerState(device, sampDesc);
}
......@@ -257,11 +336,11 @@ namespace LibVLCSharp.D3DCallbacks
mp.Media = new Media(libvlc, "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", FromType.FromLocation);
CreateContext();
// CreateContext();
form = new RenderForm("SharpDX - MiniCube Direct3D11 Sample");
//form.Handle
//InitializeDirect3D();
InitializeDirect3D();
mp.SetDirect3DCallbacks(Direct3DEngine.D3D11, Setup, Cleanup, UpdateOutput, Swap, StartEndRendering, SelectPlane, IntPtr.Zero);
mp.Play();
......@@ -269,18 +348,18 @@ namespace LibVLCSharp.D3DCallbacks
// SwapChain description
desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
//desc = new SwapChainDescription()
//{
// BufferCount = 1,
// ModeDescription =
// new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
// new Rational(60, 1), Format.R8G8B8A8_UNorm),
// IsWindowed = true,
// OutputHandle = form.Handle,
// SampleDescription = new SampleDescription(1, 0),
// SwapEffect = SwapEffect.Discard,
// Usage = Usage.RenderTargetOutput
//};
// Used for debugging dispose object references
// Configuration.EnableObjectTracking = true;
......@@ -293,201 +372,201 @@ namespace LibVLCSharp.D3DCallbacks
// Ignore all windows events
var factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "VS", "vs_4_0");
var vertexShader = new VertexShader(device, vertexShaderByteCode);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "PS", "ps_4_0");
var pixelShader = new PixelShader(device, pixelShaderByteCode);
var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
// Layout from VertexShader input signature
var layout = new InputLayout(device, signature, new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
});
// Instantiate Vertex buiffer from vertex data
var vertices = Buffer.Create(device, BindFlags.VertexBuffer, new[]
{
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
new Vector4( 1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4( 1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4( 1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
});
// Create Constant Buffer
var contantBuffer = new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
// Prepare All the stages
context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0));
context.VertexShader.SetConstantBuffer(0, contantBuffer);
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);
// Prepare matrices
var view = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
Matrix proj = Matrix.Identity;
// Use clock
var clock = new Stopwatch();
clock.Start();
// Declare texture for rendering
bool userResized = true;
Texture2D backBuffer = null;
RenderTargetView renderView = null;
Texture2D depthBuffer = null;
DepthStencilView depthView = null;
// Setup handler on resize form
form.UserResized += (sender, args) => userResized = true;
// Setup full screen mode change F5 (Full) F4 (Window)
form.KeyUp += (sender, args) =>
{
if (args.KeyCode == Keys.F5)
swapChain.SetFullscreenState(true, null);
else if (args.KeyCode == Keys.F4)
swapChain.SetFullscreenState(false, null);
else if (args.KeyCode == Keys.Escape)
form.Close();
};
// Main loop
RenderLoop.Run(form, () =>
{
// If Form resized
if (userResized)
{
// Dispose all previous allocated resources
Utilities.Dispose(ref backBuffer);
Utilities.Dispose(ref renderView);
Utilities.Dispose(ref depthBuffer);
Utilities.Dispose(ref depthView);
// Resize the backbuffer
swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);
// Get the backbuffer from the swapchain
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
// Renderview on the backbuffer
renderView = new RenderTargetView(device, backBuffer);
// Create the depth buffer
depthBuffer = new Texture2D(device, new Texture2DDescription()
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
// Create the depth buffer view
depthView = new DepthStencilView(device, depthBuffer);
// Setup targets and viewport for rendering
context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
context.OutputMerger.SetTargets(depthView, renderView);
// Setup new projection matrix with correct aspect ratio
proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 0.1f, 100.0f);
// We are done resizing
userResized = false;
}
var time = clock.ElapsedMilliseconds / 1000.0f;
var viewProj = Matrix.Multiply(view, proj);
// Clear views
context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
context.ClearRenderTargetView(renderView, Color.Black);
// Update WorldViewProj Matrix
var worldViewProj = Matrix.RotationX(time) * Matrix.RotationY(time * 2) * Matrix.RotationZ(time * .7f) * viewProj;
worldViewProj.Transpose();
context.UpdateSubresource(ref worldViewProj, contantBuffer);
// Draw the cube
context.Draw(36, 0);
// Present!
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
signature.Dispose();
vertexShaderByteCode.Dispose();
vertexShader.Dispose();
pixelShaderByteCode.Dispose();
pixelShader.Dispose();
vertices.Dispose();
layout.Dispose();
contantBuffer.Dispose();
depthBuffer.Dispose();
depthView.Dispose();
renderView.Dispose();
backBuffer.Dispose();
context.ClearState();
context.Flush();
device.Dispose();
context.Dispose();
swapChain.Dispose();
factory.Dispose();
//var factory = swapChain.GetParent<Factory>();
//factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
//// Compile Vertex and Pixel shaders
//var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "VS", "vs_4_0");
//var vertexShader = new VertexShader(device, vertexShaderByteCode);
//var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "PS", "ps_4_0");
//var pixelShader = new PixelShader(device, pixelShaderByteCode);
//var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
//// Layout from VertexShader input signature
//var layout = new InputLayout(device, signature, new[]
// {
// new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
// new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
// });
//// Instantiate Vertex buiffer from vertex data
//var vertices = Buffer.Create(device, BindFlags.VertexBuffer, new[]
// {
// new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
// new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
// new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
// new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
// new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
// new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
// new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
// new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
// new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
// new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
// new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
// new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
// new Vector4(-1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
// new Vector4( 1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
// new Vector4(-1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
// new Vector4(-1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
// new Vector4( 1.0f,-1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
// new Vector4( 1.0f,-1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
// new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
// new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
// new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
// new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
// new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
// new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
// new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
// new Vector4( 1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
// });
//// Create Constant Buffer
//var contantBuffer = new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
//// Prepare All the stages
//context.InputAssembler.InputLayout = layout;
//context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
//context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0));
//context.VertexShader.SetConstantBuffer(0, contantBuffer);
//context.VertexShader.Set(vertexShader);
//context.PixelShader.Set(pixelShader);
//// Prepare matrices
//var view = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
//Matrix proj = Matrix.Identity;
//// Use clock
//var clock = new Stopwatch();
//clock.Start();
//// Declare texture for rendering
//bool userResized = true;
//Texture2D backBuffer = null;
//RenderTargetView renderView = null;
//Texture2D depthBuffer = null;
//DepthStencilView depthView = null;
//// Setup handler on resize form
//form.UserResized += (sender, args) => userResized = true;
//// Setup full screen mode change F5 (Full) F4 (Window)
//form.KeyUp += (sender, args) =>
//{
// if (args.KeyCode == Keys.F5)
// swapChain.SetFullscreenState(true, null);
// else if (args.KeyCode == Keys.F4)
// swapChain.SetFullscreenState(false, null);
// else if (args.KeyCode == Keys.Escape)
// form.Close();
//};
//// Main loop
//RenderLoop.Run(form, () =>
//{
// // If Form resized
// if (userResized)
// {
// // Dispose all previous allocated resources
// Utilities.Dispose(ref backBuffer);
// Utilities.Dispose(ref renderView);
// Utilities.Dispose(ref depthBuffer);
// Utilities.Dispose(ref depthView);
// // Resize the backbuffer
// swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);
// // Get the backbuffer from the swapchain
// backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
// // Renderview on the backbuffer
// renderView = new RenderTargetView(device, backBuffer);
// // Create the depth buffer
// depthBuffer = new Texture2D(device, new Texture2DDescription()
// {
// Format = Format.D32_Float_S8X24_UInt,
// ArraySize = 1,
// MipLevels = 1,
// Width = form.ClientSize.Width,
// Height = form.ClientSize.Height,
// SampleDescription = new SampleDescription(1, 0),
// Usage = ResourceUsage.Default,
// BindFlags = BindFlags.DepthStencil,
// CpuAccessFlags = CpuAccessFlags.None,
// OptionFlags = ResourceOptionFlags.None
// });
// // Create the depth buffer view
// depthView = new DepthStencilView(device, depthBuffer);
// // Setup targets and viewport for rendering
// context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
// context.OutputMerger.SetTargets(depthView, renderView);
// // Setup new projection matrix with correct aspect ratio
// proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 0.1f, 100.0f);
// // We are done resizing
// userResized = false;
// }
// var time = clock.ElapsedMilliseconds / 1000.0f;
// var viewProj = Matrix.Multiply(view, proj);
// // Clear views
// context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
// context.ClearRenderTargetView(renderView, Color.Black);
// // Update WorldViewProj Matrix
// var worldViewProj = Matrix.RotationX(time) * Matrix.RotationY(time * 2) * Matrix.RotationZ(time * .7f) * viewProj;
// worldViewProj.Transpose();
// context.UpdateSubresource(ref worldViewProj, contantBuffer);
// // Draw the cube
// context.Draw(36, 0);
// // Present!
// swapChain.Present(0, PresentFlags.None);
//});
//// Release all resources
//signature.Dispose();
//vertexShaderByteCode.Dispose();
//vertexShader.Dispose();
//pixelShaderByteCode.Dispose();
//pixelShader.Dispose();
//vertices.Dispose();
//layout.Dispose();
//contantBuffer.Dispose();
//depthBuffer.Dispose();
//depthView.Dispose();
//renderView.Dispose();
//backBuffer.Dispose();
//context.ClearState();
//context.Flush();
//device.Dispose();
//context.Dispose();
//swapChain.Dispose();
//factory.Dispose();
}
private static void CreateContext()
......@@ -496,4 +575,28 @@ namespace LibVLCSharp.D3DCallbacks
context = device.ImmediateContext;
}
}
public struct Position
{
public float x { get; set; }
public float y { get; set; }
public float z { get; set; }
}
public struct Texture
{
public float x { get; set; }
public float y { get; set; }
}
public struct ShaderInput
{
//public ShaderInput(Position p, Texture t)
//{
// position = p;
// texture = t;
//}
public Position position { get; set; }
public Texture texture { get; set; }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment