Panda3D
|
00001 // Filename: shader.I 00002 // Heavily Modified: jyelon (Sep05) 00003 // Updated by: fperazzi, PandaSE(06Apr10) 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function: Shader::get_filename 00017 // Access: Public 00018 // Description: Return the Shader's filename for the given shader 00019 // type. 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE const Filename Shader:: 00022 get_filename(const ShaderType &type) const { 00023 if (_filename->_separate) { 00024 nassertr(type != ST_none || !_filename->_shared.empty(), ""); 00025 switch (type) { 00026 case ST_vertex: 00027 return _filename->_vertex; 00028 break; 00029 case ST_fragment: 00030 return _filename->_fragment; 00031 break; 00032 case ST_geometry: 00033 return _filename->_geometry; 00034 break; 00035 default: 00036 return _filename->_shared; 00037 } 00038 } else { 00039 return _filename->_shared; 00040 } 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: Shader::get_text 00045 // Access: Public 00046 // Description: Return the Shader's text for the given shader type. 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE const string &Shader:: 00049 get_text(const ShaderType &type) const { 00050 if (_text->_separate) { 00051 nassertr(type != ST_none || !_text->_shared.empty(), _text->_shared); 00052 switch (type) { 00053 case ST_vertex: 00054 return _text->_vertex; 00055 break; 00056 case ST_fragment: 00057 return _text->_fragment; 00058 break; 00059 case ST_geometry: 00060 return _text->_geometry; 00061 break; 00062 default: 00063 return _text->_shared; 00064 } 00065 } else { 00066 return _text->_shared; 00067 } 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: Shader::get_error_flag 00072 // Access: Public 00073 // Description: Returns true if the shader contains a compile-time 00074 // error. This doesn't tell you whether or not the 00075 // shader is supported on the current video card. 00076 //////////////////////////////////////////////////////////////////// 00077 INLINE const bool Shader:: 00078 get_error_flag() const { 00079 return _error_flag; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: Shader::set_shader_utilization 00084 // Access: Published, Static 00085 // Description: Set this flag to SUT_none, SUT_basic, or 00086 // SUT_advanced to limit panda's automatic shader 00087 // generation facilities. 00088 //////////////////////////////////////////////////////////////////// 00089 INLINE void Shader:: 00090 set_shader_utilization(ShaderUtilization sut) { 00091 _shader_utilization = sut; 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: Shader::get_shader_utilization 00096 // Access: Published, Static 00097 // Description: This flag returns SUT_none, SUT_basic, or 00098 // SUT_advanced and controls the automatic generation 00099 // of shaders. It is initialized from the config 00100 // variable of the same name, but it can be 00101 // subsequently adjusted. 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE ShaderUtilization Shader:: 00104 get_shader_utilization() { 00105 if (_shader_utilization == SUT_unspecified) { 00106 return shader_utilization; 00107 } else { 00108 return _shader_utilization; 00109 } 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: Shader::have_shader_utilization 00114 // Access: Published, Static 00115 // Description: If true, then get_shader_utilization has been 00116 // set using set_shader_utilization. 00117 // If false, then get_shader_utilization simply 00118 // returns the config variable of the same name. 00119 //////////////////////////////////////////////////////////////////// 00120 INLINE bool Shader:: 00121 have_shader_utilization() { 00122 return (_shader_utilization != SUT_unspecified); 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: Shader::get_language 00127 // Access: Published 00128 // Description: Returns the shader language in which this shader 00129 // was written. 00130 //////////////////////////////////////////////////////////////////// 00131 INLINE const Shader::ShaderLanguage Shader:: 00132 get_language() const { 00133 return _language; 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function: Shader::ShaderCapabilities Constructor 00138 // Access: Public 00139 // Description: 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE Shader::ShaderCaps:: 00142 ShaderCaps() { 00143 clear(); 00144 } 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: Shader::ShaderCapabilities::operator == 00148 // Access: Public 00149 // Description: 00150 //////////////////////////////////////////////////////////////////// 00151 INLINE bool Shader::ShaderCaps:: 00152 operator == (const ShaderCaps &other) const { 00153 #ifdef HAVE_CG 00154 if ((_active_vprofile != other._active_vprofile) || 00155 (_active_fprofile != other._active_fprofile) || 00156 (_active_gprofile != other._active_gprofile) || 00157 (_ultimate_vprofile != other._ultimate_vprofile) || 00158 (_ultimate_fprofile != other._ultimate_fprofile) || 00159 (_ultimate_gprofile != other._ultimate_gprofile)) { 00160 return false; 00161 } 00162 #endif 00163 return true; 00164 } 00165 00166 //////////////////////////////////////////////////////////////////// 00167 // Function: Shader::ShaderPtrData Constructor 00168 // Access: 00169 // Description: 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE Shader::ShaderPtrData:: 00172 ShaderPtrData() : 00173 _ptr(NULL), 00174 _type(SPT_unknown), 00175 _updated(true), 00176 _size(0) 00177 { 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function: Shader::ShaderPtrData Constructor 00182 // Access: 00183 // Description: 00184 //////////////////////////////////////////////////////////////////// 00185 INLINE Shader::ShaderPtrData:: 00186 ShaderPtrData(const PTA_float &ptr): 00187 _pta(ptr.v0()), 00188 _ptr(ptr.p()), 00189 _type(SPT_float), 00190 _updated(true), 00191 _size(ptr.size()) 00192 { 00193 } 00194 00195 //////////////////////////////////////////////////////////////////// 00196 // Function: Shader::ShaderPtrData Constructor 00197 // Access: 00198 // Description: 00199 //////////////////////////////////////////////////////////////////// 00200 INLINE Shader::ShaderPtrData:: 00201 ShaderPtrData(const PTA_LMatrix4f &ptr): 00202 _pta(ptr.v0()), 00203 _ptr(ptr.p()), 00204 _type(SPT_float), 00205 _updated(true), 00206 _size(ptr.size() * 16) 00207 { 00208 } 00209 00210 //////////////////////////////////////////////////////////////////// 00211 // Function: Shader::ShaderPtrData Constructor 00212 // Access: 00213 // Description: 00214 //////////////////////////////////////////////////////////////////// 00215 INLINE Shader::ShaderPtrData:: 00216 ShaderPtrData(const PTA_LMatrix3f &ptr): 00217 _pta(ptr.v0()), 00218 _ptr(ptr.p()), 00219 _type(SPT_float), 00220 _updated(true), 00221 _size(ptr.size() * 9) 00222 { 00223 } 00224 00225 //////////////////////////////////////////////////////////////////// 00226 // Function: Shader::ShaderPtrData Constructor 00227 // Access: 00228 // Description: 00229 //////////////////////////////////////////////////////////////////// 00230 INLINE Shader::ShaderPtrData:: 00231 ShaderPtrData(const PTA_LVecBase4f &ptr): 00232 _pta(ptr.v0()), 00233 _ptr(ptr.p()), 00234 _type(SPT_float), 00235 _updated(true), 00236 _size(ptr.size() * 4) 00237 { 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: Shader::ShaderPtrData Constructor 00242 // Access: 00243 // Description: 00244 //////////////////////////////////////////////////////////////////// 00245 INLINE Shader::ShaderPtrData:: 00246 ShaderPtrData(const PTA_LVecBase3f &ptr): 00247 _pta(ptr.v0()), 00248 _ptr(ptr.p()), 00249 _type(SPT_float), 00250 _updated(true), 00251 _size(ptr.size() * 3) 00252 { 00253 } 00254 00255 //////////////////////////////////////////////////////////////////// 00256 // Function: Shader::ShaderPtrData Constructor 00257 // Access: 00258 // Description: 00259 //////////////////////////////////////////////////////////////////// 00260 INLINE Shader::ShaderPtrData:: 00261 ShaderPtrData(const PTA_LVecBase2f &ptr): 00262 _pta(ptr.v0()), 00263 _ptr(ptr.p()), 00264 _type(SPT_float), 00265 _updated(true), 00266 _size(ptr.size() * 2) 00267 { 00268 } 00269 00270 //////////////////////////////////////////////////////////////////// 00271 // Function: Shader::ShaderPtrData Constructor 00272 // Access: 00273 // Description: 00274 //////////////////////////////////////////////////////////////////// 00275 INLINE Shader::ShaderPtrData:: 00276 ShaderPtrData(const LVecBase4f &vec) : 00277 _type(SPT_float), 00278 _updated(true), 00279 _size(4) 00280 { 00281 PTA_float pta = PTA_float::empty_array(4); 00282 _pta = pta.v0(); 00283 _ptr = pta.p(); 00284 nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0])); 00285 memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components()); 00286 } 00287 00288 //////////////////////////////////////////////////////////////////// 00289 // Function: Shader::ShaderPtrData Constructor 00290 // Access: 00291 // Description: 00292 //////////////////////////////////////////////////////////////////// 00293 INLINE Shader::ShaderPtrData:: 00294 ShaderPtrData(const LVecBase3f &vec) : 00295 _type(SPT_float), 00296 _updated(true), 00297 _size(3) 00298 { 00299 PTA_float pta = PTA_float::empty_array(3); 00300 _pta = pta.v0(); 00301 _ptr = pta.p(); 00302 nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0])); 00303 memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components()); 00304 } 00305 00306 //////////////////////////////////////////////////////////////////// 00307 // Function: Shader::ShaderPtrData Constructor 00308 // Access: 00309 // Description: 00310 //////////////////////////////////////////////////////////////////// 00311 INLINE Shader::ShaderPtrData:: 00312 ShaderPtrData(const LVecBase2f &vec) : 00313 _type(SPT_float), 00314 _updated(true), 00315 _size(2) 00316 { 00317 PTA_float pta = PTA_float::empty_array(2); 00318 _pta = pta.v0(); 00319 _ptr = pta.p(); 00320 nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0])); 00321 memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components()); 00322 } 00323 00324 //////////////////////////////////////////////////////////////////// 00325 // Function: Shader::ShaderPtrData Constructor 00326 // Access: 00327 // Description: 00328 //////////////////////////////////////////////////////////////////// 00329 INLINE Shader::ShaderPtrData:: 00330 ShaderPtrData(const LMatrix4f &mat) : 00331 _type(SPT_float), 00332 _updated(true), 00333 _size(16) 00334 { 00335 PTA_float pta = PTA_float::empty_array(16); 00336 _pta = pta.v0(); 00337 _ptr = pta.p(); 00338 nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0])); 00339 memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components()); 00340 } 00341 00342 //////////////////////////////////////////////////////////////////// 00343 // Function: Shader::ShaderPtrData Constructor 00344 // Access: 00345 // Description: 00346 //////////////////////////////////////////////////////////////////// 00347 INLINE Shader::ShaderPtrData:: 00348 ShaderPtrData(const LMatrix3f &mat) : 00349 _type(SPT_float), 00350 _updated(true), 00351 _size(9) 00352 { 00353 PTA_float pta = PTA_float::empty_array(9); 00354 _pta = pta.v0(); 00355 _ptr = pta.p(); 00356 nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0])); 00357 memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components()); 00358 } 00359 00360 //////////////////////////////////////////////////////////////////// 00361 // Function: Shader::ShaderPtrData Constructor 00362 // Access: 00363 // Description: 00364 //////////////////////////////////////////////////////////////////// 00365 INLINE Shader::ShaderPtrData:: 00366 ShaderPtrData(const PTA_double &ptr): 00367 _pta(ptr.v0()), 00368 _ptr(ptr.p()), 00369 _type(SPT_double), 00370 _updated(true), 00371 _size(ptr.size()) 00372 { 00373 } 00374 00375 //////////////////////////////////////////////////////////////////// 00376 // Function: Shader::ShaderPtrData Constructor 00377 // Access: 00378 // Description: 00379 //////////////////////////////////////////////////////////////////// 00380 INLINE Shader::ShaderPtrData:: 00381 ShaderPtrData(const PTA_LMatrix4d &ptr): 00382 _pta(ptr.v0()), 00383 _ptr(ptr.p()), 00384 _type(SPT_double), 00385 _updated(true), 00386 _size(ptr.size() * 16) 00387 { 00388 } 00389 00390 //////////////////////////////////////////////////////////////////// 00391 // Function: Shader::ShaderPtrData Constructor 00392 // Access: 00393 // Description: 00394 //////////////////////////////////////////////////////////////////// 00395 INLINE Shader::ShaderPtrData:: 00396 ShaderPtrData(const PTA_LMatrix3d &ptr): 00397 _pta(ptr.v0()), 00398 _ptr(ptr.p()), 00399 _type(SPT_double), 00400 _updated(true), 00401 _size(ptr.size() * 9) 00402 { 00403 } 00404 00405 //////////////////////////////////////////////////////////////////// 00406 // Function: Shader::ShaderPtrData Constructor 00407 // Access: 00408 // Description: 00409 //////////////////////////////////////////////////////////////////// 00410 INLINE Shader::ShaderPtrData:: 00411 ShaderPtrData(const PTA_LVecBase4d &ptr): 00412 _pta(ptr.v0()), 00413 _ptr(ptr.p()), 00414 _type(SPT_double), 00415 _updated(true), 00416 _size(ptr.size() * 4) 00417 { 00418 } 00419 00420 //////////////////////////////////////////////////////////////////// 00421 // Function: Shader::ShaderPtrData Constructor 00422 // Access: 00423 // Description: 00424 //////////////////////////////////////////////////////////////////// 00425 INLINE Shader::ShaderPtrData:: 00426 ShaderPtrData(const PTA_LVecBase3d &ptr): 00427 _pta(ptr.v0()), 00428 _ptr(ptr.p()), 00429 _type(SPT_double), 00430 _updated(true), 00431 _size(ptr.size() * 3) 00432 { 00433 } 00434 00435 //////////////////////////////////////////////////////////////////// 00436 // Function: Shader::ShaderPtrData Constructor 00437 // Access: 00438 // Description: 00439 //////////////////////////////////////////////////////////////////// 00440 INLINE Shader::ShaderPtrData:: 00441 ShaderPtrData(const PTA_LVecBase2d &ptr): 00442 _pta(ptr.v0()), 00443 _ptr(ptr.p()), 00444 _type(SPT_double), 00445 _updated(true), 00446 _size(ptr.size() * 2) 00447 { 00448 } 00449 00450 //////////////////////////////////////////////////////////////////// 00451 // Function: Shader::ShaderPtrData Constructor 00452 // Access: 00453 // Description: 00454 //////////////////////////////////////////////////////////////////// 00455 INLINE Shader::ShaderPtrData:: 00456 ShaderPtrData(const LVecBase4d &vec) : 00457 _type(SPT_double), 00458 _updated(true), 00459 _size(4) 00460 { 00461 PTA_double pta = PTA_double::empty_array(4); 00462 _pta = pta.v0(); 00463 _ptr = pta.p(); 00464 nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0])); 00465 memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components()); 00466 } 00467 00468 //////////////////////////////////////////////////////////////////// 00469 // Function: Shader::ShaderPtrData Constructor 00470 // Access: 00471 // Description: 00472 //////////////////////////////////////////////////////////////////// 00473 INLINE Shader::ShaderPtrData:: 00474 ShaderPtrData(const LVecBase3d &vec) : 00475 _type(SPT_double), 00476 _updated(true), 00477 _size(3) 00478 { 00479 PTA_double pta = PTA_double::empty_array(3); 00480 _pta = pta.v0(); 00481 _ptr = pta.p(); 00482 nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0])); 00483 memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components()); 00484 } 00485 00486 //////////////////////////////////////////////////////////////////// 00487 // Function: Shader::ShaderPtrData Constructor 00488 // Access: 00489 // Description: 00490 //////////////////////////////////////////////////////////////////// 00491 INLINE Shader::ShaderPtrData:: 00492 ShaderPtrData(const LVecBase2d &vec) : 00493 _type(SPT_double), 00494 _updated(true), 00495 _size(2) 00496 { 00497 PTA_double pta = PTA_double::empty_array(2); 00498 _pta = pta.v0(); 00499 _ptr = pta.p(); 00500 nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0])); 00501 memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components()); 00502 } 00503 00504 //////////////////////////////////////////////////////////////////// 00505 // Function: Shader::ShaderPtrData Constructor 00506 // Access: 00507 // Description: 00508 //////////////////////////////////////////////////////////////////// 00509 INLINE Shader::ShaderPtrData:: 00510 ShaderPtrData(const LMatrix4d &mat) : 00511 _type(SPT_double), 00512 _updated(true), 00513 _size(16) 00514 { 00515 PTA_double pta = PTA_double::empty_array(16); 00516 _pta = pta.v0(); 00517 _ptr = pta.p(); 00518 nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0])); 00519 memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components()); 00520 } 00521 00522 //////////////////////////////////////////////////////////////////// 00523 // Function: Shader::ShaderPtrData Constructor 00524 // Access: 00525 // Description: 00526 //////////////////////////////////////////////////////////////////// 00527 INLINE Shader::ShaderPtrData:: 00528 ShaderPtrData(const LMatrix3d &mat) : 00529 _type(SPT_double), 00530 _updated(true), 00531 _size(9) 00532 { 00533 PTA_double pta = PTA_double::empty_array(9); 00534 _pta = pta.v0(); 00535 _ptr = pta.p(); 00536 nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0])); 00537 memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components()); 00538 }