SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
DirectX11CubemapTexture.hpp
Go to the documentation of this file.
1#ifndef DIRECTX11CUBEMAPTEXTURE_HPP_
2#define DIRECTX11CUBEMAPTEXTURE_HPP_
3
4#include <Core/OSDef.hpp>
5#include <Runtime/Texture.hpp>
6#include <d3d11.h>
7#include <wrl/client.h>
8#include <array>
9#include <cstdint>
10#include <string>
11#include <vector>
12
13namespace Sleak {
14namespace RenderEngine {
15
16/// D3D11 cubemap texture, loadable from six face images or a single equirectangular panorama.
18public:
19 DirectX11CubemapTexture(ID3D11Device* device);
21
22 /// Loads and uploads 6 face images: +X, -X, +Y, -Y, +Z, -Z.
23 bool LoadCubemap(const std::array<std::string, 6>& facePaths);
24 /// Loads a single equirectangular panorama and resamples it into 6 cube faces.
25 bool LoadEquirectangular(const std::string& path, uint32_t faceSize = 512);
26
27 // Texture interface
28 /// Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
29 bool LoadFromMemory(const void* data, uint32_t width, uint32_t height,
30 TextureFormat format) override;
31 /// Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
32 bool LoadFromFile(const std::string& filePath) override;
33
34 void Bind(uint32_t slot = 0) const override;
35 void Unbind() const override;
36
37 void SetFilter(TextureFilter filter) override;
38 void SetWrapMode(TextureWrapMode wrapMode) override;
39
40 uint32_t GetWidth() const override { return m_width; }
41 uint32_t GetHeight() const override { return m_height; }
42 TextureFormat GetFormat() const override { return TextureFormat::RGBA8; }
43 TextureType GetType() const override { return TextureType::TextureCube; }
44
45private:
46 /// Builds the cubemap texture array and shader resource view from decoded face pixels.
47 bool CreateCubemapFromFaces(const std::vector<unsigned char*>& faceData,
48 uint32_t faceSize);
49 void CreateSamplerState();
50
51 Microsoft::WRL::ComPtr<ID3D11Device> m_device;
52 Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_deviceContext;
53 Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture;
54 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shaderResourceView;
55 Microsoft::WRL::ComPtr<ID3D11SamplerState> m_samplerState;
56
57 uint32_t m_width = 0;
58 uint32_t m_height = 0;
59};
60
61} // namespace RenderEngine
62} // namespace Sleak
63
64#endif // DIRECTX11CUBEMAPTEXTURE_HPP_
int width
int height
bool LoadEquirectangular(const std::string &path, uint32_t faceSize=512)
Loads a single equirectangular panorama and resamples it into 6 cube faces.
bool LoadFromMemory(const void *data, uint32_t width, uint32_t height, TextureFormat format) override
Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
void Bind(uint32_t slot=0) const override
void SetFilter(TextureFilter filter) override
void SetWrapMode(TextureWrapMode wrapMode) override
bool LoadFromFile(const std::string &filePath) override
Unused for cubemaps; load via LoadCubemap/LoadEquirectangular instead.
bool LoadCubemap(const std::array< std::string, 6 > &facePaths)
Loads and uploads 6 face images: +X, -X, +Y, -Y, +Z, -Z.
TextureFormat
Definition Texture.hpp:10
TextureFilter
Definition Texture.hpp:28
TextureType
Definition Texture.hpp:20
TextureWrapMode
Definition Texture.hpp:43
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10