GteDX11Resource.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
13 {
15 }
16 
18  :
19  DX11GraphicsObject(gtResource),
20  mStaging(nullptr)
21 {
22  // Derived classes must create the staging resource, because DX11 does
23  // not have a generic description structure that could be used here
24  // otherwise.
25 }
26 
27 D3D11_MAPPED_SUBRESOURCE DX11Resource::MapForWrite(ID3D11DeviceContext* context, unsigned int sri)
28 {
29  D3D11_MAPPED_SUBRESOURCE mapped;
30  HRESULT hr = context->Map(GetDXResource(), sri, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
31  if (FAILED(hr))
32  {
33  mapped.pData = nullptr;
34  mapped.RowPitch = 0;
35  mapped.DepthPitch = 0;
36  }
37  return mapped;
38 }
39 
40 void DX11Resource::Unmap(ID3D11DeviceContext* context, unsigned int sri)
41 {
42  context->Unmap(GetDXResource(), sri);
43 }
44 
46 {
48  HRESULT hr = SetPrivateName(mStaging, name);
49  CHECK_HR_RETURN_NONE("Failed to set private name");
50 }
51 
52 bool DX11Resource::PreparedForCopy(D3D11_CPU_ACCESS_FLAG access) const
53 {
54  // Verify existence of objects.
55  if (!mDXObject)
56  {
57  LogError("Resource does not exist.");
58  return false;
59  }
60  if (!mStaging)
61  {
62  LogError("Staging resource does not exist.");
63  return false;
64  }
65 
66  // Verify the copy type.
67  if ((msStagingAccess[GetResource()->GetCopyType()] & access) == 0)
68  {
69  LogError("Staging resource has incorrect CPU access.");
70  return false;
71  }
72 
73  return true;
74 }
75 
76 
78 {
79  D3D11_CPU_ACCESS_NONE, // COPY_NONE
80  D3D11_CPU_ACCESS_WRITE, // COPY_CPU_TO_STAGING
81  D3D11_CPU_ACCESS_READ, // COPY_STAGING_TO_CPU
82  D3D11_CPU_ACCESS_READ_WRITE // COPY_BIDIRECTIONAL
83 };
#define CHECK_HR_RETURN_NONE(msg)
HRESULT SetPrivateName(ID3D11DeviceChild *object, std::string const &name)
GLuint const GLchar * name
Definition: glcorearb.h:781
DX11Resource(Resource const *gtResource)
ULONG FinalRelease(T *&object)
ID3D11Resource * mStaging
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2217
void Unmap(ID3D11DeviceContext *context, unsigned int sri)
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
#define LogError(message)
Definition: GteLogger.h:92
virtual void SetName(std::string const &name) override
ID3D11DeviceChild * mDXObject
#define D3D11_CPU_ACCESS_READ_WRITE
bool PreparedForCopy(D3D11_CPU_ACCESS_FLAG access) const
#define D3D11_CPU_ACCESS_NONE
ID3D11Resource * GetDXResource() const
static UINT const msStagingAccess[]
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
D3D11_MAPPED_SUBRESOURCE MapForWrite(ID3D11DeviceContext *context, unsigned int sri)
Resource * GetResource() const
virtual void SetName(std::string const &name) override


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59