Changeset 657 for OGRE/trunk/ogre_changes/OgreMain/src
- Timestamp:
- 02/20/06 19:06:03 (19 years ago)
- Location:
- OGRE/trunk/ogre_changes/OgreMain/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
OGRE/trunk/ogre_changes/OgreMain/src/OgreRenderSystem.cpp
r316 r657 40 40 #include "OgreMaterial.h" 41 41 #include "OgreTimer.h" 42 #include "OgreHardwareOcclusionQuery.h" 42 43 43 44 namespace Ogre { … … 69 70 { 70 71 shutdown(); 72 delete mCapabilities; 73 mCapabilities = 0; 71 74 } 72 75 //----------------------------------------------------------------------- … … 324 327 void RenderSystem::shutdown(void) 325 328 { 329 // Remove occlusion queries 330 for (HardwareOcclusionQueryList::iterator i = mHwOcclusionQueries.begin(); 331 i != mHwOcclusionQueries.end(); ++i) 332 { 333 delete *i; 334 } 335 mHwOcclusionQueries.clear(); 336 326 337 // Remove all the render targets. 327 338 // (destroy primary target last since others may depend on it) … … 416 427 } 417 428 } 429 //----------------------------------------------------------------------- 430 void RenderSystem::addListener(Listener* l) 431 { 432 mEventListeners.push_back(l); 433 } 434 //----------------------------------------------------------------------- 435 void RenderSystem::removeListener(Listener* l) 436 { 437 mEventListeners.remove(l); 438 } 439 //----------------------------------------------------------------------- 440 void RenderSystem::fireEvent(const String& name, const NameValuePairList* params) 441 { 442 for(ListenerList::iterator i = mEventListeners.begin(); 443 i != mEventListeners.end(); ++i) 444 { 445 (*i)->eventOccurred(name, params); 446 } 447 } 448 //----------------------------------------------------------------------- 449 void RenderSystem::destroyHardwareOcclusionQuery( HardwareOcclusionQuery *hq) 450 { 451 for (HardwareOcclusionQueryList::iterator i = mHwOcclusionQueries.begin(); 452 i != mHwOcclusionQueries.end(); ++i) 453 { 454 if (*i == hq) 455 { 456 delete *i; 457 mHwOcclusionQueries.erase(i); 458 break; 459 } 460 } 461 } 462 418 463 } 419 464 -
OGRE/trunk/ogre_changes/OgreMain/src/OgreSceneManager.cpp
r343 r657 375 375 // Subclasses could do something smarter 376 376 destList.clear(); 377 Real squaredRadius = radius * radius;378 377 379 378 SceneLightList::iterator i, iend; … … 396 395 // only add in-range lights 397 396 Real range = lt->getAttenuationRange(); 398 if ((lt->tempSquareDist - squaredRadius) <= (range * range)) 397 Real maxDist = range + radius; 398 if (lt->tempSquareDist <= Math::Sqr(maxDist)) 399 399 { 400 400 destList.push_back(lt); … … 554 554 mSkyBoxEnabled = mSkyPlaneEnabled = mSkyDomeEnabled = false; 555 555 556 // Clear render queue, empty completely 557 if (mRenderQueue) 558 mRenderQueue->clear(true); 559 556 560 } 557 561 //----------------------------------------------------------------------- … … 593 597 AutoTrackingSceneNodes::iterator ai, aiend; 594 598 aiend = mAutoTrackingSceneNodes.end(); 595 for (ai = mAutoTrackingSceneNodes.begin(); ai != aiend; ++ai) 596 { 597 SceneNode* n = *ai; 599 for (ai = mAutoTrackingSceneNodes.begin(); ai != aiend; ) 600 { 601 // Pre-increment incase we delete 602 AutoTrackingSceneNodes::iterator curri = ai++; 603 SceneNode* n = *curri; 598 604 // Tracking this node 599 605 if (n->getAutoTrackTarget() == i->second) … … 601 607 // turn off, this will notify SceneManager to remove 602 608 n->setAutoTracking(false); 603 // no need to reset iterator since set erase does not invalidate604 609 } 605 610 // node is itself a tracker 606 611 else if (n == i->second) 607 612 { 608 mAutoTrackingSceneNodes.erase( ai);613 mAutoTrackingSceneNodes.erase(curri); 609 614 } 610 615 } … … 814 819 if (thisFrameNumber != lastFrameNumber) 815 820 { 821 // Update controllers 822 ControllerManager::getSingleton().updateAllControllers(); 816 823 // Update animations 817 824 _applySceneAnimations(); 818 // Update controllers819 ControllerManager::getSingleton().updateAllControllers();820 825 lastFrameNumber = thisFrameNumber; 821 826 } … … 868 873 } 869 874 875 // Tell params about viewport 876 mAutoParamDataSource.setCurrentViewport(vp); 870 877 // Set the viewport 871 878 setViewport(vp); … … 1409 1416 { 1410 1417 // Someone requested we skip this queue 1411 continue;1418 break; 1412 1419 } 1413 1420 … … 1713 1720 mShadowReceiverPass->_load(); 1714 1721 1715 if (l->getCastShadows() && pGroup->getShadowsEnabled())1722 if (l->getCastShadows()) 1716 1723 { 1717 1724 renderTextureShadowReceiverQueueGroupObjects(pGroup); … … 1876 1883 { 1877 1884 // Ordinary pass 1885 if (pGroup->getShadowsEnabled()) 1878 1886 renderModulativeTextureShadowedQueueGroupObjects(pGroup); 1887 else 1888 renderBasicQueueGroupObjects(pGroup); 1879 1889 } 1880 1890 } … … 2118 2128 { 2119 2129 mAmbientLight = colour; 2120 mDestRenderSystem->setAmbientLight(colour.r, colour.g, colour.b);2121 2130 } 2122 2131 //----------------------------------------------------------------------- … … 2656 2665 { 2657 2666 createShadowTextures(mShadowTextureSize, mShadowTextureCount, mShadowTextureFormat); 2667 } 2668 else 2669 { 2670 // Destroy shadow textures to optimise resource usage 2671 destroyShadowTextures(); 2658 2672 } 2659 2673 … … 2764 2778 const Vector3* corners = camera->getWorldSpaceCorners(); 2765 2779 Vector3 min, max; 2766 Vector3 extrude = light->getD irection() * -mShadowDirLightExtrudeDist;2780 Vector3 extrude = light->getDerivedDirection() * -mShadowDirLightExtrudeDist; 2767 2781 // do first corner 2768 2782 min = max = corners[0]; … … 2792 2806 else 2793 2807 { 2794 Sphere s(light->get Position(), light->getAttenuationRange());2808 Sphere s(light->getDerivedPosition(), light->getAttenuationRange()); 2795 2809 // eliminate early if camera cannot see light sphere 2796 2810 if (camera->isVisible(s)) … … 2875 2889 { 2876 2890 mShadowDebugPass = matDebug->getTechnique(0)->getPass(0); 2891 2892 if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM)) 2893 { 2894 mInfiniteExtrusionParams = mShadowDebugPass->getVertexProgramParameters(); 2895 } 2877 2896 } 2878 2897 } … … 2915 2934 { 2916 2935 mShadowStencilPass = matStencil->getTechnique(0)->getPass(0); 2936 2937 if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM)) 2938 { 2939 mFiniteExtrusionParams = mShadowStencilPass->getVertexProgramParameters(); 2940 } 2917 2941 } 2918 2942 } … … 3029 3053 Pass* SceneManager::deriveShadowCasterPass(Pass* pass) 3030 3054 { 3055 Pass* retPass = 0; 3031 3056 switch (mShadowTechnique) 3032 3057 { 3033 3058 case SHADOWTYPE_TEXTURE_MODULATIVE: 3034 if (mShadowTextureCustomCasterPass) 3059 retPass = mShadowTextureCustomCasterPass ? 3060 mShadowTextureCustomCasterPass : mShadowCasterPlainBlackPass; 3061 3062 3063 // Special case alpha-blended passes 3064 if ((pass->getSourceBlendFactor() == SBF_SOURCE_ALPHA && 3065 pass->getDestBlendFactor() == SBF_ONE_MINUS_SOURCE_ALPHA) 3066 || pass->getAlphaRejectFunction() != CMPF_ALWAYS_PASS) 3035 3067 { 3036 // Caster pass has been customised 3068 // Alpha blended passes must retain their transparency 3069 retPass->setAlphaRejectSettings(pass->getAlphaRejectFunction(), 3070 pass->getAlphaRejectValue()); 3071 retPass->setSceneBlending(pass->getSourceBlendFactor(), pass->getDestBlendFactor()); 3072 retPass->getParent()->getParent()->setTransparencyCastsShadows(true); 3073 3074 // So we allow the texture units, but override the colour functions 3075 // Copy texture state, shift up one since 0 is shadow texture 3076 size_t origPassTUCount = pass->getNumTextureUnitStates(); 3077 for (size_t t = 0; t < origPassTUCount; ++t) 3078 { 3079 TextureUnitState* tex; 3080 if (retPass->getNumTextureUnitStates() <= t) 3081 { 3082 tex = retPass->createTextureUnitState(); 3083 } 3084 else 3085 { 3086 tex = retPass->getTextureUnitState(t); 3087 } 3088 // copy base state 3089 (*tex) = *(pass->getTextureUnitState(t)); 3090 // override colour function 3091 tex->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 3092 mShadowColour); 3093 3094 } 3095 // Remove any extras 3096 while (retPass->getNumTextureUnitStates() > origPassTUCount) 3097 { 3098 retPass->removeTextureUnitState(origPassTUCount); 3099 } 3100 3101 } 3102 else 3103 { 3104 // reset 3105 retPass->setSceneBlending(SBF_ONE, SBF_ZERO); 3106 retPass->setAlphaRejectFunction(CMPF_ALWAYS_PASS); 3107 while (retPass->getNumTextureUnitStates() > 0) 3108 { 3109 retPass->removeTextureUnitState(0); 3110 } 3111 } 3112 3113 // Propagate culling modes 3114 retPass->setCullingMode(pass->getCullingMode()); 3115 retPass->setManualCullingMode(pass->getManualCullingMode()); 3116 3037 3117 3038 3118 if (!pass->getShadowCasterVertexProgramName().empty()) 3039 3119 { 3040 3120 // Have to merge the shadow caster vertex program in 3041 mShadowTextureCustomCasterPass->setVertexProgram(3121 retPass->setVertexProgram( 3042 3122 pass->getShadowCasterVertexProgramName()); 3043 const GpuProgramPtr& prg = mShadowTextureCustomCasterPass->getVertexProgram();3123 const GpuProgramPtr& prg = retPass->getVertexProgram(); 3044 3124 // Load this program if not done already 3045 3125 if (!prg->isLoaded()) 3046 3126 prg->load(); 3047 3127 // Copy params 3048 mShadowTextureCustomCasterPass->setVertexProgramParameters(3128 retPass->setVertexProgramParameters( 3049 3129 pass->getShadowCasterVertexProgramParameters()); 3130 if (retPass == mShadowTextureCustomCasterPass) 3131 { 3050 3132 // mark that we've overridden the standard 3051 3133 mShadowTextureCasterVPDirty = true; 3134 } 3052 3135 // Also have to hack the light autoparams, that is done later 3053 3136 } 3054 else if (mShadowTextureCasterVPDirty) 3137 else 3138 { 3139 retPass->setVertexProgram(StringUtil::BLANK); 3140 if (mShadowTextureCasterVPDirty) 3055 3141 { 3056 3142 // reset … … 3065 3151 mShadowTextureCasterVPDirty = false; 3066 3152 } 3067 return mShadowTextureCustomCasterPass;3068 3153 } 3069 else 3070 { 3071 // Standard pass 3072 if (pass->hasVertexProgram()) 3073 { 3074 // Have to merge the shadow caster vertex program in 3075 // This may in fact be blank, in which case it falls back on 3076 // fixed function 3077 mShadowCasterPlainBlackPass->setVertexProgram( 3078 pass->getShadowCasterVertexProgramName()); 3079 // Did this result in a new vertex program? 3080 if (mShadowCasterPlainBlackPass->hasVertexProgram()) 3081 { 3082 const GpuProgramPtr& prg = mShadowCasterPlainBlackPass->getVertexProgram(); 3083 // Load this program if not done already 3084 if (!prg->isLoaded()) 3085 prg->load(); 3086 // Copy params 3087 mShadowCasterPlainBlackPass->setVertexProgramParameters( 3088 pass->getShadowCasterVertexProgramParameters()); 3089 } 3090 // Also have to hack the light autoparams, that is done later 3091 } 3092 else if (mShadowCasterPlainBlackPass->hasVertexProgram()) 3093 { 3094 // reset 3095 mShadowCasterPlainBlackPass->setVertexProgram(""); 3096 } 3097 return mShadowCasterPlainBlackPass; 3098 } 3154 return retPass; 3099 3155 default: 3100 3156 return pass; … … 3301 3357 { 3302 3358 ShadowCaster* caster = *si; 3303 bool zfailAlgo = false;3359 bool zfailAlgo = camera->isCustomNearClipPlaneEnabled(); 3304 3360 unsigned long flags = 0; 3305 3361 … … 3705 3761 3706 3762 // destroy existing 3707 ShadowTextureList::iterator i, iend; 3708 iend = mShadowTextures.end(); 3709 for (i = mShadowTextures.begin(); i != iend; ++i) 3710 { 3711 RenderTexture* r = *i; 3712 // remove camera and destroy texture 3713 removeCamera(r->getViewport(0)->getCamera()); 3714 mDestRenderSystem->destroyRenderTexture(r->getName()); 3715 } 3716 mShadowTextures.clear(); 3763 destroyShadowTextures(); 3717 3764 3718 3765 // Recreate shadow textures … … 3762 3809 3763 3810 } 3811 } 3812 //--------------------------------------------------------------------- 3813 void SceneManager::destroyShadowTextures(void) 3814 { 3815 ShadowTextureList::iterator i, iend; 3816 iend = mShadowTextures.end(); 3817 for (i = mShadowTextures.begin(); i != iend; ++i) 3818 { 3819 RenderTexture* r = *i; 3820 // remove camera and destroy texture 3821 removeCamera(r->getViewport(0)->getCamera()); 3822 mDestRenderSystem->destroyRenderTexture(r->getName()); 3823 } 3824 mShadowTextures.clear(); 3764 3825 } 3765 3826 //--------------------------------------------------------------------- -
OGRE/trunk/ogre_changes/OgreMain/src/OgreSceneNode.cpp
r158 r657 296 296 { 297 297 SceneNode* sceneChild = static_cast<SceneNode*>(child->second); 298 sceneChild->_findVisibleObjects(cam, queue, includeChildren, displayNodes); 298 sceneChild->_findVisibleObjects(cam, queue, includeChildren, 299 displayNodes, onlyShadowCasters); 299 300 } 300 301 } … … 391 392 ChildNodeMap::iterator i, iend; 392 393 iend = mChildren.end(); 393 for (i = mChildren.begin(); i != iend; ++i)394 for (i = mChildren.begin(); i != iend;) 394 395 { 395 396 SceneNode* sn = static_cast<SceneNode*>(i->second); 397 // increment iterator before destroying (iterator invalidated by 398 // SceneManager::destroySceneNode because it causes removal from parent) 399 ++i; 396 400 sn->removeAndDestroyAllChildren(); 397 401 sn->getCreator()->destroySceneNode(sn->getName()); … … 482 486 if (vec == Vector3::ZERO) return; 483 487 484 // Adjust vector so that it is relative to local Z 485 Vector3 zAdjustVec; 486 if (localDirectionVector == Vector3::NEGATIVE_UNIT_Z) 487 { 488 zAdjustVec = -vec; 489 } 490 else 491 { 492 Quaternion localToUnitZ = localDirectionVector.getRotationTo(Vector3::UNIT_Z); 493 zAdjustVec = localToUnitZ * vec; 494 } 495 zAdjustVec.normalise(); 496 488 // The direction we want the local direction point to 489 Vector3 targetDir = vec.normalisedCopy(); 490 491 // Transform target direction to world space 492 switch (relativeTo) 493 { 494 case TS_PARENT: 495 if (mParent) 496 targetDir = mParent->_getDerivedOrientation() * targetDir; 497 break; 498 case TS_LOCAL: 499 targetDir = _getDerivedOrientation() * targetDir; 500 break; 501 } 502 503 // Calculate target orientation relative to world space 497 504 Quaternion targetOrientation; 498 505 if( mYawFixed ) 499 506 { 500 Vector3 xVec = mYawFixedAxis.crossProduct( zAdjustVec ); 507 // Calculate the quaternion for rotate local Z to target direction 508 Vector3 xVec = mYawFixedAxis.crossProduct(targetDir); 501 509 xVec.normalise(); 502 503 Vector3 yVec = zAdjustVec.crossProduct( xVec ); 510 Vector3 yVec = targetDir.crossProduct(xVec); 504 511 yVec.normalise(); 512 Quaternion unitZToTarget = Quaternion(xVec, yVec, targetDir); 505 513 506 targetOrientation.FromAxes( xVec, yVec, zAdjustVec ); 514 if (localDirectionVector == Vector3::NEGATIVE_UNIT_Z) 515 { 516 // Specail case for avoid calculate 180 degree turn 517 targetOrientation = 518 Quaternion(-unitZToTarget.y, -unitZToTarget.z, unitZToTarget.w, unitZToTarget.x); 507 519 } 508 520 else 509 521 { 510 511 // Get axes from current quaternion512 Vector3 axes[3];513 _getDerivedOrientation().ToAxes(axes);514 Quaternion rotQuat;515 if ( (axes[2]+zAdjustVec).squaredLength() < 0.00005f)522 // Calculate the quaternion for rotate local direction to target direction 523 Quaternion localToUnitZ = localDirectionVector.getRotationTo(Vector3::UNIT_Z); 524 targetOrientation = unitZToTarget * localToUnitZ; 525 } 526 } 527 else 516 528 { 529 const Quaternion& currentOrient = _getDerivedOrientation(); 530 531 // Get current local direction relative to world space 532 Vector3 currentDir = currentOrient * localDirectionVector; 533 534 if ((currentDir+targetDir).squaredLength() < 0.00005f) 535 { 517 536 // Oops, a 180 degree turn (infinite possible rotation axes) 518 537 // Default to yaw i.e. use current UP 519 rotQuat.FromAngleAxis(Radian(Math::PI), axes[1]); 520 } 521 else 522 { 538 targetOrientation = 539 Quaternion(-currentOrient.y, -currentOrient.z, currentOrient.w, currentOrient.x); 540 } 541 else 542 { 523 543 // Derive shortest arc to new direction 524 rotQuat = axes[2].getRotationTo(zAdjustVec); 525 526 } 527 targetOrientation = rotQuat * mOrientation; 528 } 529 530 if (relativeTo == TS_LOCAL || !mParent) 531 { 544 Quaternion rotQuat = currentDir.getRotationTo(targetDir); 545 targetOrientation = rotQuat * currentOrient; 546 } 547 } 548 549 // Set target orientation, transformed to parent space 550 if (mParent) 551 setOrientation(mParent->_getDerivedOrientation().UnitInverse() * targetOrientation); 552 else 532 553 setOrientation(targetOrientation); 533 }534 else535 {536 if (relativeTo == TS_PARENT)537 {538 setOrientation(targetOrientation * mParent->getOrientation().Inverse());539 }540 else if (relativeTo == TS_WORLD)541 {542 setOrientation(targetOrientation * mParent->_getDerivedOrientation().Inverse());543 }544 }545 546 547 554 } 548 555 //----------------------------------------------------------------------- … … 550 557 const Vector3& localDirectionVector) 551 558 { 552 this->setDirection(targetPoint - _getDerivedPosition(), relativeTo, 553 localDirectionVector); 559 // Calculate ourself origin relative to the given transform space 560 Vector3 origin; 561 switch (relativeTo) 562 { 563 default: // Just in case 564 case TS_WORLD: 565 origin = _getDerivedPosition(); 566 break; 567 case TS_PARENT: 568 origin = mPosition; 569 break; 570 case TS_LOCAL: 571 origin = Vector3::ZERO; 572 break; 573 } 574 575 setDirection(targetPoint - origin, relativeTo, localDirectionVector); 554 576 } 555 577 //-----------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.