00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041
00042 #include "OSGConfig.h"
00043
00044 OSG_BEGIN_NAMESPACE
00045
00046
00047
00048
00049 inline float glShortToFloat(GLshort b)
00050 {
00051 return (2.0f * b + 1.0f) / 65535.0f;
00052 }
00053
00054 inline GLshort glFloatToShort(float f)
00055 {
00056
00057 return GLshort((f * 65535.0 - 1.0f) / 2.0f);
00058 }
00059
00060 inline Vec3f glShortVecToFloatVec(const Vec3s& v)
00061 {
00062 return Vec3f(
00063 glShortToFloat(v[0]),
00064 glShortToFloat(v[1]),
00065 glShortToFloat(v[2]));
00066 }
00067
00068 inline Vec3s glFloatVecToShortVec(const Vec3f& v)
00069 {
00070 return Vec3s(
00071 glFloatToShort(v[0]),
00072 glFloatToShort(v[1]),
00073 glFloatToShort(v[2]));
00074 }
00075
00076 template<> inline
00077 Vec3f GeoProperty<GeoNormals3sPropertyDesc>::getValue(const UInt32 index)
00078 {
00079 return glShortVecToFloatVec(_field[index]);
00080 }
00081
00082 template<> inline
00083 Vec3f GeoProperty<GeoNormals3sPropertyDesc>::getValue(
00084 const UInt32 index) const
00085 {
00086 return glShortVecToFloatVec(_field[index]);
00087 }
00088
00089 template<> inline
00090 void GeoProperty<GeoNormals3sPropertyDesc>::getValue(
00091 Vec3f &res,
00092 const UInt32 index)
00093 {
00094 res.setValues(glShortToFloat(_field[index][0]),
00095 glShortToFloat(_field[index][1]),
00096 glShortToFloat(_field[index][2]));
00097 }
00098
00099 template<> inline
00100 void GeoProperty<GeoNormals3sPropertyDesc>::getValue(
00101 Vec3f &res,
00102 const UInt32 index) const
00103 {
00104 res.setValues(glShortToFloat(_field[index][0]),
00105 glShortToFloat(_field[index][1]),
00106 glShortToFloat(_field[index][2]));
00107 }
00108
00109 template<>
00110 inline void
00111 GeoProperty<GeoNormals3sPropertyDesc>::setValue( const Vec3f & val,
00112 const UInt32 index )
00113 {
00114 _field[index].setValues(glFloatToShort(val[0]),
00115 glFloatToShort(val[1]),
00116 glFloatToShort(val[2]));
00117 }
00118
00119 template<>
00120 inline void
00121 GeoProperty<GeoNormals3sPropertyDesc>::addValue( const Vec3f & val )
00122 {
00123 _field.push_back(glFloatVecToShortVec(val));
00124 }
00125
00126 template <> inline
00127 bool GeoProperty<GeoNormals3sPropertyDesc>::insertValue(const Vec3f & val,
00128 const UInt32 index)
00129 {
00130 if(_field.size() < index)
00131 {
00132 return false;
00133 }
00134 else if(_field.size() == index)
00135 {
00136 addValue(val);
00137 return true;
00138 }
00139 else
00140 {
00141 _field.insert(_field.begin() + index, glFloatVecToShortVec(val));
00142 return true;
00143 }
00144 }
00145
00146
00147
00148 inline float glByteToFloat(GLbyte b)
00149 {
00150 return (2.0f * b + 1.0f) / 255.0f;
00151 }
00152
00153 inline GLbyte glFloatToByte(float f)
00154 {
00155
00156 return GLbyte((f * 255.0 - 1.0f) / 2.0f);
00157 }
00158
00159 #ifndef OSG_NO_INT8_PNT
00160 inline Vec3f glByteVecToFloatVec(const Vec3b& v)
00161 {
00162 return Vec3f(
00163 glByteToFloat(v[0]),
00164 glByteToFloat(v[1]),
00165 glByteToFloat(v[2]));
00166 }
00167
00168 inline Vec3b glFloatVecToByteVec(const Vec3f& v)
00169 {
00170 return Vec3b(
00171 glFloatToByte(v[0]),
00172 glFloatToByte(v[1]),
00173 glFloatToByte(v[2]));
00174 }
00175
00176 template<> inline
00177 Vec3f GeoProperty<GeoNormals3bPropertyDesc>::getValue(const UInt32 index)
00178 {
00179 return glByteVecToFloatVec(_field[index]);
00180 }
00181
00182 template<> inline
00183 Vec3f GeoProperty<GeoNormals3bPropertyDesc>::getValue(
00184 const UInt32 index) const
00185 {
00186 return glByteVecToFloatVec(_field[index]);
00187 }
00188
00189 template<> inline
00190 void GeoProperty<GeoNormals3bPropertyDesc>::getValue(
00191 Vec3f &res,
00192 const UInt32 index)
00193 {
00194 res.setValues(glByteToFloat(_field[index][0]),
00195 glByteToFloat(_field[index][1]),
00196 glByteToFloat(_field[index][2]));
00197 }
00198
00199 template<> inline
00200 void GeoProperty<GeoNormals3bPropertyDesc>::getValue(
00201 Vec3f &res,
00202 const UInt32 index) const
00203 {
00204 res.setValues(glByteToFloat(_field[index][0]),
00205 glByteToFloat(_field[index][1]),
00206 glByteToFloat(_field[index][2]));
00207 }
00208
00209 template<>
00210 inline void
00211 GeoProperty<GeoNormals3bPropertyDesc>::setValue( const Vec3f & val,
00212 const UInt32 index )
00213 {
00214 _field[index].setValues(glFloatToByte(val[0]),
00215 glFloatToByte(val[1]),
00216 glFloatToByte(val[2]));
00217 }
00218
00219 template<>
00220 inline void
00221 GeoProperty<GeoNormals3bPropertyDesc>::addValue( const Vec3f & val )
00222 {
00223 _field.push_back(glFloatVecToByteVec(val));
00224 }
00225
00226 template <> inline
00227 bool GeoProperty<GeoNormals3bPropertyDesc>::insertValue(const Vec3f & val,
00228 const UInt32 index)
00229 {
00230 if(_field.size() < index)
00231 {
00232 return false;
00233 }
00234 else if(_field.size() == index)
00235 {
00236 addValue(val);
00237 return true;
00238 }
00239 else
00240 {
00241 _field.insert(_field.begin() + index, glFloatVecToByteVec(val));
00242 return true;
00243 }
00244 }
00245 #endif
00246
00247 OSG_END_NAMESPACE