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