【问题标题】:C# SharpDX - from Control to Fullscreen DXGI_ERROR_INVALID_CALLC# SharpDX - 从控制到全屏 DXGI_ERROR_INVALID_CALL
【发布时间】: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。 我知道我可以通过创建一个新窗口然后以全屏模式渲染来解决此问题,但我想知道是否可以不进行此更改。

如果有人有我没有找到的想法、信息或链接,那就太好了。

【问题讨论】:

    标签: c# .net directx sharpdx


    【解决方案1】:

    将 SwapChain 设置为 FullScreen 需要非子控件,因此您的图片框不满足此条件。

    使用调试设备创建标志,当您尝试设置为全屏时,将在输出窗口中弹出以下错误消息:

    DXGI 错误:IDXGISwapChain::SetFullscreenState:全屏不是 允许针对子窗口的交换链。应用程序是 建议创建第二个针对非子窗口的交换链。 [ 杂项错误 #82:]

    【讨论】:

    • 感谢您的回答。我之前尝试使用 DeviceCreationFlags.Debug Flag 进行调试,但我忘记了 Visual Studio 项目设置下的非托管调试标志。
    猜你喜欢
    • 2011-05-24
    • 2013-06-12
    • 2012-12-25
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多