本文整理汇总了C#中SwapChain.GetBackBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# SwapChain.GetBackBuffer方法的具体用法?C# SwapChain.GetBackBuffer怎么用?C# SwapChain.GetBackBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SwapChain
的用法示例。
在下文中一共展示了SwapChain.GetBackBuffer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SwapChainGraphicsPresenter
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
: base(device, presentationParameters)
{
PresentInterval = presentationParameters.PresentationInterval;
// Initialize the swap chain
swapChain = ToDispose(CreateSwapChain());
backBuffer = ToDispose(RenderTarget2D.New(device, swapChain.GetBackBuffer<Direct3D11.Texture2D>(0)));
}
示例2: SwapChainGraphicsPresenter
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
: base(device, presentationParameters)
{
PresentInterval = presentationParameters.PresentationInterval;
// Initialize the swap chain
swapChain = CreateSwapChain();
backBuffer = new Texture(device).InitializeFrom(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0), Description.BackBufferFormat.IsSRgb());
// Reload should get backbuffer from swapchain as well
//backBufferTexture.Reload = graphicsResource => ((Texture)graphicsResource).Recreate(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture>(0));
}
示例3: OnRecreated
public override void OnRecreated()
{
base.OnRecreated();
// Recreate swap chain
swapChain = CreateSwapChain();
// Get newly created native texture
var backBufferTexture = swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0);
// Put it in our back buffer texture
// TODO: Update new size
backBuffer.InitializeFrom(backBufferTexture, Description.BackBufferFormat.IsSRgb());
backBuffer.LifetimeState = GraphicsResourceLifetimeState.Active;
}
示例4: CreateVideoSamples
protected HRESULT CreateVideoSamples(IMFMediaType pFormat)
{
if (pFormat == null)
{
return MFHelper.MF_E_UNEXPECTED;
}
HRESULT hr = S_OK;
PresentParameters pp;
lock (m_ObjectLock)
{
hr = GetSwapChainPresentParameters(pFormat, out pp);
hr.Assert();
if (hr.Failed)
{
return hr;
}
// Create the video samples.
for (int i = 0; i < PRESENTER_BUFFER_COUNT; i++)
{
Surface _surface = null;
if (m_bUseSwapChain)
{
// Create a new swap chain.
SwapChain pSwapChain = new SwapChain(m_Device, pp);
if (pSwapChain == null)
{
return E_UNEXPECTED;
}
_surface = pSwapChain.GetBackBuffer(0);
if (_surface == null) return E_FAIL;
m_Device.ColorFill(_surface, new Color4(Color.Black));
}
else
{
_surface = Surface.CreateRenderTarget(m_Device, pp.BackBufferWidth, pp.BackBufferHeight, pp.BackBufferFormat, pp.Multisample, pp.MultisampleQuality, true);
}
// Create the video sample from the swap chain.
MFSample pVideoSample = new MFSample();
pVideoSample.Target = _surface;
hr = (HRESULT)MFHelper.MFCreateVideoSampleFromSurface(Marshal.GetObjectForIUnknown(_surface.ComPointer), out pVideoSample.Sample);
// Add it to the list.
m_SamplePool.AddSample(pVideoSample);
}
}
return NOERROR;
}
示例5: HandleDeviceChangeEnd
private void HandleDeviceChangeEnd(object sender, EventArgs e)
{
var device = _graphicsDeviceManager.GraphicsDevice;
var swapChain = (SwapChain)device.Presenter.NativePresenter;
var d = swapChain.Description;
var d3DDevice = (SharpDX.Direct3D11.Device)device;
using (var dxgiDevice = d3DDevice.QueryInterface<Device3>())
{
var adapter = dxgiDevice.Adapter;
var factory = adapter.GetParent<Factory2>();
var description = new SwapChainDescription1
{
Width = d.ModeDescription.Width,
Height = d.ModeDescription.Height,
Format = d.ModeDescription.Format,
Stereo = false,
SampleDescription = new SampleDescription(1, 0),
Usage = Usage.RenderTargetOutput,
BufferCount = 2,
SwapEffect = SwapEffect.FlipSequential,
Flags = SwapChainFlags.ForegroundLayer,
Scaling = Scaling.None,
AlphaMode = AlphaMode.Premultiplied
};
// create the foreground swap chain for the core window
using (var comWindow = new ComObject(Window.NativeWindow))
_foregroundChain = new SwapChain1(factory, (SharpDX.Direct3D11.Device)device, comWindow, ref description);
// recreate the foreground render target
using (var backBuffer = _foregroundChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0))
_foregroundRenderTarget = RenderTarget2D.New(device, backBuffer);
}
}
示例6: CreateSwapChain
/// <summary>
/// Creates a new swap chain to use when rendering to this control.
/// </summary>
private void CreateSwapChain()
{
if (_control.ClientSize.Width <= 0 || _control.ClientSize.Height <= 0)
return;
// If this is the default swap chain of the DX9Device then
// reset the DX9Device instead of creating one.
if (_dx9Driver.DX9Device.PresentationParameters.DeviceWindow == _control)
{
_swapChain = null;
return;
}
bool isPreviousSwapChain = (_dx9Driver.SwapChain == _swapChain);
if (_swapChain != null)
_swapChain.Dispose();
_presentParameters = Direct3D9Driver.CreatePresentParameters(_control, _control.ClientSize.Width, _control.ClientSize.Height, _flags);
_swapChain = new SwapChain(_dx9Driver.DX9Device, _presentParameters);
if (isPreviousSwapChain == true)
{
_dx9Driver.SwapChain = _swapChain;
_dx9Driver.DX9Device.SetRenderTarget(0, _swapChain.GetBackBuffer(0, BackBufferType.Mono));
}
}
示例7: Initialise
public bool Initialise(SwapChain swapChain)
{
return Initialise(swapChain.GetDevice<Device>(), swapChain.GetBackBuffer<Texture2D>(0));
}
示例8: InitializeOculus
private void InitializeOculus()
{
RenderForm form = new RenderForm("OculusWrap SharpDX demo");
Wrap oculus = new Wrap();
Hmd hmd;
form.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Window_KeyUp);
//form.moused
//form.Activate();
//form.Show();
int textureWidth = 0, textureHeight = 0;
newTextureArrived = false;
//zoom == 2 is not implemented, because the visual quality would be too low.
//zoom == 4 will be implemented in the future.
if (zoom == 3)
{
textureWidth = 3328;
textureHeight = 1664;
}
bool success = oculus.Initialize();
if (!success)
{
System.Windows.Forms.MessageBox.Show("Failed to initialize the Oculus runtime library.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Use the head mounted display, if it's available, otherwise use the debug HMD.
int numberOfHeadMountedDisplays = oculus.Hmd_Detect();
if (numberOfHeadMountedDisplays > 0)
hmd = oculus.Hmd_Create(0);
else
hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2);
if (hmd == null)
{
System.Windows.Forms.MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (hmd.ProductName == string.Empty)
System.Windows.Forms.MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Specify which head tracking capabilities to enable.
hmd.SetEnabledCaps(OVR.HmdCaps.LowPersistence | OVR.HmdCaps.DynamicPrediction);
// Start the sensor which informs of the Rift's pose and motion
hmd.ConfigureTracking(OVR.TrackingCaps.ovrTrackingCap_Orientation | OVR.TrackingCaps.ovrTrackingCap_MagYawCorrection | OVR.TrackingCaps.ovrTrackingCap_Position, OVR.TrackingCaps.None);
// Create a set of layers to submit.
EyeTexture[] eyeTextures = new EyeTexture[2];
OVR.ovrResult result;
// Create DirectX drawing device.
SharpDX.Direct3D11.Device device = new Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug);
// Create DirectX Graphics Interface factory, used to create the swap chain.
Factory factory = new Factory();
DeviceContext immediateContext = device.ImmediateContext;
// Define the properties of the swap chain.
SwapChainDescription swapChainDescription = new SwapChainDescription();
swapChainDescription.BufferCount = 1;
swapChainDescription.IsWindowed = true;
swapChainDescription.OutputHandle = form.Handle;
swapChainDescription.SampleDescription = new SampleDescription(1, 0);
swapChainDescription.Usage = Usage.RenderTargetOutput | Usage.ShaderInput;
swapChainDescription.SwapEffect = SwapEffect.Sequential;
swapChainDescription.Flags = SwapChainFlags.AllowModeSwitch;
swapChainDescription.ModeDescription.Width = form.Width;
swapChainDescription.ModeDescription.Height = form.Height;
swapChainDescription.ModeDescription.Format = Format.R8G8B8A8_UNorm;
swapChainDescription.ModeDescription.RefreshRate.Numerator = 0;
swapChainDescription.ModeDescription.RefreshRate.Denominator = 1;
// Create the swap chain.
SharpDX.DXGI.SwapChain swapChain = new SwapChain(factory, device, swapChainDescription);
// Retrieve the back buffer of the swap chain.
Texture2D backBuffer = swapChain.GetBackBuffer<Texture2D>(0);
RenderTargetView backBufferRenderTargetView = new RenderTargetView(device, backBuffer);
// Create a depth buffer, using the same width and height as the back buffer.
Texture2DDescription depthBufferDescription = new Texture2DDescription();
depthBufferDescription.Format = Format.D32_Float;
depthBufferDescription.ArraySize = 1;
depthBufferDescription.MipLevels = 1;
depthBufferDescription.Width = form.Width;
depthBufferDescription.Height = form.Height;
depthBufferDescription.SampleDescription = new SampleDescription(1, 0);
depthBufferDescription.Usage = ResourceUsage.Default;
depthBufferDescription.BindFlags = BindFlags.DepthStencil;
depthBufferDescription.CpuAccessFlags = CpuAccessFlags.None;
depthBufferDescription.OptionFlags = ResourceOptionFlags.None;
//.........这里部分代码省略.........