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 #include <sofa/component/visualmodel/OglVariable.h>
00026 #include <sofa/core/ObjectFactory.h>
00027
00028 namespace sofa
00029 {
00030
00031 namespace component
00032 {
00033
00034 namespace visualmodel
00035 {
00036
00038 SOFA_DECL_CLASS(OglIntVariable)
00039 SOFA_DECL_CLASS(OglInt2Variable)
00040 SOFA_DECL_CLASS(OglInt3Variable)
00041 SOFA_DECL_CLASS(OglInt4Variable)
00042
00043
00044 int OglIntVariableClass = core::RegisterObject("OglIntVariable")
00045 .add< OglIntVariable >()
00046 ;
00047
00048 int OglInt2VariableClass = core::RegisterObject("OglInt2Variable")
00049 .add< OglInt2Variable >()
00050 ;
00051
00052 int OglInt3VariableClass = core::RegisterObject("OglInt3Variable")
00053 .add< OglInt3Variable >()
00054 ;
00055
00056 int OglInt4VariableClass = core::RegisterObject("OglInt4Variable")
00057 .add< OglInt4Variable >()
00058 ;
00059
00060 OglIntVariable::OglIntVariable()
00061 : value(initData(&value, (int) 0, "value", "Set a int value"))
00062 {
00063
00064 }
00065
00066 OglInt2Variable::OglInt2Variable()
00067 : value(initData(&value, (defaulttype::Vec<2, int>) defaulttype::Vec<2, int>(0,0) , "value", "Set a Vec2i value"))
00068 {
00069
00070 }
00071
00072 OglInt3Variable::OglInt3Variable()
00073 : value(initData(&value, (defaulttype::Vec<3, int>) defaulttype::Vec<3, int>(0,0,0) , "value", "Set a Vec3i value"))
00074 {
00075
00076 }
00077
00078 OglInt4Variable::OglInt4Variable()
00079 : value(initData(&value, (defaulttype::Vec<4, int>) defaulttype::Vec<4, int>(0,0,0,0) , "value", "Set a Vec4i value"))
00080 {
00081
00082 }
00083
00084 void OglIntVariable::initVisual()
00085 {
00086 shader->setInt(id.getValue().c_str(), value.getValue());
00087 }
00088
00089
00090 void OglInt2Variable::initVisual()
00091 {
00092 shader->setInt2(id.getValue().c_str(), value.getValue()[0], value.getValue()[1]);
00093 }
00094
00095 void OglInt3Variable::initVisual()
00096 {
00097 shader->setInt3(id.getValue().c_str(), value.getValue()[0], value.getValue()[1], value.getValue()[2]);
00098 }
00099
00100 void OglInt4Variable::initVisual()
00101 {
00102 shader->setInt4(id.getValue().c_str(), value.getValue()[0], value.getValue()[1], value.getValue()[2], value.getValue()[3]);
00103 }
00104
00107 SOFA_DECL_CLASS(OglFloatVariable)
00108 SOFA_DECL_CLASS(OglFloat2Variable)
00109 SOFA_DECL_CLASS(OglFloat3Variable)
00110 SOFA_DECL_CLASS(OglFloat4Variable)
00111
00112
00113 int OglFloatVariableClass = core::RegisterObject("OglFloatVariable")
00114 .add< OglFloatVariable >()
00115 ;
00116
00117 int OglFloat2VariableClass = core::RegisterObject("OglFloat2Variable")
00118 .add< OglFloat2Variable >()
00119 ;
00120
00121 int OglFloat3VariableClass = core::RegisterObject("OglFloat3Variable")
00122 .add< OglFloat3Variable >()
00123 ;
00124
00125 int OglFloat4VariableClass = core::RegisterObject("OglFloat4Variable")
00126 .add< OglFloat4Variable >()
00127 ;
00128
00129 OglFloatVariable::OglFloatVariable()
00130 : value(initData(&value, (float) 0.0, "value", "Set a float value"))
00131 {
00132
00133 }
00134
00135 OglFloat2Variable::OglFloat2Variable()
00136 : value(initData(&value, (defaulttype::Vec2f) defaulttype::Vec2f(0.0,0.0) , "value", "Set a Vec2f value"))
00137 {
00138
00139 }
00140
00141 OglFloat3Variable::OglFloat3Variable()
00142 : value(initData(&value, (defaulttype::Vec3f) defaulttype::Vec3f(0.0,0.0,0.0) , "value", "Set a Vec3f value"))
00143 {
00144
00145 }
00146
00147 OglFloat4Variable::OglFloat4Variable()
00148 : value(initData(&value, (defaulttype::Vec4f) defaulttype::Vec4f(0.0,0.0,0.0,0.0) , "value", "Set a Vec4f value"))
00149 {
00150
00151 }
00152
00153 void OglFloatVariable::initVisual()
00154 {
00155 shader->setFloat(id.getValue().c_str(), value.getValue());
00156 }
00157
00158
00159 void OglFloat2Variable::initVisual()
00160 {
00161 shader->setFloat2(id.getValue().c_str(), value.getValue()[0], value.getValue()[1]);
00162 }
00163
00164 void OglFloat3Variable::initVisual()
00165 {
00166 shader->setFloat3(id.getValue().c_str(), value.getValue()[0], value.getValue()[1], value.getValue()[2]);
00167 }
00168
00169 void OglFloat4Variable::initVisual()
00170 {
00171 shader->setFloat4(id.getValue().c_str(), value.getValue()[0], value.getValue()[1], value.getValue()[2], value.getValue()[3]);
00172 }
00173
00174
00176 SOFA_DECL_CLASS(OglIntVectorVariable)
00177 SOFA_DECL_CLASS(OglIntVector2Variable)
00178 SOFA_DECL_CLASS(OglIntVector3Variable)
00179 SOFA_DECL_CLASS(OglIntVector4Variable)
00180
00181
00182 int OglIntVectorVariableClass = core::RegisterObject("OglIntVectorVariable")
00183 .add< OglIntVectorVariable >()
00184 ;
00185
00186
00187 int OglIntVector2VariableClass = core::RegisterObject("OglIntVector2Variable")
00188 .add< OglIntVector2Variable >()
00189 ;
00190
00191
00192 int OglIntVector3VariableClass = core::RegisterObject("OglIntVector3Variable")
00193 .add< OglIntVector3Variable >()
00194 ;
00195
00196
00197 int OglIntVector4VariableClass = core::RegisterObject("OglIntVector4Variable")
00198 .add< OglIntVector4Variable >()
00199 ;
00200
00201 OglIntVectorVariable::OglIntVectorVariable()
00202 : iv(initData(&iv, (helper::vector<GLint>) helper::vector<GLint>(1), "values", "Set int array values"))
00203 {
00204
00205 }
00206
00207 OglIntVector2Variable::OglIntVector2Variable()
00208 {
00209
00210 }
00211
00212 OglIntVector3Variable::OglIntVector3Variable()
00213 {
00214
00215 }
00216
00217 OglIntVector4Variable::OglIntVector4Variable()
00218 {
00219
00220 }
00221
00222
00223 void OglIntVectorVariable::init()
00224 {
00225 OglVariable::init();
00226 }
00227
00228 void OglIntVector2Variable::init()
00229 {
00230 OglIntVectorVariable::init();
00231 helper::vector<GLint> temp = iv.getValue();
00232 if (iv.getValue().size() %2 != 0)
00233 {
00234 std::cerr << "The number of values is not even ; padding with one zero" << std::endl;
00235 temp.push_back(0);
00236 iv.setValue(temp);
00237
00238 }
00239 }
00240
00241 void OglIntVector3Variable::init()
00242 {
00243 OglIntVectorVariable::init();
00244 helper::vector<GLint> temp = iv.getValue();
00245
00246 if (iv.getValue().size() %3 != 0)
00247 {
00248 std::cerr << "The number of values is not a multiple of 3 ; padding with zero(s)" << std::endl;
00249 while (iv.getValue().size() %3 != 0)
00250 temp.push_back(0);
00251 iv.setValue(temp);
00252 }
00253 }
00254
00255 void OglIntVector4Variable::init()
00256 {
00257 OglIntVectorVariable::init();
00258 helper::vector<GLint> temp = iv.getValue();
00259
00260 if (iv.getValue().size() %4 != 0)
00261 {
00262 std::cerr << "The number of values is not a multiple of 4 ; padding with zero(s)" << std::endl;
00263 while (iv.getValue().size() %4 != 0)
00264 temp.push_back(0);
00265 iv.setValue(temp);
00266 }
00267 }
00268
00269 void OglIntVectorVariable::initVisual()
00270 {
00271 shader->setIntVector(id.getValue().c_str(), iv.getValue().size(), &(iv.getValue()[0]));
00272 }
00273
00274 void OglIntVector2Variable::initVisual()
00275 {
00276 shader->setIntVector2(id.getValue().c_str(), iv.getValue().size()/2, &(iv.getValue()[0]));
00277 }
00278
00279 void OglIntVector3Variable::initVisual()
00280 {
00281 shader->setIntVector3(id.getValue().c_str(), iv.getValue().size()/3, &(iv.getValue()[0]));
00282 }
00283
00284 void OglIntVector4Variable::initVisual()
00285 {
00286 shader->setIntVector4(id.getValue().c_str(), iv.getValue().size()/4, &(iv.getValue()[0]));
00287 }
00288
00289
00291 SOFA_DECL_CLASS(OglFloatVectorVariable)
00292 SOFA_DECL_CLASS(OglFloatVector2Variable)
00293 SOFA_DECL_CLASS(OglFloatVector3Variable)
00294 SOFA_DECL_CLASS(OglFloatVector4Variable)
00295
00296
00297 int OglFloatVectorVariableClass = core::RegisterObject("OglFloatVectorVariable")
00298 .add< OglFloatVectorVariable >()
00299 ;
00300
00301
00302 int OglFloatVector2VariableClass = core::RegisterObject("OglFloatVector2Variable")
00303 .add< OglFloatVector2Variable >()
00304 ;
00305
00306
00307 int OglFloatVector3VariableClass = core::RegisterObject("OglFloatVector3Variable")
00308 .add< OglFloatVector3Variable >()
00309 ;
00310
00311 int OglFloatVector4VariableClass = core::RegisterObject("OglFloatVector4Variable")
00312 .add< OglFloatVector4Variable >()
00313 ;
00314
00315 OglFloatVectorVariable::OglFloatVectorVariable()
00316 : fv(initData(&fv, (helper::vector<float>) helper::vector<float>(1), "values", "Set float array values"))
00317 {
00318
00319 }
00320
00321 OglFloatVector2Variable::OglFloatVector2Variable()
00322 {
00323
00324 }
00325
00326 OglFloatVector3Variable::OglFloatVector3Variable()
00327 {
00328
00329 }
00330
00331 OglFloatVector4Variable::OglFloatVector4Variable()
00332 {
00333
00334 }
00335
00336
00337 void OglFloatVectorVariable::init()
00338 {
00339 OglVariable::init();
00340 }
00341
00342 void OglFloatVector2Variable::init()
00343 {
00344 OglFloatVectorVariable::init();
00345 helper::vector<float> temp = fv.getValue();
00346 if (fv.getValue().size() %2 != 0)
00347 {
00348 std::cerr << "The number of values is not even ; padding with one zero" << std::endl;
00349 temp.push_back(0.0);
00350 fv.setValue(temp);
00351 }
00352 }
00353
00354 void OglFloatVector3Variable::init()
00355 {
00356 OglFloatVectorVariable::init();
00357 helper::vector<float> temp = fv.getValue();
00358
00359 if (fv.getValue().size() %3 != 0)
00360 {
00361 std::cerr << "The number of values is not a multiple of 3 ; padding with zero(s)" << std::endl;
00362 while (fv.getValue().size() %3 != 0)
00363 temp.push_back(0.0);
00364 fv.setValue(temp);
00365 }
00366 }
00367
00368 void OglFloatVector4Variable::init()
00369 {
00370 OglFloatVectorVariable::init();
00371 helper::vector<float> temp = fv.getValue();
00372
00373 if (fv.getValue().size() %4 != 0)
00374 {
00375 std::cerr << "The number of values is not a multiple of 4 ; padding with zero(s)" << std::endl;
00376 while (fv.getValue().size() %4 != 0)
00377 temp.push_back(0.0);
00378 fv.setValue(temp);
00379 }
00380 }
00381
00382 void OglFloatVectorVariable::initVisual()
00383 {
00384 shader->setFloatVector(id.getValue().c_str(), fv.getValue().size(), &(fv.getValue()[0]));
00385 }
00386
00387 void OglFloatVector2Variable::initVisual()
00388 {
00389 shader->setFloatVector2(id.getValue().c_str(), fv.getValue().size()/2, &(fv.getValue()[0]));
00390 }
00391
00392 void OglFloatVector3Variable::initVisual()
00393 {
00394 shader->setFloatVector3(id.getValue().c_str(), fv.getValue().size()/3, &(fv.getValue()[0]));
00395 }
00396
00397 void OglFloatVector4Variable::initVisual()
00398 {
00399 shader->setFloatVector4(id.getValue().c_str(), fv.getValue().size()/4, &(fv.getValue()[0]));
00400 }
00401
00402
00403 }
00404
00405 }
00406
00407 }