OGLplus  (0.59.0) a C++ wrapper for rendering APIs

image_spec.hpp
Go to the documentation of this file.
1 
9 #ifndef OGLPLUS_UTILS_IMAGE_SPEC_HPP
10 #define OGLPLUS_UTILS_IMAGE_SPEC_HPP
11 
12 #include "../gl_api/enum_types.hpp"
13 #include <eagine/assert.hpp>
14 #include <eagine/memory/block.hpp>
15 #include <eagine/span.hpp>
16 
17 namespace eagine::oglp {
18 
19 class image_dimensions {
20 private:
21  gl_types::sizei_type _width{1};
22  gl_types::sizei_type _height{1};
23  gl_types::sizei_type _depth{1};
24  gl_types::sizei_type _channels{1};
25 
26 public:
27  image_dimensions(
31  gl_types::sizei_type c) noexcept
32  : _width(w)
33  , _height(h)
34  , _depth(d)
35  , _channels(c) {
36  EAGINE_ASSERT(_width > 0 && _height > 0 && _depth > 0);
37  }
38 
39  auto is_1d() const noexcept -> bool {
40  return _width > 1 && _height == 1 && _depth == 1;
41  }
42 
43  auto is_2d() const noexcept -> bool {
44  return _width > 1 && _height > 1 && _depth == 1;
45  }
46 
47  auto is_3d() const noexcept -> bool {
48  return _width > 1 && _height > 1 && _depth > 1;
49  }
50 
51  auto width() const noexcept -> gl_types::sizei_type {
52  return _width;
53  }
54 
55  auto height() const noexcept -> gl_types::sizei_type {
56  return _height;
57  }
58 
59  auto depth() const noexcept -> gl_types::sizei_type {
60  return _depth;
61  }
62 
63  auto channels() const noexcept -> gl_types::sizei_type {
64  return _channels;
65  }
66 };
67 
68 class image_pixel_format {
69 private:
70  pixel_format _format;
71  pixel_internal_format _internal_format;
72 
73 public:
74  image_pixel_format(pixel_format fmt, pixel_internal_format ifmt) noexcept
75  : _format(fmt)
76  , _internal_format(ifmt) {}
77 
78  image_pixel_format(pixel_format fmt) noexcept
79  : _format(fmt)
80  , _internal_format(pixel_internal_format(GLenum(fmt))) {}
81 
82  auto format() const noexcept -> pixel_format {
83  return _format;
84  }
85 
86  auto internal_format() const noexcept -> pixel_internal_format {
87  return _internal_format;
88  }
89 };
90 
91 class image_pixel_data {
92 private:
93  pixel_data_type _type;
94  memory::const_block _pixels;
95  span_size_t _elem_size;
96 
97 public:
98  image_pixel_data(
99  pixel_data_type pix_type,
100  memory::const_block pix_data,
101  span_size_t type_size) noexcept
102  : _type(pix_type)
103  , _pixels(pix_data)
104  , _elem_size(type_size) {
105  EAGINE_ASSERT(_elem_size > 0);
106  }
107 
108  auto type() const noexcept -> pixel_data_type {
109  return _type;
110  }
111 
112  auto data() const noexcept -> memory::const_block {
113  return _pixels;
114  }
115 
116  auto elem_size() const noexcept -> span_size_t {
117  return _elem_size;
118  }
119 };
120 
121 class image_spec
122  : public image_dimensions
123  , public image_pixel_format
124  , public image_pixel_data {
125 public:
126  image_spec(
127  const image_dimensions& dims,
128  const image_pixel_format& fmt,
129  const image_pixel_data& pix_data) noexcept
130  : image_dimensions(dims)
131  , image_pixel_format(fmt)
132  , image_pixel_data(pix_data) {}
133 };
134 
135 } // namespace eagine::oglp
136 
137 #endif // OGLPLUS_UTILS_IMAGE_SPEC_HPP
GLsizei sizei_type
Signed integer size type.
Definition: config.hpp:88
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
static auto format(std::string &&fmt_str) noexcept -> format_string_and_list< 0 >
Function taking a format string, returning an object for variable specification.
Definition: str_format.hpp:118
auto type_size(const basic_gl_api< A > &, shapes::attrib_data_type) noexcept -> span_size_t
Returns the byte size of a shape attribute data type.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).