@@ -13,7 +13,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1313</editor-fold> */
1414
1515#include < vsg/core/Data.h>
16-
1716#include < vsg/maths/mat4.h>
1817#include < vsg/maths/vec2.h>
1918#include < vsg/maths/vec3.h>
@@ -68,11 +67,15 @@ namespace vsg
6867 dirty ();
6968 }
7069
71- Array2D (uint32_t width, uint32_t height, value_type* data, Properties in_properties = {}) :
70+ Array2D (uint32_t width, uint32_t height, value_type* data, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr ) :
7271 Data (in_properties, sizeof (value_type)),
7372 _data (data),
7473 _width (width),
75- _height (height) { dirty (); }
74+ _height (height)
75+ {
76+ setMipmapLayout (mipmapLayout);
77+ dirty ();
78+ }
7679
7780 Array2D (uint32_t width, uint32_t height, const value_type& value, Properties in_properties = {}) :
7881 Data (in_properties, sizeof (value_type)),
@@ -88,13 +91,13 @@ namespace vsg
8891 }
8992 }
9093
91- Array2D (ref_ptr<Data> data, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {}) :
94+ Array2D (ref_ptr<Data> data, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr ) :
9295 Data (),
9396 _data (nullptr ),
9497 _width (0 ),
9598 _height (0 )
9699 {
97- assign (data, offset, stride, width, height, in_properties);
100+ assign (data, offset, stride, width, height, in_properties, mipmapLayout );
98101 }
99102
100103 template <typename ... Args>
@@ -144,7 +147,12 @@ namespace vsg
144147
145148 if (input.matchPropertyName (" data" ))
146149 {
147- size_t new_size = computeValueCountIncludingMipmaps (w, h, 1 , properties.maxNumMipmaps );
150+ properties.stride = sizeof (value_type);
151+ _width = w;
152+ _height = h;
153+ _storage = nullptr ;
154+
155+ size_t new_size = computeValueCountIncludingMipmaps ();
148156
149157 if (_data) // if data exists already may be able to reuse it
150158 {
@@ -159,11 +167,6 @@ namespace vsg
159167 _data = _allocate (new_size);
160168 }
161169
162- properties.stride = sizeof (value_type);
163- _width = w;
164- _height = h;
165- _storage = nullptr ;
166-
167170 if (_data) input.read (new_size, _data);
168171
169172 dirty ();
@@ -190,7 +193,7 @@ namespace vsg
190193 output.writeEndOfLine ();
191194 }
192195
193- size_t size () const { return (properties.maxNumMipmaps <= 1 ) ? (static_cast <size_t >(_width) * static_cast <size_t >(_height)) : computeValueCountIncludingMipmaps (_width, _height, 1 , properties. maxNumMipmaps ); }
196+ size_t size () const { return (properties.mipLevels <= 1 ) ? (static_cast <size_t >(_width) * static_cast <size_t >(_height)) : computeValueCountIncludingMipmaps (); }
194197
195198 bool available () const { return _data != nullptr ; }
196199 bool empty () const { return _data == nullptr ; }
@@ -211,7 +214,8 @@ namespace vsg
211214
212215 clear ();
213216
214- properties = rhs.properties ;
217+ _copy (rhs);
218+
215219 _width = rhs._width ;
216220 _height = rhs._height ;
217221
@@ -227,7 +231,7 @@ namespace vsg
227231 return *this ;
228232 }
229233
230- void assign (uint32_t width, uint32_t height, value_type* data, Properties in_properties = {})
234+ void assign (uint32_t width, uint32_t height, value_type* data, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr )
231235 {
232236 _delete ();
233237
@@ -238,10 +242,12 @@ namespace vsg
238242 _data = data;
239243 _storage = nullptr ;
240244
245+ setMipmapLayout (mipmapLayout);
246+
241247 dirty ();
242248 }
243249
244- void assign (ref_ptr<Data> storage, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {})
250+ void assign (ref_ptr<Data> storage, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr )
245251 {
246252 _delete ();
247253
@@ -261,6 +267,8 @@ namespace vsg
261267 _height = 0 ;
262268 }
263269
270+ setMipmapLayout (mipmapLayout);
271+
264272 dirty ();
265273 }
266274
@@ -360,6 +368,8 @@ namespace vsg
360368 else if (properties.allocatorType != 0 )
361369 vsg::deallocate (_data);
362370 }
371+
372+ _clear ();
363373 }
364374
365375 private:
0 commit comments