Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Array.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Array_INCLUDE_ONCE
33 #define Array_INCLUDE_ONCE
34 
36 #include <vlCore/half.hpp>
37 #include <vector>
38 
39 namespace vl
40 {
41 //-----------------------------------------------------------------------------
42 // ArrayAbstract
43 //-----------------------------------------------------------------------------
58  class ArrayAbstract: public Object
59  {
61 
62  public:
65  {
66  VL_DEBUG_SET_OBJECT_NAME()
68  mBufferObjectDirty = true;
71  mNormalize = false;
72  }
73 
75  ArrayAbstract(const ArrayAbstract& other): Object(other)
76  {
77  VL_DEBUG_SET_OBJECT_NAME()
79  mBufferObjectDirty = true;
82  mNormalize = false;
83  operator=(other);
84  }
85 
87  void operator=(const ArrayAbstract& other)
88  {
89  bufferObject()->resize( other.bufferObject()->bytesUsed() );
90  memcpy( ptr(), other.ptr(), bytesUsed() );
92  mNormalize = other.mNormalize;
93  }
94 
95  virtual ref<ArrayAbstract> clone() const = 0;
96 
97  const BufferObject* bufferObject() const { return mBufferObject.get(); }
99 
100  void clear() { if (bufferObject()) bufferObject()->clear(); }
101 
103  const unsigned char* ptr() const { return bufferObject() ? bufferObject()->ptr() : NULL; }
104 
106  unsigned char* ptr() { return bufferObject() ? bufferObject()->ptr() : NULL; }
107 
109  virtual size_t bytesUsed() const { return bufferObject() ? bufferObject()->bytesUsed() : 0; }
110 
112  virtual size_t glSize() const = 0;
113 
115  virtual GLenum glType() const = 0;
116 
118  virtual size_t size() const = 0;
119 
121  virtual Sphere computeBoundingSphere() const = 0;
122 
124  virtual AABB computeBoundingBox() const = 0;
125 
127  virtual void transform(const mat4& m) = 0;
128 
130  virtual void normalize() = 0;
131 
133  virtual vec4 getAsVec4(size_t vector_index) const = 0;
134 
136  virtual vec3 getAsVec3(size_t vector_index) const = 0;
137 
139  virtual vec2 getAsVec2(size_t vector_index) const = 0;
140 
142  virtual int compare(int a, int b) const = 0;
143 
147  bool isBufferObjectDirty() const { return mBufferObjectDirty; }
148 
152  void setBufferObjectDirty(bool dirty=true) { mBufferObjectDirty = dirty; }
153 
156 
159 
163  {
165  setBufferObjectDirty(false);
166  }
167 
172 
176  bool normalize() const { return mNormalize; }
177 
180 
183 
184  protected:
190  };
191 //-----------------------------------------------------------------------------
192 // Array
193 //-----------------------------------------------------------------------------
212  template <typename T_VectorType, typename T_Scalar, size_t T_GL_Size, GLenum T_GL_Type>
213  class Array: public ArrayAbstract
214  {
216 
217  public:
218  typedef T_Scalar scalar_type;
219  typedef T_VectorType vector_type;
220  static const size_t gl_size = T_GL_Size;
221  static const GLenum gl_type = T_GL_Type;
222 
223  virtual size_t glSize() const { return T_GL_Size; }
224 
225  virtual GLenum glType() const { return T_GL_Type; }
226 
227  virtual size_t bytesPerVector() const { return sizeof(T_VectorType); }
228 
229  // ---
230 
231  void clear() { resize(0); bufferObject()->deleteBufferObject(); }
232 
233  void resize(size_t dim) { bufferObject()->resize(dim*bytesPerVector()); }
234 
235  size_t size() const { return bytesUsed() / bytesPerVector(); }
236 
237  size_t sizeBufferObject() const { return bufferObject() ? bufferObject()->byteCountBufferObject() / bytesPerVector() : 0; }
238 
239  size_t scalarCount() const { return size() * T_GL_Size; }
240 
241  size_t scalarCountBufferObject() const { return sizeBufferObject() * T_GL_Size; }
242 
243  // ---
244 
245  const T_VectorType* begin() const { return reinterpret_cast<const T_VectorType*>(ptr()); }
246 
247  T_VectorType* begin() { return reinterpret_cast<T_VectorType*>(ptr()); }
248 
249  const T_VectorType* end() const { return (reinterpret_cast<const T_VectorType*>(ptr()))+size(); }
250 
251  T_VectorType* end() { return (reinterpret_cast<T_VectorType*>(ptr()))+size(); }
252 
253  // ---
254 
255  T_VectorType& at(size_t i) { VL_CHECK(i<size()); return *(reinterpret_cast<T_VectorType*>(ptr())+i); }
256 
257  const T_VectorType& at(size_t i) const { VL_CHECK(i<size()); return *(reinterpret_cast<const T_VectorType*>(ptr())+i); }
258 
259  T_VectorType& operator[](size_t i) { return at(i); }
260 
261  const T_VectorType& operator[](size_t i) const { return at(i); }
262 
263  // ---
264 
265  virtual ref<ArrayAbstract> createArray() const { return new Array; }
266 
267  virtual ref<ArrayAbstract> clone() const
268  {
269  ref<Array> arr = createArray()->template as<Array>(); VL_CHECK(arr);
270  if (size())
271  {
272  arr->resize(size());
273  memcpy(arr->ptr(), ptr(), bytesUsed());
274  }
275  return arr;
276  }
277 
278  // ---
279 
281  {
282  AABB aabb;
283  const int count = T_GL_Size == 4 ? 3 : T_GL_Size;
284  for(size_t i=0; i<size(); ++i)
285  {
286  vec3 v;
287  const T_Scalar* pv = reinterpret_cast<const T_Scalar*>(&at(i));
288  for( int j=0; j<count; ++j )
289  v.ptr()[j] = (real)pv[j];
290  aabb += v;
291  }
292  real radius = 0;
293  vec3 center = aabb.center();
294  for(size_t i=0; i<size(); ++i)
295  {
296  vec3 v;
297  const T_Scalar* pv = reinterpret_cast<const T_Scalar*>(&at(i));
298  for( int j=0; j<count; ++j )
299  v.ptr()[j] = (real)pv[j];
300  real r = (v-center).lengthSquared();
301  if (r > radius)
302  radius = r;
303  }
304  return Sphere( center, sqrt(radius) );
305  }
306 
308  {
309  AABB aabb;
310  const int count = T_GL_Size == 4 ? 3 : T_GL_Size;
311  for(size_t i=0; i<size(); ++i)
312  {
313  vec3 v;
314  const T_Scalar* pv = reinterpret_cast<const T_Scalar*>(&at(i));
315  for( int j=0; j<count; ++j )
316  v.ptr()[j] = (real)pv[j];
317  aabb += v;
318  }
319  return aabb;
320  }
321 
322  void transform(const mat4& m)
323  {
324  for(size_t i=0; i<size(); ++i)
325  {
326  vec4 v(0,0,0,1);
327  T_Scalar* pv = reinterpret_cast<T_Scalar*>(&at(i));
328  // read
329  for( size_t j=0; j<T_GL_Size; ++j )
330  v.ptr()[j] = (real)pv[j];
331  // transform
332  v = m * v;
333  // write
334  for( size_t j=0; j<T_GL_Size; ++j )
335  pv[j] = (T_Scalar)v.ptr()[j];
336  }
337  }
338 
339  void normalize()
340  {
341  for(size_t i=0; i<size(); ++i)
342  {
343  vec4 v(0,0,0,0);
344  T_Scalar* pv = reinterpret_cast<T_Scalar*>(&at(i));
345  // read
346  for( size_t j=0; j<T_GL_Size; ++j )
347  v.ptr()[j] = (real)pv[j];
348  // normalize
349  v.normalize();
350  // write
351  for( unsigned j=0; j<T_GL_Size; ++j )
352  pv[j] = (T_Scalar)v.ptr()[j];
353  }
354  }
355 
356  vec4 getAsVec4(size_t vector_index) const
357  {
358  vec4 v(0,0,0,1);
359  const T_Scalar* pv = reinterpret_cast<const T_Scalar*>(&at(vector_index));
360  for( size_t j=0; j<T_GL_Size; ++j )
361  v.ptr()[j] = (real)pv[j];
362  return v;
363  }
364 
365  vec3 getAsVec3(size_t vector_index) const
366  {
367  vec3 v;
368  const T_Scalar* pv = reinterpret_cast<const T_Scalar*>(&at(vector_index));
369  const int count = T_GL_Size <= 3 ? T_GL_Size : 3;
370  for( int j=0; j<count; ++j )
371  v.ptr()[j] = (real)pv[j];
372  return v;
373  }
374 
375  vec2 getAsVec2(size_t vector_index) const
376  {
377  vec2 v;
378  const T_Scalar* pv = reinterpret_cast<const T_Scalar*>(&at(vector_index));
379  const int count = T_GL_Size <= 2 ? T_GL_Size : 2;
380  for( int j=0; j<count; ++j )
381  v.ptr()[j] = (real)pv[j];
382  return v;
383  }
384 
385  int compare(int a, int b) const
386  {
387  const T_Scalar* pa = reinterpret_cast<const T_Scalar*>(&at(a));
388  const T_Scalar* pb = reinterpret_cast<const T_Scalar*>(&at(b));
389  for( size_t i=0; i<T_GL_Size; ++i )
390  if ( pa[i] != pb[i] )
391  return pa[i] < pb[i] ? -1 : +1;
392  return 0;
393  }
394 
395  void initFrom(const std::vector<T_VectorType>& vector)
396  {
397  resize(vector.size());
398  if (vector.empty())
399  return;
400  else
401  memcpy(ptr(),&vector[0],sizeof(vector[0])*vector.size());
402  }
403  };
404 //-----------------------------------------------------------------------------
405 // Array typedefs
406 //-----------------------------------------------------------------------------
407 
408 
410  class ArrayFloat1: public Array<GLfloat, GLfloat, 1, GL_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayFloat1, VL_GROUP(Array<GLfloat, GLfloat, 1, GL_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFloat1; } };
412  class ArrayFloat2: public Array<fvec2, GLfloat, 2, GL_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayFloat2, VL_GROUP(Array<fvec2, GLfloat, 2, GL_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFloat2; } };
414  class ArrayFloat3: public Array<fvec3, GLfloat, 3, GL_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayFloat3, VL_GROUP(Array<fvec3, GLfloat, 3, GL_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFloat3; } };
416  class ArrayFloat4: public Array<fvec4, GLfloat, 4, GL_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayFloat4, VL_GROUP(Array<fvec4, GLfloat, 4, GL_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFloat4; } };
417 
419  class ArrayDouble1: public Array<GLdouble, GLdouble, 1, GL_DOUBLE> { VL_INSTRUMENT_CLASS(vl::ArrayDouble1, VL_GROUP(Array<GLdouble, GLdouble, 1, GL_DOUBLE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayDouble1; } };
421  class ArrayDouble2: public Array<dvec2, GLdouble, 2, GL_DOUBLE> { VL_INSTRUMENT_CLASS(vl::ArrayDouble2, VL_GROUP(Array<dvec2, GLdouble, 2, GL_DOUBLE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayDouble2; } };
423  class ArrayDouble3: public Array<dvec3, GLdouble, 3, GL_DOUBLE> { VL_INSTRUMENT_CLASS(vl::ArrayDouble3, VL_GROUP(Array<dvec3, GLdouble, 3, GL_DOUBLE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayDouble3; } };
425  class ArrayDouble4: public Array<dvec4, GLdouble, 4, GL_DOUBLE> { VL_INSTRUMENT_CLASS(vl::ArrayDouble4, VL_GROUP(Array<dvec4, GLdouble, 4, GL_DOUBLE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayDouble4; } };
426 
428  class ArrayInt1: public Array<GLint, GLint, 1, GL_INT> { VL_INSTRUMENT_CLASS(vl::ArrayInt1, VL_GROUP(Array<GLint, GLint, 1, GL_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayInt1; } };
430  class ArrayInt2: public Array<ivec2, GLint, 2, GL_INT> { VL_INSTRUMENT_CLASS(vl::ArrayInt2, VL_GROUP(Array<ivec2, GLint, 2, GL_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayInt2; } };
432  class ArrayInt3: public Array<ivec3, GLint, 3, GL_INT> { VL_INSTRUMENT_CLASS(vl::ArrayInt3, VL_GROUP(Array<ivec3, GLint, 3, GL_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayInt3; } };
434  class ArrayInt4: public Array<ivec4, GLint, 4, GL_INT> { VL_INSTRUMENT_CLASS(vl::ArrayInt4, VL_GROUP(Array<ivec4, GLint, 4, GL_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayInt4; } };
435 
437  class ArrayUInt1: public Array<GLuint,GLuint, 1, GL_UNSIGNED_INT> { VL_INSTRUMENT_CLASS(vl::ArrayUInt1, VL_GROUP(Array<GLuint,GLuint, 1, GL_UNSIGNED_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt1; } };
439  class ArrayUInt2: public Array<uvec2, GLuint, 2, GL_UNSIGNED_INT> { VL_INSTRUMENT_CLASS(vl::ArrayUInt2, VL_GROUP(Array<uvec2, GLuint, 2, GL_UNSIGNED_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt2; } };
441  class ArrayUInt3: public Array<uvec3, GLuint, 3, GL_UNSIGNED_INT> { VL_INSTRUMENT_CLASS(vl::ArrayUInt3, VL_GROUP(Array<uvec3, GLuint, 3, GL_UNSIGNED_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt3; } };
443  class ArrayUInt4: public Array<uvec4, GLuint, 4, GL_UNSIGNED_INT> { VL_INSTRUMENT_CLASS(vl::ArrayUInt4, VL_GROUP(Array<uvec4, GLuint, 4, GL_UNSIGNED_INT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt4; } };
444 
446  class ArrayByte1: public Array<GLbyte, GLbyte, 1, GL_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayByte1, VL_GROUP(Array<GLbyte, GLbyte, 1, GL_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayByte1; } };
448  class ArrayByte2: public Array<bvec2, GLbyte, 2, GL_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayByte2, VL_GROUP(Array<bvec2, GLbyte, 2, GL_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayByte2; } };
450  class ArrayByte3: public Array<bvec3, GLbyte, 3, GL_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayByte3, VL_GROUP(Array<bvec3, GLbyte, 3, GL_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayByte3; } };
452  class ArrayByte4: public Array<bvec4, GLbyte, 4, GL_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayByte4, VL_GROUP(Array<bvec4, GLbyte, 4, GL_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayByte4; } };
453 
455  class ArrayUByte1: public Array<GLubyte, GLubyte, 1, GL_UNSIGNED_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayUByte1, VL_GROUP(Array<GLubyte, GLubyte, 1, GL_UNSIGNED_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUByte1; } };
457  class ArrayUByte2: public Array<ubvec2, GLubyte, 2, GL_UNSIGNED_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayUByte2, VL_GROUP(Array<ubvec2, GLubyte, 2, GL_UNSIGNED_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUByte2; } };
459  class ArrayUByte3: public Array<ubvec3, GLubyte, 3, GL_UNSIGNED_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayUByte3, VL_GROUP(Array<ubvec3, GLubyte, 3, GL_UNSIGNED_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUByte3; } };
461  class ArrayUByte4: public Array<ubvec4, GLubyte, 4, GL_UNSIGNED_BYTE> { VL_INSTRUMENT_CLASS(vl::ArrayUByte4, VL_GROUP(Array<ubvec4, GLubyte, 4, GL_UNSIGNED_BYTE>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUByte4; } };
462 
464  class ArrayShort1: public Array<GLshort, GLshort, 1, GL_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayShort1, VL_GROUP(Array<GLshort, GLshort, 1, GL_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayShort1; } };
466  class ArrayShort2: public Array<svec2, GLshort, 2, GL_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayShort2, VL_GROUP(Array<svec2, GLshort, 2, GL_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayShort2; } };
468  class ArrayShort3: public Array<svec3, GLshort, 3, GL_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayShort3, VL_GROUP(Array<svec3, GLshort, 3, GL_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayShort3; } };
470  class ArrayShort4: public Array<svec4, GLshort, 4, GL_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayShort4, VL_GROUP(Array<svec4, GLshort, 4, GL_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayShort4; } };
471 
473  class ArrayUShort1: public Array<GLushort, GLushort, 1, GL_UNSIGNED_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayUShort1, VL_GROUP(Array<GLushort, GLushort, 1, GL_UNSIGNED_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUShort1; } };
475  class ArrayUShort2: public Array<usvec2, GLushort, 2, GL_UNSIGNED_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayUShort2, VL_GROUP(Array<usvec2, GLushort, 2, GL_UNSIGNED_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUShort2; } };
477  class ArrayUShort3: public Array<usvec3, GLushort, 3, GL_UNSIGNED_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayUShort3, VL_GROUP(Array<usvec3, GLushort, 3, GL_UNSIGNED_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUShort3; } };
479  class ArrayUShort4: public Array<usvec4, GLushort, 4, GL_UNSIGNED_SHORT> { VL_INSTRUMENT_CLASS(vl::ArrayUShort4, VL_GROUP(Array<usvec4, GLushort, 4, GL_UNSIGNED_SHORT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUShort4; } };
480 
482  class ArrayHFloat1: public Array<half, half, 1, GL_HALF_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayHFloat1, VL_GROUP(Array<half, half, 1, GL_HALF_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayHFloat1; } };
484  class ArrayHFloat2: public Array<hvec2, half, 2, GL_HALF_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayHFloat2, VL_GROUP(Array<hvec2, half, 2, GL_HALF_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayHFloat2; } };
486  class ArrayHFloat3: public Array<hvec3, half, 3, GL_HALF_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayHFloat3, VL_GROUP(Array<hvec3, half, 3, GL_HALF_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayHFloat3; } };
488  class ArrayHFloat4: public Array<hvec4, half, 4, GL_HALF_FLOAT> { VL_INSTRUMENT_CLASS(vl::ArrayHFloat4, VL_GROUP(Array<hvec4, half, 4, GL_HALF_FLOAT>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayHFloat4; } };
489 
491  class ArrayFixed1: public Array<GLuint,GLuint, 1, GL_FIXED> { VL_INSTRUMENT_CLASS(vl::ArrayFixed1, VL_GROUP(Array<GLuint,GLuint, 1, GL_FIXED>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFixed1; } };
493  class ArrayFixed2: public Array<uvec2, GLuint, 2, GL_FIXED> { VL_INSTRUMENT_CLASS(vl::ArrayFixed2, VL_GROUP(Array<uvec2, GLuint, 2, GL_FIXED>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFixed2; } };
495  class ArrayFixed3: public Array<uvec3, GLuint, 3, GL_FIXED> { VL_INSTRUMENT_CLASS(vl::ArrayFixed3, VL_GROUP(Array<uvec3, GLuint, 3, GL_FIXED>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFixed3; } };
497  class ArrayFixed4: public Array<uvec4, GLuint, 4, GL_FIXED> { VL_INSTRUMENT_CLASS(vl::ArrayFixed4, VL_GROUP(Array<uvec4, GLuint, 4, GL_FIXED>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayFixed4; } };
498 
507 
509  class ArrayUInt_2_10_10_10_REV1: public Array<GLuint,GLuint, 1, GL_UNSIGNED_INT_2_10_10_10_REV> { VL_INSTRUMENT_CLASS(vl::ArrayUInt_2_10_10_10_REV1, VL_GROUP(Array<GLuint,GLuint, 1, GL_UNSIGNED_INT_2_10_10_10_REV>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt_2_10_10_10_REV1; } };
511  class ArrayUInt_2_10_10_10_REV2: public Array<uvec2, GLuint, 2, GL_UNSIGNED_INT_2_10_10_10_REV> { VL_INSTRUMENT_CLASS(vl::ArrayUInt_2_10_10_10_REV2, VL_GROUP(Array<uvec2, GLuint, 2, GL_UNSIGNED_INT_2_10_10_10_REV>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt_2_10_10_10_REV2; } };
513  class ArrayUInt_2_10_10_10_REV3: public Array<uvec3, GLuint, 3, GL_UNSIGNED_INT_2_10_10_10_REV> { VL_INSTRUMENT_CLASS(vl::ArrayUInt_2_10_10_10_REV3, VL_GROUP(Array<uvec3, GLuint, 3, GL_UNSIGNED_INT_2_10_10_10_REV>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt_2_10_10_10_REV3; } };
515  class ArrayUInt_2_10_10_10_REV4: public Array<uvec4, GLuint, 4, GL_UNSIGNED_INT_2_10_10_10_REV> { VL_INSTRUMENT_CLASS(vl::ArrayUInt_2_10_10_10_REV4, VL_GROUP(Array<uvec4, GLuint, 4, GL_UNSIGNED_INT_2_10_10_10_REV>)) virtual ref<ArrayAbstract> createArray() const { return new ArrayUInt_2_10_10_10_REV4; } };
516 }
517 
518 #endif
An array of GL_INT_2_10_10_10_REV.
Definition: Array.hpp:500
The ArrayAbstract class defines an abstract interface to conveniently manipulate data stored in a Buf...
Definition: Array.hpp:58
An array of vl::svec3.
Definition: Array.hpp:468
An array of vl::uvec2.
Definition: Array.hpp:439
bool mBufferObjectDirty
Definition: Array.hpp:187
An array of vl::uvec4.
Definition: Array.hpp:443
const T_VectorType & at(size_t i) const
Definition: Array.hpp:257
An array of vl::fvec4.
Definition: Array.hpp:416
T sqrt(T a)
Definition: glsl_math.hpp:592
const T_VectorType * end() const
Definition: Array.hpp:249
An array of GLubyte.
Definition: Array.hpp:455
T_VectorType * begin()
Definition: Array.hpp:247
An array of vl::usvec4.
Definition: Array.hpp:479
#define VL_GROUP(...)
Definition: TypeInfo.hpp:77
An array 4d GL_FIXED vectors.
Definition: Array.hpp:497
void normalize()
Normalizes the vectors contained in the buffer.
Definition: Array.hpp:339
T_Scalar scalar_type
Definition: Array.hpp:218
void setNormalize(bool normalize)
The &#39;normalized&#39; parameter as used with glVertexAttribPointer()
Definition: Array.hpp:171
A 3d array of GL_HALF_FLOAT vectors.
Definition: Array.hpp:486
An array of vl::ivec4.
Definition: Array.hpp:434
virtual ref< ArrayAbstract > clone() const =0
size_t scalarCountBufferObject() const
Definition: Array.hpp:241
An array of GLuint.
Definition: Array.hpp:437
vec3 getAsVec3(size_t vector_index) const
Returns a vector from the buffer as a vec3 value.
Definition: Array.hpp:365
ArrayAbstract(const ArrayAbstract &other)
Copies only the local data and not the BufferObject related fields.
Definition: Array.hpp:75
void operator=(const ArrayAbstract &other)
Copies only the local data and not the BufferObject related fields.
Definition: Array.hpp:87
void setInterpretation(EVertexAttribInterpretation behavior)
How the data is interpreted by the OpenGL, see EVertexAttribInterpretation.
Definition: Array.hpp:179
BufferObject * bufferObject()
Definition: Array.hpp:98
An array of vl::uvec3.
Definition: Array.hpp:441
vec3 center() const
Returns the center of the AABB.
Definition: AABB.cpp:184
virtual size_t glSize() const =0
Returns the number of scalar components for the array, ie 3 for ArrayFloat3, 1 for ArrayUInt1 etc...
vec2 getAsVec2(size_t vector_index) const
Returns a vector from the buffer as a vec2 value.
Definition: Array.hpp:375
void resize(size_t dim)
Definition: Array.hpp:233
void clear()
Definition: Buffer.hpp:119
An array of vl::ubvec2.
Definition: Array.hpp:457
EVertexAttribInterpretation interpretation() const
How the data is interpreted by the OpenGL, see EVertexAttribInterpretation.
Definition: Array.hpp:182
An array of GLdouble.
Definition: Array.hpp:419
EBufferObjectUsage
virtual vec2 getAsVec2(size_t vector_index) const =0
Returns a vector from the buffer as a vec2 value.
virtual size_t bytesPerVector() const
Definition: Array.hpp:227
vec4 getAsVec4(size_t vector_index) const
Returns a vector from the buffer as a vec4 value.
Definition: Array.hpp:356
size_t bytesUsed() const
Definition: Buffer.hpp:197
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
virtual vec3 getAsVec3(size_t vector_index) const =0
Returns a vector from the buffer as a vec3 value.
const T_VectorType * begin() const
Definition: Array.hpp:245
virtual Sphere computeBoundingSphere() const =0
Computes the bounding sphere enclosing the vectors contained in the buffer.
ref< BufferObject > mBufferObject
Definition: Array.hpp:185
void transform(const mat4 &m)
Transforms the vectors contained in the buffer.
Definition: Array.hpp:322
size_t scalarCount() const
Definition: Array.hpp:239
size_t size() const
Returns the number of elements of an array.
Definition: Array.hpp:235
T_VectorType * end()
Definition: Array.hpp:251
Visualization Library main namespace.
int compare(int a, int b) const
Compares two vectors.
Definition: Array.hpp:385
const BufferObject * bufferObject() const
Definition: Array.hpp:97
const T_VectorType & operator[](size_t i) const
Definition: Array.hpp:261
void setBufferObjectDirty(bool dirty=true)
Wether the BufferObject should be updated or not using the local storage.
Definition: Array.hpp:152
virtual void normalize()=0
Normalizes the vectors contained in the buffer.
T_Scalar * ptr()
Definition: Vector2.hpp:129
const unsigned char * ptr() const
Returns the pointer to the first element of the local buffer. Equivalent to bufferObject()->ptr() ...
Definition: Array.hpp:103
Sphere computeBoundingSphere() const
Computes the bounding sphere enclosing the vectors contained in the buffer.
Definition: Array.hpp:280
An array of vl::ivec3.
Definition: Array.hpp:432
void setUsage(EBufferObjectUsage usage)
BU_STATIC_DRAW by default.
Definition: Array.hpp:158
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
unsigned char * ptr()
Returns the pointer to the first element of the local buffer. Equivalent to bufferObject()->ptr() ...
Definition: Array.hpp:106
virtual size_t glSize() const
Returns the number of scalar components for the array, ie 3 for ArrayFloat3, 1 for ArrayUInt1 etc...
Definition: Array.hpp:223
An array of GLushort.
Definition: Array.hpp:473
An array of GL_UNSIGNED_INT_2_10_10_10_REV.
Definition: Array.hpp:509
An array of vl::ubvec3.
Definition: Array.hpp:459
void initFrom(const std::vector< T_VectorType > &vector)
Definition: Array.hpp:395
A 3d array of GL_UNSIGNED_INT_2_10_10_10_REV vectors.
Definition: Array.hpp:513
The base class for all the reference counted objects.
Definition: Object.hpp:158
An array of vl::dvec2.
Definition: Array.hpp:421
T_VectorType & operator[](size_t i)
Definition: Array.hpp:259
virtual GLenum glType() const
Returns the OpenGL type for the array, ie GL_FLOAT for ArrayFloat3, GL_UNSIGNED_INT for ArrayUInt1 et...
Definition: Array.hpp:225
virtual ref< ArrayAbstract > clone() const
Definition: Array.hpp:267
An array of vl::bvec4.
Definition: Array.hpp:452
void updateBufferObject(EBufferObjectUpdateMode mode=BUM_KeepRamBuffer)
Updates the BufferObject.
Definition: Array.hpp:162
bool isBufferObjectDirty() const
Wether the BufferObject should be updated or not using the local storage.
Definition: Array.hpp:147
bool normalize() const
The &#39;normalized&#39; parameter as used with glVertexAttribPointer()
Definition: Array.hpp:176
EBufferObjectUpdateMode
#define NULL
Definition: OpenGLDefs.hpp:81
The Sphere class defines a sphere using a center and a radius using vl::real precision.
Definition: Sphere.hpp:43
An array of vl::ivec2.
Definition: Array.hpp:430
Data will be sent using glVertexAttribPointer(), that is, data will be converted to floating point pr...
T_Scalar * ptr()
Definition: Vector3.hpp:86
An array of GLfloat.
Definition: Array.hpp:410
Keeps the local buffer on RAM and updates the BufferObject only if it is marked as dirty...
A 2d array of GL_HALF_FLOAT vectors.
Definition: Array.hpp:484
virtual AABB computeBoundingBox() const =0
Computes the axis aligned bounding box enclosing the vectors contained in the buffer.
T_VectorType & at(size_t i)
Definition: Array.hpp:255
An array of vl::usvec2.
Definition: Array.hpp:475
A 2d array of GL_UNSIGNED_INT_2_10_10_10_REV vectors.
Definition: Array.hpp:511
size_t sizeBufferObject() const
Definition: Array.hpp:237
virtual GLenum glType() const =0
Returns the OpenGL type for the array, ie GL_FLOAT for ArrayFloat3, GL_UNSIGNED_INT for ArrayUInt1 et...
T_VectorType vector_type
Definition: Array.hpp:219
The BufferObject class is a Buffer that can upload its data on the GPU memory.
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:145
An array of vl::ubvec4.
Definition: Array.hpp:461
A 4d array of GL_UNSIGNED_INT_2_10_10_10_REV vectors.
Definition: Array.hpp:515
An array of vl::bvec2.
Definition: Array.hpp:448
An array of vl::dvec3.
Definition: Array.hpp:423
virtual size_t size() const =0
Returns the number of elements of an array.
T_Scalar * ptr()
Definition: Vector4.hpp:98
const Vector4 & normalize(T_Scalar *len=NULL)
Definition: Vector4.hpp:254
void clear()
Definition: Array.hpp:231
A 4d array of GL_INT_2_10_10_10_REV vectors.
Definition: Array.hpp:506
An array of vl::svec2.
Definition: Array.hpp:466
virtual int compare(int a, int b) const =0
Compares two vectors.
An array of GL_FIXED.
Definition: Array.hpp:491
unsigned char * ptr()
Definition: Buffer.hpp:201
The Array class is a template array used to conveniently manipulate data stored in a BufferObject...
Definition: Array.hpp:213
A 2d array of GL_INT_2_10_10_10_REV vectors.
Definition: Array.hpp:502
An array of vl::svec4.
Definition: Array.hpp:470
GLsizeiptr byteCountBufferObject() const
An array of vl::bvec3.
Definition: Array.hpp:450
void setBufferData(EBufferObjectUsage usage, bool discard_local_storage=false)
virtual vec4 getAsVec4(size_t vector_index) const =0
Returns a vector from the buffer as a vec4 value.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
void resize(size_t byte_count, size_t alignment=0)
Definition: Buffer.hpp:130
An array of vl::fvec3.
Definition: Array.hpp:414
virtual void transform(const mat4 &m)=0
Transforms the vectors contained in the buffer.
EBufferObjectUsage usage() const
BU_STATIC_DRAW by default.
Definition: Array.hpp:155
Data is specified once and used many times as the source of drawing or image specification commands...
An array of GLint.
Definition: Array.hpp:428
virtual size_t bytesUsed() const
Returns the amount of memory in bytes used by an array. Equivalent to bufferObject()->bytesUsed().
Definition: Array.hpp:109
An array of vl::fvec2.
Definition: Array.hpp:412
virtual ref< ArrayAbstract > createArray() const
Definition: Array.hpp:265
An array of GL_HALF_FLOAT.
Definition: Array.hpp:482
#define VL_CHECK(expr)
Definition: checks.hpp:73
EVertexAttribInterpretation mInterpretation
Definition: Array.hpp:188
EVertexAttribInterpretation
Specifies how the data of a VertexAttribInfo is sent to the OpenGL driver, see also http://www...
An array of vl::usvec3.
Definition: Array.hpp:477
An array 3d GL_FIXED vectors.
Definition: Array.hpp:495
An array of GLbyte.
Definition: Array.hpp:446
An array of vl::dvec4.
Definition: Array.hpp:425
AABB computeBoundingBox() const
Computes the axis aligned bounding box enclosing the vectors contained in the buffer.
Definition: Array.hpp:307
A 3d array of GL_INT_2_10_10_10_REV vectors.
Definition: Array.hpp:504
An array of GLshort.
Definition: Array.hpp:464
A 4d array of GL_HALF_FLOAT vectors.
Definition: Array.hpp:488
EBufferObjectUsage mBufferObjectUsage
Definition: Array.hpp:186
ArrayAbstract()
Default constructor.
Definition: Array.hpp:64
An array 2d GL_FIXED vectors.
Definition: Array.hpp:493