本文整理汇总了C#中SwapChain.Present方法的典型用法代码示例。如果您正苦于以下问题:C# SwapChain.Present方法的具体用法?C# SwapChain.Present怎么用?C# SwapChain.Present使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SwapChain
的用法示例。
在下文中一共展示了SwapChain.Present方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Select a File to play
var openFileDialog = new OpenFileDialog { Title = "Select a file", Filter = "Media Files(*.WMV;*.MP4;*.AVI)|*.WMV;*.MP4;*.AVI" };
var result = openFileDialog.ShowDialog();
if (result == DialogResult.Cancel)
{
return;
}
// Initialize MediaFoundation
MediaManager.Startup();
var renderForm = new SharpDX.Windows.RenderForm();
device = CreateDeviceForVideo(out dxgiManager);
// Creates the MediaEngineClassFactory
var mediaEngineFactory = new MediaEngineClassFactory();
//Assign our dxgi manager, and set format to bgra
MediaEngineAttributes attr = new MediaEngineAttributes();
attr.VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm;
attr.DxgiManager = dxgiManager;
// Creates MediaEngine for AudioOnly
var mediaEngine = new MediaEngine(mediaEngineFactory, attr, MediaEngineCreateFlags.None);
// Register our PlayBackEvent
mediaEngine.PlaybackEvent += OnPlaybackCallback;
// Query for MediaEngineEx interface
mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>();
// Opens the file
var fileStream = openFileDialog.OpenFile();
// Create a ByteStream object from it
var stream = new ByteStream(fileStream);
// Creates an URL to the file
var url = new Uri(openFileDialog.FileName, UriKind.RelativeOrAbsolute);
// Set the source stream
mediaEngineEx.SetSourceFromByteStream(stream, url.AbsoluteUri);
// Wait for MediaEngine to be ready
if (!eventReadyToPlay.WaitOne(1000))
{
Console.WriteLine("Unexpected error: Unable to play this file");
}
//Create our swapchain
swapChain = CreateSwapChain(device, renderForm.Handle);
//Get DXGI surface to be used by our media engine
var texture = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
var surface = texture.QueryInterface<SharpDX.DXGI.Surface>();
//Get our video size
int w, h;
mediaEngine.GetNativeVideoSize(out w, out h);
// Play the music
mediaEngineEx.Play();
long ts;
RenderLoop.Run(renderForm, () =>
{
//Transfer frame if a new one is available
if (mediaEngine.OnVideoStreamTick(out ts))
{
mediaEngine.TransferVideoFrame(surface, null, new SharpDX.Rectangle(0, 0, w, h), null);
}
swapChain.Present(1, SharpDX.DXGI.PresentFlags.None);
});
mediaEngine.Shutdown();
swapChain.Dispose();
device.Dispose();
}
示例2: InitializeOculus
//.........这里部分代码省略.........
int textureIndex = eyeTexture.SwapTextureSet.CurrentIndex++;
immediateContext.OutputMerger.SetRenderTargets(eyeTexture.DepthStencilView, eyeTexture.RenderTargetViews[textureIndex]);
immediateContext.ClearRenderTargetView(eyeTexture.RenderTargetViews[textureIndex], Color.Black);
immediateContext.ClearDepthStencilView(eyeTexture.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
immediateContext.Rasterizer.SetViewport(eyeTexture.Viewport);
//added a custom rasterizer
immediateContext.Rasterizer.State = rasterizerState;
// Retrieve the eye rotation quaternion and use it to calculate the LookAt direction and the LookUp direction.
Quaternion rotationQuaternion = SharpDXHelpers.ToQuaternion(eyePoses[eyeIndex].Orientation);
Matrix rotationMatrix = Matrix.RotationQuaternion(rotationQuaternion);
Vector3 lookUp = Vector3.Transform(new Vector3(0, -1, 0), rotationMatrix).ToVector3();
Vector3 lookAt = Vector3.Transform(new Vector3(0, 0, 1), rotationMatrix).ToVector3();
Vector3 viewPosition = position - eyePoses[eyeIndex].Position.ToVector3();
//use this to get the first rotation to goal
Matrix world = Matrix.Scaling(1.0f) /** Matrix.RotationX(timeSinceStart*0.2f) */* Matrix.RotationY(timeSinceStart * 2 / 10f) /** Matrix.RotationZ(timeSinceStart*3/10f)*/;
Matrix viewMatrix = Matrix.LookAtRH(viewPosition, viewPosition + lookAt, lookUp);
Matrix projectionMatrix = OVR.ovrMatrix4f_Projection(eyeTexture.FieldOfView, 0.1f, 10.0f, OVR.ProjectionModifier.None).ToMatrix();
projectionMatrix.Transpose();
Matrix worldViewProjection = world * viewMatrix * projectionMatrix;
worldViewProjection.Transpose();
// Update the transformation matrix.
immediateContext.UpdateSubresource(ref worldViewProjection, constantBuffer);
// Draw the cube
//immediateContext.Draw(vertices.Length/2, 0);
immediateContext.DrawIndexed(indices.Length, 0, 0);
}
hmd.SubmitFrame(0, layers);
immediateContext.CopyResource(mirrorTextureD3D11, backBuffer);
swapChain.Present(0, PresentFlags.None);
if (newTextureArrived == true)
{
newTextureArrived = false;
DataBox map = device.ImmediateContext.MapSubresource(myTexture, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);
//load the BitMapSource with appropriate formating (Format32bppPRGBA)
SharpDX.WIC.BitmapSource bitMap = LoadBitmap(new SharpDX.WIC.ImagingFactory(), streamTexture);
//string newFile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\img_merged.jpg";
//SharpDX.WIC.BitmapSource bitMap = LoadBitmapFromFile(new SharpDX.WIC.ImagingFactory(), newFile);
int width = bitMap.Size.Width;
int height = bitMap.Size.Height;
int stride = bitMap.Size.Width * 4;
bitMap.CopyPixels(stride, map.DataPointer, height * stride);
device.ImmediateContext.UnmapSubresource(myTexture, 0);
//bitMap.Dispose();
streamTexture.Seek(0, SeekOrigin.Begin);
}
});
#endregion
// Release all resources
inputLayout.Dispose();
constantBuffer.Dispose();
indexBuffer.Dispose();
vertexBuffer.Dispose();
inputLayout.Dispose();
shaderSignature.Dispose();
pixelShader.Dispose();
pixelShaderByteCode.Dispose();
vertexShader.Dispose();
vertexShaderByteCode.Dispose();
mirrorTextureD3D11.Dispose();
layers.Dispose();
eyeTextures[0].Dispose();
eyeTextures[1].Dispose();
immediateContext.ClearState();
immediateContext.Flush();
immediateContext.Dispose();
depthStencilState.Dispose();
depthStencilView.Dispose();
depthBuffer.Dispose();
backBufferRenderTargetView.Dispose();
backBuffer.Dispose();
swapChain.Dispose();
factory.Dispose();
// Disposing the device, before the hmd, will cause the hmd to fail when disposing.
// Disposing the device, after the hmd, will cause the dispose of the device to fail.
// It looks as if the hmd steals ownership of the device and destroys it, when it's shutting down.
// device.Dispose();
hmd.Dispose();
oculus.Dispose();
}