// 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++)
{
//.........这里部分代码省略.........
// 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
{
//.........这里部分代码省略.........
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;
}
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;
}
请发表评论