#include using namespace osg; CullStack::CullStack() { _cullingMode = ENABLE_ALL_CULLING; _LODBias = 1.0f; _smallFeatureCullingPixelSize = 3.0f; } CullStack::~CullStack() { reset(); } void CullStack::reset() { // // first unref all referenced objects and then empty the containers. // _projectionStack.clear(); _modelviewStack.clear(); _viewportStack.clear(); _eyePointStack.clear(); _clipspaceCullingStack.clear(); _projectionCullingStack.clear(); _modelviewCullingStack.clear(); osg::Vec3 lookVector(0.0,0.0,-1.0); _bbCornerFar = (lookVector.x()>=0?1:0) | (lookVector.y()>=0?2:0) | (lookVector.z()>=0?4:0); _bbCornerNear = (~_bbCornerFar)&7; } void CullStack::pushCullingSet() { _MVPW_Stack.push_back(0L); if (_modelviewStack.empty()) { _modelviewCullingStack.push_back(_projectionCullingStack.back()); } else { const osg::Viewport& W = *_viewportStack.back(); const osg::Matrix& P = *_projectionStack.back(); const osg::Matrix& M = *_modelviewStack.back(); // pre adjust P00,P20,P23,P33 by multiplying them by the viewport window matrix. // here we do it in short hand with the knowledge of how the window matrix is formed // note P23,P33 are multiplied by an implicit 1 which would come from the window matrix. // Robert Osfield, June 2002. float P00 = P(0,0)*W.width()*0.5f; float P20 = P(2,0)*W.width()*0.5f + P(2,3)*W.width()*0.5f; osg::Vec3 scale(M(0,0)*P00 + M(0,2)*P20, M(1,0)*P00 + M(1,2)*P20, M(2,0)*P00 + M(2,2)*P20); float P23 = P(2,3); float P33 = P(3,3); osg::Vec4 pixelSizeVector2(M(0,2)*P23, M(1,2)*P23, M(2,2)*P23, M(3,2)*P23 + M(3,3)*P33); pixelSizeVector2 /= scale.length(); //cout << "pixelSizeVector = "<