当前位置: 首页>>代码示例>>C++>>正文


C++ D3D11CreateDevice函数代码示例

本文整理汇总了C++中D3D11CreateDevice函数的典型用法代码示例。如果您正苦于以下问题:C++ D3D11CreateDevice函数的具体用法?C++ D3D11CreateDevice怎么用?C++ D3D11CreateDevice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了D3D11CreateDevice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ARRAYSIZE

HRESULT DeviceResources::Initialize()
{
	HRESULT hr;

	D3D_FEATURE_LEVEL featureLevels[] =
	{
		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
	};

	UINT numFeatureLevels = ARRAYSIZE(featureLevels);

	UINT createDeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

#ifdef _DEBUG
	createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

	this->_d3dDriverType = D3D_DRIVER_TYPE_HARDWARE;

	hr = D3D11CreateDevice(nullptr, this->_d3dDriverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &this->_d3dDevice, &this->_d3dFeatureLevel, &this->_d3dDeviceContext);

	if (FAILED(hr))
	{
		this->_d3dDriverType = D3D_DRIVER_TYPE_WARP;

		hr = D3D11CreateDevice(nullptr, this->_d3dDriverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &this->_d3dDevice, &this->_d3dFeatureLevel, &this->_d3dDeviceContext);
	}

	this->CheckMultisamplingSupport();

	if (SUCCEEDED(hr))
	{
		hr = this->LoadMainResources();
	}

	if (SUCCEEDED(hr))
	{
		hr = this->LoadResources();
	}

	if (FAILED(hr))
	{
		static bool messageShown = false;

		if (!messageShown)
		{
			MessageBox(nullptr, _com_error(hr).ErrorMessage(), __FUNCTION__, MB_ICONERROR);
		}

		messageShown = true;
	}

	return hr;
}
开发者ID:UIKit0,项目名称:xwa_ddraw_d3d11,代码行数:59,代码来源:DeviceResources.cpp

示例2: CreateDevice

/*-------------------------------------------
	デバイスの作成
--------------------------------------------*/
HRESULT CreateDevice(void)
{
	HRESULT hr;

	// ハードウェア デバイスを試す
	hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0,
			g_pFeatureLevels, _countof(g_pFeatureLevels), D3D11_SDK_VERSION, &g_pD3DDevice,
			&g_FeatureLevelsSupported, &g_pImmediateContext);
	if (SUCCEEDED(hr)) {
		//「コンピュート シェーダ」「未処理バッファー」「構造化バッファ」のサポート調査
	    D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
	    g_pD3DDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
	    if(hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x) {
			wprintf_s(L"[D3D_DRIVER_TYPE_HARDWARE]\n");
			return hr;
		}
		SAFE_RELEASE(g_pImmediateContext);
		SAFE_RELEASE(g_pD3DDevice);
	}

	// WARPデバイスを試す
	hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0,
			g_pFeatureLevels, _countof(g_pFeatureLevels), D3D11_SDK_VERSION, &g_pD3DDevice,
			&g_FeatureLevelsSupported, &g_pImmediateContext);
	if (SUCCEEDED(hr)) {
		//「コンピュート シェーダ」「未処理バッファー」「構造化バッファ」のサポート調査
	    D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
	    g_pD3DDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
	    if(hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x) {
			wprintf_s(L"[D3D_DRIVER_TYPE_WARP]\n");
			return hr;
		}
		SAFE_RELEASE(g_pImmediateContext);
		SAFE_RELEASE(g_pD3DDevice);
	}

	// リファレンス デバイスを試す
	hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0,
			g_pFeatureLevels, _countof(g_pFeatureLevels), D3D11_SDK_VERSION, &g_pD3DDevice,
			&g_FeatureLevelsSupported, &g_pImmediateContext);
	if (SUCCEEDED(hr)) {
		//「コンピュート シェーダ」「未処理バッファー」「構造化バッファ」のサポート調査
	    D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
	    g_pD3DDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
	    if(hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x) {
			wprintf_s(L"[D3D_DRIVER_TYPE_REFERENCE]\n");
			return hr;
		}
		SAFE_RELEASE(g_pImmediateContext);
		SAFE_RELEASE(g_pD3DDevice);
	}

	// 失敗
	return DXTRACE_ERR(L"D3D11CreateDevice", hr);;
}
开发者ID:Sumio-Katakura,项目名称:Study,代码行数:58,代码来源:D3D11Sample19.cpp

示例3: CreateDevice

