SleakEngine 1.0.0
C++23 multi-backend game engine
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
15namespace Sleak {
16namespace RenderEngine {
17
18/// D3D12 cubemap texture, loadable from six face images or a single equirectangular panorama.
19class ENGINE_API DirectX12CubemapTexture : public ::Sleak::Texture {
20public:
21 DirectX12CubemapTexture(ID3D12Device* device,
22 ID3D12CommandQueue* commandQueue);
23 ~DirectX12CubemapTexture() override;
24
25 /// Loads and uploads 6 face images: +X, -X, +Y, -Y, +Z, -Z.
26 bool LoadCubemap(const std::array<std::string, 6>& facePaths);
27 /// Loads a single equirectangular panorama and resamples it into 6 cube faces.
28 bool LoadEquirectangular(const std::string& path, uint32_t faceSize = 512);
29
30 // Texture interface
31 /// Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
32 bool LoadFromMemory(const void* data, uint32_t width, uint32_t height,
33 TextureFormat format) override;
34 /// Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
35 bool LoadFromFile(const std::string& filePath) override;
36
37 void Bind(uint32_t slot = 0) const override;
38 void Unbind() const override;
39
40 void SetFilter(TextureFilter filter) override;
41 void SetWrapMode(TextureWrapMode wrapMode) override;
42
43 uint32_t GetWidth() const override { return m_width; }
44 uint32_t GetHeight() const override { return m_height; }
45 TextureFormat GetFormat() const override { return TextureFormat::RGBA8; }
46 TextureType GetType() const override { return TextureType::TextureCube; }
47
48 ID3D12Resource* GetResource() const { return m_texture.Get(); }
49
50 /// Binds this cubemap's SRV table at the given root parameter for a draw.
51 void BindToCommandList(ID3D12GraphicsCommandList* cmdList,
52 UINT rootParameterIndex) const;
53
54 // Set shared SRV heap slot (called by renderer during creation)
55 void SetSharedSrvGPUHandle(D3D12_GPU_DESCRIPTOR_HANDLE handle) { m_srvGpuHandle = handle; m_usesSharedHeap = true; }
56 // Create SRV directly into an externally-provided CPU handle (cube SRV)
57 void CreateSRVIntoHandle(D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle);
58
59private:
60 /// Builds the cubemap texture array and shader resource view from decoded face pixels.
61 bool CreateCubemapFromFaces(const std::vector<unsigned char*>& faceData,
62 uint32_t faceSize);
63 /// Blocks until the upload-heap copy to the GPU-resident cubemap resource completes.
64 void WaitForUpload();
65
66 ID3D12Device* m_device = nullptr;
67 ID3D12CommandQueue* m_commandQueue = nullptr;
68
69 Microsoft::WRL::ComPtr<ID3D12Resource> m_texture;
70 Microsoft::WRL::ComPtr<ID3D12Resource> m_uploadBuffer;
71 Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> m_srvHeap; // fallback
72 D3D12_GPU_DESCRIPTOR_HANDLE m_srvGpuHandle = {};
73 bool m_usesSharedHeap = false;
74
75 uint32_t m_width = 0;
76 uint32_t m_height = 0;
77};
78
79} // namespace RenderEngine
80} // namespace Sleak
81
82#endif // PLATFORM_WIN
83
84#endif // DIRECTX12CUBEMAPTEXTURE_HPP_
int width
int height
TextureFormat
Definition Texture.hpp:10
TextureType
Definition Texture.hpp:20
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10