TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_texture_manager.hpp
1 
10 #ifndef _TurtleBraines_TextureManager_hpp
11 #define _TurtleBraines_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 tbImplementation { class TextureManagerCreator; class TextureHandleSaver { }; }
21 
22 namespace TurtleBrains
23 {
24  namespace Graphics
25  {
26 
30  typedef float TexelSpace;
31 
37 
43 
47  TextureHandle InvalidTexture(void);
48 
54  extern const TextureHandle& kBlankTexture;
55 
60  enum class TextureFormat
61  {
62  ColorARGB8,
63  Depth16,
64  Depth24,
65  };
66 
71  {
75  };
76 
92  {
93  public:
102  static void PreMultiplyAlpha(tbCore::byte* imageData, const PixelSpace& imageWidth, const PixelSpace& imageHeight);
103 
112  TextureHandle CreateTextureFromFile(const tbCore::tbString& filename);
113 
124  TextureHandle CreateTextureFromFileData(const unsigned char* fileDataInMemory, const size_t& fileSizeInBytes);
125 
138  TextureHandle CreateTextureFromPixelData(const unsigned char* pixelDataARGB, const PixelSpace& textureWidth, const PixelSpace& textureHeight);
139 
150  TextureHandle CreateTextureEmpty(const PixelSpace& textureWidth, const PixelSpace& textureHeight,
151  const TextureFormat& format = TextureFormat::ColorARGB8);
152 
162  TextureHandle CreateTextureReference(const TextureHandle& textureHandle);
163 
171  void DestroyTexture(const TextureHandle& textureHandle);
172 
180  void BindTexture(const TextureHandle& textureHandle);
181 
187  void BindTexture(const TextureHandle& textureHandle, tbCore::uint8 textureUnit);
188 
194  PixelSpace GetTextureWidth(const TextureHandle& textureHandle) const;
195 
201  PixelSpace GetTextureHeight(const TextureHandle& textureHandle) const;
202 
213  void SetTextureWrapMode(const TextureHandle& textureHandle, TextureWrapMode wrapMode);
214 
218  void SetTextureWrapMode(const TextureHandle& textureHandle, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV);
219 
226 
232  void CreateGraphicsContext(void);
233 
238  void DestroyGraphicsContext(void);
239 
240  private:
245  explicit TextureManager(void);
246 
251  ~TextureManager(void);
252 
253  friend class tbImplementation::TextureManagerCreator;
254  };
255 
261 
262  }; /* namespace Graphics */
263 }; /* namespace TurtleBrains */
264 
266 
267 #endif /* _TurtleBraines_TextureManager_hpp */
PixelSpace GetTextureWidth(const TextureHandle &textureHandle) const
TextureHandle CreateTextureReference(const TextureHandle &textureHandle)
Definition: tb_texture_manager.hpp:91
ClampToEdge wrap mode will keep the U or V coordinate within 0 to 1 top stop at texture edge...
Definition: tb_texture_manager.hpp:74
Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring th...
TextureHandle CreateTextureFromFile(const tbCore::tbString &filename)
TextureFormat
Definition: tb_texture_manager.hpp:60
32 bits per pixel, colored texture with alpha, red, green, blue channels each having 8 bits...
TurtleBrains::Core::ResourceHandle< tbImplementation::TextureHandleSaver > TextureHandle
Definition: tb_texture_manager.hpp:42
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.hpp:26
void BindTexture(const TextureHandle &textureHandle)
Definition: tb_noncopyable.hpp:22
static void PreMultiplyAlpha(tbCore::byte *imageData, const PixelSpace &imageWidth, const PixelSpace &imageHeight)
16 bits per pixel, depth texture.
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
TextureManager & theTextureManager
TextureHandle InvalidTexture(void)
TextureHandle CreateTextureFromPixelData(const unsigned char *pixelDataARGB, const PixelSpace &textureWidth, const PixelSpace &textureHeight)
uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:30
TextureHandle CreateTextureFromFileData(const unsigned char *fileDataInMemory, const size_t &fileSizeInBytes)
void DestroyTexture(const TextureHandle &textureHandle)
uint8 byte
Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255.
Definition: tb_types.hpp:24
TextureHandle CreateTextureEmpty(const PixelSpace &textureWidth, const PixelSpace &textureHeight, const TextureFormat &format=TextureFormat::ColorARGB8)
uint8_t uint8
Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
Definition: tb_types.hpp:23
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
PixelSpace GetTextureHeight(const TextureHandle &textureHandle) const
Mirrored repeat, ignoring the integral part of the U or V coordinate only when even.
Definition: tb_texture_manager.hpp:73
24 bits per pixel, depth texture.
TextureWrapMode
Definition: tb_texture_manager.hpp:70
Definition: tb_texture_manager.hpp:20
void SetTextureWrapMode(const TextureHandle &textureHandle, TextureWrapMode wrapMode)
const TextureHandle & kBlankTexture
float TexelSpace
Definition: tb_texture_manager.hpp:30
Set the texture to repeat, ignoring the integral part of the U or V coordinate.
Definition: tb_texture_manager.hpp:72
std::string tbString
Definition: tb_string.hpp:335
Definition: tb_application_dialog.hpp:19
tbCore::uint64 ComputeMemoryUsage(void) const