GlTexture.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "gl.h"
5 
6 namespace iv
7 {
8 
9 class RenderTarget;
10 
11 enum class GlMagFiltering
12 {
13  Nearest = GL_NEAREST,
14  Linear = GL_LINEAR,
15 };
16 
17 enum class GlMinFiltering
18 {
19  Nearest = GL_NEAREST,
20  Linear = GL_LINEAR,
21  NearestMipmapNearest = GL_NEAREST_MIPMAP_NEAREST,
22  LinearMipmapNearest = GL_LINEAR_MIPMAP_NEAREST,
23  NearestMipmapLinear = GL_NEAREST_MIPMAP_LINEAR,
24  LinearMipmapLinear = GL_LINEAR_MIPMAP_LINEAR,
25 };
26 
27 enum class PixelFormat
28 {
29  RGBA, // 8R 8G 8B 8A, in sRGB space
30  BGRA, // 8B 8G 8R 8A, in sRGB space
31 };
32 
33 enum class ColorSpace
34 {
35  sRGB,
36  Linear,
37 };
38 
46 class GlTexture
47 {
48 public:
49  GlTexture();
50 
51  //------------------------- loading ------------------------------
56  void CreateTexture( Context const * logger, RenderTarget * target, int2 size, GlMinFiltering, GlMagFiltering, bool repeat, PixelFormat storage_format, ColorSpace color_space );
57 
61  void LoadData( Context const * logger, RenderTarget * target, uint8_t * values, size_t values_size, PixelFormat data_format );
62 
65  void DestroyTexture( Context const * logger, RenderTarget * target );
66 
70  void DropTexture( Context const * logger, RenderTarget * target );
71 
72  //------------------------- getters --------------------------------
73  bool allocated() const;
74  int2 size() const;
75  GLuint texture_id() const;
76  ColorSpace gpu_color_space() const;
77 
78 private:
79  GLuint _texture_id;
80  int2 _size;
81  bool _mipmaps;
82  PixelFormat _format;
83  ColorSpace _color_space;
84 };
85 
86 template<>
87 struct StringIO< PixelFormat > : public StringIO_Table< PixelFormat >
88 {
89  static const ValuesType Values;
90 };
91 
92 template<>
93 struct StringIO< ColorSpace > : public StringIO_Table< ColorSpace >
94 {
95  static const ValuesType Values;
96 };
97 
98 }