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


C++ ComPtr::CreateSwapChain方法代码示例

本文整理汇总了C++中microsoft::wrl::ComPtr::CreateSwapChain方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::CreateSwapChain方法的具体用法?C++ ComPtr::CreateSwapChain怎么用?C++ ComPtr::CreateSwapChain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在microsoft::wrl::ComPtr的用法示例。


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

示例1: onInit


//.........这里部分代码省略.........
				OutputDebugStringA(std::string("このアダプターを使用します。 adapterIndex = " + std::to_string(adapterIndex) + "\n").c_str());
			}

			//期待通りに動作してくれなかった
			//LARGE_INTEGER version;
			//hr = pAdapterIt->CheckInterfaceSupport(__uuidof(ID3D11Device), &version);
			//DXGI_ERROR_UNSUPPORTED;
			//if (S_OK == hr) {
			//	pAdapter = pAdapterIt;
			//	OutputDebugStringA(std::string("このアダプターを使用します。 adapterIndex = " + std::to_string(adapterIndex) + "\n").c_str());
			//}
		}

		//使い終わったら必ずReleaseすること
		pAdapterIt.Reset();
	}

	//ID3D11DeviceとID3D11DeviceContextの作成
	std::array<D3D_FEATURE_LEVEL, 3> featureLevels = { {
			D3D_FEATURE_LEVEL_11_0,
			D3D_FEATURE_LEVEL_10_1,
			D3D_FEATURE_LEVEL_10_0
		} };
	UINT flags = 0;
#ifdef _DEBUG
	flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
	D3D_FEATURE_LEVEL usedLevel;
	hr = D3D11CreateDevice(
		this->mpAdapter.Get(),
		D3D_DRIVER_TYPE_UNKNOWN,
		nullptr,
		flags,
		featureLevels.data(),
		static_cast<UINT>(featureLevels.size()),
		D3D11_SDK_VERSION,
		this->mpDevice.GetAddressOf(),
		&usedLevel,
		this->mpImmediateContext.GetAddressOf()
		);

	if (FAILED(hr)) {
		throw std::runtime_error("ID3D11Deviceの作成に失敗。");
	}

	//IDXGISwapChainの作成
	DXGI_SWAP_CHAIN_DESC swapChainDesc = { 0 };
	swapChainDesc.OutputWindow = Win32Application::hwnd();
	swapChainDesc.BufferCount = 2;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;

	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
	//swapChainDesc.Flags = 0;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	//フルスクリーンとウィンドモードの切り替えがしたい場合は、まずウィンドウモードとして生成することを推奨しているみたい
	//https://msdn.microsoft.com/en-us/library/bb174579(v=vs.85).aspx
	swapChainDesc.Windowed = true;

	//希望する画面設定
	swapChainDesc.BufferDesc.Width = this->width();
	swapChainDesc.BufferDesc.Height = this->height();
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	//上の画面設定に一番近いものを調べる
	Microsoft::WRL::ComPtr<IDXGIOutput> pOutput;
	if (DXGI_ERROR_NOT_FOUND == this->mpAdapter->EnumOutputs(0, pOutput.GetAddressOf())) {
		throw std::runtime_error("アダプターの出力先が見つかりません。");
	}
	DXGI_MODE_DESC modeDesc;
	hr = pOutput->FindClosestMatchingMode(&swapChainDesc.BufferDesc, &modeDesc, this->mpDevice.Get());
	if (FAILED(hr)) {
		throw std::runtime_error("表示モードの取得に失敗");
	}
	//IDXGISwapChainの作成
	swapChainDesc.BufferDesc = modeDesc;
	hr = pFactory->CreateSwapChain(this->mpDevice.Get(), &swapChainDesc, this->mpSwapChain.GetAddressOf());
	if (FAILED(hr)) {
		throw std::runtime_error("IDXGISwapChainの作成に失敗");
	}

	//ディスプレイの画面モードの一覧を取得する
	//IDXGIOutput* pOutput;
	//this->mpSwapChain->GetContainingOutput(&pOutput);
	//UINT num;
	//UINT flag = DXGI_ENUM_MODES_INTERLACED;
	//pOutput->GetDisplayModeList(swapChainDesc.BufferDesc.Format, flag, &num, nullptr);
	//std::vector<DXGI_MODE_DESC> modeDesces;
	//modeDesces.resize(num);
	//pOutput->GetDisplayModeList(swapChainDesc.BufferDesc.Format, flag, &num, &modeDesces[0]);
	//pOutput->Release();

	//
	//	後はバックバッファのレンダーターゲットビューの作成、必要ならZバッファの作成とビューポートの設定を行う
	//
	initRenderTargetAndDepthStencil(swapChainDesc.BufferDesc.Width, swapChainDesc.BufferDesc.Height);
}
开发者ID:tositeru,项目名称:ImasaraDX11,代码行数:101,代码来源:Scene.cpp

