【发布时间】:2014-04-08 10:30:20
【问题描述】:
我正在尝试制作简单的 SlimDX 示例来测试与 GDI 相比的一些性能,但不幸的是我一开始就卡住了。我在 VS2010 中创建了简单的控制台应用程序并将此代码添加到程序主方法中:
// 0. STEP
SlimDX.Direct3D10.Device device = new SlimDX.Direct3D10.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport);
SlimDX.Direct2D.Factory factory = new SlimDX.Direct2D.Factory();
// 1. STEP
Texture2DDescription textureDesc = new Texture2DDescription();
textureDesc.Width = 512;
textureDesc.Height = 512;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
textureDesc.SampleDescription = new SampleDescription(1, 0);
textureDesc.Usage = ResourceUsage.Default;
textureDesc.BindFlags = BindFlags.RenderTarget;
textureDesc.CpuAccessFlags = CpuAccessFlags.None;
textureDesc.OptionFlags = ResourceOptionFlags.None;
Texture2D maskTexture = new Texture2D(device, textureDesc);
// 2. STEP
SlimDX.DXGI.Surface surface = maskTexture.AsSurface();
// 3. STEPpro
RenderTargetProperties props = new RenderTargetProperties
{
HorizontalDpi = 96,
VerticalDpi = 96,
MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
PixelFormat = new PixelFormat(SlimDX.DXGI.Format.Unknown, AlphaMode.Premultiplied),
Type = RenderTargetType.Default,
Usage = RenderTargetUsage.None
};
RenderTarget target = RenderTarget.FromDXGI(factory, surface, props);
这会在 RenderTarget.FromDXGI 调用中崩溃并显示以下消息:
Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)
不幸的是,我无法启用 DirectX 调试输出,如此 SO 问题中所述: DirectX 10 debug output not working
...所以,这就是我所拥有的。
但是,我在家里(win8.1,vs2013)和工作中(win7,vs2010sp1)都试过了. 当我开始常规调试或尝试手动启动 exe 时,它不起作用。在工作中它根本不起作用。
仅来自代码的任何想法?我在这里有点绝望。 :(
【问题讨论】:
-
您需要将
DeviceCreationFlags.Debug传递给Device构造函数以获得调试输出。我不确定是否可以使用未知像素格式创建渲染目标。对我来说没有多大意义。特别是如果底层纹理具有已知格式。顺便说一句,使用Device.CreateWithSwapChain方法创建设备和渲染目标要舒服得多。 -
1) 当我尝试使用 Debug 标志创建设备时,我收到此错误:E_FAIL:发生未确定的错误; 2)我已将渲染目标的格式设置为与您建议的纹理相同; 3)我不需要渲染到视觉控制,所以我没有使用交换链。我只需要将一些线条渲染到纹理,然后将其导出到位图。
-
您是否安装了 Windows SDK 中包含的 DirectX SDK 一段时间?
-
在我的家用机器 (win8.1) 上我安装了 Windows SDK,在我的工作机器 (win7) 上我安装了 DirectX SDK。我还将 DebugLevel.Information 设置为 D2D 工厂,以便我可以获取更多日志信息,但即使我通过此链接额外安装了它,我仍然收到“无法加载 D2D 调试层”:msdn.microsoft.com/en-us/library/dd940309%28VS.85%29.aspx
标签: c# directx slimdx directx-10