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][0]),
00106 glShortToFloat(_field[index][0]));
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 inline Vec3f glByteVecToFloatVec(const Vec3b& v)
00160 {
00161 return Vec3f(
00162 glByteToFloat(v[0]),
00163 glByteToFloat(v[1]),
00164 glByteToFloat(v[2]));
00165 }
00166
00167 inline Vec3b glFloatVecToByteVec(const Vec3f& v)
00168 {
00169 return Vec3b(
00170 glFloatToByte(v[0]),
00171 glFloatToByte(v[1]),
00172 glFloatToByte(v[2]));
00173 }
00174
00175 template<> inline
00176 Vec3f GeoProperty<GeoNormals3bPropertyDesc>::getValue(const UInt32 index)
00177 {
00178 return glByteVecToFloatVec(_field[index]);
00179 }
00180
00181 template<> inline
00182 Vec3f GeoProperty<GeoNormals3bPropertyDesc>::getValue(
00183 const UInt32 index) const
00184 {
00185 return glByteVecToFloatVec(_field[index]);
00186 }
00187
00188 template<> inline
00189 void GeoProperty<GeoNormals3bPropertyDesc>::getValue(
00190 Vec3f &res,
00191 const UInt32 index)
00192 {
00193 res.setValues(glByteToFloat(_field[index][0]),
00194 glByteToFloat(_field[index][1]),
00195 glByteToFloat(_field[index][2]));
00196 }
00197
00198 template<> inline
00199 void GeoProperty<GeoNormals3bPropertyDesc>::getValue(
00200 Vec3f &res,
00201 const UInt32 index) const
00202 {
00203 res.setValues(glByteToFloat(_field[index][0]),
00204 glByteToFloat(_field[index][1]),
00205 glByteToFloat(_field[index][2]));
00206 }
00207
00208 template<>
00209 inline void
00210 GeoProperty<GeoNormals3bPropertyDesc>::setValue( const Vec3f & val,
00211 const UInt32 index )
00212 {
00213 _field[index].setValues(glFloatToByte(val[0]),
00214 glFloatToByte(val[1]),
00215 glFloatToByte(val[2]));
00216 }
00217
00218 template<>
00219 inline void
00220 GeoProperty<GeoNormals3bPropertyDesc>::addValue( const Vec3f & val )
00221 {
00222 _field.push_back(glFloatVecToByteVec(val));
00223 }
00224
00225 template <> inline
00226 bool GeoProperty<GeoNormals3bPropertyDesc>::insertValue(const Vec3f & val,
00227 const UInt32 index)
00228 {
00229 if(_field.size() < index)
00230 {
00231 return false;
00232 }
00233 else if(_field.size() == index)
00234 {
00235 addValue(val);
00236 return true;
00237 }
00238 else
00239 {
00240 _field.insert(_field.begin() + index, glFloatVecToByteVec(val));
00241 return true;
00242 }
00243 }
00244
00245 OSG_END_NAMESPACE