示例2: deviceContext

//-----------------------------------------------------------------------
GraphicsContextDirect3D11::GraphicsContextDirect3D11(
    HWND windowHandle,
    Microsoft::WRL::ComPtr<IDXGIFactory1> const& dxgiFactory,
    Microsoft::WRL::ComPtr<ID3D11Device> const& device,
    Microsoft::WRL::ComPtr<ID3D11DeviceContext> const& deviceContextIn,
    PresentationParameters const& presentationParameters)
    : deviceContext(deviceContextIn)
    , blendFactor({1.0f, 1.0f, 1.0f, 1.0f})
    , preferredBackBufferWidth(1)
    , preferredBackBufferHeight(1)
    , backBufferCount(2)
    , backBufferFormat(DXGIFormatHelper::ToDXGIFormat(presentationParameters.BackBufferFormat))
    , backBufferDepthFormat(presentationParameters.DepthStencilFormat)
    , needToApplyPipelineState(true)
{
    using Microsoft::WRL::ComPtr;

    POMDOG_ASSERT(device);
    POMDOG_ASSERT(deviceContext);

    DXGI_SAMPLE_DESC sampleDesc;
    sampleDesc.Count = 1;
    sampleDesc.Quality = 0;

    if (presentationParameters.MultiSampleCount > 1) {
        ChooseMultiSampleSetting(
            device.Get(),
            backBufferFormat,
            presentationParameters.MultiSampleCount,
            sampleDesc);
    }

#if defined(DEBUG) && !defined(NDEBUG)
    Log::Internal(StringHelper::Format(
        "DXGI_SAMPLE_DESC.Count  : %d\n"
        "DXGI_SAMPLE_DESC.Quality: %d",
        sampleDesc.Count,
        sampleDesc.Quality));
#endif

    {
        RECT rect;
        ::GetClientRect(windowHandle, &rect);
        auto const windowWidth = rect.right - rect.left;
        auto const windowHeight = rect.bottom - rect.top;

        preferredBackBufferWidth = std::max<int>(preferredBackBufferWidth, windowWidth);
        preferredBackBufferHeight = std::max<int>(preferredBackBufferHeight, windowHeight);
    }
    {
        DXGI_SWAP_CHAIN_DESC swapChainDesc;
        ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
        swapChainDesc.BufferCount = backBufferCount;
        swapChainDesc.BufferDesc.Width = preferredBackBufferWidth;
        swapChainDesc.BufferDesc.Height = preferredBackBufferHeight;
        swapChainDesc.BufferDesc.Format = backBufferFormat;
        swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
        swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
        swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
        swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
        swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
        swapChainDesc.OutputWindow = windowHandle;
        swapChainDesc.Windowed = (!presentationParameters.IsFullScreen ? TRUE : FALSE);
        swapChainDesc.SampleDesc.Count = sampleDesc.Count;
        swapChainDesc.SampleDesc.Quality = sampleDesc.Quality;

        POMDOG_ASSERT(dxgiFactory);
        HRESULT hr = dxgiFactory->CreateSwapChain(device.Get(), &swapChainDesc, &swapChain);

        if (FAILED(hr)) {
            // FUS RO DAH!
            POMDOG_THROW_EXCEPTION(std::runtime_error, "Failed to create SwapChain");
        }
    }
    {
        ///@todo MSAA is not implemented yet
        constexpr int multiSampleCount = 1;

        backBuffer = std::make_shared<RenderTarget2DDirect3D11>(
            device.Get(),
            swapChain.Get(),
            preferredBackBufferWidth,
            preferredBackBufferHeight,
            backBufferDepthFormat,
            multiSampleCount);

        renderTargets.reserve(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT);
        renderTargets.push_back(backBuffer);
    }

    SetRenderTarget();

    textureResourceViews.fill(nullptr);
}
开发者ID:Mourtz,项目名称:pomdog,代码行数:95,代码来源:GraphicsContextDirect3D11.cpp


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