bool Renderer::CreateDevice() {
	D3D_FEATURE_LEVEL SupportedLevel;
	if(D3D11CreateDevice(
		NULL,
		D3D_DRIVER_TYPE_HARDWARE, // we want hardware acceleration
		NULL, // pointer to software renderer. don't use that
		D3D11_CREATE_DEVICE_SINGLETHREADED,
		NULL,
		0,
		D3D11_SDK_VERSION,
		&D3DDevice,
		&SupportedLevel,
		&DeviceContext
	) != S_OK) {
		MessageBox(hwnd,"Error creating device","Error",MB_OK);
		return false;
	}
	
	// Exit if it's not supported
	if(SupportedLevel != D3D_FEATURE_LEVEL_11_0) {
		MessageBox(hwnd,"Your computer does not support DirectX 11","Error",MB_OK);
		return false;
	}
	
	return true;
}
开发者ID:JohanMes,项目名称:JohanEngine11,代码行数:26,代码来源:Renderer.cpp

示例4: myDevice

    KT_API D3D11Device::D3D11Device(
		kT::GraphicsDevice<kTD3D11DeviceTemplateListLineTypes>::ProcessingMethod processingMethod,
		bool debugFlag ):
     myDevice( 0 ),
     myProcessingMethod( processingMethod ),
     myImmediateContext( 0 )
    {
        D3D_DRIVER_TYPE driverTypes[] = {
            D3D_DRIVER_TYPE_HARDWARE,
            D3D_DRIVER_TYPE_WARP,
            D3D_DRIVER_TYPE_REFERENCE
        };

		UINT flags = debugFlag ? D3D11_CREATE_DEVICE_DEBUG : 0;
		ID3D11DeviceContext* imDev = 0;

		HRESULT hr = 0;
		for( size_t i = 0; i < 3; i++ )
		{
			D3D_FEATURE_LEVEL lvl;

			hr = D3D11CreateDevice( NULL, driverTypes[i], NULL, flags, NULL, 0, D3D11_SDK_VERSION, &myDevice, &lvl, &imDev );
			if( !FAILED(hr) )
				break;

			myFeatureLevel = lvl;
		}

        if( FAILED(hr) )
            kTLaunchException( kT::Exception, "Error while trying to create the D3D11 device" );

		myImmediateContext = new D3D11ImmediateContext( imDev );
    }
开发者ID:Ziple,项目名称:kT,代码行数:33,代码来源:D3D11Device.cpp

示例5: Dx11

	Dx11() {
		HRESULT hr;
		// D3D_FEATURE_LEVEL
		std::array<D3D_FEATURE_LEVEL, 1> FeatureLevel = {
			D3D_FEATURE_LEVEL_11_0
		};

#if defined(DEBUG) || defined(_DEBUG)
		UINT createDeviceFlag = D3D11_CREATE_DEVICE_DEBUG;
#else
		UINT createDeviceFlag = 0;
#endif
		D3D_FEATURE_LEVEL selected;

		hr = D3D11CreateDevice(
			nullptr,                  // 使用するアダプターを設定。NULLの場合はデフォルトのアダプター。
			D3D_DRIVER_TYPE_HARDWARE,    // D3D_DRIVER_TYPEのいずれか。ドライバーの種類。pAdapterが NULL 以外の場合は、D3D_DRIVER_TYPE_UNKNOWNを指定する。
			NULL,                       // ソフトウェアラスタライザを実装するDLLへのハンドル。D3D_DRIVER_TYPE を D3D_DRIVER_TYPE_SOFTWARE に設定している場合は NULL にできない。
			createDeviceFlag,           // D3D11_CREATE_DEVICE_FLAGの組み合わせ。デバイスを作成時に使用されるパラメータ。
			FeatureLevel.data(),               // D3D_FEATURE_LEVELのポインタ
			FeatureLevel.size(),                 // D3D_FEATURE_LEVEL配列の要素数
			D3D11_SDK_VERSION,          // DirectX SDKのバージョン。この値は固定。
			&d3d11device,               // 初期化されたデバイス
			&selected,              // 採用されたフィーチャーレベル
			&d3d11deviceContext         // 初期化されたデバイスコンテキスト
		);
		if (FAILED(hr)) {
			printf("failed to initialize dx11");
		}
	}
开发者ID:Ushio,项目名称:ofxExtremeGpuVideo,代码行数:30,代码来源:ofApp.cpp

示例6: create_device

