| 1 | 1 | new file mode 100644 | 
| ... | ... | @@ -0,0 +1,107 @@ | 
| 1 | +#ifndef GLTEXTURE3D_HPP_ | |
| 2 | +#define GLTEXTURE3D_HPP_ | |
| 3 | + | |
| 4 | + | |
| 5 | +#include <string> | |
| 6 | +#include <utility> | |
| 7 | + | |
| 8 | +#include <gltexturend.hpp> | |
| 9 | + | |
| 10 | + | |
| 11 | +/// Class | |
| 12 | + | |
| 13 | +class GLTexture3D : public GLTextureND<3> | |
| 14 | +{ | |
| 15 | +public: | |
| 16 | + | |
| 17 | + /// Special member functions | |
| 18 | + | |
| 19 | + explicit GLTexture3D( | |
| 20 | + std::string object_label, | |
| 21 | + Size size, | |
| 22 | + GLenum internal_format = GL_RGBA8, | |
| 23 | + GLenum wrap = GL_CLAMP_TO_EDGE, | |
| 24 | + GLenum min_filter = GL_LINEAR, | |
| 25 | + GLenum mag_filter = GL_LINEAR | |
| 26 | + ); | |
| 27 | + | |
| 28 | + /// Core | |
| 29 | + | |
| 30 | + GLTexture3D static const & empty(); | |
| 31 | + | |
| 32 | +private: | |
| 33 | + | |
| 34 | + /// Core | |
| 35 | + | |
| 36 | + void virtual data_( | |
| 37 | + void const * data, | |
| 38 | + GLenum target, | |
| 39 | + GLenum format, | |
| 40 | + GLenum type | |
| 41 | + ) override; | |
| 42 | +}; | |
| 43 | + | |
| 44 | + | |
| 45 | +/// Special member functions | |
| 46 | + | |
| 47 | +inline GLTexture3D::GLTexture3D( | |
| 48 | + std::string object_label, | |
| 49 | + Size size, | |
| 50 | + GLenum internal_format, | |
| 51 | + GLenum wrap, | |
| 52 | + GLenum min_filter, | |
| 53 | + GLenum mag_filter | |
| 54 | +) | |
| 55 | +: | |
| 56 | + GLTextureND( | |
| 57 | + std::move(object_label), | |
| 58 | + GL_TEXTURE_3D, | |
| 59 | + GL_TEXTURE_BINDING_3D, | |
| 60 | + GL_MAX_3D_TEXTURE_SIZE, | |
| 61 | + size, | |
| 62 | + internal_format, | |
| 63 | + wrap, | |
| 64 | + min_filter, | |
| 65 | + mag_filter | |
| 66 | + ) | |
| 67 | +{ | |
| 68 | + try | |
| 69 | +    { | |
| 70 | + glTexImage3D( | |
| 71 | + target_, 0, | |
| 72 | + (GLint)internal_format, | |
| 73 | + size[0], size[1], size[2], 0, | |
| 74 | + GL_RED, GL_UNSIGNED_BYTE, nullptr | |
| 75 | + ); | |
| 76 | + check_error_(glGetError()); | |
| 77 | + } | |
| 78 | + catch (...) | |
| 79 | +    { | |
| 80 | +        fail_action_("create"); | |
| 81 | + } | |
| 82 | +} | |
| 83 | + | |
| 84 | +/// Core | |
| 85 | + | |
| 86 | +inline GLTexture3D const & GLTexture3D::empty() | |
| 87 | +{ | |
| 88 | + return empty_<GLTexture3D>(); | |
| 89 | +} | |
| 90 | + | |
| 91 | +inline void GLTexture3D::data_( | |
| 92 | + void const * data, | |
| 93 | + GLenum target, | |
| 94 | + GLenum format, | |
| 95 | + GLenum type | |
| 96 | +) | |
| 97 | +{ | |
| 98 | + glTexSubImage3D( | |
| 99 | + target, 0, | |
| 100 | + 0, 0, 0, | |
| 101 | + size()[0], size()[1], size()[2], | |
| 102 | + format, type, data | |
| 103 | + ); | |
| 104 | +} | |
| 105 | + | |
| 106 | + | |
| 107 | +#endif // GLTEXTURE3D_HPP_ |