Avionics
Dropship Simulator
DeviceObject.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "DXUT.h"
4 
6 {
7  UINT Ordinal;
8  ID3D10Device* pd3dDevice = nullptr;
9  ID3DX10Sprite* pSprite = nullptr;
10 
12  std::vector<ID3D10ShaderResourceView*> textureSRV;
13  std::vector<std::string> files;
14 
15  ID3D10ShaderResourceView* GetTextureSRV(Logger* prmLogger, std::string pathAndFilename)
16  {
18  for (UINT i = 0; i < files.size(); i++)
19  {
20  if (_strcmpi(files.at(i).c_str(), pathAndFilename.c_str()) == 0)
21  return textureSRV.at(i);
22  }
23 
24  HRESULT hr;
25  ID3D10ShaderResourceView* srv;
26  if (FAILED(hr = D3DX10CreateShaderResourceViewFromFileA(pd3dDevice, pathAndFilename.c_str(), NULL, NULL, &srv, NULL)))
27  {
28  char err[255];
29  sprintf_s(err, "DEVICE_OBJECT::GetTextureSRV Could not load texture: %s!", pathAndFilename.c_str());
30  prmLogger->Log(err, Logger::Error, hr);
31  return nullptr;
32  }
33 
34  textureSRV.push_back(srv);
35  files.push_back(pathAndFilename);
36 
37  return srv;
38  }
39 
40  void Destroy()
41  {
42  SAFE_RELEASE(pSprite);
43 
44  for (UINT i = 0; i < textureSRV.size(); i++)
45  {
46  SAFE_RELEASE(textureSRV.at(i));
47  }
48 
49  SAFE_RELEASE(pd3dDevice);
50  }
51 };
ID3DX10Sprite * pSprite
Definition: DeviceObject.h:9
Definition: Logger.h:5
ID3D10Device * pd3dDevice
Definition: DeviceObject.h:8
std::vector< ID3D10ShaderResourceView * > textureSRV
Definition: DeviceObject.h:12
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
void Destroy()
Definition: DeviceObject.h:40
ID3D10ShaderResourceView * GetTextureSRV(Logger *prmLogger, std::string pathAndFilename)
Definition: DeviceObject.h:15
std::vector< std::string > files
Definition: DeviceObject.h:13