texture2d.hpp 1.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once
#include <GL/gl3w.h>

namespace scigl_render
{
/** RAII style creation of a 2D texture */
class Texture2D
{
public:
  Texture2D(GLsizei width, GLsizei height,
            GLenum format, GLenum internal_format, GLenum type);
  Texture2D(const Texture2D &) = delete;
  ~Texture2D();

  /** activates texture_n for use in shaders */
  static void activate(GLenum texture_n);

18
19
20
21
22
23
24
  /** 
   * bind this texture to an image unit for imageLoad 
   * \param unit the binding unit
   * \param access GL_READ_ONLY, GL_WRITE_ONLY, or GL_READ_WRITE
   */
  void bind_image_unit(GLuint unit, GLenum access) const;

25
26
27
28
29
30
  /** binds this texture to GL_TEXTURE_2D */
  void bind() const;

  /** unbinds this texture */
  void unbind() const;

Tim Übelhör's avatar
Tim Übelhör committed
31
32
33
34
35
36
37
38
39
  /** 
   * Reads the texture in the pixels pointer.
   * Note: If a non-zero named buffer object is bound to the 
   * GL_PIXEL_PACK_BUFFER target (see glBindBuffer) while a texture image is 
   * specified, pixels is treated as a byte offset into the buffer object's
   * data store.
   */
  void read_image(GLvoid *pixels);

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  /** upload an image to the texture. */
  void store_image(const GLvoid *image) const;

  GLuint get_raw() const;
  GLsizei get_width() const;
  GLsizei get_height() const;
  GLenum get_format() const;
  GLenum get_internal_format() const;
  GLenum get_type() const;

private:
  const GLsizei width, height;
  const GLenum format, internal_format, type;
  GLuint texture;
};
} // namespace scigl_render