BOOL CALLBACK create_device(PINIT_ONCE ignored, void *ignored2,
    void **ignored3) {
  debug_log("creating device");
  HRESULT hr;
  hr = CreateDXGIFactory1(__uuidof(IDXGIFactory2), (void **)&dxgi_factory);
  assert(hr == S_OK);
  hr = dxgi_factory->EnumAdapters1(0, &dxgi_adapter);
  assert(hr == S_OK);
  hr = dxgi_adapter->EnumOutputs(0, &dxgi_output);
  assert(hr == S_OK);
  hr = dxgi_output->QueryInterface(__uuidof(IDXGIOutput1),
      (void **)&dxgi_output1);
  assert(hr == S_OK);
  const D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_0 };
  D3D_FEATURE_LEVEL out_level;
  UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifndef NDEBUG
  flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
  hr = D3D11CreateDevice(dxgi_adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
      levels, 1, D3D11_SDK_VERSION, &device, &out_level, &context);
  assert(hr == S_OK);
  hr = dxgi_output1->DuplicateOutput(device, &dxgi_output_duplication);
  assert(hr == S_OK);
  InitializeCriticalSection(&directx_critical_section);
  return TRUE;
}
开发者ID:mammon163,项目名称:latency-benchmark,代码行数:27,代码来源:screenscraper.cpp

示例7: InitializeD3D11

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;
    }
}
开发者ID:unity3d-jp,项目名称:FrameCapturer,代码行数:31,代码来源:GraphicsDevice.cpp

示例8: initializeDevice

    void initializeDevice()
    {
        if (!mInitialized)
        {
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
            mD3d11Module = LoadLibrary(TEXT("d3d11.dll"));
            ASSERT(mD3d11Module);

            PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice");
            ASSERT(D3D11CreateDevice != NULL);
#endif // !ANGLE_ENABLE_WINDOWS_STORE

            ID3D11Device* device = NULL;
            ID3D11DeviceContext* context = NULL;

            HRESULT hr = E_FAIL;

            // Create a D3D_DRIVER_TYPE_NULL device, which is much cheaper than other types of device.
            hr =  D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_NULL, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device, NULL, &context);
            ASSERT(SUCCEEDED(hr));

            hr = context->QueryInterface(__uuidof(mUserDefinedAnnotation), reinterpret_cast<void**>(&mUserDefinedAnnotation));
            ASSERT(SUCCEEDED(hr) && mUserDefinedAnnotation != NULL);

            SafeRelease(device);
            SafeRelease(context);

            mInitialized = true;
        }
    }
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:30,代码来源:debug.cpp

示例9: find_output

static HRESULT find_output()
{
	CComPtr<IDXGIFactory1> pFactory;
	HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)(&pFactory));
	for (UINT i = 0; ; i++) {
		CComPtr<IDXGIAdapter1> pAdapter;
		if (S_OK != (hr = pFactory->EnumAdapters1(i, &pAdapter))) {
			break;
		}

		aslog::info(L"Found adapter %d", i);

		for (UINT j = 0; ; j++) {
			CComPtr<IDXGIOutput> pOutput;
			if (S_OK != (hr = pAdapter->EnumOutputs(j, &pOutput))) {
				break;
			}

			aslog::info(L"Found output %d-%d", i, j);
			DXGI_OUTPUT_DESC desc;
			pOutput->GetDesc(&desc);
			aslog::info(L"Output %d-%d name: %s", i, j, desc.DeviceName);
			aslog::info(L"Output %d-%d attached to desktop: %s", i, j, desc.AttachedToDesktop ? L"true" : L"false");

			g_pAdapter = pAdapter;
			g_pOutput = pOutput;
			hr = D3D11CreateDevice(pAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, 0, D3D11_SDK_VERSION, &g_pDevice, NULL, &g_pContext);
			return hr;
		}
	}
	return hr;
}
开发者ID:smmckay,项目名称:auto-screengrab,代码行数:32,代码来源:auto-screengrab.cpp

示例10:

static ID3D11Device *create_device(D3D_FEATURE_LEVEL feature_level)
{
    ID3D11Device *device;

    if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &feature_level, 1, D3D11_SDK_VERSION,
            &device, NULL, NULL)))
        return device;
    if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, &feature_level, 1, D3D11_SDK_VERSION,
            &device, NULL, NULL)))
        return device;
    if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, &feature_level, 1, D3D11_SDK_VERSION,
            &device, NULL, NULL)))
        return device;

    return NULL;
}
开发者ID:xcution,项目名称:wine,代码行数:16,代码来源:d3d11.c

示例11: get_info

