TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_texture_manager.hpp
1 
10 #ifndef TurtleBrains_TextureManager_hpp
11 #define TurtleBrains_TextureManager_hpp
12 
13 #include <turtle_brains/core/tb_noncopyable.hpp>
14 #include <turtle_brains/core/tb_string.hpp>
15 #include <turtle_brains/core/tb_types.hpp>
16 #include <turtle_brains/core/tb_resource_handle.hpp>
17 
18 #include <cstddef>
19 
20 namespace TurtleBrains::Graphics
21 {
22  namespace Implementation { class TextureManagerCreator; class TextureHandleSaver {}; }
23 
24 
28  using TexelSpace = float;
29 
35 
41 
46 
52  extern const TextureHandle& kBlankTexture;
53 
59  {
60  ColorARGB8,
61 
62  FloatRGB10A2,
63  FloatR11G11B10,
64  FloatARGB16, // <64 bits per pixel, colored texture with alpha, red, green, blue, channels each having 16 bit floats.
65 
66  Depth16,
67  Depth24,
68 
69  Depth24_Stencil8,
70 
71  InvalidFormat,
72  };
73 
78  {
79  Repeat,
82  };
83 
85  {
86  Closest,
87  Linear,
88  DepthCompare,
89  };
90 
106  {
107  public:
116  static void PreMultiplyAlpha(tbCore::byte* imageData, const PixelSpace& imageWidth, const PixelSpace& imageHeight);
117 
127  TextureHandle CreateTextureFromFile(const String& filename, const bool mipmapped = true);
128 
140  TextureHandle CreateTextureFromFileData(const unsigned char* fileDataInMemory, const tbCore::uint32 fileSizeInBytes, const bool mipmapped = true);
141 
161  TextureHandle CreateTextureFromPixelData(const PixelSpace& textureWidth, const PixelSpace& textureHeight,
162  const TextureFormat& format, const unsigned char* pixelData, const bool mipmapped = true);
163 
177  TextureHandle CreateTextureEmpty(const PixelSpace& textureWidth, const PixelSpace& textureHeight,
178  const TextureFormat& format = TextureFormat::ColorARGB8);
179 
190 
198  void DestroyTexture(const TextureHandle& textureHandle);
199 
207  void BindTexture(const TextureHandle& textureHandle);
208 
214  void BindTexture(const TextureHandle& textureHandle, tbCore::uint8 textureUnit);
215 
221  PixelSpace GetTextureWidth(const TextureHandle& textureHandle) const;
222 
228  PixelSpace GetTextureHeight(const TextureHandle& textureHandle) const;
229 
240  void SetTextureWrapMode(const TextureHandle& textureHandle, TextureWrapMode wrapMode);
241 
245  void SetTextureWrapMode(const TextureHandle& textureHandle, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV);
246 
250  void SetTextureFiltering(const TextureHandle& textureHandle, TextureFilter filter);
251 
256 
260  void Unstable_RunSoftwareShader(const TextureHandle& textureHandle, std::function<tbCore::uint32(PixelSpace x, PixelSpace y, tbCore::uint32)> shader);
261 
268 
275 
281 
282  private:
287  explicit TextureManager(void);
288 
293  ~TextureManager(void);
294 
295  friend class Implementation::TextureManagerCreator;
296  };
297 
303 
304 }; /* namespace TurtleBrains::Graphics */
305 
307 
308 #endif /* TurtleBrains_TextureManager_hpp */
Definition: tb_noncopyable.hpp:21
Definition: tb_texture_manager.hpp:106
TextureHandle CreateTextureFromFile(const String &filename, const bool mipmapped=true)
PixelSpace GetTextureWidth(const TextureHandle &textureHandle) const
TextureHandle CreateTextureEmpty(const PixelSpace &textureWidth, const PixelSpace &textureHeight, const TextureFormat &format=TextureFormat::ColorARGB8)
TextureHandle CreateTextureFromFileData(const unsigned char *fileDataInMemory, const tbCore::uint32 fileSizeInBytes, const bool mipmapped=true)
void SetTextureWrapMode(const TextureHandle &textureHandle, TextureWrapMode wrapMode)
void BindTexture(const TextureHandle &textureHandle, tbCore::uint8 textureUnit)
PixelSpace GetTextureHeight(const TextureHandle &textureHandle) const
TextureHandle CreateTextureReference(const TextureHandle &textureHandle)
TextureHandle CreateTextureFromPixelData(const PixelSpace &textureWidth, const PixelSpace &textureHeight, const TextureFormat &format, const unsigned char *pixelData, const bool mipmapped=true)
tbCore::uint64 ComputeMemoryUsage(void) const
static void PreMultiplyAlpha(tbCore::byte *imageData, const PixelSpace &imageWidth, const PixelSpace &imageHeight)
void SetTextureWrapMode(const TextureHandle &textureHandle, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV)
void BindTexture(const TextureHandle &textureHandle)
void DestroyTexture(const TextureHandle &textureHandle)
std::uint8_t uint8
Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
Definition: tb_types.hpp:22
std::uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.hpp:25
std::uint8_t byte
Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
Definition: tb_types.hpp:23
std::uint32_t uint32
Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1).
Definition: tb_types.hpp:27
std::uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:29
Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring th...
const TextureHandle & kBlankTexture
TextureFilter
Definition: tb_texture_manager.hpp:85
@ DepthCompare
Depth compare with <=, used for ShadowMaps, may not actually be a filter as much as a state.
TextureHandle InvalidTexture(void)
TextureWrapMode
Definition: tb_texture_manager.hpp:78
@ MirroredRepeat
Mirrored repeat, ignoring the integral part of the U or V coordinate only when even.
@ Repeat
Set the texture to repeat, ignoring the integral part of the U or V coordinate.
@ ClampToEdge
ClampToEdge wrap mode will keep the U or V coordinate within 0 to 1 top stop at texture edge.
float TexelSpace
Definition: tb_texture_manager.hpp:28
TextureFormat
Definition: tb_texture_manager.hpp:59
@ ColorARGB8
32 bits per pixel, colored texture with alpha, red, green, blue channels each having 8 bits.
@ Depth16
16 bits per pixel, depth texture.
@ Depth24
24 bits per pixel, depth texture.
TextureManager & theTextureManager
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:34