summaryrefslogtreecommitdiffstats
path: root/Whisper/D3D/MappedResource.cpp
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-16 14:52:43 +0100
committerKonstantin <const@const.me>2023-01-16 14:52:43 +0100
commit8c4603c73675958efc960fbd4bb599a2909d106a (patch)
tree714dc6fc9a1672d5fd7f89676b97e10959662abc /Whisper/D3D/MappedResource.cpp
parent990a8d0dbaefc996244097397259e92758b15cce (diff)
Source codes
Diffstat (limited to 'Whisper/D3D/MappedResource.cpp')
-rw-r--r--Whisper/D3D/MappedResource.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Whisper/D3D/MappedResource.cpp b/Whisper/D3D/MappedResource.cpp
new file mode 100644
index 0000000..d6e8119
--- /dev/null
+++ b/Whisper/D3D/MappedResource.cpp
@@ -0,0 +1,33 @@
+#include "stdafx.h"
+#include "MappedResource.h"
+using namespace DirectCompute;
+#define CHECK( hr ) { const HRESULT __hr = ( hr ); if( FAILED( __hr ) ) return __hr; }
+
+MappedResource::MappedResource()
+{
+ mapped.pData = nullptr;
+ mapped.RowPitch = mapped.DepthPitch = 0;
+ resource = nullptr;
+}
+
+HRESULT MappedResource::map( ID3D11Resource* res, bool reading )
+{
+ if( nullptr == resource )
+ {
+ D3D11_MAP mt = reading ? D3D11_MAP_READ : D3D11_MAP_WRITE_DISCARD;
+ CHECK( context()->Map( res, 0, mt, 0, &mapped ) );
+ resource = res;
+ return S_OK;
+ }
+ return HRESULT_FROM_WIN32( ERROR_ALREADY_INITIALIZED );
+}
+
+MappedResource::~MappedResource()
+{
+ if( nullptr != resource )
+ {
+ context()->Unmap( resource, 0 );
+ resource = nullptr;
+ mapped.pData = nullptr;
+ }
+} \ No newline at end of file