我正在尝试制作一个简单的SlimDX示例来测试一些性能与GDI,不幸的是我一开始就陷入困境。我在VS2010中创建了简单的控制台应用程序,并将此代码添加到程序main方法:
// 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)
不幸的是,我无法启用此SO问题中所述的DirectX调试输出: DirectX 10 debug output not working
......所以,这就是我所拥有的一切。
但是,我在家里(win8.1,vs2013)和工作(win7,vs2010sp1)尝试了这一点,在家里,当我使用2013年的Graphics Diagnostics调试应用程序时,它可以工作当我开始定期调试或尝试手动启动exe时,它不起作用。在工作中它根本不起作用。
来自代码的任何想法?我在这里绝望。 :(
答案 0 :(得分:0)
我刚刚注意到你对我的另一个答案的评论。这是我使用的创建功能:
public static Texture2D CreateRenderTexture(this RenderHelper helper, int width, int height)
{
Texture2DDescription description = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
Width = width,
Height = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
Usage = ResourceUsage.Default,
};
return new Texture2D(helper.Device, description);
}