本文整理汇总了C++中IID_PPV_ARGS函数的典型用法代码示例。如果您正苦于以下问题:C++ IID_PPV_ARGS函数的具体用法?C++ IID_PPV_ARGS怎么用?C++ IID_PPV_ARGS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IID_PPV_ARGS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThrowIfFailed
// Load the sample assets.
void D3D12Fullscreen::LoadAssets()
{
// Create an empty root signature.
{
CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
ComPtr<ID3DBlob> signature;
ComPtr<ID3DBlob> error;
ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature)));
NAME_D3D12_OBJECT(m_rootSignature);
}
// Create the pipeline state, which includes compiling and loading shaders.
{
ComPtr<ID3DBlob> vertexShader;
ComPtr<ID3DBlob> pixelShader;
ComPtr<ID3DBlob> error;
#if defined(_DEBUG)
// Enable better shader debugging with the graphics debugging tools.
UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
#else
UINT compileFlags = 0;
#endif
ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, &error));
ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, &error));
// Define the vertex input layout.
D3D12_INPUT_ELEMENT_DESC inputElementDescs[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
};
// Describe and create the graphics pipeline state object (PSO).
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) };
psoDesc.pRootSignature = m_rootSignature.Get();
psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader.Get());
psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader.Get());
psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState.DepthEnable = FALSE;
psoDesc.DepthStencilState.StencilEnable = FALSE;
psoDesc.SampleMask = UINT_MAX;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.NumRenderTargets = 1;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
psoDesc.SampleDesc.Count = 1;
ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState)));
NAME_D3D12_OBJECT(m_pipelineState);
}
// Create the command list.
ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocators[m_frameIndex].Get(), m_pipelineState.Get(), IID_PPV_ARGS(&m_commandList)));
NAME_D3D12_OBJECT(m_commandList);
LoadSizeDependentResources();
// Close the command list and execute it to begin the vertex buffer copy into
// the default heap.
ThrowIfFailed(m_commandList->Close());
ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
// Create synchronization objects and wait until assets have been uploaded to the GPU.
{
ThrowIfFailed(m_device->CreateFence(m_fenceValues[m_frameIndex], D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence)));
m_fenceValues[m_frameIndex]++;
// Create an event handle to use for frame synchronization.
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (m_fenceEvent == nullptr)
{
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
}
// Wait for the command list to execute; we are reusing the same command
// list in our main loop but for now, we just want to wait for setup to
// complete before continuing.
WaitForGpu();
}
}
示例2: defined
// Load the rendering pipeline dependencies.
void D3D12PredicationQueries::LoadPipeline()
{
#if defined(_DEBUG)
// Enable the D3D12 debug layer.
{
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
}
}
#endif
ComPtr<IDXGIFactory4> factory;
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
if (m_useWarpDevice)
{
ComPtr<IDXGIAdapter> warpAdapter;
ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
ThrowIfFailed(D3D12CreateDevice(
warpAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);
ThrowIfFailed(D3D12CreateDevice(
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
}
// Describe and create the command queue.
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
ThrowIfFailed(m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)));
NAME_D3D12_OBJECT(m_commandQueue);
// Describe and create the swap chain.
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
swapChainDesc.BufferCount = FrameCount;
swapChainDesc.Width = m_width;
swapChainDesc.Height = m_height;
swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.SampleDesc.Count = 1;
ComPtr<IDXGISwapChain1> swapChain;
ThrowIfFailed(factory->CreateSwapChainForCoreWindow(
m_commandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it.
reinterpret_cast<IUnknown*>(Windows::UI::Core::CoreWindow::GetForCurrentThread()),
&swapChainDesc,
nullptr,
&swapChain
));
ThrowIfFailed(swapChain.As(&m_swapChain));
m_frameIndex = m_swapChain->GetCurrentBackBufferIndex();
// Create descriptor heaps.
{
// Describe and create a render target view (RTV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
rtvHeapDesc.NumDescriptors = FrameCount;
rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ThrowIfFailed(m_device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&m_rtvHeap)));
// Describe and create a depth stencil view (DSV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
dsvHeapDesc.NumDescriptors = 1;
dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ThrowIfFailed(m_device->CreateDescriptorHeap(&dsvHeapDesc, IID_PPV_ARGS(&m_dsvHeap)));
// Describe and create a constant buffer view (CBV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC cbvHeapDesc = {};
cbvHeapDesc.NumDescriptors = CbvCountPerFrame * FrameCount;
cbvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
cbvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
ThrowIfFailed(m_device->CreateDescriptorHeap(&cbvHeapDesc, IID_PPV_ARGS(&m_cbvHeap)));
NAME_D3D12_OBJECT(m_cbvHeap);
// Describe and create a heap for occlusion queries.
D3D12_QUERY_HEAP_DESC queryHeapDesc = {};
queryHeapDesc.Count = 1;
queryHeapDesc.Type = D3D12_QUERY_HEAP_TYPE_OCCLUSION;
ThrowIfFailed(m_device->CreateQueryHeap(&queryHeapDesc, IID_PPV_ARGS(&m_queryHeap)));
//.........这里部分代码省略.........
示例3: GetProcAddress
/// <summary>
/// Get image .NET runtime version
/// </summary>
/// <returns>runtime version, "n/a" if nothing found</returns>
std::wstring ImageNET::GetImageRuntimeVer( const wchar_t* ImagePath )
{
std::wstring LatestVersion = L"n/a";
CComPtr<ICLRMetaHost> MetaHost;
// Check if .NET 4 or higher is present
auto clrCreate = reinterpret_cast<fnCLRCreateInstancen>(
GetProcAddress( LoadLibraryW( L"mscoree.dll" ), "CLRCreateInstance" ));
// Legacy runtime. Get exact required version
if(!clrCreate)
{
wchar_t ver[64] = { 0 };
DWORD bytes = 0;
auto clrGetVer = reinterpret_cast<fnGetRequestedRuntimeVersion>(
GetProcAddress( GetModuleHandleW( L"mscoree.dll" ), "GetRequestedRuntimeVersion" ));
clrGetVer( const_cast<LPWSTR>(ImagePath), ver, 64, &bytes );
FreeLibrary( GetModuleHandleW( L"mscoree.dll" ) );
return ver;
}
// Get highest available
else
{
if (FAILED( clrCreate( CLSID_CLRMetaHost, IID_ICLRMetaHost, reinterpret_cast<LPVOID*>(&MetaHost) ) ))
return LatestVersion;
CComPtr<IEnumUnknown> Runtimes;
if (FAILED( MetaHost->EnumerateInstalledRuntimes( &Runtimes ) ))
return LatestVersion;
CComPtr<IUnknown> Runtime;
CComPtr<ICLRRuntimeInfo> Latest;
while (Runtimes->Next( 1, &Runtime, NULL ) == S_OK)
{
CComPtr<ICLRRuntimeInfo> Current;
wchar_t tmpString[MAX_PATH];
DWORD tmp = MAX_PATH * sizeof(wchar_t);
if (SUCCEEDED( Runtime->QueryInterface( IID_PPV_ARGS( &Current ) ) ))
{
if (!Latest)
{
if (SUCCEEDED( Current->QueryInterface( IID_PPV_ARGS( &Latest ) ) ))
{
Latest->GetVersionString( tmpString, &tmp );
LatestVersion = tmpString;
}
}
else
{
if (SUCCEEDED( Current->GetVersionString( tmpString, &tmp ) ))
{
std::wstring CurrentVersion = tmpString;
if (CurrentVersion.compare( LatestVersion ) > 0)
{
LatestVersion = CurrentVersion;
Latest.Release();
Current->QueryInterface( IID_PPV_ARGS( &Latest ) );
}
}
}
}
Runtime.Release();
}
return LatestVersion;
}
}
示例4: WriteContentPropertiesBulk
// Writes a set of properties for all objects.
void WriteContentPropertiesBulk(
IPortableDevice* pDevice)
{
if (pDevice == NULL)
{
printf("! A NULL IPortableDevice interface pointer was received\n");
return;
}
HRESULT hr = S_OK;
GUID guidContext = GUID_NULL;
CSetBulkValuesCallback* pCallback = NULL;
CComPtr<IPortableDeviceProperties> pProperties;
CComPtr<IPortableDevicePropertiesBulk> pPropertiesBulk;
CComPtr<IPortableDeviceValues> pObjectProperties;
CComPtr<IPortableDeviceContent> pContent;
CComPtr<IPortableDeviceValuesCollection> pPropertiesToWrite;
CComPtr<IPortableDevicePropVariantCollection> pObjectIDs;
DWORD cObjectIDs = 0;
// 1) Get an IPortableDeviceContent interface from the IPortableDevice interface to
// access the content-specific methods.
hr = pDevice->Content(&pContent);
if (FAILED(hr))
{
printf("! Failed to get IPortableDeviceContent from IPortableDevice, hr = 0x%lx\n",hr);
}
// 2) Get an IPortableDeviceProperties interface from the IPortableDeviceContent interface
// to access the property-specific methods.
if (SUCCEEDED(hr))
{
hr = pContent->Properties(&pProperties);
if (FAILED(hr))
{
printf("! Failed to get IPortableDeviceProperties from IPortableDevice, hr = 0x%lx\n",hr);
}
}
// 3) Check to see if the driver supports BULK property operations by call QueryInterface
// on the IPortableDeviceProperties interface for IPortableDevicePropertiesBulk
if (SUCCEEDED(hr))
{
hr = pProperties->QueryInterface(IID_PPV_ARGS(&pPropertiesBulk));
if (FAILED(hr))
{
printf("This driver does not support BULK property operations.\n");
}
}
// 4) CoCreate an IPortableDeviceValuesCollection interface to hold the the properties
// we wish to write.
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pPropertiesToWrite));
if (FAILED(hr))
{
printf("! Failed to CoCreate IPortableDeviceValuesCollection for bulk property values, hr = 0x%lx\n", hr);
}
}
// 6) Create an instance of the IPortableDevicePropertiesBulkCallback object.
if (SUCCEEDED(hr))
{
pCallback = new (std::nothrow) CSetBulkValuesCallback();
if (pCallback == NULL)
{
hr = E_OUTOFMEMORY;
printf("! Failed to allocate CSetBulkValuesCallback, hr = 0x%lx\n", hr);
}
}
// 7) Call our helper function CreateIPortableDevicePropVariantCollectionWithAllObjectIDs
// to enumerate and create an IPortableDevicePropVariantCollection with the object
// identifiers needed to perform the bulk operation on.
if (SUCCEEDED(hr))
{
hr = CreateIPortableDevicePropVariantCollectionWithAllObjectIDs(pContent,
&pObjectIDs);
}
if (SUCCEEDED(hr))
{
hr = pObjectIDs->GetCount(&cObjectIDs);
if (FAILED(hr))
{
printf("! Failed to get number of objectIDs from IPortableDevicePropVariantCollection, hr = 0x%lx\n", hr);
}
}
// 8) Iterate through object list and add appropriate IPortableDeviceValues to collection
if (SUCCEEDED(hr))
{
for(DWORD dwIndex = 0; (dwIndex < cObjectIDs) && (hr == S_OK); dwIndex++)
{
//.........这里部分代码省略.........
示例5: lib
void DirectShowMetaDataControl::updateMetadata(IFilterGraph2 *graph, IBaseFilter *source, const QString &fileSrc)
{
m_metadata.clear();
#ifndef QT_NO_SHELLITEM
if (!sHCreateItemFromParsingName) {
QSystemLibrary lib(QStringLiteral("shell32"));
sHCreateItemFromParsingName = (q_SHCreateItemFromParsingName)(lib.resolve("SHCreateItemFromParsingName"));
}
if (!fileSrc.isEmpty() && sHCreateItemFromParsingName) {
IShellItem2* shellItem = 0;
if (sHCreateItemFromParsingName(reinterpret_cast<const WCHAR*>(fileSrc.utf16()),
0, IID_PPV_ARGS(&shellItem)) == S_OK) {
IPropertyStore *pStore = 0;
if (shellItem->GetPropertyStore(GPS_DEFAULT, IID_PPV_ARGS(&pStore)) == S_OK) {
DWORD cProps;
if (SUCCEEDED(pStore->GetCount(&cProps))) {
for (DWORD i = 0; i < cProps; ++i)
{
PROPERTYKEY key;
PROPVARIANT var;
PropVariantInit(&var);
if (FAILED(pStore->GetAt(i, &key)))
continue;
if (FAILED(pStore->GetValue(key, &var)))
continue;
if (IsEqualPropertyKey(key, PKEY_Author)) {
m_metadata.insert(QMediaMetaData::Author, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Title)) {
m_metadata.insert(QMediaMetaData::Title, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_SubTitle)) {
m_metadata.insert(QMediaMetaData::SubTitle, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_ParentalRating)) {
m_metadata.insert(QMediaMetaData::ParentalRating, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Comment)) {
m_metadata.insert(QMediaMetaData::Description, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Copyright)) {
m_metadata.insert(QMediaMetaData::Copyright, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_ProviderStyle)) {
m_metadata.insert(QMediaMetaData::Genre, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_Year)) {
m_metadata.insert(QMediaMetaData::Year, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_DateEncoded)) {
m_metadata.insert(QMediaMetaData::Date, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Rating)) {
m_metadata.insert(QMediaMetaData::UserRating,
int((convertValue(var).toUInt() - 1) / qreal(98) * 100));
} else if (IsEqualPropertyKey(key, PKEY_Keywords)) {
m_metadata.insert(QMediaMetaData::Keywords, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Language)) {
m_metadata.insert(QMediaMetaData::Language, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_Publisher)) {
m_metadata.insert(QMediaMetaData::Publisher, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_Duration)) {
m_metadata.insert(QMediaMetaData::Duration,
(convertValue(var).toLongLong() + 10000) / 10000);
} else if (IsEqualPropertyKey(key, PKEY_Audio_EncodingBitrate)) {
m_metadata.insert(QMediaMetaData::AudioBitRate, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Media_AverageLevel)) {
m_metadata.insert(QMediaMetaData::AverageLevel, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Audio_ChannelCount)) {
m_metadata.insert(QMediaMetaData::ChannelCount, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Audio_PeakValue)) {
m_metadata.insert(QMediaMetaData::PeakValue, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Audio_SampleRate)) {
m_metadata.insert(QMediaMetaData::SampleRate, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_AlbumTitle)) {
m_metadata.insert(QMediaMetaData::AlbumTitle, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_AlbumArtist)) {
m_metadata.insert(QMediaMetaData::AlbumArtist, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_Artist)) {
m_metadata.insert(QMediaMetaData::ContributingArtist, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_Composer)) {
m_metadata.insert(QMediaMetaData::Composer, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_Conductor)) {
m_metadata.insert(QMediaMetaData::Conductor, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_Lyrics)) {
m_metadata.insert(QMediaMetaData::Lyrics, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_Mood)) {
m_metadata.insert(QMediaMetaData::Mood, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_TrackNumber)) {
m_metadata.insert(QMediaMetaData::TrackNumber, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Music_Genre)) {
m_metadata.insert(QMediaMetaData::Genre, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_ThumbnailStream)) {
m_metadata.insert(QMediaMetaData::ThumbnailImage, convertValue(var));
} else if (IsEqualPropertyKey(key, PKEY_Video_FrameHeight)) {
QSize res;
res.setHeight(convertValue(var).toUInt());
if (SUCCEEDED(pStore->GetValue(PKEY_Video_FrameWidth, &var)))
res.setWidth(convertValue(var).toUInt());
m_metadata.insert(QMediaMetaData::Resolution, res);
} else if (IsEqualPropertyKey(key, PKEY_Video_HorizontalAspectRatio)) {
QSize aspectRatio;
aspectRatio.setWidth(convertValue(var).toUInt());
if (SUCCEEDED(pStore->GetValue(PKEY_Video_VerticalAspectRatio, &var)))
aspectRatio.setHeight(convertValue(var).toUInt());
//.........这里部分代码省略.........
示例6: GetObjectIdentifierFromPersistentUniqueIdentifier
// Retreives the object identifier for the persistent unique identifer
void GetObjectIdentifierFromPersistentUniqueIdentifier(
IPortableDevice* pDevice)
{
if (pDevice == NULL)
{
printf("! A NULL IPortableDevice interface pointer was received\n");
return;
}
HRESULT hr = S_OK;
WCHAR szSelection[81] = {0};
CComPtr<IPortableDeviceContent> pContent;
CComPtr<IPortableDevicePropVariantCollection> pPersistentUniqueIDs;
CComPtr<IPortableDevicePropVariantCollection> pObjectIDs;
//<SnippetContentProp7>
// Prompt user to enter an unique identifier to convert to an object idenifier.
printf("Enter the Persistant Unique Identifier of the object you wish to convert into an object identifier.\n>");
hr = StringCbGetsW(szSelection,sizeof(szSelection));
if (FAILED(hr))
{
printf("An invalid persistent object identifier was specified, aborting the query operation\n");
}
//</SnippetContentProp7>
// 1) Get an IPortableDeviceContent interface from the IPortableDevice interface to
// access the content-specific methods.
//<SnippetContentProp8>
if (SUCCEEDED(hr))
{
hr = pDevice->Content(&pContent);
if (FAILED(hr))
{
printf("! Failed to get IPortableDeviceContent from IPortableDevice, hr = 0x%lx\n",hr);
}
}
//</SnippetContentProp8>
// 2) CoCreate an IPortableDevicePropVariantCollection interface to hold the the Unique Identifiers
// to query for Object Identifiers.
//
// NOTE: This is a collection interface so more than 1 identifier can be requested at a time.
// This sample only requests a single unique identifier.
//<SnippetContentProp9>
hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pPersistentUniqueIDs));
//</SnippetContentProp9>
//<SnippetContentProp10>
if (SUCCEEDED(hr))
{
if (pPersistentUniqueIDs != NULL)
{
PROPVARIANT pv = {0};
PropVariantInit(&pv);
// Initialize a PROPVARIANT structure with the object identifier string
// that the user selected above. Notice we are allocating memory for the
// PWSTR value. This memory will be freed when PropVariantClear() is
// called below.
pv.vt = VT_LPWSTR;
pv.pwszVal = AtlAllocTaskWideString(szSelection);
if (pv.pwszVal != NULL)
{
// Add the object identifier to the objects-to-delete list
// (We are only deleting 1 in this example)
hr = pPersistentUniqueIDs->Add(&pv);
if (SUCCEEDED(hr))
{
// 3) Attempt to get the unique idenifier for the object from the device
hr = pContent->GetObjectIDsFromPersistentUniqueIDs(pPersistentUniqueIDs,
&pObjectIDs);
if (SUCCEEDED(hr))
{
PROPVARIANT pvId = {0};
hr = pObjectIDs->GetAt(0, &pvId);
if (SUCCEEDED(hr))
{
printf("The persistent unique identifier '%ws' relates to object identifier '%ws' on the device.\n", szSelection, pvId.pwszVal);
}
else
{
printf("! Failed to get the object identifier for '%ws' from the IPortableDevicePropVariantCollection, hr = 0x%lx\n",szSelection, hr);
}
// Free the returned allocated string from the GetAt() call
PropVariantClear(&pvId);
}
else
{
printf("! Failed to get the object identifier from persistent object idenifier '%ws', hr = 0x%lx\n",szSelection, hr);
}
}
else
{
printf("! Failed to get the object identifier from persistent object idenifier because we could no add the persistent object identifier string to the IPortableDevicePropVariantCollection, hr = 0x%lx\n",hr);
}
}
else
{
//.........这里部分代码省略.........
示例7: CFileDialog
CSaveThumbnailsDialog::CSaveThumbnailsDialog(
int rows, int cols, int width, int quality, int levelPNG,
LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(FALSE, lpszDefExt, lpszFileName,
OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_NOCHANGEDIR,
lpszFilter, pParentWnd)
, m_rows(rows)
, m_cols(cols)
, m_width(width)
, m_quality(quality)
, m_levelPNG(levelPNG)
{
if (IsWinVistaOrLater()) {
IFileDialogCustomize* pfdc = GetIFileDialogCustomize();
if (pfdc) {
// Create an event handling object, and hook it up to the dialog.
IFileDialogEvents *pfde = NULL;
HRESULT hr = _CDialogEventHandler_CreateInstance(IID_PPV_ARGS(&pfde));
if (SUCCEEDED(hr)) {
// Hook up the event handler.
DWORD dwCookie;
hr = GetIFileSaveDialog()->Advise(pfde, &dwCookie);
if (SUCCEEDED(hr)) {
;
}
}
CString str;
pfdc->StartVisualGroup(IDS_THUMB_THUMBNAILS, ResStr(IDS_THUMB_THUMBNAILS));
pfdc->AddText(IDS_THUMB_ROWNUMBER, ResStr(IDS_THUMB_ROWNUMBER));
str.Format(L"%d", max(1, min(20, m_rows)));
pfdc->AddEditBox(IDC_EDIT1, str);
pfdc->AddText(IDS_THUMB_COLNUMBER, ResStr(IDS_THUMB_COLNUMBER));
str.Format(L"%d", max(1, min(10, m_cols)));
pfdc->AddEditBox(IDC_EDIT2, str);
pfdc->EndVisualGroup();
pfdc->StartVisualGroup(IDS_THUMB_IMAGE_WIDTH, ResStr(IDS_THUMB_IMAGE_WIDTH));
pfdc->AddText(IDS_THUMB_PIXELS, ResStr(IDS_THUMB_PIXELS));
str.Format(L"%d", max(256, min(2560, m_width)));
pfdc->AddEditBox(IDC_EDIT3, str);
pfdc->EndVisualGroup();
pfdc->StartVisualGroup(IDS_THUMB_IMAGE_QUALITY, ResStr(IDS_THUMB_IMAGE_QUALITY));
pfdc->AddText(IDS_THUMB_QUALITY, ResStr(IDS_THUMB_QUALITY));
str.Format(L"%d", max(70, min(100, m_quality)));
pfdc->AddEditBox(IDC_EDIT4, str);
pfdc->AddText(IDS_THUMB_LEVEL, ResStr(IDS_THUMB_LEVEL));
str.Format(L"%d", max(1, min(9, m_levelPNG)));
pfdc->AddEditBox(IDC_EDIT5, str);
pfdc->EndVisualGroup();
pfdc->Release();
}
} else {
SetTemplate(0, IDD_SAVETHUMBSDIALOGTEMPL);
}
}
示例8: CoCreateInstance
bool ResourceManager::LoadFile(ID2D1HwndRenderTarget* renderTarget, wchar_t * filename)
{
HRESULT result;
IWICImagingFactory2* wicFactory;
IWICBitmapDecoder* wicDecoder;
IWICBitmapFrameDecode* wicFrame;
IWICBitmapFlipRotator* wicFlip;
IWICFormatConverter *wicConverter;
Sprite* newSprite;
// WIC의 각종 인터페이스를 사용하기 위한 factory 생성
result = CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wicFactory));
if (FAILED(result))
return false;
// 파일을 읽고 디코딩 하기 위한 decoder 생성
result = wicFactory->CreateDecoderFromFilename(filename, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &wicDecoder);
if (FAILED(result))
return false;
// decoder에서 프레임을 얻어옴, // 일반적인 이미지 파일은 single frame만을 지원하므로 0으로 고정
result = wicDecoder->GetFrame(0, &wicFrame);
if (FAILED(result))
return false;
// 수평으로 뒤집힌 이미지를 얻기 위해 BitmapFlipRotator 생성
result = wicFactory->CreateBitmapFlipRotator(&wicFlip);
if (FAILED(result))
return false;
// wicFrame를 수평으로 뒤집음
wicFlip->Initialize(wicFrame, WICBitmapTransformFlipHorizontal);
// WICBitmap을 D2DBitmap으로 변환시키기 위해 format converter 생성
result = wicFactory->CreateFormatConverter(&wicConverter);
if (FAILED(result))
return false;
// Converter[0]의 Format을 일반 이미지(wicFrame)에 맞춤
result = wicConverter->Initialize(wicFrame, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeCustom);
if (FAILED(result))
return false;
// 리소스 정보를 저장 할 Sprite 생성
newSprite = new Sprite(renderTarget);
if (!newSprite)
return false;
// WICBitmap을 D2DBitmap으로 변환
//result = renderTarget->CreateBitmapFromWicBitmap(wicConverter, nullptr, &m_Bitmap);
result = renderTarget->CreateBitmapFromWicBitmap(wicConverter, nullptr, newSprite->GetBitmap());
if (FAILED(result))
return false;
ID2D1Bitmap* bitmap = *(newSprite->GetBitmap());
int numberOfFrame = bitmap->GetSize().width / IMAGE_SIZE;
int numberOfAction = bitmap->GetSize().height / IMAGE_SIZE;
newSprite->Initialize(numberOfFrame, numberOfAction);
wchar_t* buffer = new wchar_t[128];
wcscpy_s(buffer, wcslen(filename) + 1, filename);
// 스프라이트 등록
m_Sprites.push_back(newSprite);
m_Filenames.push_back(buffer);
wicConverter->Release();
wicConverter = nullptr;
wicFrame->Release();
wicFrame = nullptr;
wicFlip->Release();
wicFlip = nullptr;
wicDecoder->Release();
wicDecoder = nullptr;
wicFactory->Release();
wicFactory = nullptr;
return true;
}
示例9: ThrowIfFailed
// Load the rendering pipeline dependencies.
void D3D1211on12::LoadPipeline()
{
UINT d3d11DeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};
#ifdef _DEBUG
// Enable the D2D debug layer.
d2dFactoryOptions.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
// Enable the D3D11 debug layer.
d3d11DeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
// Enable the D3D12 debug layer.
{
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
}
}
#endif
ComPtr<IDXGIFactory4> factory;
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
if (m_useWarpDevice)
{
ComPtr<IDXGIAdapter> warpAdapter;
ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
ThrowIfFailed(D3D12CreateDevice(
warpAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_d3d12Device)
));
}
else
{
ThrowIfFailed(D3D12CreateDevice(
nullptr,
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_d3d12Device)
));
}
// Describe and create the command queue.
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
ThrowIfFailed(m_d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)));
// Describe the swap chain.
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = FrameCount;
swapChainDesc.BufferDesc.Width = m_width;
swapChainDesc.BufferDesc.Height = m_height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.OutputWindow = m_hwnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.Windowed = TRUE;
ComPtr<IDXGISwapChain> swapChain;
ThrowIfFailed(factory->CreateSwapChain(
m_commandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it.
&swapChainDesc,
&swapChain
));
ThrowIfFailed(swapChain.As(&m_swapChain));
m_frameIndex = m_swapChain->GetCurrentBackBufferIndex();
// Create an 11 device wrapped around the 12 device and share
// 12's command queue.
ComPtr<ID3D11Device> d3d11Device;
ThrowIfFailed(D3D11On12CreateDevice(
m_d3d12Device.Get(),
d3d11DeviceFlags,
nullptr,
0,
reinterpret_cast<IUnknown**>(m_commandQueue.GetAddressOf()),
1,
0,
&d3d11Device,
&m_d3d11DeviceContext,
nullptr
));
// Query the 11On12 device from the 11 device.
ThrowIfFailed(d3d11Device.As(&m_d3d11On12Device));
// Create D2D/DWrite components.
{
D2D1_DEVICE_CONTEXT_OPTIONS deviceOptions = D2D1_DEVICE_CONTEXT_OPTIONS_NONE;
ThrowIfFailed(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &m_d2dFactory));
ComPtr<IDXGIDevice> dxgiDevice;
ThrowIfFailed(m_d3d11On12Device.As(&dxgiDevice));
//.........这里部分代码省略.........
示例10: CoCreateInstance
HBITMAP CGene::DecodePicture(CString filePath) {
HRESULT hr;
HBITMAP bitmapHandle = NULL;
#if WIC
if (bitmapHandle == NULL) {
// Windows Imaging Component and Direct2D Image Viewer Win32 Sample\C++\WicViewerD2D.cpp
CComPtr<IWICImagingFactory> pWICFactory;
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pWICFactory)
);
if (SUCCEEDED(hr)) {
CComPtr<IWICBitmapDecoder> pDecoder;
hr = pWICFactory->CreateDecoderFromFilename(
filePath,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnDemand,
&pDecoder
);
if (SUCCEEDED(hr)) {
CComPtr<IWICBitmapFrameDecode> pFrame;
hr = pDecoder->GetFrame(0, &pFrame);
if (SUCCEEDED(hr)) {
CComPtr<IWICFormatConverter> pConvertedSourceBitmap;
hr = pWICFactory->CreateFormatConverter(&pConvertedSourceBitmap);
if (SUCCEEDED(hr)) {
hr = pConvertedSourceBitmap->Initialize(
pFrame,
GUID_WICPixelFormat32bppBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeCustom
);
if (SUCCEEDED(hr)) {
UINT cx = 0, cy = 0;
hr = pConvertedSourceBitmap->GetSize(&cx, &cy);
if (SUCCEEDED(hr)) {
struct CompatibleDCHandle {
HDC hMemDC;
CompatibleDCHandle(): hMemDC(CreateCompatibleDC(NULL)) { }
~CompatibleDCHandle() {
if (hMemDC != NULL) {
DeleteDC(hMemDC);
}
}
};
CompatibleDCHandle compatDC;
BITMAPINFO bi = {
sizeof(BITMAPINFOHEADER),
(LONG)cx,
-(LONG)cy,
1,
32,
BI_RGB,
4 * cx * cy
};
struct DIBSectionHandle {
HBITMAP bitmapHandle;
void *pvBits;
DIBSectionHandle(CompatibleDCHandle &compatDC, BITMAPINFO &bi) {
bitmapHandle = CreateDIBSection(
compatDC.hMemDC, &bi, DIB_RGB_COLORS, &pvBits, NULL, 0
);
}
~DIBSectionHandle() {
if (bitmapHandle != NULL) {
DeleteObject(bitmapHandle);
}
}
HBITMAP Detach() {
HBITMAP hbm = bitmapHandle;
bitmapHandle = NULL;
return hbm;
}
bool Has() const {
return bitmapHandle != NULL;
}
};
DIBSectionHandle bitmap(compatDC, bi);
if (bitmap.Has()) {
WICRect bitmapRect = {0, 0, cx, cy};
hr = pConvertedSourceBitmap->CopyPixels(
&bitmapRect,
4 * cx,
bi.bmiHeader.biSizeImage,
reinterpret_cast<PBYTE>(bitmap.pvBits)
);
if (SUCCEEDED(hr)) {
bitmapHandle = bitmap.Detach();
//.........这里部分代码省略.........
示例11: defined
// Load the rendering pipeline dependencies.
void D3D12Fullscreen::LoadPipeline()
{
#if defined(_DEBUG)
// Enable the D3D12 debug layer.
{
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
}
}
#endif
ComPtr<IDXGIFactory4> factory;
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
if (m_useWarpDevice)
{
ComPtr<IDXGIAdapter> warpAdapter;
ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
ThrowIfFailed(D3D12CreateDevice(
warpAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);
ThrowIfFailed(D3D12CreateDevice(
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
}
// Describe and create the command queue.
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
ThrowIfFailed(m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)));
NAME_D3D12_OBJECT(m_commandQueue);
// Describe and create the swap chain.
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
swapChainDesc.BufferCount = FrameCount;
swapChainDesc.Width = m_width;
swapChainDesc.Height = m_height;
swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.SampleDesc.Count = 1;
ComPtr<IDXGISwapChain1> swapChain;
ThrowIfFailed(factory->CreateSwapChainForHwnd(
m_commandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it.
Win32Application::GetHwnd(),
&swapChainDesc,
nullptr,
nullptr,
&swapChain
));
// This sample does not support fullscreen transitions.
ThrowIfFailed(factory->MakeWindowAssociation(Win32Application::GetHwnd(), DXGI_MWA_NO_ALT_ENTER));
ThrowIfFailed(swapChain.As(&m_swapChain));
m_frameIndex = m_swapChain->GetCurrentBackBufferIndex();
// Create descriptor heaps.
{
// Describe and create a render target view (RTV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
rtvHeapDesc.NumDescriptors = FrameCount;
rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ThrowIfFailed(m_device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&m_rtvHeap)));
m_rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
}
// Create a command allocator for each frame.
for (UINT n = 0; n < FrameCount; n++)
{
ThrowIfFailed(m_device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocators[n])));
}
}
示例12: rtvHandle
void D3D12Fullscreen::LoadSizeDependentResources()
{
m_viewport.Width = static_cast<float>(m_width);
m_viewport.Height = static_cast<float>(m_height);
m_viewport.MaxDepth = 1.0f;
m_scissorRect.right = static_cast<LONG>(m_width);
m_scissorRect.bottom = static_cast<LONG>(m_height);
// Create frame resources.
{
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart());
// Create a RTV for each frame.
for (UINT n = 0; n < FrameCount; n++)
{
ThrowIfFailed(m_swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n])));
m_device->CreateRenderTargetView(m_renderTargets[n].Get(), nullptr, rtvHandle);
rtvHandle.Offset(1, m_rtvDescriptorSize);
WCHAR name[25];
if (swprintf_s(name, L"m_renderTargets[%u]", n) > 0)
{
SetName(m_renderTargets[n].Get(), name);
}
}
}
// Create/update the vertex buffer. When updating the vertex buffer it is important
// to ensure that the GPU is finished using the resource before it is released.
// The OnSizeChanged method waits for the GPU to be idle before this method is
// called.
{
// Define the geometry for a triangle that stays the same size regardless
// of the window size. This is not the recommended way to transform vertices.
// The same effect could be achieved by using constant buffers and
// transforming a static set of vertices in the vertex shader, but this
// sample merely demonstrates modifying a resource that is tied to the render
// target size.
// Other apps might also resize intermediate render targets or depth stencils
// at this time.
float x = TriangleWidth / m_viewport.Width;
float y = TriangleWidth / m_viewport.Height;
Vertex triangleVertices[] =
{
{ { 0.0f, y, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
{ { x, -y, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { -x, -y, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
};
const UINT vertexBufferSize = sizeof(triangleVertices);
ThrowIfFailed(m_device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize),
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(&m_vertexBuffer)));
ThrowIfFailed(m_device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&m_vertexBufferUpload)));
NAME_D3D12_OBJECT(m_vertexBuffer);
// Copy data to the intermediate upload heap and then schedule a copy
// from the upload heap to the vertex buffer.
UINT8* pVertexDataBegin;
CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU.
ThrowIfFailed(m_vertexBufferUpload->Map(0, &readRange, reinterpret_cast<void**>(&pVertexDataBegin)));
memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices));
m_vertexBufferUpload->Unmap(0, nullptr);
m_commandList->CopyBufferRegion(m_vertexBuffer.Get(), 0, m_vertexBufferUpload.Get(), 0, vertexBufferSize);
m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_vertexBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER));
// Initialize the vertex buffer views.
m_vertexBufferView.BufferLocation = m_vertexBuffer->GetGPUVirtualAddress();
m_vertexBufferView.StrideInBytes = sizeof(Vertex);
m_vertexBufferView.SizeInBytes = vertexBufferSize;
}
m_resizeResources = false;
}
示例13: CD3DX12_CLEAR_VALUE
FramebufferManager::FramebufferManager()
{
m_target_width = std::max(Renderer::GetTargetWidth(), 1);
m_target_height = std::max(Renderer::GetTargetHeight(), 1);
DXGI_SAMPLE_DESC sample_desc;
sample_desc.Count = g_ActiveConfig.iMultisamples;
sample_desc.Quality = 0;
ID3D12Resource* buf12;
D3D12_RESOURCE_DESC texdesc12;
D3D12_CLEAR_VALUE optimized_clear_valueRTV = { DXGI_FORMAT_R8G8B8A8_UNORM, { 0.0f, 0.0f, 0.0f, 1.0f } };
D3D12_CLEAR_VALUE optimized_clear_valueDSV = CD3DX12_CLEAR_VALUE(DXGI_FORMAT_D32_FLOAT, 0.0f, 0);
HRESULT hr;
m_EFBLayers = m_efb.slices = (g_ActiveConfig.iStereoMode > 0) ? 2 : 1;
// EFB color texture - primary render target
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_target_width, m_target_height, m_efb.slices, 1, sample_desc.Count, sample_desc.Quality, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
hr = D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, &optimized_clear_valueRTV, IID_PPV_ARGS(&buf12));
m_efb.color_tex = new D3DTexture2D(buf12, (D3D11_BIND_FLAG)(D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET), DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM, (sample_desc.Count > 1), D3D12_RESOURCE_STATE_COMMON);
SAFE_RELEASE(buf12);
// Temporary EFB color texture - used in ReinterpretPixelData
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_target_width, m_target_height, m_efb.slices, 1, sample_desc.Count, sample_desc.Quality, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
CheckHR(D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, &optimized_clear_valueRTV, IID_PPV_ARGS(&buf12)));
m_efb.color_temp_tex = new D3DTexture2D(buf12, (D3D11_BIND_FLAG)(D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET), DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM, (sample_desc.Count > 1), D3D12_RESOURCE_STATE_COMMON);
SAFE_RELEASE(buf12);
D3D::SetDebugObjectName12(m_efb.color_temp_tex->GetTex12(), "EFB color temp texture");
// AccessEFB - Sysmem buffer used to retrieve the pixel data from color_tex
texdesc12 = CD3DX12_RESOURCE_DESC::Buffer(64 * 1024);
CheckHR(D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_efb.color_staging_buf)));
CHECK(hr == S_OK, "create EFB color staging buffer (hr=%#x)", hr);
// EFB depth buffer - primary depth buffer
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_TYPELESS, m_target_width, m_target_height, m_efb.slices, 1, sample_desc.Count, sample_desc.Quality, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
CheckHR(D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, &optimized_clear_valueDSV, IID_PPV_ARGS(&buf12)));
m_efb.depth_tex = new D3DTexture2D(buf12, (D3D11_BIND_FLAG)(D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE), DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN, (sample_desc.Count > 1), D3D12_RESOURCE_STATE_COMMON);
SAFE_RELEASE(buf12);
D3D::SetDebugObjectName12(m_efb.depth_tex->GetTex12(), "EFB depth texture");
// Render buffer for AccessEFB (depth data)
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 1, 1, m_efb.slices, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
optimized_clear_valueRTV.Format = DXGI_FORMAT_R32_FLOAT;
hr = D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, &optimized_clear_valueRTV, IID_PPV_ARGS(&buf12));
CHECK(hr == S_OK, "create EFB depth read texture (hr=%#x)", hr);
m_efb.depth_read_texture = new D3DTexture2D(buf12, D3D11_BIND_RENDER_TARGET, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_COMMON);
SAFE_RELEASE(buf12);
D3D::SetDebugObjectName12(m_efb.depth_read_texture->GetTex12(), "EFB depth read texture (used in Renderer::AccessEFB)");
// AccessEFB - Sysmem buffer used to retrieve the pixel data from depth_read_texture
texdesc12 = CD3DX12_RESOURCE_DESC::Buffer(64 * 1024);
hr = D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_efb.depth_staging_buf));
CHECK(hr == S_OK, "create EFB depth staging buffer (hr=%#x)", hr);
D3D::SetDebugObjectName12(m_efb.depth_staging_buf, "EFB depth staging texture (used for Renderer::AccessEFB)");
if (g_ActiveConfig.iMultisamples > 1)
{
// Framebuffer resolve textures (color+depth)
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_target_width, m_target_height, m_efb.slices, 1);
hr = D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&buf12));
CHECK(hr == S_OK, "create EFB color resolve texture (size: %dx%d)", m_target_width, m_target_height);
m_efb.resolved_color_tex = new D3DTexture2D(buf12, D3D11_BIND_SHADER_RESOURCE, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_COMMON);
SAFE_RELEASE(buf12);
D3D::SetDebugObjectName12(m_efb.resolved_color_tex->GetTex12(), "EFB color resolve texture shader resource view");
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_TYPELESS, m_target_width, m_target_height, m_efb.slices, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
hr = D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&buf12));
CHECK(hr == S_OK, "create EFB depth resolve texture (size: %dx%d; hr=%#x)", m_target_width, m_target_height, hr);
m_efb.resolved_depth_tex = new D3DTexture2D(buf12, (D3D11_BIND_FLAG)(D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE), DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_COMMON);
SAFE_RELEASE(buf12);
D3D::SetDebugObjectName12(m_efb.resolved_depth_tex->GetTex12(), "EFB depth resolve texture shader resource view");
m_depth_resolve_depth_stencil_desc = {};
m_depth_resolve_depth_stencil_desc.StencilEnable = FALSE;
m_depth_resolve_depth_stencil_desc.DepthEnable = TRUE;
m_depth_resolve_depth_stencil_desc.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
m_depth_resolve_depth_stencil_desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
}
else
{
m_efb.resolved_color_tex = nullptr;
m_efb.resolved_depth_tex = nullptr;
}
s_xfbEncoder.Init();
}
示例14: ThrowIfFailed
void dx::initialise()
{
gDX.viewport.Width = static_cast<float>(platform::ui::width());
gDX.viewport.Height = static_cast<float>(platform::ui::height());
gDX.viewport.MaxDepth = 1.0f;
gDX.scissorRect.right = static_cast<LONG>(platform::ui::width());
gDX.scissorRect.bottom = static_cast<LONG>(platform::ui::height());
#ifdef _DEBUG
// Enable the D3D12 debug layer.
{
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
}
}
#endif
ComPtr<IDXGIFactory4> factory;
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
// Always use WARP for now...
static const bool USE_WARP_DEVICE = true;
if (USE_WARP_DEVICE)
{
ComPtr<IDXGIAdapter> warpAdapter;
ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
ThrowIfFailed(D3D12CreateDevice(
warpAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&gDX.device)
));
} else
{
ThrowIfFailed(D3D12CreateDevice(
nullptr,
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&gDX.device)
));
}
// Describe and create the command queue.
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
ThrowIfFailed(gDX.device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&gDX.commandQueue)));
// Describe and create the swap chain.
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = gDX.FrameCount;
swapChainDesc.BufferDesc.Width = platform::ui::width();
swapChainDesc.BufferDesc.Height = platform::ui::height();
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.OutputWindow = (HWND)platform::ui::hwnd();
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.Windowed = TRUE;
ComPtr<IDXGISwapChain> swapChain;
ThrowIfFailed(factory->CreateSwapChain(
gDX.commandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it.
&swapChainDesc,
&swapChain
));
ThrowIfFailed(swapChain.As(&gDX.swapChain));
gDX.frameIndex = gDX.swapChain->GetCurrentBackBufferIndex();
// Create descriptor heaps.
{
// Describe and create a render target view (RTV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
rtvHeapDesc.NumDescriptors = gDX.FrameCount + 128;
rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
gDX.rtvHeap = new DXHeap(gDX.device.Get(), rtvHeapDesc);
// Describe and create a depth stencil view (DSV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
dsvHeapDesc.NumDescriptors = 128;
dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
gDX.dsvHeap = new DXHeap(gDX.device.Get(), dsvHeapDesc);
// Describe and create a constant buffer view (CBV), Shader resource
// view (SRV), and unordered access view (UAV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {};
srvHeapDesc.NumDescriptors = 2048;
srvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
srvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
gDX.srvHeap = new DXHeap(gDX.device.Get(), srvHeapDesc);
}
//.........这里部分代码省略.........
示例15: BasicFileOpen
HRESULT BasicFileOpen(PWSTR* filePath)
{
// CoCreate the File Open Dialog object.
IFileDialog *pfd = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Create an event handling object, and hook it up to the dialog.
IFileDialogEvents *pfde = NULL;
//DWORD dwCookie;
// Set the options on the dialog.
DWORD dwFlags;
// Before setting, always get the options first in order
// not to override existing options.
hr = pfd->GetOptions(&dwFlags);
if (SUCCEEDED(hr))
{
// In this case, get shell items only for file system items.
hr = pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
if (SUCCEEDED(hr))
{
static const COMDLG_FILTERSPEC c_rgSaveTypes[] =
{
{L"Executable Files(*.exe)", L"*.exe"},
};
// Set the file types to display only.
// Notice that this is a 1-based array.
hr = pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
if (SUCCEEDED(hr))
{
// Set the selected file type index to Word Docs for this example.
hr = pfd->SetFileTypeIndex(1);
if (SUCCEEDED(hr))
{
// Set the default extension to be ".doc" file.
hr = pfd->SetDefaultExtension(L"exe");
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(g_hwnd);
if (SUCCEEDED(hr))
{
// Obtain the result once the user clicks
// the 'Open' button.
// The result is an IShellItem object.
IShellItem *psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
// We are just going to print out the
// name of the file for sample sake.
PWSTR pszFilePath = NULL;
hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH,
&pszFilePath);
if (SUCCEEDED(hr))
{
*filePath=pszFilePath;
}
psiResult->Release();
}
}
}
}
}
}
}
pfd->Release();
}
else
{
hr=E_OUTOFMEMORY;
OPENFILENAME ofn;
LPWSTR pszFile=(LPWSTR)CoTaskMemAlloc(260*2);
if(pszFile!=NULL)
{
memset1(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = g_hwnd;
ofn.lpstrFile = pszFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = L'\0';
ofn.nMaxFile = 260;
ofn.lpstrFilter = L"Executable Files(*.exe)\0*.exe\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE)
{
*filePath=pszFile;
hr=0;
}
//.........这里部分代码省略.........