| 0.6.1

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

texture.hpp
Go to the documentation of this file.
1
29 #pragma once
30
31 #include "image.hpp"
32
33 namespace gli
34 {
35 class texture
36 {
37 public:
38 typedef size_t size_type;
39 typedef format format_type;
40
41 texture();
42
43 texture(
44 size_type const & Layers,
45 size_type const & Faces,
46 size_type const & Levels,
47 format_type const & Format,
48 storage::dim_type const & Dimensions);
49
50 texture(storage const & Storage);
51
52 texture(
53 storage const & Storage,
54 format_type const & Format,
55 size_type BaseLayer, size_type MaxLayer,
56 size_type BaseFace, size_type MaxFace,
57 size_type BaseLevel, size_type MaxLevel);
58
59 bool empty() const;
60 format_type format() const;
61
62 size_type baseLayer() const;
63 size_type maxLayer() const;
64 size_type layers() const;
65
66 size_type baseFace() const;
67 size_type maxFace() const;
68 size_type faces() const;
69
70 size_type baseLevel() const;
71 size_type maxLevel() const;
72 size_type levels() const;
73
74 size_type size() const;
75 template <typename genType>
76 size_type size() const;
77
78 void * data();
79 template <typename genType>
80 genType * data();
81 void const * data() const;
82 template <typename genType>
83 genType const * data() const;
84
85 void clear();
86 template <typename genType>
87 void clear(genType const & Texel);
88
89 protected:
90 storage Storage;
91 format_type const Format;
92 size_type const BaseLayer;
93 size_type const MaxLayer;
94 size_type const BaseFace;
95 size_type const MaxFace;
96 size_type const BaseLevel;
97 size_type const MaxLevel;
98 void * const Data;
99 size_type const Size;
100
101 private:
102 void * const compute_data();
103 size_type compute_size() const;
104 };
105
106 inline texture::texture()
107 : Format(static_cast<gli::format>(FORMAT_INVALID))
108 , BaseLayer(0), MaxLayer(0)
109 , BaseFace(0), MaxFace(0)
110 , BaseLevel(0), MaxLevel(0)
111 , Data(nullptr)
112 , Size(0)
113 {}
114
115 inline texture::texture
116 (
117 size_type const & Layers,
118 size_type const & Faces,
119 size_type const & Levels,
120 format_type const & Format,
121 storage::dim_type const & Dimensions
122 )
123 : Storage(Layers, Faces, Levels, Format, Dimensions)
124 , Format(Format)
125 , BaseLayer(0), MaxLayer(Layers - 1)
126 , BaseFace(0), MaxFace(Faces - 1)
127 , BaseLevel(0), MaxLevel(Levels - 1)
128 , Data(this->compute_data())
129 , Size(this->compute_size())
130 {}
131
132 inline texture::texture
133 (
134 storage const & Storage
135 )
136 : Storage(Storage)
137 , Format(Storage.format())
138 , BaseLayer(0), MaxLayer(Storage.layers() - 1)
139 , BaseFace(0), MaxFace(Storage.faces() - 1)
140 , BaseLevel(0), MaxLevel(Storage.levels() - 1)
141 , Data(this->compute_data())
142 , Size(this->compute_size())
143 {}
144
145 inline texture::texture
146 (
147 storage const & Storage,
148 format_type const & Format,
149 size_type BaseLayer, size_type MaxLayer,
150 size_type BaseFace, size_type MaxFace,
151 size_type BaseLevel, size_type MaxLevel
152 )
153 : Storage(Storage)
154 , Format(Format)
155 , BaseLayer(BaseLayer), MaxLayer(MaxLayer)
156 , BaseFace(BaseFace), MaxFace(MaxFace)
157 , BaseLevel(BaseLevel), MaxLevel(MaxLevel)
158 , Data(this->compute_data())
159 , Size(this->compute_size())
160 {}
161
162 inline texture::size_type texture::size() const
163 {
164 assert(!this->empty());
165
166 return this->Size;
167 }
168
169 template <typename genType>
170 inline texture::size_type texture::size() const
171 {
172 assert(!this->empty());
173 assert(block_size(this->Storage.format()) >= sizeof(genType));
174
175 return this->size() / sizeof(genType);
176 }
177
178 inline void * texture::data()
179 {
180 return this->Data;
181 }
182
183 inline void const * texture::data() const
184 {
185 return this->Data;
186 }
187
188 template <typename genType>
189 inline genType * texture::data()
190 {
191 assert(!this->empty());
192 assert(block_size(this->format()) >= sizeof(genType));
193
194 return reinterpret_cast<genType *>(this->data());
195 }
196
197 template <typename genType>
198 inline genType const * texture::data() const
199 {
200 assert(!this->empty());
201 assert(block_size(this->format()) >= sizeof(genType));
202
203 return reinterpret_cast<genType const *>(this->data());
204 }
205
206 inline bool texture::empty() const
207 {
208 return this->Storage.empty();
209 }
210
211 inline texture::format_type texture::format() const
212 {
213 return this->Format;
214 }
215
216 inline texture::size_type texture::baseLayer() const
217 {
218 return this->BaseLayer;
219 }
220
221 inline texture::size_type texture::maxLayer() const
222 {
223 return this->MaxLayer;
224 }
225
226 inline texture::size_type texture::layers() const
227 {
228 return this->maxLayer() - this->baseLayer() + 1;
229 }
230
231 inline texture::size_type texture::baseFace() const
232 {
233 return this->BaseFace;
234 }
235
236 inline texture::size_type texture::maxFace() const
237 {
238 return this->MaxFace;
239 }
240
241 inline texture::size_type texture::faces() const
242 {
243 //assert(this->maxFace() - this->baseFace() + 1 == 1);
244 return this->maxFace() - this->baseFace() + 1;
245 }
246
247 inline texture::size_type texture::baseLevel() const
248 {
249 return this->BaseLevel;
250 }
251
252 inline texture::size_type texture::maxLevel() const
253 {
254 return this->MaxLevel;
255 }
256
257 inline texture::size_type texture::levels() const
258 {
259 return this->maxLevel() - this->baseLevel() + 1;
260 }
261
262 inline void texture::clear()
263 {
264 memset(this->data<glm::byte>(), 0, this->size<glm::byte>());
265 }
266
267 template <typename genType>
268 inline void texture::clear(genType const & Texel)
269 {
270 assert(!this->empty());
271 assert(block_size(this->Storage.format()) == sizeof(genType));
272
273 genType* Data = this->data<genType>();
274 size_type const TexelCount = this->size<genType>();
275
276 for(size_type TexelIndex = 0; TexelIndex < TexelCount; ++TexelIndex)
277 *(Data + TexelIndex) = Texel;
278 }
279
280 void * const texture::compute_data()
281 {
282 size_type const offset = detail::imageAddressing(
283 this->Storage, this->baseLayer(), this->baseFace(), this->baseLevel());
284
285 return this->Storage.data() + offset;
286 }
287
288 inline texture::size_type texture::compute_size() const
289 {
290 assert(!this->empty());
291
292 return this->Storage.layer_size(
293 this->baseFace(), this->maxFace(),
294 this->baseLevel(), this->maxLevel()) * this->layers();
295 }
296 }//namespace gli
297
298 #include "texture1d.hpp"
299 #include "texture1d_array.hpp"
300 #include "texture2d.hpp"
301 #include "texture2d_array.hpp"
302 #include "texture3d.hpp"
303 #include "texture_cube.hpp"
304 #include "texture_cube_array.hpp"
305
306 #include "addressing.hpp"
307
308 #include "texture1d.inl"
309 #include "texture1d_array.inl"
310 #include "texture2d.inl"
311 #include "texture2d_array.inl"
312 #include "texture3d.inl"
313 #include "texture_cube.inl"
314 #include "texture_cube_array.inl"
gli::texture::size_type
size_t size_type
Definition: texture.hpp:38
gli::storage::layers
size_type layers() const
texture2d_array.hpp
OpenGL Image (gli.g-truc.net)
gli::texture::levels
size_type levels() const
Definition: texture.hpp:257
gli::texture::MaxLayer
size_type const MaxLayer
Definition: texture.hpp:93
image.hpp
OpenGL Image (gli.g-truc.net)
gli::storage::dim_type
dim3_t dim_type
Definition: storage.hpp:59
addressing.hpp
OpenGL Image (gli.g-truc.net)
texture_cube_array.hpp
OpenGL Image (gli.g-truc.net)
gli::texture::Size
size_type const Size
Definition: texture.hpp:99
gli::format
format
Definition: format.hpp:33
gli::block_size
std::uint32_t block_size(format const &Format)
gli::texture::baseFace
size_type baseFace() const
Definition: texture.hpp:231
gli::texture::layers
size_type layers() const
Definition: texture.hpp:226
gli::texture::baseLayer
size_type baseLayer() const
Definition: texture.hpp:216
gli::texture::maxLayer
size_type maxLayer() const
Definition: texture.hpp:221
gli::texture::BaseFace
size_type const BaseFace
Definition: texture.hpp:94
gli::storage::layer_size
size_type layer_size(size_type const &BaseFace, size_type const &MaxFace, size_type const &BaseLevel, size_type const &MaxLevel) const
texture_cube.hpp
OpenGL Image (gli.g-truc.net)
gli::storage
Definition: storage.hpp:56
gli::texture::BaseLayer
size_type const BaseLayer
Definition: texture.hpp:92
texture2d.hpp
OpenGL Image (gli.g-truc.net)
gli::storage::data
data_type * data()
gli::texture::MaxFace
size_type const MaxFace
Definition: texture.hpp:95
gli::detail::imageAddressing
size_t imageAddressing(storage const &Storage, size_t const &LayerOffset, size_t const &FaceOffset, size_t const &LevelOffset)
gli::texture::Storage
storage Storage
Definition: texture.hpp:90
gli::texture::MaxLevel
size_type const MaxLevel
Definition: texture.hpp:97
gli::texture::Data
void *const Data
Definition: texture.hpp:98
gli::texture::faces
size_type faces() const
Definition: texture.hpp:241
gli::texture::Format
format_type const Format
Definition: texture.hpp:91
gli::storage::faces
size_type faces() const
gli::storage::empty
bool empty() const
gli::texture::empty
bool empty() const
Definition: texture.hpp:206
texture1d_array.hpp
OpenGL Image (gli.g-truc.net)
gli::FORMAT_INVALID
Definition: format.hpp:213
gli::storage::format
format_type format() const
gli::texture::maxLevel
size_type maxLevel() const
Definition: texture.hpp:252
gli::texture::size
size_type size() const
Definition: texture.hpp:162
gli::texture::BaseLevel
size_type const BaseLevel
Definition: texture.hpp:96
texture3d.hpp
OpenGL Image (gli.g-truc.net)
gli::texture::format_type
format format_type
Definition: texture.hpp:39
gli
Definition: addressing.hpp:33
gli::texture::data
void * data()
Definition: texture.hpp:178
gli::texture::maxFace
size_type maxFace() const
Definition: texture.hpp:236
gli::texture::baseLevel
size_type baseLevel() const
Definition: texture.hpp:247
gli::texture::format
format_type format() const
Definition: texture.hpp:211
gli::texture::clear
void clear()
Definition: texture.hpp:262
gli::storage::levels
size_type levels() const
gli::texture::texture
texture()
Definition: texture.hpp:106
texture1d.hpp
OpenGL Image (gli.g-truc.net)
gli::texture
Definition: texture.hpp:35