1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADAMax. 5 6 Portions of the code are: 7 Copyright (c) 2005-2007 Feeling Software Inc. 8 Copyright (c) 2005-2007 Sony Computer Entertainment America 9 Copyright (c) 2004-2005 Alias Systems Corp. 10 11 Licensed under the MIT Open Source License, 12 for details please see LICENSE file or the website 13 http://www.opensource.org/licenses/mit-license.php 14 */ 15 16 #include "COLLADAMaxStableHeaders.h" 17 18 #include "COLLADAMaxHwShaderExporter.h" 19 #include "COLLADAMaxEffectExporter.h" 20 #include "COLLADAMaxEffectTextureExporter.h" 21 #include "COLLADAMaxAnimationExporter.h" 22 23 #include "COLLADASWPass.h" 24 #include "COLLADASWRenderState.h" 25 #include "COLLADASWShader.h" 26 #include "COLLADASWAnnotation.h" 27 #include "COLLADASWOpenGLConstants.h" 28 #include "COLLADASWConstants.h" 29 30 #include <iostream> 31 32 namespace COLLADAMax 33 { 34 35 // --------------------------------- exportPluginHwShaderNode(const String & effectId,COLLADASW::EffectProfile * effectProfile,ExportNode * exportNode,StdMat2 * material,float weight)36 void HwShaderExporter::exportPluginHwShaderNode ( 37 const String &effectId, 38 COLLADASW::EffectProfile *effectProfile, 39 ExportNode* exportNode, 40 StdMat2* material, 41 float weight 42 ) 43 { 44 // Set the effect profile 45 mEffectProfile = effectProfile; 46 47 exportParameterAnimations( effectId, material ); 48 //:TODO: check if this call is necessary (might have been done earlier) 49 exportNode->addSymbol ( material, NativeString(material->GetName().data()) ); 50 exportCgfxShader ( effectProfile, material, weight ); 51 } 52 53 // --------------------------------- exportParameterAnimations(const String & effectId,StdMat2 * material)54 void HwShaderExporter::exportParameterAnimations( 55 const String &effectId, 56 StdMat2* material 57 ) 58 { 59 IParamBlock2 * pblock = material->GetParamBlock ( 0 ); 60 int parameterCount = pblock->NumParams(); 61 62 for ( int i = 0; i < parameterCount; i++ ) 63 { 64 ParamID parameterID = pblock->IndextoID( i ); 65 ParamType2 parameterType = pblock->GetParameterType( parameterID ); 66 67 if( parameterType != TYPE_FLOAT ) 68 { 69 continue; 70 } 71 72 ParamDef parameterDef = pblock->GetParamDef( parameterID ); 73 74 const TCHAR* paramName = parameterDef.int_name; 75 #ifdef MAX_2012_OR_NEWER 76 Control *controller = pblock->GetControllerByID(parameterID); 77 #else 78 Control *controller = pblock->GetController(parameterID); 79 #endif 80 81 if( controller != 0 ) 82 { 83 #ifdef UNICODE 84 String paramNameString = COLLADABU::StringUtils::wideString2utf8String( paramName ); 85 mDocumentExporter->getAnimationExporter()->addAnimatedFloat( controller, effectId, paramNameString.c_str(), 0 ); 86 #else 87 mDocumentExporter->getAnimationExporter()->addAnimatedFloat( controller, effectId, paramName, 0 ); 88 #endif 89 } 90 } 91 } 92 93 // --------------------------------- 94 exportCgfxShader(COLLADASW::EffectProfile * effectProfile,StdMat2 * material,float weight)95 void HwShaderExporter::exportCgfxShader ( 96 COLLADASW::EffectProfile *effectProfile, 97 StdMat2* material, 98 float weight 99 ) 100 { 101 // Set the current shader scope to CG 102 setShaderScope ( COLLADASW::Shader::SCOPE_CG ); 103 104 // Writes the current effect profile into the collada document 105 mEffectProfile->setProfileType ( COLLADASW::EffectProfile::CG ); 106 mEffectProfile->openProfile (); 107 108 //// Get the filename of the current cgfx file 109 //MString shaderFxFile = cgfxFindFile(shaderNodeCgfx->shaderFxFile()); 110 //String shaderFxFileName = shaderFxFile.asChar (); // check3d.cgfx 111 //COLLADASW::URI shaderFxFileUri ( COLLADASW::URI::nativePathToUri ( shaderFxFileName ) ); 112 //setShaderFxFileUri ( shaderFxFileUri ); 113 114 // Get the current CGeffect 115 //CGeffect cgEffect = shaderNodeCgfx->effect(); 116 117 // Set the current include file 118 //if ( ExportOptions::exportCgfxFileReferences () ) 119 // mEffectProfile->setInclude ( shaderFxFileUri, shaderFxFileUri.getPathFileBase() ); 120 //else 121 //{ 122 // // Add the source code 123 // CGcontext cgContext = cgGetEffectContext ( cgEffect ); 124 // CGprogram cgProgram = cgGetFirstProgram ( cgContext ); 125 // const char* programSourceCG = cgGetProgramString ( cgProgram, CG_PROGRAM_SOURCE ); 126 // String sourceString = getProgramSourceString ( programSourceCG ); 127 // // Get the code sid 128 // String codeSid = shaderFxFileUri.getPathFileBase (); 129 // // Set the code into the collada effect profile 130 // mEffectProfile->setCode ( sourceString, codeSid ); 131 //} 132 133 // Add the source code and the include file 134 mEffectProfile->addProfileElements (); 135 136 // Export the effects parameter 137 exportEffectParameters ( material ); 138 139 /* 140 // Find if effect parameter is used by any program of the selected technique 141 CGtechnique cgTechnique = cgGetFirstTechnique ( cgEffect ); 142 while ( cgTechnique ) 143 { 144 exportTechnique ( cgTechnique ); 145 cgTechnique = cgGetNextTechnique ( cgTechnique ); 146 } 147 */ 148 mEffectProfile->closeProfile (); 149 } 150 151 // -------------------------------- 152 /* 153 void HwShaderExporter::exportTechnique ( 154 const CGtechnique& cgTechnique ) 155 { 156 mEffectProfile->setTechniqueSid ( cgGetTechniqueName ( cgTechnique ) ); 157 String techniqueName = cgGetTechniqueName ( cgTechnique ); 158 159 // Open the current technique element 160 mEffectProfile->openTechnique ( techniqueName ); 161 162 // Go through the passes and write it into the collada file. 163 CGpass cgPass = cgGetFirstPass ( cgTechnique ); 164 while ( cgPass ) 165 { 166 exportPass ( cgPass ); 167 cgPass = cgGetNextPass ( cgPass ); 168 } 169 170 // Close the current technique element 171 mEffectProfile->closeTechnique (); 172 173 } 174 */ 175 // -------------------------------------- 176 /* 177 void HwShaderExporter::exportShaderProgramData ( 178 const CGstateassignment& cgStateAssignment, 179 const bool readCode ) 180 { 181 // Get the current stream writer 182 COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); 183 184 // Write the render states. 185 CGstate cgState = cgGetStateAssignmentState ( cgStateAssignment ); 186 const char* cgStateNameC = cgGetStateName ( cgState ); 187 String cgStateName ( cgStateNameC ); 188 CGtype cgStateType = cgGetStateType ( cgState ); 189 if ( cgStateType != CG_PROGRAM_TYPE ) return; 190 191 // The state name depend on the current shader scope 192 COLLADASW::Shader::Stage shaderStage = COLLADASW::Shader::getStageTypeByName ( cgStateName ); 193 194 // Create a shader and export it 195 COLLADASW::Shader shader ( streamWriter, mShaderScope, shaderStage ); 196 shader.openShader(); 197 198 // Get the program 199 CGprogram cgProgram = cgGetProgramStateAssignmentValue ( cgStateAssignment ); 200 201 // const char* programCompiledString = cgGetProgramString ( cgProgram, CG_COMPILED_PROGRAM ); 202 // const char* programProfileString = cgGetProgramString ( cgProgram, CG_PROGRAM_PROFILE ); // arbvp1 203 204 // Set the current programs profile 205 CGprofile cgProgramProfile = cgGetProgramProfile( cgProgram ); 206 const char* profileString = cgGetProfileString ( cgProgramProfile ); // arbvp1 207 if ( profileString != NULL ) 208 shader.addCompilerTarget ( profileString ); 209 210 // Set a reference to the sources. 211 const char* programEntryString = cgGetProgramString ( cgProgram, CG_PROGRAM_ENTRY ); // VShader || goochVS 212 if ( programEntryString != NULL ) 213 { 214 // Get the code sid 215 COLLADASW::URI fileURI = getShaderFxFileUri (); 216 String codeSid = fileURI.getPathFileBase (); 217 shader.addName ( programEntryString, codeSid ); 218 } 219 220 if ( !ExportOptions::exportCgfxFileReferences () ) 221 { 222 // Add the global bind parameters 223 CGparameter progParam = cgGetFirstParameter ( cgProgram, CG_GLOBAL ); // CG_PROGRAM=IN || CG_GLOBAL 224 while ( progParam ) 225 { 226 const char* paramName = cgGetParameterName ( progParam ); // VShader 227 CGtype paramType = cgGetParameterBaseType ( progParam ); 228 229 CGbool isUsed = cgIsParameterUsed ( progParam, cgProgram ); 230 CGbool isReferenced = cgIsParameterReferenced ( progParam ); 231 if ( isUsed && !COLLADASW::Utils::equals( paramName, programEntryString ) ) 232 { 233 // Get the connected parameter 234 CGparameter connectedParam = cgGetConnectedParameter ( progParam ); 235 if ( connectedParam ) 236 { 237 COLLADASW::ParamBase bindParam ( streamWriter, &COLLADASW::CSWC::CSW_ELEMENT_BIND ); 238 bindParam.openParam (); 239 bindParam.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_SYMBOL, paramName ); 240 241 const char* connectedParamName = cgGetParameterName ( connectedParam ); 242 243 COLLADASW::ParamBase param ( streamWriter ); 244 param.openParam ( connectedParamName ); 245 param.closeParam (); 246 bindParam.closeParam (); 247 } 248 } 249 250 progParam = cgGetNextParameter ( progParam ); 251 } 252 253 // Add the program specific bind parameters 254 progParam = cgGetFirstParameter ( cgProgram, CG_PROGRAM ); 255 while ( progParam ) 256 { 257 const char* paramName = cgGetParameterName ( progParam ); // VShader 258 CGtype paramType = cgGetParameterBaseType ( progParam ); 259 260 CGbool isUsed = cgIsParameterUsed ( progParam, cgProgram ); 261 CGbool isReferenced = cgIsParameterReferenced ( progParam ); 262 if ( isUsed && !COLLADASW::Utils::equals( paramName, "IN" ) ) 263 { 264 // Get the connected parameter 265 CGparameter connectedParam = cgGetConnectedParameter ( progParam ); 266 if ( connectedParam ) 267 { 268 COLLADASW::ParamBase bindParam ( streamWriter, &COLLADASW::CSWC::CSW_ELEMENT_BIND ); 269 bindParam.openParam (); 270 bindParam.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_SYMBOL, paramName ); 271 272 const char* connectedParamName = cgGetParameterName ( connectedParam ); 273 274 COLLADASW::ParamBase param ( streamWriter ); 275 param.openParam ( connectedParamName ); 276 param.closeParam (); 277 bindParam.closeParam (); 278 } 279 } 280 281 progParam = cgGetNextParameter ( progParam ); 282 } 283 } 284 285 shader.closeShader(); 286 } 287 */ 288 // -------------------------------------- 289 /* 290 template <class Type> 291 void HwShaderExporter::exportRenderStateParam ( 292 const String& renderStateName, 293 const Type* values, 294 const int valueCount ) 295 { 296 COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); 297 298 COLLADASW::ParamBase param ( streamWriter, &renderStateName ); 299 param.openParam(); 300 for ( int j=0; j<valueCount; ++j ) 301 param.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, 302 COLLADASW::Utils::toString ( values[j] ) ); 303 param.closeParam(); 304 } 305 */ 306 // -------------------------------------- 307 /* 308 void HwShaderExporter::exportRenderStateParam ( 309 const String& renderStateName, 310 const CGbool* values, 311 const int valueCount ) 312 { 313 COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); 314 315 COLLADASW::ParamBase param ( streamWriter, &renderStateName ); 316 param.openParam(); 317 for ( int j=0; j<valueCount; ++j ) 318 { 319 if ( values[j] > 0 ) 320 param.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, "true" ); 321 else 322 param.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, "false" ); 323 } 324 param.closeParam(); 325 } 326 */ 327 // -------------------------------------- 328 /* 329 void HwShaderExporter::exportPass ( const CGpass& cgPass ) 330 { 331 COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); 332 333 // Write the pass into the collada file 334 COLLADASW::Pass colladaPass ( streamWriter ); 335 const char* cgPassName = cgGetPassName ( cgPass ); 336 if ( cgPassName == NULL ) cgPassName = EMPTY_CSTRING; 337 colladaPass.openPass ( cgPassName ); 338 339 // Go through the pass's render state assignments and write it into the collada file. 340 // The shaders will be exported last. 341 CGstateassignment cgStateAssignment = cgGetFirstStateAssignment ( cgPass ); 342 while ( cgStateAssignment ) 343 { 344 // Export the current pass render state 345 exportPassRenderState ( cgStateAssignment ); 346 347 // Get the next state assignment 348 cgStateAssignment = cgGetNextStateAssignment( cgStateAssignment ); 349 } 350 351 // Export the shaders 352 exportShaders ( cgPass ); 353 354 // Close the collada pass element 355 colladaPass.closePass(); 356 } 357 */ 358 // -------------------------------------- 359 /* 360 void HwShaderExporter::exportShaders ( const CGpass& cgPass ) 361 { 362 CGstateassignment cgStateAssignment; 363 364 // Export the vertex stage assignment 365 cgStateAssignment = cgGetNamedStateAssignment ( cgPass, 366 COLLADASW::CSWC::CSW_FX_SHADER_STAGE_VERTEXPROGRAM.c_str() ); 367 if ( cgStateAssignment ) 368 exportShaderProgramData ( cgStateAssignment ); 369 370 // Export the fragment stage assignment 371 cgStateAssignment = cgGetNamedStateAssignment ( cgPass, 372 COLLADASW::CSWC::CSW_FX_SHADER_STAGE_FRAGMENTPROGRAM.c_str() ); 373 if ( cgStateAssignment ) 374 exportShaderProgramData ( cgStateAssignment ); 375 } 376 */ 377 // -------------------------------------- 378 /* 379 void HwShaderExporter::exportPassRenderState ( const CGstateassignment& cgStateAssignment ) 380 { 381 COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); 382 383 // Write the render states. 384 CGstate cgState = cgGetStateAssignmentState ( cgStateAssignment ); 385 const char* cgStateNameC = cgGetStateName ( cgState ); 386 String cgStateName ( cgStateNameC ); 387 CGtype cgStateType = cgGetStateType ( cgState ); 388 389 COLLADASW::RenderState::PassState passState = 390 COLLADASW::RenderState::getRenderStateFromCgName( cgStateNameC ); 391 const String& renderStateName = COLLADASW::RenderState::getColladaRenderStateName ( passState ); 392 393 switch ( cgStateType ) 394 { 395 case CG_BOOL: 396 case CG_BOOL1: 397 case CG_BOOL2: 398 case CG_BOOL3: 399 case CG_BOOL4: 400 { 401 int valueCount = 0; 402 const CGbool* values = cgGetBoolStateAssignmentValues( cgStateAssignment, &valueCount ); 403 exportRenderStateParam ( renderStateName, values, valueCount ); 404 break; 405 } 406 case CG_INT: 407 case CG_INT1: 408 case CG_INT2: 409 case CG_INT3: 410 case CG_INT4: 411 { 412 int valueCount = 0; 413 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 414 415 COLLADASW::ParamBase param ( streamWriter, &renderStateName ); 416 param.openParam (); 417 for ( int j=0; j<valueCount; ++j ) 418 { 419 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[j] ); 420 COLLADASW::RenderState::PassStateFunction passStateFunction = 421 COLLADASW::RenderState::getPassStateFunction ( cgStateEnum ); 422 const String renderStateFunctionName = 423 COLLADASW::RenderState::getColladaPassStateString ( passStateFunction ); 424 param.appendAttribute ( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, renderStateFunctionName ); 425 } 426 param.closeParam (); 427 break; 428 } 429 case CG_FLOAT: 430 case CG_FLOAT1: 431 case CG_FLOAT2: 432 case CG_FLOAT3: 433 case CG_FLOAT4: 434 { 435 int valueCount = 0; 436 const float* values = cgGetFloatStateAssignmentValues( cgStateAssignment, &valueCount ); 437 exportRenderStateParam( renderStateName, values, valueCount ); 438 break; 439 } 440 case CG_STRING: 441 { 442 const char* val = cgGetStringStateAssignmentValue( cgStateAssignment ); 443 COLLADASW::ParamBase param ( streamWriter, &renderStateName ); 444 param.openParam(); 445 param.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, val ); 446 param.closeParam(); 447 break; 448 } 449 case CG_TEXTURE: 450 { 451 CGparameter textureParam = cgGetTextureStateAssignmentValue ( cgStateAssignment ); 452 const char* textureName = cgGetParameterName( textureParam ); 453 COLLADASW::ParamBase param ( streamWriter, &renderStateName ); 454 param.openParam(); 455 param.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, textureName ); 456 param.closeParam(); 457 break; 458 } 459 case CG_SAMPLER1D: 460 case CG_SAMPLER2D: 461 case CG_SAMPLER3D: 462 case CG_SAMPLERCUBE: 463 case CG_SAMPLERRECT: 464 { 465 CGparameter samplerParam = cgGetSamplerStateAssignmentValue ( cgStateAssignment ); 466 const char* samplerName = cgGetParameterName( samplerParam ); 467 COLLADASW::ParamBase param ( streamWriter, &renderStateName ); 468 param.openParam(); 469 param.appendAttribute( COLLADASW::CSWC::CSW_ATTRIBUTE_VALUE, samplerName ); 470 param.closeParam(); 471 break; 472 } 473 case CG_PROGRAM_TYPE: 474 { 475 // Nothing to do here, the shaders will be exported later. 476 // // Export the shader program data into the collada file 477 // exportShaderProgramData ( cgStateAssignment ); 478 break; 479 } 480 default: 481 assert ( "Parameter type not supported! " + cgStateType ); 482 // printf("UNEXPECTED CASE: 0x%x (%d)\n", cgStateType, cgStateType); 483 break; 484 485 } 486 } 487 */ 488 // -------------------------------------- 489 exportEffectParameters(StdMat2 * material)490 void HwShaderExporter::exportEffectParameters ( 491 StdMat2* material 492 ) 493 { 494 COLLADASW::StreamWriter* streamWriter = &mDocumentExporter->getStreamWriter(); 495 496 IParamBlock2 * pblock = material->GetParamBlock ( 0 ); 497 int parameterCount = pblock->NumParams(); 498 499 for ( int i = 0; i < parameterCount; i++ ) 500 { 501 ParamID parameterID = pblock->IndextoID( i ); 502 ParamType2 parameterType = pblock->GetParameterType( parameterID ); 503 ParamDef parameterDef = pblock->GetParamDef( parameterID ); 504 505 const TCHAR* paramName = parameterDef.int_name; 506 507 switch ( parameterType ) 508 { 509 case TYPE_FLOAT: 510 { 511 COLLADASW::NewParam<> newParam ( streamWriter ); 512 newParam.setParamType ( COLLADASW::ValueType::FLOAT ); 513 514 int numOfValues = 1; 515 float paramValue = pblock->GetFloat( parameterID ); 516 517 exportParam ( paramName, &newParam, ¶mValue, numOfValues ); 518 519 break; 520 } 521 522 case TYPE_INT: 523 { 524 COLLADASW::NewParam<> newParam ( streamWriter ); 525 newParam.setParamType ( COLLADASW::ValueType::INT ); 526 527 int numOfValues = 1; 528 int paramValue = pblock->GetInt( parameterID ); 529 530 exportParam ( paramName, &newParam, ¶mValue, numOfValues ); 531 532 break; 533 } 534 535 case TYPE_RGBA: 536 case TYPE_FRGBA: 537 { 538 COLLADASW::NewParam<> newParam ( streamWriter ); 539 newParam.setParamType ( COLLADASW::ValueType::FLOAT4 ); 540 541 int numOfValues = 4; 542 AColor paramPoint3Value = pblock->GetAColor( parameterID ); 543 float* paramValue = (float*)paramPoint3Value; 544 545 exportParam ( paramName, &newParam, paramValue, numOfValues ); 546 547 break; 548 } 549 550 case TYPE_POINT3: 551 { 552 COLLADASW::NewParam<> newParam ( streamWriter ); 553 newParam.setParamType ( COLLADASW::ValueType::FLOAT3 ); 554 555 int numOfValues = 3; 556 Point3 paramPoint3Value = pblock->GetPoint3( parameterID ); 557 float* paramValue = (float*)paramPoint3Value; 558 559 exportParam ( paramName, &newParam, paramValue, numOfValues ); 560 561 break; 562 } 563 564 case TYPE_BOOL: 565 { 566 COLLADASW::NewParam<> newParam ( streamWriter ); 567 newParam.setParamType ( COLLADASW::ValueType::BOOL ); 568 569 int numOfValues = 1; 570 /*bool*/ int paramValue = pblock->GetInt( parameterID ); 571 572 exportParam ( paramName, &newParam, ¶mValue, numOfValues ); 573 574 break; 575 } 576 577 //TYPE_ANGLE 578 //TYPE_PCNT_FRAC 579 //TYPE_WORLD 580 581 case TYPE_STRING: 582 { 583 COLLADASW::NewParam<> newParam ( streamWriter ); 584 585 const MCHAR * paramValue = pblock->GetStr( parameterID ); 586 exportParam ( paramName, &newParam, paramValue ); 587 588 break; 589 } 590 591 //TYPE_FILENAME 592 //TYPE_HSV 593 //TYPE_COLOR_CHANNEL 594 //TYPE_TIMEVALUE 595 //TYPE_RADIOBTN_INDEX 596 //TYPE_MTL 597 //TYPE_TEXMAP 598 599 case TYPE_BITMAP: 600 { 601 PBBitmap * bitmap = pblock->GetBitmap( parameterID ); 602 exportSampler ( paramName, bitmap ); 603 604 break; 605 } 606 607 //TYPE_INODE 608 //TYPE_REFTARG 609 //TYPE_INDEX 610 //TYPE_MATRIX3 611 //TYPE_PBLOCK2 612 613 case TYPE_POINT4: 614 { 615 COLLADASW::NewParam<> newParam ( streamWriter ); 616 newParam.setParamType ( COLLADASW::ValueType::FLOAT4 ); 617 618 int numOfValues = 4; 619 Point4 paramPoint3Value = pblock->GetPoint4( parameterID ); 620 float* paramValue = (float*)paramPoint3Value; 621 622 exportParam ( paramName, &newParam, paramValue, numOfValues ); 623 624 break; 625 } 626 627 default: 628 { 629 //:TODO: warning (file and/or popup) 630 GetCOREInterface()->Log()->LogEntry( SYSLOG_WARN, DISPLAY_DIALOG, _M( "Parameter export problem" ),_M( "Unsupported parameter type (%i) for parameter %s\n" ), parameterType, paramName ); 631 } 632 } 633 } 634 } 635 636 // -------------------------------------- 637 638 template <class Type> exportParam(const TCHAR * paramName,COLLADASW::ParamBase * param,const Type * paramValues,const int numOfValues)639 void HwShaderExporter::exportParam ( 640 //const CGparameter& cgParameter, 641 const TCHAR* paramName, 642 COLLADASW::ParamBase* param, 643 const Type* paramValues, 644 const int numOfValues ) 645 { 646 #ifdef UNICODE 647 String stringParamName = COLLADABU::StringUtils::wideString2utf8String( paramName ); 648 param->openParam ( stringParamName ); 649 #else 650 param->openParam ( paramName ); 651 #endif 652 653 //exportAnnotations ( cgParameter, param ); 654 //exportSemantic ( cgParameter, param ); 655 656 for ( int i=0; i<numOfValues; ++i ) 657 param->appendValues ( paramValues[i] ); 658 659 param->closeParam(); 660 } 661 662 // -------------------------------------- 663 exportParam(const TCHAR * paramName,COLLADASW::ParamBase * param,const TCHAR * paramValue)664 void HwShaderExporter::exportParam ( 665 //const CGparameter& cgParameter, 666 const TCHAR* paramName, 667 COLLADASW::ParamBase* param, 668 const TCHAR* paramValue ) 669 { 670 #ifdef UNICODE 671 String stringParamName = COLLADABU::StringUtils::wideString2utf8String( paramName ); 672 param->openParam ( stringParamName ); 673 674 //exportAnnotations ( cgParameter, param ); 675 //exportSemantic ( cgParameter, param ); 676 677 String stringParamValue = COLLADABU::StringUtils::wideString2utf8String( paramValue ); 678 param->appendValues ( stringParamValue ); 679 #else 680 param->openParam ( paramName ); 681 682 //exportAnnotations ( cgParameter, param ); 683 //exportSemantic ( cgParameter, param ); 684 685 param->appendValues ( paramValue ); 686 #endif 687 688 param->closeParam(); 689 } 690 691 // -------------------------------------- 692 /* 693 void HwShaderExporter::exportAnnotations ( 694 const CGparameter& cgParameter, 695 COLLADASW::ParamBase* param ) 696 { 697 CGannotation cgAnno = cgGetFirstParameterAnnotation ( cgParameter ); 698 while ( cgAnno ) 699 { 700 CGtype cgAnnoType = cgGetAnnotationType( cgAnno ); 701 const char* cgAnnoName = cgGetAnnotationName( cgAnno ); 702 String annotationName ( cgAnnoName ); 703 switch ( cgAnnoType ) 704 { 705 case CG_BOOL: 706 case CG_BOOL1: 707 case CG_BOOL2: 708 case CG_BOOL3: 709 case CG_BOOL4: 710 { 711 int nvalues = 0; 712 const CGbool* values = cgGetBoolAnnotationValues( cgAnno, &nvalues ); 713 param->addAnnotation ( annotationName, COLLADASW::ValueType::BOOL, values, nvalues ); 714 break; 715 } 716 case CG_INT: 717 case CG_INT1: 718 case CG_INT2: 719 case CG_INT3: 720 case CG_INT4: 721 { 722 int nvalues = 0; 723 const int* values = cgGetIntAnnotationValues( cgAnno, &nvalues ); 724 param->addAnnotation ( annotationName, COLLADASW::ValueType::BOOL, values, nvalues ); 725 break; 726 } 727 case CG_HALF: 728 case CG_HALF2: 729 case CG_HALF3: 730 case CG_HALF4: 731 case CG_FLOAT: 732 case CG_FLOAT1: 733 case CG_FLOAT2: 734 case CG_FLOAT3: 735 case CG_FLOAT4: 736 { 737 int nvalues = 0; 738 const float* values = cgGetFloatAnnotationValues ( cgAnno, &nvalues ); 739 param->addAnnotation ( annotationName, COLLADASW::ValueType::FLOAT, values, nvalues ); 740 break; 741 } 742 case CG_HALF4x4: 743 case CG_FLOAT4x4: 744 { 745 // TODO 746 assert ( "Annotation type not supported! " + cgAnnoType ); 747 break; 748 } 749 case CG_STRING: 750 { 751 const char* val = cgGetStringAnnotationValue ( cgAnno ); 752 param->addAnnotation ( annotationName, COLLADASW::ValueType::STRING, String ( val ) ); 753 break; 754 } 755 default: 756 assert ( "Annotation type not supported! " + cgAnnoType ); 757 break; 758 } 759 760 cgAnno = cgGetNextAnnotation ( cgAnno ); 761 } 762 } 763 */ 764 // -------------------------------------- 765 /* 766 void HwShaderExporter::exportSemantic ( const CGparameter& cgParameter, COLLADASW::ParamBase* param ) 767 { 768 const char *semantic = cgGetParameterSemantic( cgParameter ); 769 770 if ( semantic && strlen(semantic) ) 771 param->addSemantic ( semantic ); 772 } 773 */ 774 // -------------------------------------- 775 exportSampler(const TCHAR * paramName,const PBBitmap * bitmap)776 void HwShaderExporter::exportSampler ( 777 const TCHAR* paramName, 778 const PBBitmap* bitmap 779 ) 780 { 781 COLLADASW::StreamWriter* streamWriter = &mDocumentExporter->getStreamWriter(); 782 783 // Name of the current texture 784 #ifdef UNICODE 785 String stringParamName = COLLADABU::StringUtils::wideString2utf8String( paramName ); 786 const char* surfaceSid = stringParamName.c_str(); 787 #else 788 const char* surfaceSid = paramName;//cgGetParameterName( cgTextureParam ); 789 #endif 790 791 // Get the name of the current parameter 792 //const char* samplerSid = cgGetParameterName ( cgParameter ); 793 char samplerSid[256]; 794 _snprintf_s( samplerSid, 256, "%sSampler", surfaceSid ); 795 796 // Create the collada sampler object 797 COLLADASW::Sampler sampler ( COLLADASW::Sampler::SAMPLER_TYPE_UNSPECIFIED, samplerSid, surfaceSid ); 798 799 /* 800 // Look for the wraps 801 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_WRAP_S.c_str() ); 802 if ( cgStateAssignment ) 803 { 804 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 805 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 806 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[0] ); 807 sampler.setWrapS ( COLLADASW::OPEN_GL::getWrapModeFromOpenGL ( cgStateEnum ) ); 808 } 809 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_WRAP_T.c_str() ); 810 if ( cgStateAssignment ) 811 { 812 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 813 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 814 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[0] ); 815 sampler.setWrapT ( COLLADASW::OPEN_GL::getWrapModeFromOpenGL ( cgStateEnum ) ); 816 } 817 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_WRAP_P.c_str() ); 818 if ( cgStateAssignment ) 819 { 820 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 821 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 822 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[0] ); 823 sampler.setWrapP ( COLLADASW::OPEN_GL::getWrapModeFromOpenGL ( cgStateEnum ) ); 824 } 825 826 // Look for the filters 827 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_MAGFILTER.c_str() ); 828 if ( cgStateAssignment ) 829 { 830 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 831 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 832 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[0] ); 833 sampler.setMagFilter( COLLADASW::OPEN_GL::getSamplerFilterFromOpenGL ( cgStateEnum ) ); 834 } 835 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_MINFILTER.c_str() ); 836 if ( cgStateAssignment ) 837 { 838 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 839 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 840 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[0] ); 841 sampler.setMinFilter( COLLADASW::OPEN_GL::getSamplerFilterFromOpenGL ( cgStateEnum ) ); 842 } 843 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_MIPFILTER.c_str() ); 844 if ( cgStateAssignment ) 845 { 846 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 847 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 848 const char* cgStateEnum = cgGetStateEnumerantName ( cgState, values[0] ); 849 sampler.setMipFilter( COLLADASW::OPEN_GL::getSamplerFilterFromOpenGL ( cgStateEnum ) ); 850 } 851 852 // Look for the border color 853 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_BORDER_COLOR.c_str() ); 854 if ( cgStateAssignment ) 855 { 856 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 857 const float* values = cgGetFloatStateAssignmentValues ( cgStateAssignment, &valueCount ); 858 if ( valueCount == 3 ) 859 sampler.setBorderColor ( COLLADASW::Color ( values[0], values[1], values[2] ) ); 860 else if ( valueCount == 4 ) 861 sampler.setBorderColor ( COLLADASW::Color ( values[0], values[1], values[2], values[3] ) ); 862 } 863 864 // Look for the mipmaps 865 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_MIPMAP_MAXLEVEL.c_str() ); 866 if ( cgStateAssignment ) 867 { 868 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 869 const int* values = cgGetIntStateAssignmentValues ( cgStateAssignment, &valueCount ); 870 sampler.setMipmapMaxlevel ( ( unsigned char ) ( values[0] ) ); 871 } 872 cgStateAssignment = cgGetNamedSamplerStateAssignment ( cgParameter, COLLADASW::CSWC::CSW_ELEMENT_MIPMAP_BIAS.c_str() ); 873 if ( cgStateAssignment ) 874 { 875 CGstate cgState = cgGetSamplerStateAssignmentState ( cgStateAssignment ); 876 const float* values = cgGetFloatStateAssignmentValues ( cgStateAssignment, &valueCount ); 877 sampler.setMipmapBias ( values[0] ); 878 } 879 880 // TODO Look for extra tags 881 // exportSamplerStateAssignments (cgParameter, cgTextureParam, surfaceType, samplerType, samplerValueType); 882 */ 883 884 //:TODO: get sampler type from data 885 COLLADASW::Sampler::SamplerType samplerType = COLLADASW::Sampler::SAMPLER_TYPE_2D; 886 887 // Set the sampler type 888 sampler.setSamplerType ( samplerType ); 889 890 // Add the texture, if exist 891 setTexture ( bitmap, sampler ); 892 893 //if ( writeNewParam ) 894 { 895 // Get the surface annotations. 896 std::vector<COLLADASW::Annotation> surfaceAnnotations; 897 //getAnnotations( surfaceAnnotations, cgTextureParam ); 898 899 // Get the sampler annotations. 900 std::vector<COLLADASW::Annotation> samplerAnnotations; 901 //getAnnotations( samplerAnnotations, cgParameter ); 902 903 // Add the parameter. 904 sampler.addInNewParam ( streamWriter, &surfaceAnnotations, &samplerAnnotations ); 905 } 906 /* 907 else 908 { 909 // Add the parameter. 910 sampler.addInSetParam ( streamWriter ); 911 } 912 */ 913 } 914 915 // -------------------------------------- 916 /* 917 void HwShaderExporter::getAnnotations ( 918 std::vector<COLLADASW::Annotation>& annotations, 919 const CGparameter& cgParameter ) 920 { 921 // Get a pointer to the current stream writer. 922 COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); 923 924 CGannotation cgAnno = cgGetFirstParameterAnnotation ( cgParameter ); 925 while ( cgAnno ) 926 { 927 COLLADASW::ValueType::ColladaType valueType = COLLADASW::ValueType::VALUE_TYPE_UNSPECIFIED; 928 int nvalues = -1; 929 930 CGtype cgAnnoType = cgGetAnnotationType( cgAnno ); 931 const char* cgAnnoName = cgGetAnnotationName( cgAnno ); 932 String annotationName ( cgAnnoName ); 933 switch ( cgAnnoType ) 934 { 935 case CG_BOOL: 936 case CG_BOOL1: 937 { 938 valueType = COLLADASW::ValueType::BOOL; 939 const CGbool* values = cgGetBoolAnnotationValues( cgAnno, &nvalues ); 940 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 941 annotations.push_back ( annotation ); 942 break; 943 } 944 case CG_BOOL2: 945 { 946 valueType = COLLADASW::ValueType::BOOL2; 947 const CGbool* values = cgGetBoolAnnotationValues( cgAnno, &nvalues ); 948 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 949 annotations.push_back ( annotation ); 950 break; 951 } 952 case CG_BOOL3: 953 { 954 valueType = COLLADASW::ValueType::BOOL3; 955 const CGbool* values = cgGetBoolAnnotationValues( cgAnno, &nvalues ); 956 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 957 annotations.push_back ( annotation ); 958 break; 959 } 960 case CG_BOOL4: 961 { 962 valueType = COLLADASW::ValueType::BOOL4; 963 const CGbool* values = cgGetBoolAnnotationValues( cgAnno, &nvalues ); 964 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 965 annotations.push_back ( annotation ); 966 break; 967 } 968 case CG_INT: 969 case CG_INT1: 970 { 971 valueType = COLLADASW::ValueType::INT; 972 const int* values = cgGetIntAnnotationValues( cgAnno, &nvalues ); 973 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 974 annotations.push_back ( annotation ); 975 break; 976 } 977 case CG_INT2: 978 { 979 valueType = COLLADASW::ValueType::INT2; 980 const int* values = cgGetIntAnnotationValues( cgAnno, &nvalues ); 981 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 982 annotations.push_back ( annotation ); 983 break; 984 } 985 case CG_INT3: 986 { 987 valueType = COLLADASW::ValueType::INT3; 988 const int* values = cgGetIntAnnotationValues( cgAnno, &nvalues ); 989 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 990 annotations.push_back ( annotation ); 991 break; 992 } 993 case CG_INT4: 994 { 995 valueType = COLLADASW::ValueType::INT4; 996 const int* values = cgGetIntAnnotationValues( cgAnno, &nvalues ); 997 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 998 annotations.push_back ( annotation ); 999 break; 1000 } 1001 case CG_FLOAT: 1002 case CG_FLOAT1: 1003 { 1004 valueType = COLLADASW::ValueType::FLOAT; 1005 const float* values = cgGetFloatAnnotationValues ( cgAnno, &nvalues ); 1006 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 1007 annotations.push_back ( annotation ); 1008 break; 1009 } 1010 case CG_FLOAT2: 1011 { 1012 valueType = COLLADASW::ValueType::FLOAT2; 1013 const float* values = cgGetFloatAnnotationValues ( cgAnno, &nvalues ); 1014 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 1015 annotations.push_back ( annotation ); 1016 break; 1017 } 1018 case CG_FLOAT3: 1019 { 1020 valueType = COLLADASW::ValueType::FLOAT3; 1021 const float* values = cgGetFloatAnnotationValues ( cgAnno, &nvalues ); 1022 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 1023 annotations.push_back ( annotation ); 1024 break; 1025 } 1026 case CG_FLOAT4: 1027 { 1028 valueType = COLLADASW::ValueType::FLOAT4; 1029 const float* values = cgGetFloatAnnotationValues ( cgAnno, &nvalues ); 1030 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 1031 annotations.push_back ( annotation ); 1032 break; 1033 } 1034 case CG_FLOAT4x4: 1035 { 1036 valueType = COLLADASW::ValueType::FLOAT4x4; 1037 const float* values = cgGetFloatAnnotationValues ( cgAnno, &nvalues ); 1038 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values, nvalues ); 1039 annotations.push_back ( annotation ); 1040 break; 1041 } 1042 case CG_HALF: 1043 case CG_HALF2: 1044 case CG_HALF3: 1045 case CG_HALF4: 1046 case CG_HALF4x4: 1047 { 1048 assert ( "Annotation type not supported! " + cgAnnoType ); 1049 break; 1050 } 1051 case CG_STRING: 1052 { 1053 valueType = COLLADASW::ValueType::STRING; 1054 const char* values = cgGetStringAnnotationValue ( cgAnno ); 1055 COLLADASW::Annotation annotation ( streamWriter, annotationName, valueType, values ); 1056 annotations.push_back ( annotation ); 1057 break; 1058 } 1059 default: 1060 assert ( "Annotation type not supported! " + cgAnnoType ); 1061 break; 1062 } 1063 1064 cgAnno = cgGetNextAnnotation ( cgAnno ); 1065 } 1066 } 1067 */ 1068 // -------------------------------------- 1069 setTexture(const PBBitmap * bitmap,COLLADASW::Sampler & sampler)1070 void HwShaderExporter::setTexture ( 1071 const PBBitmap * bitmap, 1072 COLLADASW::Sampler& sampler 1073 ) 1074 { 1075 if ( !bitmap ) 1076 { 1077 //:TODO: retrieve default values from fx file 1078 return; 1079 } 1080 1081 // Set the texture format. 1082 //:TODO: read from BitmapInfo::Type () 1083 sampler.setFormat ( EffectTextureExporter::FORMAT ); 1084 1085 // Get the necessary exporters. 1086 EffectExporter* effectExporter = mDocumentExporter->getEffectExporter (); 1087 EffectTextureExporter* textureExporter = effectExporter->getTextureExporter(); 1088 1089 // The file name to connect to. 1090 #ifdef UNICODE 1091 String fileName = bitmap->bi.Name() ? COLLADASW::URI::nativePathToUri( COLLADABU::StringUtils::wideString2utf8String(bitmap->bi.Name()) ) : ""; 1092 #else 1093 String fileName = bitmap->bi.Name() ? COLLADASW::URI::nativePathToUri( bitmap->bi.Name() ) : ""; 1094 #endif 1095 1096 // Export, if we have a file name. 1097 if ( !fileName.empty () ) 1098 { 1099 // Get the image path 1100 COLLADASW::URI shaderFxFileUri = mEffectProfile->getIncludeURI(); 1101 1102 // Take the filename for the unique image name 1103 COLLADASW::URI sourceFileUri ( shaderFxFileUri, fileName ); 1104 if ( sourceFileUri.getScheme ().empty () ) 1105 sourceFileUri.setScheme ( COLLADASW::URI::SCHEME_FILE ); 1106 String maxImageId = /*DocumentExporter::mayaNameToColladaName*/ ( sourceFileUri.getPathFileBase().c_str () ); 1107 1108 // Get the image id of the maya image 1109 String colladaImageId = textureExporter->findColladaImageId ( maxImageId ); 1110 1111 if ( colladaImageId.empty () ) 1112 { 1113 colladaImageId = textureExporter->getImageIdList ().addId ( maxImageId ); 1114 textureExporter->getMaxIdColladaImageId () [maxImageId] = colladaImageId; 1115 } 1116 1117 // Export the image 1118 COLLADASW::Image* colladaImage = textureExporter->exportImage ( maxImageId, colladaImageId, sourceFileUri ); 1119 1120 // Get the image id of the exported collada image 1121 colladaImageId = colladaImage->getImageId(); 1122 1123 // Set the image reference 1124 sampler.setImageId ( colladaImageId ); 1125 } 1126 } 1127 1128 // -------------------------------------- 1129 /* 1130 void HwShaderExporter::getResourceType( 1131 const CGparameter& cgTextureParam, 1132 COLLADASW::Sampler::SamplerType &samplerType, 1133 COLLADASW::ValueType::ColladaType &samplerValueType ) 1134 { 1135 // Get the type of the resource for default value 1136 CGannotation resourceTypeAnnotation = 1137 cgGetNamedParameterAnnotation( cgTextureParam, 1138 COLLADASW::CSWC::CSW_FX_ANNOTATION_RESOURCE_TYPE.c_str() ); 1139 if ( resourceTypeAnnotation ) 1140 { 1141 // Get the name of the annotation 1142 const char* annotationValue = cgGetStringAnnotationValue ( resourceTypeAnnotation ); 1143 String resourceTypeString ( annotationValue ); 1144 1145 if ( COLLADASW::Utils::equalsIgnoreCase ( resourceTypeString, COLLADASW::CSWC::CSW_SURFACE_TYPE_1D ) ) 1146 { 1147 //surfaceType = COLLADASW::Surface::SURFACE_TYPE_1D; 1148 samplerType = COLLADASW::Sampler::SAMPLER_TYPE_1D; 1149 samplerValueType = COLLADASW::ValueType::SAMPLER_1D; 1150 } 1151 else if ( COLLADASW::Utils::equalsIgnoreCase ( resourceTypeString, COLLADASW::CSWC::CSW_SURFACE_TYPE_2D ) ) 1152 { 1153 //surfaceType = COLLADASW::Surface::SURFACE_TYPE_2D; 1154 samplerType = COLLADASW::Sampler::SAMPLER_TYPE_2D; 1155 samplerValueType = COLLADASW::ValueType::SAMPLER_2D; 1156 } 1157 else if ( COLLADASW::Utils::equalsIgnoreCase ( resourceTypeString, COLLADASW::CSWC::CSW_SURFACE_TYPE_3D ) ) 1158 { 1159 //surfaceType = COLLADASW::Surface::SURFACE_TYPE_3D; 1160 samplerType = COLLADASW::Sampler::SAMPLER_TYPE_3D; 1161 samplerValueType = COLLADASW::ValueType::SAMPLER_3D; 1162 } 1163 else if ( COLLADASW::Utils::equalsIgnoreCase ( resourceTypeString, COLLADASW::CSWC::CSW_SURFACE_TYPE_CUBE ) ) 1164 { 1165 //surfaceType = COLLADASW::Surface::SURFACE_TYPE_CUBE; 1166 samplerType = COLLADASW::Sampler::SAMPLER_TYPE_CUBE; 1167 samplerValueType = COLLADASW::ValueType::SAMPLER_CUBE; 1168 } 1169 else if ( COLLADASW::Utils::equalsIgnoreCase ( resourceTypeString, COLLADASW::CSWC::CSW_SURFACE_TYPE_RECT ) ) 1170 { 1171 //surfaceType = COLLADASW::Surface::SURFACE_TYPE_RECT; 1172 samplerType = COLLADASW::Sampler::SAMPLER_TYPE_RECT; 1173 samplerValueType = COLLADASW::ValueType::SAMPLER_RECT; 1174 } 1175 } 1176 } 1177 */ 1178 // -------------------------------------- 1179 getProgramSourceString(const char * programSourceCG)1180 String HwShaderExporter::getProgramSourceString ( const char* programSourceCG ) 1181 { 1182 // Generate the source string 1183 String sourceString ( programSourceCG ); 1184 1185 COLLADASW::Utils::translateToXML ( sourceString ); 1186 1187 // // Remove the comments /** */ 1188 // String uncommentedString = sourceString; 1189 // size_t commentStart = uncommentedString.find ( "/*" ); 1190 // while ( commentStart != String::npos ) 1191 // { 1192 // size_t commentEnd = uncommentedString.find ( "*/" ); 1193 // String startString = uncommentedString.substr ( 0, commentStart ); 1194 // String endString = uncommentedString.substr ( commentEnd+2 ); 1195 // uncommentedString = startString + endString; 1196 // commentStart = uncommentedString.find ( "/*" ); 1197 // } 1198 // sourceString = uncommentedString; 1199 // 1200 // // Remove the // comments (valid until line end) 1201 // uncommentedString = sourceString; 1202 // commentStart = uncommentedString.find ( "//" ); 1203 // while ( commentStart != String::npos ) 1204 // { 1205 // size_t commentEnd = uncommentedString.find ( '\n' ); 1206 // String commentString = uncommentedString.substr ( commentStart ); 1207 // String startString = uncommentedString.substr ( 0, commentStart ); 1208 // String endString = uncommentedString.substr ( commentEnd+2 ); 1209 // uncommentedString = startString + endString; 1210 // commentStart = uncommentedString.find ( "//" ); 1211 // } 1212 // sourceString = uncommentedString; 1213 1214 // TODO Remove all techniques. 1215 1216 // Find the position of the first "technique" element 1217 size_t techniqueStart = sourceString.find ( COLLADASW::CSWC::CSW_ELEMENT_TECHNIQUE ); 1218 1219 // Get the substring from the beginning to the first "technique" element 1220 String withoutTechniqueString = sourceString.substr ( 0, techniqueStart ); 1221 1222 // TODO Don't believe, that the "technique" element is always the last... 1223 // String withTechniqueString = sourceString.substr ( techniqueStart+COLLADASW::CSWC::CSW_ELEMENT_TECHNIQUE.length() ); 1224 // 1225 // size_t numOfOpenBraces = 0; 1226 // 1227 // size_t braceOpenPos = withTechniqueString.find ( "{" ); 1228 // if ( braceOpenPos != String::npos ) 1229 // { 1230 // numOfOpenBraces += 1; 1231 // size_t braceClosePos = withTechniqueString.find ( "}" ); 1232 // 1233 // String nextOpenString = withTechniqueString.substr ( braceOpenPos ); 1234 // size_t nextBraceOpenPos = nextOpenString.find ( "{" ); 1235 // 1236 // if ( nextBraceOpenPos < braceClosePos ) 1237 // { 1238 // numOfOpenBraces += 1; 1239 // } 1240 // else 1241 // { 1242 // withoutTechniqueString += 1243 // } 1244 // } 1245 1246 return withoutTechniqueString; 1247 } 1248 1249 } 1250