SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
DirectX12CubemapTexture.hpp
Go to the documentation of this file.
1
#ifndef DIRECTX12CUBEMAPTEXTURE_HPP_
2
#define DIRECTX12CUBEMAPTEXTURE_HPP_
3
4
#include <
Core/OSDef.hpp
>
5
6
#ifdef PLATFORM_WIN
7
8
#include <
Runtime/Texture.hpp
>
9
#include <d3d12.h>
10
#include <wrl/client.h>
11
#include <array>
12
#include <string>
13
#include <vector>
14
15
namespace
Sleak
{
16
namespace
RenderEngine
{
17
class
DirectX12UploadContext
;
18
19
/// D3D12 cubemap texture, loadable from six face images or a single equirectangular panorama.
20
class
ENGINE_API DirectX12CubemapTexture :
public
::Sleak::Texture {
21
public
:
22
/// Uploads go through the shared uploader when given, else they block.
23
DirectX12CubemapTexture(ID3D12Device* device, ID3D12CommandQueue* commandQueue,
24
DirectX12UploadContext* uploader =
nullptr
);
25
~DirectX12CubemapTexture()
override
;
26
27
/// Loads and uploads 6 face images: +X, -X, +Y, -Y, +Z, -Z.
28
bool
LoadCubemap(
const
std::array<std::string, 6>& facePaths);
29
/// Loads a single equirectangular panorama and resamples it into 6 cube faces.
30
bool
LoadEquirectangular(
const
std::string& path, uint32_t faceSize = 512);
31
32
// Texture interface
33
/// Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
34
bool
LoadFromMemory(
const
void
* data, uint32_t
width
, uint32_t
height
,
35
TextureFormat format)
override
;
36
/// Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
37
bool
LoadFromFile(
const
std::string& filePath)
override
;
38
39
void
Bind(uint32_t slot = 0)
const override
;
40
void
Unbind()
const override
;
41
42
void
SetFilter(TextureFilter filter)
override
;
43
void
SetWrapMode(TextureWrapMode wrapMode)
override
;
44
45
uint32_t GetWidth()
const override
{
return
m_width; }
46
uint32_t GetHeight()
const override
{
return
m_height; }
47
TextureFormat
GetFormat()
const override
{
return
TextureFormat::RGBA8; }
48
TextureType
GetType()
const override
{
return
TextureType::TextureCube; }
49
50
ID3D12Resource* GetResource()
const
{
return
m_texture.Get(); }
51
52
/// Binds this cubemap's SRV table at the given root parameter for a draw.
53
void
BindToCommandList(ID3D12GraphicsCommandList* cmdList,
54
UINT rootParameterIndex)
const
;
55
56
// Set shared SRV heap slot (called by renderer during creation)
57
void
SetSharedSrvGPUHandle(D3D12_GPU_DESCRIPTOR_HANDLE handle) {
58
m_srvGpuHandle = handle;
59
m_usesSharedHeap =
true
;
60
}
61
// Create SRV directly into an externally-provided CPU handle (cube SRV)
62
void
CreateSRVIntoHandle(D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle);
63
64
private
:
65
/// Builds the cubemap texture array and shader resource view from decoded face pixels.
66
bool
CreateCubemapFromFaces(
const
std::vector<unsigned char*>& faceData,
67
uint32_t faceSize);
68
69
ID3D12Device* m_device =
nullptr
;
70
ID3D12CommandQueue* m_commandQueue =
nullptr
;
71
DirectX12UploadContext* m_uploader =
nullptr
;
72
73
Microsoft::WRL::ComPtr<ID3D12Resource> m_texture;
74
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> m_srvHeap;
// fallback
75
D3D12_GPU_DESCRIPTOR_HANDLE m_srvGpuHandle = {};
76
bool
m_usesSharedHeap =
false
;
77
78
uint32_t m_width = 0;
79
uint32_t m_height = 0;
80
};
81
82
}
// namespace RenderEngine
83
}
// namespace Sleak
84
85
#endif
// PLATFORM_WIN
86
87
#endif
// DIRECTX12CUBEMAPTEXTURE_HPP_
width
int width
Definition
Application.cpp:40
height
int height
Definition
Application.cpp:41
OSDef.hpp
Texture.hpp
Sleak::RenderEngine::DirectX12UploadContext
Definition
DirectX12UploadContext.hpp:15
Sleak::TextureFormat
TextureFormat
Definition
Texture.hpp:10
Sleak::TextureType
TextureType
Definition
Texture.hpp:20
Sleak::RenderEngine
Backend-facing rendering layer shared by the four graphics backends.
Definition
Application.hpp:60
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
include
private
Graphics
DirectX12
DirectX12CubemapTexture.hpp
Generated on
for SleakEngine by
1.18.0