static info_t get_info(int adapter_index, IDXGIAdapter* adapter)
{
	struct ctx_t
	{
		DXGI_ADAPTER_DESC adapter_desc;
		info_t adapter_info;
	};

	ctx_t ctx;
	adapter->GetDesc(&ctx.adapter_desc);
	
	// There's a new adapter called teh Basic Render Driver that is not a video driver, so 
	// it won't show up with enumerate_video_drivers, so handle it explicitly here.
	if (ctx.adapter_desc.VendorId == 0x1414 && ctx.adapter_desc.DeviceId == 0x8c) // Microsoft Basic Render Driver
	{
		ctx.adapter_info.description = "Microsoft Basic Render Driver";
		ctx.adapter_info.plugnplay_id = "Microsoft Basic Render Driver";
		ctx.adapter_info.version = version_t(1,0);
		ctx.adapter_info.vendor = vendor::microsoft;
		ctx.adapter_info.feature_level = version_t(11,1);
	}

	else
	{
		detail::enumerate_video_drivers([](const info_t& info, void* user)->bool
		{
			auto& ctx = *(ctx_t*)user;

			char vendor[128];
			char device[128];
			snprintf(vendor, "VEN_%X", ctx.adapter_desc.VendorId);
			snprintf(device, "DEV_%04X", ctx.adapter_desc.DeviceId);
			if (strstr(info.plugnplay_id, vendor) && strstr(info.plugnplay_id, device))
			{
				ctx.adapter_info = info;
				return false;
			}
			return true;
		}, &ctx);
	}

	*(int*)&ctx.adapter_info.id = adapter_index;

	D3D_FEATURE_LEVEL FeatureLevel;
	// Note that the out-device is null, thus this isn't that expensive a call
	if (SUCCEEDED(D3D11CreateDevice(
		adapter
		, D3D_DRIVER_TYPE_UNKNOWN
		, nullptr
		, 0 // D3D11_CREATE_DEVICE_DEBUG // squelches a _com_error warning
		, nullptr
		, 0
		, D3D11_SDK_VERSION
		, nullptr
		, &FeatureLevel
		, nullptr)))
		ctx.adapter_info.feature_level = version_t((FeatureLevel>>12) & 0xff, (FeatureLevel>>8) & 0xf);

	return ctx.adapter_info;
}
开发者ID:igHunterKiller,项目名称:ouroboros,代码行数:60,代码来源:adapter.cpp

示例12: CHECKED

void DesktopDuplication::init()
{
	IDXGIFactory1* dxgiFactory = nullptr;
	CHECKED(hr, CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory)));

	IDXGIAdapter1* dxgiAdapter = nullptr;
	CHECKED(hr, dxgiFactory->EnumAdapters1(adapter, &dxgiAdapter));
	dxgiFactory->Release();

	CHECKED(hr, D3D11CreateDevice(dxgiAdapter,
		D3D_DRIVER_TYPE_UNKNOWN,
		NULL,
		NULL,
		NULL,
		NULL,
		D3D11_SDK_VERSION,
		&d3dDevice,
		NULL,
		&d3dContext));

	IDXGIOutput* dxgiOutput = nullptr;
	CHECKED(hr, dxgiAdapter->EnumOutputs(output, &dxgiOutput));
	dxgiAdapter->Release();

	IDXGIOutput1* dxgiOutput1 = nullptr;
	CHECKED(hr, dxgiOutput->QueryInterface(__uuidof(dxgiOutput1), reinterpret_cast<void**>(&dxgiOutput1)));
	dxgiOutput->Release();

	IDXGIDevice* dxgiDevice = nullptr;
	CHECKED(hr, d3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice)));

	CHECKED(hr, dxgiOutput1->DuplicateOutput(dxgiDevice, &outputDuplication));
	dxgiOutput1->Release();
	dxgiDevice->Release();
}
开发者ID:filinger,项目名称:blitzle,代码行数:35,代码来源:DesktopDuplication.cpp

示例13: sizeof

    HRESULT DisplayerImpl::CreateD3D11Device(IDXGIAdapter* adapter, D3D_DRIVER_TYPE driverType, UINT flags,
                                             ID3D11Device** ppDevice, ID3D11DeviceContext** ppDevCtx, D3D_FEATURE_LEVEL* resultLevel) {
        HRESULT hr = S_OK;

        static const 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
        };

        uint32_t arraySize = sizeof(featureLevels) / sizeof(featureLevels[0]);

        D3D_FEATURE_LEVEL result;
        ID3D11Device* device = nullptr;
        ID3D11DeviceContext* devctx = nullptr;

        hr = D3D11CreateDevice(adapter, driverType, 0, flags, featureLevels, arraySize, D3D11_SDK_VERSION, &device, &result, &devctx);
        if (FAILED(hr))
            return hr;

        if (resultLevel) {
            *resultLevel = result;
        }
        *ppDevice = device;
        *ppDevCtx = devctx;

        return hr;
    }
