gdk-graphics  1b6d84e044c2c953fd7c9501e628a67e80f4da0d
webgl1es2_texture.h
1 // © Joseph Cameron - All Rights Reserved
2 
3 #ifndef GDK_GFX_WEBGL1ES2_TEXTURE_H
4 #define GDK_GFX_WEBGL1ES2_TEXTURE_H
5 
6 #include <gdk/opengl.h>
7 #include <gdk/texture.h>
8 #include <jfc/unique_handle.h>
9 
10 #include <array>
11 #include <cstddef>
12 #include <string>
13 #include <vector>
14 
15 namespace gdk
16 {
18  class webgl1es2_texture final : public texture
19  {
20  public:
23  //
24  virtual void update_data(const image_data_2d_view &) override;
25 
26  virtual void update_data(const image_data_2d_view &, const size_t offsetX, const size_t offsetY) override;
28 
33  enum class format
34  {
35  rgba,
36  rgb,
38  luminance,
39  a,
41  };
42 
46  {
49  linear,
50 
53  nearest,
54 
58  nearest_mipmap_nearest,
59 
63  linear_mipmap_nearest,
64 
70  nearest_mipmap_linear,
71 
76  linear_mipmap_linear
77  };
78 
82  {
85  nearest,
86 
89  linear
90  };
91 
94  enum class wrap_mode
95  {
97  clamp_to_edge,
98 
101  repeat,
102 
106  mirrored_repeat
107  };
108 
110  enum class bind_target
111  {
112  texture_2d,
113  cube_map
114  };
115 
117  //TODO make use of this
120  {
121  size_t width;
122  size_t height;
123 
125 
128  std::array<std::byte *, 6> data;
129  };
130 
131  public:
133  //TODO consider abstracting this away. Currently only used by Shader, to bind the webgl1es2_texture. Exposing the raw handle
134  // like this makes it trivial to put a webgl1es2_texture into an unintended state for example by getting the handle and deleting it.)
135  GLuint getHandle() const;
136 
138  bool operator==(const webgl1es2_texture &) const;
140  bool operator!=(const webgl1es2_texture &) const;
141 
145  webgl1es2_texture(webgl1es2_texture &&) = default;
146 
147  //TODO: consider supporting copy semantics. How useful are they to a user? they are expensive. need to read about usecases.
148 
154  const wrap_mode wrapMode = wrap_mode::repeat);
155 
156  //webgl1es2_texture(
157 
158  //TODO cubic ctor
163 
166  static const std::shared_ptr<gdk::webgl1es2_texture> GetCheckerboardOfDeath();
167 
171  static webgl1es2_texture make_from_png_rgba32(const std::vector<std::underlying_type<std::byte>::type> aRGBA32PNGData);
172 
173  private:
175  GLenum m_BindTarget;
176 
178  jfc::unique_handle<GLuint> m_Handle;
179 
180  size_t m_CurrentDataWidth;
181  size_t m_CurrentDataHeight;
182  GLint m_CurrentDataFormat;
183  };
184 }
185 
186 #endif
wrap_mode
Definition: webgl1es2_texture.h:94
size_t height
height of a single image in the cube (all must be same)
Definition: webgl1es2_texture.h:122
1 channel input: rgb = luminance, a = 1
GLuint getHandle() const
returns the handle to the webgl1es2_texture in the opengl context
bool operator==(const webgl1es2_texture &) const
equality semantics
bind_target
GLES2.0/Web1.0 defines 2 bind targets.
Definition: webgl1es2_texture.h:110
4channel input: red, green, blue, alpha channels
Definition: camera.h:9
static webgl1es2_texture make_from_png_rgba32(const std::vector< std::underlying_type< std::byte >::type > aRGBA32PNGData)
constructs a 2d webgl1es2_texture from png rgba32 encoded file data
minification_filter
Definition: webgl1es2_texture.h:45
a texture generally represents the color of a surface
Definition: webgl1es2_texture.h:18
webgl1es2_texture::format format
format of the image data. must be same for all surfaces
Definition: webgl1es2_texture.h:124
std::array< std::byte *, 6 > data
Definition: webgl1es2_texture.h:128
static const std::shared_ptr< gdk::webgl1es2_texture > GetCheckerboardOfDeath()
creates a cubic webgl1es2_texture from decoded image data.
2 channel input: rgb = luminance, a = alpha
magnification_filter
Definition: webgl1es2_texture.h:81
2d color data, usually used to color the surfaces of a 3d model. more accurately: used to color fragm...
Definition: texture.h:17
webgl1es2_texture & operator=(webgl1es2_texture &&)=default
move semantics
virtual void update_data(const image_data_2d_view &) override
replace the texture data with new data
size_t width
width of a single image in the cube (all must be same)
Definition: webgl1es2_texture.h:121
pod struct representing a view on decoded image data
Definition: texture.h:35
bool operator!=(const webgl1es2_texture &) const
equality semantics
format
format of uncompressed image data provided to the ctor & format of the webgl1es2_texture data within ...
Definition: webgl1es2_texture.h:33
1 channel input: rgb=0, a=alpha
webgl1es2_texture(webgl1es2_texture &&)=default
move semantics
Used to attach a texture to one of an FBO&#39;s buffers.
3 channel input: red, green, blue channels only, alpha is set to 1
description of a cubic image
Definition: webgl1es2_texture.h:119