【发布时间】:2014-06-10 22:56:29
【问题描述】:
我在从渲染切换到 Windows 窗体控件以渲染到全屏时遇到问题。 所以我将问题分解为一个小示例项目,该项目仅包括交换链和设备初始化以及全屏切换。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using SharpDX;
using SharpDX.DXGI;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using Device = SharpDX.Direct3D11.Device;
namespace ControlToFullscreenTest
{
static class Program
{
static Device device;
static SwapChain swapchain;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form = new Form1();
Control control = form.pictureBox1; //Doesnt work
//Control control = form; //works
control.MouseClick += new MouseEventHandler(click);
SwapChainDescription sd = new SwapChainDescription()
{
BufferCount = 1,
Flags = SwapChainFlags.AllowModeSwitch,
IsWindowed = true, //false doesnt work too !
ModeDescription = new ModeDescription(control.ClientSize.Width, control.ClientSize.Height, Rational.Empty, Format.R8G8B8A8_UNorm),
OutputHandle = control.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
};
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, sd, out device, out swapchain);
Factory DxgiFactory;
SharpDX.DXGI.Device d = device.QueryInterface<SharpDX.DXGI.Device>();
Adapter a = d.GetParent<Adapter>();
DxgiFactory = a.GetParent<Factory>();
DxgiFactory.MakeWindowAssociation(control.Handle, WindowAssociationFlags.None);
form.Show();
while(form.Focused)
{
swapchain.Present(0, PresentFlags.None);
Application.DoEvents();
}
}
static void click(object o, EventArgs args)
{
swapchain.ResizeBuffers(1, 1920, 1080, Format.Unknown, SwapChainFlags.AllowModeSwitch);
swapchain.SetFullscreenState(true, null);
}
}
}
该开关在普通的 Windows 窗体中可以正常工作,但不能在控件中使用。
swapchain.SetFullscreenState(true, null);
投掷 HRESULT:[0x887A0001],模块:[SharpDX.DXGI],ApiCode:[DXGI_ERROR_INVALID_CALL/InvalidCall]
在 MSDN 中没有关于它的内容。 甚至无法使用控件在全屏模式下初始化 Swapchain。 我知道我可以通过创建一个新窗口然后以全屏模式渲染来解决此问题,但我想知道是否可以不进行此更改。
如果有人有我没有找到的想法、信息或链接,那就太好了。
【问题讨论】: