-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.cpp
More file actions
44 lines (37 loc) · 1.17 KB
/
Texture.cpp
File metadata and controls
44 lines (37 loc) · 1.17 KB
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
39
40
41
42
43
44
#include "Texture.h"
#include <iostream>
#include <DirectXTex.h>
#include "GraphicsEngine.h"
Texture::Texture(const wchar_t* fullPath) : AResource(fullPath)
{
DirectX::ScratchImage imageData;
HRESULT res = DirectX::LoadFromWICFile(fullPath, DirectX::WIC_FLAGS_NONE, NULL, imageData);
if (SUCCEEDED(res)) {
ID3D11Device* dxDevice = GraphicsEngine::get()->getDirect3DDevice();
res = DirectX::CreateTexture(dxDevice, imageData.GetImages(),
imageData.GetImageCount(), imageData.GetMetadata(), &this->myTexture);
D3D11_SHADER_RESOURCE_VIEW_DESC desc = {};
desc.Format = imageData.GetMetadata().format;
desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
desc.Texture2D.MipLevels = (UINT)imageData.GetMetadata().mipLevels;
desc.Texture2D.MostDetailedMip = 0;
dxDevice->CreateShaderResourceView(this->myTexture, &desc, &this->shaderResView);
}
else {
std::cout << "Texture not created successfully. \n";
}
}
Texture::~Texture()
{
AResource::~AResource();
this->shaderResView->Release();
this->myTexture->Release();
}
AResource::String Texture::getPath()
{
return this->fullPath;
}
ID3D11ShaderResourceView* Texture::getShaderResource()
{
return this->shaderResView;
}