我想找出我的 C# UWP 程序支持哪些 Direct 3D 功能级别(此处显示)。
注意:我这样做是为了研究我的问题的可能答案,我怎么知道,在代码中,如果 RadialGradientBrush 没有正确显示?
在 C++ 中,对D3D11CreateDevice的调用可能很有用,但似乎没有 C# 等效项。
或者,更好的是ID3D11Device,它有一个GetFeatureLevel()调用。同样,这些是 C++ 项。
我想出了这个:
C++ DLL:
#include "pch.h"
#include <wrl.h>
#include <d3d11_2.h>
#include "BKGraphicsDLL.h"
using Microsoft::WRL::ComPtr;
extern "C"
{
__declspec(dllexport) D3D_FEATURE_LEVEL GetGraphicsFeatureLevel()
{
HRESULT hr = E_FAIL;
D3D_FEATURE_LEVEL MaxSupportedFeatureLevel = D3D_FEATURE_LEVEL_9_1;
D3D_FEATURE_LEVEL FeatureLevels[] = {
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
hr = D3D11CreateDevice(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
FeatureLevels,
ARRAYSIZE(FeatureLevels),
D3D11_SDK_VERSION,
NULL,
&MaxSupportedFeatureLevel,
NULL
);
return MaxSupportedFeatureLevel;
}
}
一个枚举和一个 NativeMethods 类来访问我的 MainPage C# 中的 DLL:
public enum D3DFeatureLevel
{
D3D_FEATURE_LEVEL_9_1 = 0x9100,
D3D_FEATURE_LEVEL_9_2 = 0x9200,
D3D_FEATURE_LEVEL_9_3 = 0x9300,
D3D_FEATURE_LEVEL_10_0 = 0xa000,
D3D_FEATURE_LEVEL_10_1 = 0xa100,
D3D_FEATURE_LEVEL_11_0 = 0xb000,
D3D_FEATURE_LEVEL_11_1 = 0xb100,
D3D_FEATURE_LEVEL_12_0 = 0xc000,
D3D_FEATURE_LEVEL_12_1 = 0xc100
};
// used to get Graphics capabilities
internal static class NativeMethods
{
[DllImport("BKGraphicsDLL.dll", ExactSpelling = true)]
public static extern D3DFeatureLevel GetGraphicsFeatureLevel();
}
无论我需要在代码中的何处设置功能级别,都使用以下行:
D3DFeatureLevel maxFeatureLevel = NativeMethods.GetGraphicsFeatureLevel();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句