Added CullSettings::InitialFrustumCallback to enable Camera to provide customization of the the initialzation of the frustum.

This commit is contained in:
Robert Osfield 2020-12-23 16:16:56 +00:00
parent 08c8f3bd7b
commit 2d6e0b6a66
3 changed files with 26 additions and 2 deletions

View File

@ -23,6 +23,7 @@ namespace osg {
// forward declare
class ArgumentParser;
class ApplicationUsage;
class Polytope;
class OSG_EXPORT CullSettings
{
@ -77,6 +78,7 @@ class OSG_EXPORT CullSettings
LIGHT = (0x1 << 16),
DRAW_BUFFER = (0x1 << 17),
READ_BUFFER = (0x1 << 18),
INITIAL_FRUSTUM_CALLBACK = (0x1 << 19),
NO_VARIABLES = 0x00000000,
ALL_VARIABLES = 0x7FFFFFFF
@ -243,6 +245,17 @@ class OSG_EXPORT CullSettings
const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); }
/** Callback to override the initial frustum, in clip space, set up at the start of cull traversal prior to projection and view matrices transforming.*/
struct InitialFrustumCallback : public osg::Referenced
{
virtual void setInitialFrustum(CullStack& cullStack, Polytope& frustum) const = 0;
};
void setInitialFrustumCallback(InitialFrustumCallback* ifc) { _initialFrustumCallback = ifc; applyMaskAction(INITIAL_FRUSTUM_CALLBACK); }
InitialFrustumCallback* getInitialFrustumCallback() { return _initialFrustumCallback.get(); }
const InitialFrustumCallback* getInitialFrustumCallback() const { return _initialFrustumCallback.get(); }
/** Write out internal settings of CullSettings. */
void write(std::ostream& out);
@ -267,7 +280,7 @@ class OSG_EXPORT CullSettings
Node::NodeMask _cullMaskLeft;
Node::NodeMask _cullMaskRight;
ref_ptr<InitialFrustumCallback> _initialFrustumCallback;
};
template<class matrix_type, class value_type>

View File

@ -70,6 +70,8 @@ void CullSettings::setCullSettings(const CullSettings& rhs)
_cullMask = rhs._cullMask;
_cullMaskLeft = rhs._cullMaskLeft;
_cullMaskRight = rhs._cullMaskRight;
_initialFrustumCallback = rhs._initialFrustumCallback;
}
@ -88,6 +90,7 @@ void CullSettings::inheritCullSettings(const CullSettings& settings, unsigned in
if (inheritanceMask & LOD_SCALE) _LODScale = settings._LODScale;
if (inheritanceMask & SMALL_FEATURE_CULLING_PIXEL_SIZE) _smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize;
if (inheritanceMask & CLAMP_PROJECTION_MATRIX_CALLBACK) _clampProjectionMatrixCallback = settings._clampProjectionMatrixCallback;
if (inheritanceMask & INITIAL_FRUSTUM_CALLBACK) _initialFrustumCallback = settings._initialFrustumCallback;
}

View File

@ -162,7 +162,15 @@ void CullStack::pushProjectionMatrix(RefMatrix* matrix)
osg::CullingSet& cullingSet = _projectionCullingStack.back();
// set up view frustum.
cullingSet.getFrustum().setToUnitFrustum(((_cullingMode&NEAR_PLANE_CULLING)!=0),((_cullingMode&FAR_PLANE_CULLING)!=0));
if (_initialFrustumCallback.valid())
{
_initialFrustumCallback->setInitialFrustum(*this, cullingSet.getFrustum());
}
else
{
cullingSet.getFrustum().setToUnitFrustum(((_cullingMode&NEAR_PLANE_CULLING)!=0),((_cullingMode&FAR_PLANE_CULLING)!=0));
}
cullingSet.getFrustum().transformProvidingInverse(*matrix);
// set the culling mask ( There should be a more elegant way!) Nikolaus H.