iridescence
Loading...
Searching...
No Matches
texture.hpp
Go to the documentation of this file.
1#ifndef GLK_TEXTURE_HPP
2#define GLK_TEXTURE_HPP
3
4#include <vector>
5#include <GL/gl3w.h>
6#include <Eigen/Core>
7
8namespace glk {
9
11class Texture {
12public:
20 Texture(const Eigen::Vector2i& size, GLuint internal_format, GLuint format, GLuint type, const void* pixels = nullptr);
22
23 // Forbid copy
24 Texture(const Texture& temp_obj) = delete;
25 Texture& operator=(const Texture& temp_obj) = delete;
26
28 GLuint id() const;
30 Eigen::Vector2i size() const;
32 void set_size(const Eigen::Vector2i& size);
33
35 void bind() const;
37 void bind(GLenum target) const;
39 void unbind() const;
41 void unbind(GLenum target) const;
42
43 // They are semantically const but not logically const
45 const Texture& set_filer_mode(GLenum mode) const;
47 const Texture& set_clamp_mode(GLenum mode) const;
48
55 template <typename T>
56 std::vector<T> read_pixels(GLuint format = GL_RGBA, GLuint type = GL_UNSIGNED_BYTE, int num_elements = 4) const;
57
58private:
59 int width;
60 int height;
61
62 GLuint internal_format;
63 GLuint format;
64 GLuint type;
65
66 GLuint filter_mode;
67
68 GLuint texture;
69};
70
71class Texture1D {
72public:
73 Texture1D(int width, GLuint internal_format, GLuint format, GLuint type, const void* pixels = nullptr);
75
76 GLuint id() const;
77 int size() const;
78
79private:
80 int width;
81 GLuint texture;
82};
83} // namespace glk
84
85#endif
GLuint id() const
Texture1D(int width, GLuint internal_format, GLuint format, GLuint type, const void *pixels=nullptr)
int size() const
const Texture & set_filer_mode(GLenum mode) const
Set the filtering mode of the texture (e.g., GL_LINEAR, GL_NEAREST).
void set_size(const Eigen::Vector2i &size)
Change the size of the texture. This will invalidate the texture data and change the texture ID.
void unbind() const
Unbind the texture.
Texture(const Eigen::Vector2i &size, GLuint internal_format, GLuint format, GLuint type, const void *pixels=nullptr)
Constructor.
void unbind(GLenum target) const
Unbind the texture from the specified target (e.g., GL_TEXTURE0).
void bind(GLenum target) const
Bind the texture to the specified target (e.g., GL_TEXTURE0).
Texture & operator=(const Texture &temp_obj)=delete
std::vector< T > read_pixels(GLuint format=GL_RGBA, GLuint type=GL_UNSIGNED_BYTE, int num_elements=4) const
Read the pixel data from the texture into a vector.
GLuint id() const
Texture ID.
Eigen::Vector2i size() const
Texture size.
void bind() const
Bind the texture.
Texture(const Texture &temp_obj)=delete
const Texture & set_clamp_mode(GLenum mode) const
Set the clamping mode of the texture (e.g., GL_CLAMP_TO_EDGE, GL_REPEAT).
Definition async_buffer_copy.hpp:6