SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Texture.hpp
Go to the documentation of this file.
1#ifndef _TEXTURE_H_
2#define _TEXTURE_H_
3
4#include <string>
5#include <cstdint>
6
7namespace Sleak {
8/// Pixel layout a Texture's data is stored/uploaded in.
9/// @ingroup rendering
17
18/// Dimensionality/layout a Texture represents on the GPU.
19/// @ingroup rendering
25
26/// Sampling quality, from point sampling up through anisotropic filtering.
27/// @ingroup rendering
28enum class TextureFilter {
29 Nearest, // Point / no filtering
30 Bilinear, // Linear min/mag, nearest mip
31 Trilinear, // Linear min/mag/mip (best quality without anisotropy)
32 Anisotropic2x, // Anisotropic 2x
33 Anisotropic4x, // Anisotropic 4x
34 Anisotropic8x, // Anisotropic 8x
35 Anisotropic16x, // Anisotropic 16x (highest quality)
36 // Legacy aliases kept for backward compatibility
39};
40
41/// How UV coordinates outside [0,1] are resolved when sampling.
42/// @ingroup rendering
50
51/// Backend-agnostic GPU texture interface; each renderer backend supplies its own implementation.
52///
53/// You rarely construct one directly. Materials create and own their
54/// textures when you call a `Set...Texture(path)` setter, ModelLoader
55/// creates them while importing, and Sleak::UI::CreateTextureFromPixels
56/// makes one from raw pixel data for UI use. The concrete type is whatever
57/// the active backend provides, which is why every method here is virtual.
58///
59/// Filtering and wrap mode are set per texture, not per material, so
60/// change them on the object a material hands back. Reach for
61/// TextureFilter::Nearest on pixel art and atlases where bleeding between
62/// neighboring tiles would show, and an anisotropic mode on ground planes
63/// viewed at glancing angles.
64///
65/// @code{.cpp}
66/// // Load through a material, then adjust sampling on the result
67/// material->SetDiffuseTexture("assets/textures/atlas.png");
68///
69/// if (Sleak::Texture* tex = material->GetDiffuseTexture()) {
70/// tex->SetFilter(Sleak::TextureFilter::Nearest);
71/// tex->SetWrapMode(Sleak::TextureWrapMode::ClampToEdge);
72/// SLEAK_INFO("Atlas is {}x{}", tex->GetWidth(), tex->GetHeight());
73/// }
74/// @endcode
75///
76/// @see Material, TextureFilter, TextureWrapMode, TextureFormat, ModelLoader
77/// @ingroup rendering
78class Texture {
79public:
80 virtual ~Texture() = default;
81
82 /// Uploads raw pixel data as the texture's contents, replacing any existing image.
83 virtual bool LoadFromMemory(const void* data, uint32_t width, uint32_t height, TextureFormat format) = 0;
84
85 /// Loads and uploads an image file from disk.
86 virtual bool LoadFromFile(const std::string& filePath) = 0;
87
88 virtual void Bind(uint32_t slot = 0) const = 0;
89
90 virtual void Unbind() const = 0;
91
92 virtual void SetFilter(TextureFilter filter) = 0;
93
94 virtual void SetWrapMode(TextureWrapMode wrapMode) = 0;
95
96 virtual uint32_t GetWidth() const = 0;
97
98 virtual uint32_t GetHeight() const = 0;
99
100 virtual TextureFormat GetFormat() const = 0;
101
102 virtual TextureType GetType() const = 0;
103
104 virtual void SetLodBias(float bias) {}
105 virtual float GetLodBias() const { return 0.0f; }
106
107 virtual uint64_t GetImGuiTextureID() const { return 0; }
108};
109
110} // namespace Sleak
111
112#endif
int width
int height
virtual uint32_t GetHeight() const =0
virtual TextureType GetType() const =0
virtual bool LoadFromMemory(const void *data, uint32_t width, uint32_t height, TextureFormat format)=0
Uploads raw pixel data as the texture's contents, replacing any existing image.
virtual ~Texture()=default
virtual uint32_t GetWidth() const =0
virtual uint64_t GetImGuiTextureID() const
Definition Texture.hpp:107
virtual void Bind(uint32_t slot=0) const =0
virtual void Unbind() const =0
virtual TextureFormat GetFormat() const =0
virtual void SetLodBias(float bias)
Definition Texture.hpp:104
virtual void SetFilter(TextureFilter filter)=0
virtual void SetWrapMode(TextureWrapMode wrapMode)=0
virtual bool LoadFromFile(const std::string &filePath)=0
Loads and uploads an image file from disk.
virtual float GetLodBias() const
Definition Texture.hpp:105
TextureFormat
Definition Texture.hpp:10
TextureFilter
Definition Texture.hpp:28
TextureType
Definition Texture.hpp:20
TextureWrapMode
Definition Texture.hpp:43
Root namespace for everything the engine exposes.
Definition Camera.hpp:10