开发者ID:copyliu,项目名称:libwtfdanmaku,代码行数:32,代码来源:DisplayerImpl.cpp

示例14: LoadLibrary

void DebugAnnotator11::initializeDevice()
{
    if (!mInitialized)
    {
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
        mD3d11Module = LoadLibrary(TEXT("d3d11.dll"));
        ASSERT(mD3d11Module);

        PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice");
        ASSERT(D3D11CreateDevice != nullptr);
#endif // !ANGLE_ENABLE_WINDOWS_STORE

        ID3D11Device *device = nullptr;
        ID3D11DeviceContext *context = nullptr;

        HRESULT hr = E_FAIL;

        // Create a D3D_DRIVER_TYPE_NULL device, which is much cheaper than other types of device.
        hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_NULL, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &device, nullptr, &context);
        ASSERT(SUCCEEDED(hr));
        if (SUCCEEDED(hr))
        {
            mUserDefinedAnnotation = d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context);
            ASSERT(mUserDefinedAnnotation != nullptr);
            mInitialized = true;
        }

        SafeRelease(device);
        SafeRelease(context);
    }
}
开发者ID:dreamsxin,项目名称:bombyx3d,代码行数:31,代码来源:DebugAnnotator11.cpp

示例15: ARRAYSIZE

int ContextD3D11::CreateDeviceResources() {
  UINT creationFlags = D3D11_CREATE_DEVICE_SINGLETHREADED;//D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
  creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

  D3D_DRIVER_TYPE driverTypes[] =
  {
      D3D_DRIVER_TYPE_HARDWARE,
      D3D_DRIVER_TYPE_WARP,
      D3D_DRIVER_TYPE_REFERENCE,
  };
  UINT numDriverTypes = ARRAYSIZE( driverTypes );

  D3D_FEATURE_LEVEL featureLevels[] =
  {
    D3D_FEATURE_LEVEL_12_1,
    D3D_FEATURE_LEVEL_12_0,
    D3D_FEATURE_LEVEL_11_1,
    D3D_FEATURE_LEVEL_11_0,
    D3D_FEATURE_LEVEL_10_1,
    D3D_FEATURE_LEVEL_10_0,
  };
  UINT numFeatureLevels = ARRAYSIZE( featureLevels );
  D3D_FEATURE_LEVEL feature_level;
  ID3D11Device* device;
  ID3D11DeviceContext* devicecontext;

  auto hr = D3D11CreateDevice(adaptor_, D3D_DRIVER_TYPE_UNKNOWN, nullptr,	creationFlags, featureLevels, ARRAYSIZE(featureLevels),	D3D11_SDK_VERSION, &device, &feature_level, &devicecontext);
  if (FAILED(hr)) {
    OutputDebugString("ContextD3D11::CreateDeviceResources : D3D11CreateDevice Failed");
    return hr;
  }
  device_ = (ID3D11Device1*)device;
  device_context_ = (ID3D11DeviceContext1*)devicecontext;

  SafeRelease(&default_blend_state);
  D3D11_BLEND_DESC BlendStateDescription;
  ZeroMemory(&BlendStateDescription,sizeof(BlendStateDescription));
  BlendStateDescription.RenderTarget[0].BlendEnable           = true;
  BlendStateDescription.RenderTarget[0].SrcBlend              = D3D11_BLEND_SRC_ALPHA;        //D3D11_BLEND_SRC_COLOR;
  BlendStateDescription.RenderTarget[0].DestBlend             = D3D11_BLEND_INV_SRC_ALPHA;//D3D11_BLEND_DEST_COLOR;
  BlendStateDescription.RenderTarget[0].SrcBlendAlpha         = D3D11_BLEND_SRC_ALPHA;//D3D11_BLEND_SRC_ALPHA;
  BlendStateDescription.RenderTarget[0].DestBlendAlpha        = D3D11_BLEND_ZERO;//D3D11_BLEND_DEST_ALPHA;
  BlendStateDescription.RenderTarget[0].BlendOp               = D3D11_BLEND_OP_ADD;
  BlendStateDescription.RenderTarget[0].BlendOpAlpha          = D3D11_BLEND_OP_ADD;
  BlendStateDescription.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
    
  device_->CreateBlendState(&BlendStateDescription,&default_blend_state);
  float blendFactor[] = {1,1, 1, 1};
  UINT sampleMask   = 0xffffffff;
  device_context_->OMSetBlendState(default_blend_state,blendFactor,sampleMask);


  

  return S_OK;
}
开发者ID:Noplace,项目名称:Solar,代码行数:58,代码来源:contextd3d11.cpp


注:本文中的D3D11CreateDevice函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。