]> git.localhorst.tv Git - blobs.git/blob - src/graphics/TextureBase.hpp
remote outdated TODO
[blobs.git] / src / graphics / TextureBase.hpp
1 #ifndef BLOBS_GRAPHICS_TEXTUREBASE_HPP_
2 #define BLOBS_GRAPHICS_TEXTUREBASE_HPP_
3
4 #include <GL/glew.h>
5
6
7 namespace blobs {
8 namespace graphics {
9
10 template<GLenum TARGET, GLsizei COUNT = 1>
11 class TextureBase {
12
13 public:
14         TextureBase();
15         ~TextureBase();
16
17         TextureBase(TextureBase &&other) noexcept;
18         TextureBase &operator =(TextureBase &&) noexcept;
19
20         TextureBase(const TextureBase &) = delete;
21         TextureBase &operator =(const TextureBase &) = delete;
22
23 public:
24         void Bind(GLsizei which = 0) noexcept {
25                 glBindTexture(TARGET, handle[which]);
26         }
27
28         void FilterNearest() noexcept {
29                 glTexParameteri(TARGET, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
30                 glTexParameteri(TARGET, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
31         }
32         void FilterLinear() noexcept {
33                 glTexParameteri(TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
34                 glTexParameteri(TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
35         }
36         void FilterTrilinear() noexcept {
37                 glTexParameteri(TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
38                 glTexParameteri(TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
39                 glGenerateMipmap(TARGET);
40         }
41
42         void WrapEdge() noexcept {
43                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
44                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
45                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
46         }
47         void WrapBorder() noexcept {
48                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
49                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
50                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
51         }
52         void WrapRepeat() noexcept {
53                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_R, GL_REPEAT);
54                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_S, GL_REPEAT);
55                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_T, GL_REPEAT);
56         }
57         void WrapMirror() noexcept {
58                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_R, GL_MIRRORED_REPEAT);
59                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
60                 glTexParameteri(TARGET, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
61         }
62
63 private:
64         GLuint handle[COUNT];
65
66 };
67
68 }
69 }
70
71 #endif