SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
DirectX11Texture.hpp
Go to the documentation of this file.
1#ifndef _DIRECTX11_TEXTURE_H_
2#define _DIRECTX11_TEXTURE_H_
3
4#include <Runtime/Texture.hpp>
5#include <d3d11.h>
6#include <wrl/client.h>
7
8namespace Sleak {
9namespace RenderEngine {
10
11/// D3D11 2D texture, loadable from disk or an in-memory pixel buffer.
13public:
14 DirectX11Texture(ID3D11Device* device);
16
17 // Load texture from raw data
18 bool LoadFromMemory(const void* data, uint32_t width, uint32_t height, TextureFormat format) override;
19
20 bool LoadFromFile(const std::string& filePath) override;
21
22 // Bind the texture to a specific slot
23 void Bind(uint32_t slot = 0) const override;
24
25 // Unbind the texture
26 void Unbind() const override;
27
28 // Set texture filter mode
29 void SetFilter(TextureFilter filter) override;
30
31 // Set texture wrap mode
32 void SetWrapMode(TextureWrapMode wrapMode) override;
33
34 void SetLodBias(float bias) override;
35 float GetLodBias() const override { return m_lodBias; }
36
37 // Get texture width
38 uint32_t GetWidth() const override;
39
40 // Get texture height
41 uint32_t GetHeight() const override;
42
43 // Get texture format
44 TextureFormat GetFormat() const override;
45
46 // Get texture type
47 TextureType GetType() const override;
48
49 uint64_t GetImGuiTextureID() const override {
50 return reinterpret_cast<uint64_t>(m_shaderResourceView.Get());
51 }
52
53private:
54 Microsoft::WRL::ComPtr<ID3D11Device> m_device;
55 Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_deviceContext;
56 Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture;
57 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shaderResourceView;
58 Microsoft::WRL::ComPtr<ID3D11SamplerState> m_samplerState;
59 uint32_t m_width;
60 uint32_t m_height;
61 TextureFormat m_format;
62 TextureType m_type;
63 TextureFilter m_filter;
64 TextureWrapMode m_wrapMode;
65 float m_lodBias = 0.0f;
66
67 /// (Re)creates the sampler state from the current filter/wrap/LOD-bias settings.
68 void CreateSamplerState();
69 /// Maps the engine's TextureFormat to the matching DXGI_FORMAT.
70 DXGI_FORMAT GetDXGIFormat(TextureFormat format) const;
71 /// Maps the engine's TextureFilter to the matching D3D11_FILTER.
72 D3D11_FILTER GetD3D11Filter(TextureFilter filter) const;
73 /// Maps the engine's TextureWrapMode to the matching D3D11_TEXTURE_ADDRESS_MODE.
74 D3D11_TEXTURE_ADDRESS_MODE GetD3D11WrapMode(TextureWrapMode wrapMode) const;
75};
76
77} // namespace RenderEngine
78} // namespace Sleak
79
80#endif // _DIRECTX11_TEXTURE_H_
int width
int height
void SetWrapMode(TextureWrapMode wrapMode) override
TextureType GetType() const override
bool LoadFromMemory(const void *data, uint32_t width, uint32_t height, TextureFormat format) override
Uploads raw pixel data as the texture's contents, replacing any existing image.
void Bind(uint32_t slot=0) const override
uint64_t GetImGuiTextureID() const override
void SetFilter(TextureFilter filter) override
bool LoadFromFile(const std::string &filePath) override
Loads and uploads an image file from disk.
TextureFormat GetFormat() const override
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