-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphicBuffer.cpp
38 lines (31 loc) · 1.17 KB
/
GraphicBuffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "GraphicBuffer.h"
#include "Includes.h"
#include <d3d11.h>
#include <ScreenGrab.h> //SaveWICTextureToFile
#include <wincodec.h> //GUID_ContainerFormatPng
#include "wrl_no_warnings.h"
#include "ErrorMacros.h"
#include "DepthStencilView.h"
#include "Graphics.h"
void GraphicBuffer::SaveToFile(GFX& gfx)
{
HRESULT hr;
//DepthStencilView will use D formats which are not supported by the library we use
const bool wicCantProcess = dynamic_cast<DepthStencilView*>(this) != nullptr;
ID3D11DeviceContext* deviceContext = GFX::GetDeviceContext(gfx);
Microsoft::WRL::ComPtr<ID3D11Resource> resource;
std::string fileName = "SavedImages\\" + std::to_string(m_savedImages) + '_';
fileName += typeid(*this).name();
fileName += wicCantProcess ? ".dds" : ".png";
GetBuffer(&resource);
if (wicCantProcess)
{
THROW_GFX_IF_FAILED(DirectX::SaveDDSTextureToFile(deviceContext, resource.Get(), std::wstring(fileName.begin(), fileName.end()).c_str()));
}
else
{
THROW_GFX_IF_FAILED(DirectX::SaveWICTextureToFile(deviceContext, resource.Get(), GUID_ContainerFormatPng, std::wstring(fileName.begin(), fileName.end()).c_str()));
}
m_savedImages++;
}
size_t GraphicBuffer::m_savedImages = 0;