Ejemplo n.º 1
0
static void UNITY_INTERFACE_API UnityOnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType)
{
    if (eventType == kUnityGfxDeviceEventInitialize) {
        auto unity_gfx = g_unity_interface->Get<IUnityGraphics>();
        auto api = unity_gfx->GetRenderer();

#ifdef fcSupportD3D11
        if (api == kUnityGfxRendererD3D11) {
            fcGfxInitializeD3D11(g_unity_interface->Get<IUnityGraphicsD3D11>()->GetDevice());
        }
#endif
#ifdef fcSupportD3D9
        if (api == kUnityGfxRendererD3D9) {
            fcGfxInitializeD3D9(g_unity_interface->Get<IUnityGraphicsD3D9>()->GetDevice());
        }
#endif
#ifdef fcSupportOpenGL
        if (api == kUnityGfxRendererOpenGL ||
            api == kUnityGfxRendererOpenGLCore ||
            api == kUnityGfxRendererOpenGLES20 ||
            api == kUnityGfxRendererOpenGLES30)
        {
            fcGfxInitializeOpenGL();
        }
#endif
    }
    else if (eventType == kUnityGfxDeviceEventShutdown) {
        fcGfxFinalize();
    }
}
Ejemplo n.º 2
0
bool InitializeD3D11()
{
    D3D_FEATURE_LEVEL feature_levels[] = {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
    };
    D3D_FEATURE_LEVEL valid_feature_level;

    IDXGIAdapter *adapter = nullptr;
    ID3D11Device *dev = nullptr;
    ID3D11DeviceContext *ctx = nullptr;
    HRESULT hr = D3D11CreateDevice(
        adapter,
        D3D_DRIVER_TYPE_HARDWARE,
        nullptr,
        0,
        feature_levels,
        _countof(feature_levels),
        D3D11_SDK_VERSION,
        &dev,
        &valid_feature_level,
        &ctx);

    if (dev) {
        fcGfxInitializeD3D11(dev);
        return true;
    }
    else {
        return false;
    }
}