-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoxaNovusTexture.cpp
More file actions
42 lines (37 loc) · 1.31 KB
/
VoxaNovusTexture.cpp
File metadata and controls
42 lines (37 loc) · 1.31 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
#include "VoxaNovusTexture.h"
#include "VoxaNovusSurface.h"
#include "VoxaNovusGfxExceptionMacros.h"
namespace wrl = Microsoft::WRL;
Texture::Texture(Graphics& gfx, const Surface& s) {
INFOMAN(gfx);
D3D11_TEXTURE2D_DESC textureDesc = {};
textureDesc.Width = s.GetWidth();
textureDesc.Height = s.GetHeight();
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = s.GetBufferPtr();
sd.SysMemPitch = s.GetWidth() * sizeof(Surface::Color);
wrl::ComPtr<ID3D11Texture2D> pTexture;
GFX_THROW_INFO(GetDevice(gfx)->CreateTexture2D(
&textureDesc, &sd, &pTexture
));
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
GFX_THROW_INFO(GetDevice(gfx)->CreateShaderResourceView(
pTexture.Get(), &srvDesc, &pTextureView
));
}
void Texture::Bind(Graphics& gfx) noexcept {
GetContext(gfx)->PSSetShaderResources(0u, 1u, pTextureView.GetAddressOf());
}