24 #ifndef __HdlDynamicDataSpecial_INCLUDE__
25 #define __HdlDynamicDataSpecial_INCLUDE__
72 const bool floatingPointType,
81 static GLenum getRelatedGLSupportingType(
const GLenum& t);
89 const GLenum& getGLType(
void)
const;
90 const GLenum& getGLSupportingType(
void)
const;
91 const bool& isFloatingPointType(
void)
const;
92 const bool& isIntegerType(
void)
const;
93 const bool& isBooleanType(
void)
const;
94 const bool& isUnsignedType(
void)
const;
95 const int& getNumRows(
void)
const;
96 const int& getNumColumns(
void)
const;
97 int getNumElements(
void)
const;
98 bool isInside(
const int& i,
const int& j)
const;
99 int getIndex(
const int& i,
const int& j)
const;
100 void getCoordinates(
const int& index,
int& i,
int& j)
const;
109 virtual float getf(
const int& i=0,
const int& j=0)
const = 0;
118 virtual void setf(
const float& value,
const int& i=0,
const int& j=0) = 0;
127 virtual double get(
const int& i=0,
const int& j=0)
const = 0;
136 virtual void set(
const double& value,
const int& i=0,
const int& j=0) = 0;
143 virtual const void* getPtr(
void)
const = 0;
150 virtual void* getPtr(
void) = 0;
161 GLIP_API_FUNC
friend std::ostream& operator<<(std::ostream& os,
const HdlDynamicData& d);
163 friend std::ostream& operator<<(std::ostream& os,
const HdlDynamicData& d);
170 GLIP_API_FUNC std::ostream& operator<<(std::ostream& os,
const HdlDynamicData& d);
179 HdlDynamicDataSpecial(
const HdlDynamicDataSpecial& cpy);
180 const HdlDynamicDataSpecial& operator=(
const HdlDynamicDataSpecial& cpy);
183 HdlDynamicDataSpecial(
const GLenum& _type,
int _rows=1,
int _columns=1);
188 virtual ~HdlDynamicDataSpecial(
void);
190 float getf(
const int& i=0,
const int& j=0)
const;
191 void setf(
const float& value,
const int& i=0,
const int& j=0);
192 double get(
const int& i=0,
const int& j=0)
const;
193 void set(
const double& value,
const int& i=0,
const int& j=0);
195 const void* getPtr(
void)
const;
203 HdlDynamicDataSpecial<T>::HdlDynamicDataSpecial(
const GLenum& _type,
int _rows,
int _columns)
213 HdlDynamicDataSpecial<T>::~HdlDynamicDataSpecial(
void)
220 float HdlDynamicDataSpecial<T>::getf(
const int& i,
const int& j)
const
225 return static_cast<float>(data[ getIndex(i, j) ]);
229 void HdlDynamicDataSpecial<T>::setf(
const float& value,
const int& i,
const int& j)
234 data[ getIndex(i, j) ] =
static_cast<T
>(value);
238 double HdlDynamicDataSpecial<T>::get(
const int& i,
const int& j)
const
243 return static_cast<double>(data[ getIndex(i, j) ]);
247 void HdlDynamicDataSpecial<T>::set(
const double& value,
const int& i,
const int& j)
252 data[ getIndex(i, j) ] =
static_cast<T
>(value);
256 const void* HdlDynamicDataSpecial<T>::getPtr(
void)
const
258 return reinterpret_cast<void*
>(data);
262 void* HdlDynamicDataSpecial<T>::getPtr(
void)
264 return reinterpret_cast<void*
>(data);
268 const HdlDynamicData& HdlDynamicDataSpecial<T>::operator=(
const HdlDynamicData& cpy)
270 if(cpy.getGLType()!=getGLType())
271 throw Exception(
"HdlDynamicDataSpecial<T>::operator= - Data types do not match (target : \"" + getGLEnumName(cpy.getGLType()) +
"\"; source : \"" + getGLEnumName(cpy.getGLType()) +
"\").", __FILE__, __LINE__,
Exception::CoreException);
273 std::memcpy(data, cpy.getPtr(), getNumElements()*
sizeof(T));
311 HdlDynamicTable(
const GLenum& _type,
int _columns,
int _rows,
int _slices,
bool _normalized=
false,
int _alignment=1,
bool _proxy=
false);
316 const GLenum& getGLType(
void)
const;
317 bool isFloatingPointType(
void)
const;
318 bool isIntegerType(
void)
const;
319 bool isBooleanType(
void)
const;
320 bool isUnsignedType(
void)
const;
321 const int& getNumRows(
void)
const;
322 const int& getNumColumns(
void)
const;
323 const int& getNumSlices(
void)
const;
324 int getNumElements(
void)
const;
325 const int& getAlignment(
void)
const;
332 virtual size_t getElementSize(
void)
const = 0;
334 size_t getSliceSize(
void)
const;
335 size_t getRowSize(
void)
const;
336 size_t getSize(
void)
const;
337 bool isProxy(
void)
const;
338 bool isNormalized(
void)
const;
339 bool isInside(
const int& j,
const int& i,
const int& d)
const;
340 int getIndex(
const int& j,
const int& i,
const int& d)
const;
341 size_t getOffset(
const int& j,
const int& i,
const int& d)
const;
342 size_t getRowOffset(
const int& i)
const;
352 virtual float getf(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
362 virtual void setf(
const float& value,
const int& j=0,
const int& i=0,
const int& d=0) = 0;
372 virtual double getd(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
382 virtual void setd(
const double& value,
const int& j=0,
const int& i=0,
const int& d=0) = 0;
392 virtual long long getl(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
402 virtual void setl(
const long long& value,
const int& j=0,
const int& i=0,
const int& d=0) = 0;
412 virtual int geti(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
422 virtual void seti(
const int& value,
const int& j=0,
const int& i=0,
const int& d=0) = 0;
432 virtual unsigned char getb(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
442 virtual void setb(
const unsigned char& value,
const int& j=0,
const int& i=0,
const int& d=0) = 0;
452 virtual float getNormalized(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
462 virtual void setNormalized(
const float& value,
const int& j=0,
const int& i=0,
const int& d=0) = 0;
472 virtual void*
get(
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
482 virtual void set(
void* value,
const int& j=0,
const int& i=0,
const int& d=0)
const = 0;
490 virtual float readf(
size_t offset)
const = 0;
498 virtual void writef(
const float& value,
size_t offset) = 0;
506 virtual double readd(
size_t offset)
const = 0;
514 virtual void writed(
const double& value,
size_t offset) = 0;
522 virtual long long readl(
size_t offset)
const = 0;
530 virtual void writel(
const long long& value,
size_t offset) = 0;
538 virtual int readi(
size_t offset)
const = 0;
546 virtual void writei(
const int& value,
size_t offset) = 0;
554 virtual unsigned char readb(
size_t offset)
const = 0;
562 virtual void writeb(
const unsigned char& value,
size_t offset) = 0;
570 virtual float readNormalized(
size_t offset)
const = 0;
578 virtual void writeNormalized(
const float& value,
size_t offset) = 0;
586 virtual void write(
const void* value,
size_t offset) = 0;
588 void writeBytes(
const void* value,
size_t length,
size_t offset);
595 virtual const void* getPtr(
void)
const = 0;
602 virtual void* getPtr(
void) = 0;
610 virtual const void* getRowPtr(
int i)
const = 0;
618 virtual void* getRowPtr(
int i) = 0;
628 void memset(
unsigned char c);
630 static HdlDynamicTable* build(
const GLenum& type,
const int& _columns,
const int& _rows,
const int& _slices,
bool _normalized=
false,
int _alignment=1);
631 static HdlDynamicTable* buildProxy(
void* buffer,
const GLenum& type,
const int& _columns,
const int& _rows,
const int& _slices,
bool _normalized=
false,
int _alignment=1);
642 HdlDynamicTableSpecial(
const HdlDynamicTableSpecial& cpy);
643 const HdlDynamicTableSpecial& operator=(
const HdlDynamicTableSpecial& cpy);
646 HdlDynamicTableSpecial(
const GLenum& _type,
int _columns=1,
int _rows=1,
int _slices=1,
bool _normalized=
false,
int _alignment=1);
647 HdlDynamicTableSpecial(
void* _data,
const GLenum& _type,
int _columns=1,
int _rows=1,
int _slices=1,
bool _normalized=
false,
int _alignment=1);
652 virtual ~HdlDynamicTableSpecial(
void);
654 size_t getElementSize(
void)
const;
656 float getf(
const int& j=0,
const int& i=0,
const int& d=0)
const;
657 void setf(
const float& value,
const int& j=0,
const int& i=0,
const int& d=0);
658 double getd(
const int& j=0,
const int& i=0,
const int& d=0)
const;
659 void setd(
const double& value,
const int& j=0,
const int& i=0,
const int& d=0);
660 long long getl(
const int& j=0,
const int& i=0,
const int& d=0)
const;
661 void setl(
const long long& value,
const int& j=0,
const int& i=0,
const int& d=0);
662 int geti(
const int& j=0,
const int& i=0,
const int& d=0)
const;
663 void seti(
const int& value,
const int& j=0,
const int& i=0,
const int& d=0);
664 unsigned char getb(
const int& j=0,
const int& i=0,
const int& d=0)
const;
665 void setb(
const unsigned char& value,
const int& j=0,
const int& i=0,
const int& d=0);
666 float getNormalized(
const int& j=0,
const int& i=0,
const int& d=0)
const;
667 void setNormalized(
const float& value,
const int& j=0,
const int& i=0,
const int& d=0);
668 void*
get(
const int& j=0,
const int& i=0,
const int& d=0)
const;
669 void set(
void* value,
const int& j=0,
const int& i=0,
const int& d=0)
const ;
671 float readf(
size_t offset)
const;
672 void writef(
const float& value,
size_t offset);
673 double readd(
size_t offset)
const;
674 void writed(
const double& value,
size_t offset);
675 long long readl(
size_t offset)
const;
676 void writel(
const long long& value,
size_t offset);
677 int readi(
size_t offset)
const;
678 void writei(
const int& value,
size_t offset);
679 unsigned char readb(
size_t offset)
const;
680 void writeb(
const unsigned char& value,
size_t offset);
681 float readNormalized(
size_t offset)
const;
682 void writeNormalized(
const float& value,
size_t offset);
683 void write(
const void* value,
size_t offset);
685 const void* getPtr(
void)
const;
687 const void* getRowPtr(
int i)
const;
688 void* getRowPtr(
int i);
692 static float normalize(
const T& t);
693 static T denormalize(
const float& t);
698 float HdlDynamicTableSpecial<float>::normalize(
const float& t);
701 float HdlDynamicTableSpecial<double>::normalize(
const double& t);
704 float HdlDynamicTableSpecial<float>::denormalize(
const float& t);
707 double HdlDynamicTableSpecial<double>::denormalize(
const float& t);
711 HdlDynamicTableSpecial<T>::HdlDynamicTableSpecial(
const GLenum& _type,
int _columns,
int _rows,
int _slices,
bool _normalized,
int _alignment)
712 :
HdlDynamicTable(_type, _columns, _rows, _slices, _normalized, _alignment),
715 data =
new unsigned char[
getSize()];
717 std::memset(data, 0,
getSize());
721 HdlDynamicTableSpecial<T>::HdlDynamicTableSpecial(
void* _data,
const GLenum& _type,
int _columns,
int _rows,
int _slices,
bool _normalized,
int _alignment)
722 : HdlDynamicTable(_type, _columns, _rows, _slices, _normalized, _alignment, true),
723 data(reinterpret_cast<unsigned char*>(_data))
727 HdlDynamicTableSpecial<T>::~HdlDynamicTableSpecial(
void)
737 size_t HdlDynamicTableSpecial<T>::getElementSize(
void)
const
743 float HdlDynamicTableSpecial<T>::getf(
const int& j,
const int& i,
const int& d)
const
746 return static_cast<float>(*
reinterpret_cast<T*
>(data + getOffset(j, i, d)));
748 return HdlDynamicTableSpecial<float>::denormalize(*reinterpret_cast<T*>(data + getOffset(j, i, d)));
752 void HdlDynamicTableSpecial<T>::setf(
const float& value,
const int& j,
const int& i,
const int& d)
755 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) =
static_cast<T
>(value);
757 (*reinterpret_cast<T*>(data + getOffset(j, i, d))) = HdlDynamicTableSpecial<float>::normalize(value);
761 double HdlDynamicTableSpecial<T>::getd(
const int& j,
const int& i,
const int& d)
const
764 return static_cast<double>(*
reinterpret_cast<T*
>(data + getOffset(j, i, d)));
766 return HdlDynamicTableSpecial<double>::denormalize(*reinterpret_cast<T*>(data + getOffset(j, i, d)));
770 void HdlDynamicTableSpecial<T>::setd(
const double& value,
const int& j,
const int& i,
const int& d)
773 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) =
static_cast<T
>(value);
775 (*reinterpret_cast<T*>(data + getOffset(j, i, d))) = HdlDynamicTableSpecial<double>::normalize(value);
779 long long HdlDynamicTableSpecial<T>::getl(
const int& j,
const int& i,
const int& d)
const
782 return static_cast<long long>(*
reinterpret_cast<T*
>(data + getOffset(j, i, d)));
784 return HdlDynamicTableSpecial<long long>::denormalize(*reinterpret_cast<T*>(data + getOffset(j, i, d)));
788 void HdlDynamicTableSpecial<T>::setl(
const long long& value,
const int& j,
const int& i,
const int& d)
791 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) =
static_cast<T
>(value);
793 (*reinterpret_cast<T*>(data + getOffset(j, i, d))) = HdlDynamicTableSpecial<long long>::normalize(value);
797 int HdlDynamicTableSpecial<T>::geti(
const int& j,
const int& i,
const int& d)
const
800 return static_cast<int>(*
reinterpret_cast<T*
>(data + getOffset(j, i, d)));
802 return HdlDynamicTableSpecial<int>::denormalize(*reinterpret_cast<T*>(data + getOffset(j, i, d)));
806 void HdlDynamicTableSpecial<T>::seti(
const int& value,
const int& j,
const int& i,
const int& d)
809 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) =
static_cast<T
>(value);
811 (*reinterpret_cast<T*>(data + getOffset(j, i, d))) = HdlDynamicTableSpecial<int>::normalize(value);
815 unsigned char HdlDynamicTableSpecial<T>::getb(
const int& j,
const int& i,
const int& d)
const
818 return static_cast<unsigned char>(*
reinterpret_cast<T*
>(data + getOffset(j, i, d)));
820 return HdlDynamicTableSpecial<unsigned char>::denormalize(*reinterpret_cast<T*>(data + getOffset(j, i, d)));
824 void HdlDynamicTableSpecial<T>::setb(
const unsigned char& value,
const int& j,
const int& i,
const int& d)
827 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) =
static_cast<T
>(value);
829 (*reinterpret_cast<T*>(data + getOffset(j, i, d))) = HdlDynamicTableSpecial<unsigned char>::normalize(value);
833 float HdlDynamicTableSpecial<T>::getNormalized(
const int& j,
const int& i,
const int& d)
const
836 return HdlDynamicTableSpecial<T>::normalize(*reinterpret_cast<T*>(data + getOffset(j, i, d)));
838 return static_cast<float>(*
reinterpret_cast<T*
>(data + getOffset(j, i, d)));
842 void HdlDynamicTableSpecial<T>::setNormalized(
const float& value,
const int& j,
const int& i,
const int& d)
845 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) =
static_cast<T
>(HdlDynamicTableSpecial<T>::denormalize(value));
847 (*reinterpret_cast<T*>(data + getOffset(j, i, d))) = static_cast<T>(value);
851 void* HdlDynamicTableSpecial<T>::get(
const int& j,
const int& i,
const int& d)
const
853 return reinterpret_cast<void*
>(data + getOffset(j, i, d));
857 void HdlDynamicTableSpecial<T>::set(
void* value,
const int& j,
const int& i,
const int& d)
const
859 (*
reinterpret_cast<T*
>(data + getOffset(j, i, d))) = (*
reinterpret_cast<T*
>(value));
863 float HdlDynamicTableSpecial<T>::readf(
size_t offset)
const
866 return static_cast<float>(*
reinterpret_cast<const T*
>(data+offset));
868 return HdlDynamicTableSpecial<float>::denormalize(*reinterpret_cast<const T*>(data+offset));
872 void HdlDynamicTableSpecial<T>::writef(
const float& value,
size_t offset)
875 (*
reinterpret_cast<T*
>(data+offset)) =
static_cast<T
>(value);
877 (*reinterpret_cast<T*>(data+offset)) = HdlDynamicTableSpecial<float>::normalize(value);
881 double HdlDynamicTableSpecial<T>::readd(
size_t offset)
const
884 return static_cast<double>(*
reinterpret_cast<const T*
>(data+offset));
886 return HdlDynamicTableSpecial<double>::denormalize(*reinterpret_cast<const T*>(data+offset));
890 void HdlDynamicTableSpecial<T>::writed(
const double& value,
size_t offset)
893 (*
reinterpret_cast<T*
>(data+offset)) =
static_cast<T
>(value);
895 (*reinterpret_cast<T*>(data+offset)) = HdlDynamicTableSpecial<double>::normalize(value);
899 long long HdlDynamicTableSpecial<T>::readl(
size_t offset)
const
902 return static_cast<long long>(*
reinterpret_cast<const T*
>(data+offset));
904 return HdlDynamicTableSpecial<long long>::denormalize(*reinterpret_cast<const T*>(data+offset));
908 void HdlDynamicTableSpecial<T>::writel(
const long long& value,
size_t offset)
911 (*
reinterpret_cast<T*
>(data+offset)) =
static_cast<T
>(value);
913 (*reinterpret_cast<T*>(data+offset)) = HdlDynamicTableSpecial<long long>::normalize(value);
917 int HdlDynamicTableSpecial<T>::readi(
size_t offset)
const
920 return static_cast<int>(*
reinterpret_cast<const T*
>(data+offset));
922 return HdlDynamicTableSpecial<int>::denormalize(*reinterpret_cast<const T*>(data+offset));
926 void HdlDynamicTableSpecial<T>::writei(
const int& value,
size_t offset)
929 (*
reinterpret_cast<T*
>(data+offset)) =
static_cast<T
>(value);
931 (*reinterpret_cast<T*>(data+offset)) = HdlDynamicTableSpecial<int>::normalize(value);
935 unsigned char HdlDynamicTableSpecial<T>::readb(
size_t offset)
const
938 return static_cast<unsigned char>(*
reinterpret_cast<const T*
>(data+offset));
940 return HdlDynamicTableSpecial<unsigned char>::denormalize(*reinterpret_cast<const T*>(data+offset));
944 void HdlDynamicTableSpecial<T>::writeb(
const unsigned char& value,
size_t offset)
947 (*
reinterpret_cast<T*
>(data+offset)) =
static_cast<T
>(value);
949 (*reinterpret_cast<T*>(data+offset)) = HdlDynamicTableSpecial<unsigned char>::normalize(value);
953 float HdlDynamicTableSpecial<T>::readNormalized(
size_t offset)
const
956 return HdlDynamicTableSpecial<T>::normalize(*reinterpret_cast<const T*>(data+offset));
958 return static_cast<float>(*
reinterpret_cast<const T*
>(data+offset));
962 void HdlDynamicTableSpecial<T>::writeNormalized(
const float& value,
size_t offset)
965 (*
reinterpret_cast<T*
>(data+offset)) = HdlDynamicTableSpecial<T>::denormalize(value);
967 (*reinterpret_cast<T*>(data+offset)) =
static_cast<T
>(value);
971 void HdlDynamicTableSpecial<T>::write(
const void* value,
size_t offset)
973 (*
reinterpret_cast<T*
>(data+offset)) = (*
reinterpret_cast<const T*
>(value));
977 const void* HdlDynamicTableSpecial<T>::getPtr(
void)
const
979 return reinterpret_cast<void*
>(data);
983 void* HdlDynamicTableSpecial<T>::getPtr(
void)
985 return reinterpret_cast<void*
>(data);
989 const void* HdlDynamicTableSpecial<T>::getRowPtr(
int i)
const
991 return reinterpret_cast<void*
>(data + i *getRowSize());
995 void* HdlDynamicTableSpecial<T>::getRowPtr(
int i)
997 return reinterpret_cast<void*
>(data + i *getRowSize());
1000 template<
typename T>
1001 const HdlDynamicTable& HdlDynamicTableSpecial<T>::operator=(
const HdlDynamicTable& cpy)
1003 if(cpy.getGLType()!=getGLType())
1004 throw Exception(
"HdlDynamicTableSpecial<T>::operator= - Data types do not match (target : \"" + getGLEnumName(cpy.getGLType()) +
"\"; source : \"" + getGLEnumName(cpy.getGLType()) +
"\").", __FILE__, __LINE__,
Exception::CoreException);
1005 if(cpy.getNumRows()!=getNumRows() || cpy.getNumColumns()!=getNumColumns() || cpy.getNumSlices()!=getNumSlices())
1006 throw Exception(
"HdlDynamicTableSpecial<T>::operator= - Data format does not match.", __FILE__, __LINE__,
Exception::CoreException);
1008 if(cpy.getAlignment()==getAlignment())
1009 std::memcpy(data, cpy.getPtr(), getSize());
1013 for(
int i=0; i<cpy.getNumRows(); i++)
1014 std::memcpy(getRowPtr(i), cpy.getRowPtr(i), std::min(getRowSize(), cpy.getRowSize()));
1020 template<
typename T>
1021 float HdlDynamicTableSpecial<T>::normalize(
const T& t)
1023 return (static_cast<float>(t) - static_cast<float>(std::numeric_limits<T>::min())) / (
static_cast<float>(std::numeric_limits<T>::max()) - static_cast<float>(std::numeric_limits<T>::min()));
1026 template<
typename T>
1027 T HdlDynamicTableSpecial<T>::denormalize(
const float& t)
1029 return static_cast<T
>(t * (
static_cast<float>(std::numeric_limits<T>::max()) - static_cast<float>(std::numeric_limits<T>::min())) +
static_cast<float>(std::numeric_limits<T>::min()));
Definition: Component.hpp:32
Dynamic table allocator for GL types (run-time resolution of type).
Definition: HdlDynamicData.hpp:299
Dynamic allocator for GL types (run-time resolution of type).
Definition: HdlDynamicData.hpp:65
int getNumElements(void) const
Get the number of elements of the matrix (rows times columns).
Definition: HdlDynamicData.cpp:176
size_t getSize(void) const
Get the size of whole table, in bytes.
Definition: HdlDynamicData.cpp:477
OpenGL includes and tools.
From a core library component.
Definition: Exception.hpp:49