courtessy @Lopuska: opengl occlusion query fix

This commit is contained in:
Azaezel 2016-01-18 00:28:09 -06:00
parent 45a19453ee
commit 23c4b52e1f
4 changed files with 25 additions and 56 deletions

View file

@ -318,6 +318,8 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
const U32 numPrims = curEntry.numPrims;
const U32 numVerts = curEntry.vertBuffer->mNumVerts;
ShadowMapParams *lsp = curLightInfo->getExtended<ShadowMapParams>();
// Skip lights which won't affect the scene.
if ( !curLightMat || curLightInfo->getBrightness() <= 0.001f )
continue;
@ -329,15 +331,12 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
mShadowManager->setLightShadowMap( curEntry.shadowMap );
mShadowManager->setLightDynamicShadowMap( curEntry.dynamicShadowMap );
// Let the shadow know we're about to render from it.
if ( curEntry.shadowMap )
curEntry.shadowMap->preLightRender();
if ( curEntry.dynamicShadowMap ) curEntry.dynamicShadowMap->preLightRender();
// Set geometry
GFX->setVertexBuffer( curEntry.vertBuffer );
GFX->setPrimitiveBuffer( curEntry.primBuffer );
lsp->getOcclusionQuery()->begin();
// Render the material passes
while( curLightMat->matInstance->setupPass( state, sgData ) )
{
@ -352,10 +351,7 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
GFX->drawPrimitive(GFXTriangleList, 0, numPrims);
}
// Tell it we're done rendering.
if ( curEntry.shadowMap )
curEntry.shadowMap->postLightRender();
if ( curEntry.dynamicShadowMap ) curEntry.dynamicShadowMap->postLightRender();
lsp->getOcclusionQuery()->end();
}
// Set NULL for active shadow map (so nothing gets confused)

View file

@ -89,8 +89,6 @@ LightShadowMap::LightShadowMap( LightInfo *light )
mLastUpdate( 0 ),
mLastCull( 0 ),
mIsViewDependent( false ),
mVizQuery( NULL ),
mWasOccluded( false ),
mLastScreenSize( 0.0f ),
mLastPriority( 0.0f ),
mIsDynamic( false )
@ -98,9 +96,7 @@ LightShadowMap::LightShadowMap( LightInfo *light )
GFXTextureManager::addEventDelegate( this, &LightShadowMap::_onTextureEvent );
mTarget = GFX->allocRenderToTextureTarget();
mVizQuery = GFX->createOcclusionQuery();
smShadowMaps.push_back(this);
smShadowMaps.push_back( this );
mStaticRefreshTimer = PlatformTimer::create();
mDynamicRefreshTimer = PlatformTimer::create();
}
@ -108,8 +104,9 @@ LightShadowMap::LightShadowMap( LightInfo *light )
LightShadowMap::~LightShadowMap()
{
mTarget = NULL;
SAFE_DELETE( mVizQuery );
SAFE_DELETE(mStaticRefreshTimer);
SAFE_DELETE(mDynamicRefreshTimer);
releaseTextures();
smShadowMaps.remove( this );
@ -334,23 +331,6 @@ void LightShadowMap::render( RenderPassManager* renderPass,
mLastUpdate = Sim::getCurrentTime();
}
void LightShadowMap::preLightRender()
{
PROFILE_SCOPE( LightShadowMap_prepLightRender );
if ( mVizQuery )
{
mWasOccluded = mVizQuery->getStatus( true ) == GFXOcclusionQuery::Occluded;
mVizQuery->begin();
}
}
void LightShadowMap::postLightRender()
{
if ( mVizQuery )
mVizQuery->end();
}
BaseMatInstance* LightShadowMap::getShadowMaterial( BaseMatInstance *inMat ) const
{
// See if we have an existing material hook.
@ -610,11 +590,14 @@ ShadowMapParams::ShadowMapParams( LightInfo *light )
shadowSoftness = 0.15f;
fadeStartDist = 0.0f;
lastSplitTerrainOnly = false;
mQuery = GFX->createOcclusionQuery();
_validate();
}
ShadowMapParams::~ShadowMapParams()
{
SAFE_DELETE( mQuery );
SAFE_DELETE( mShadowMap );
SAFE_DELETE( mDynamicShadowMap );
}

View file

@ -47,6 +47,9 @@
#ifndef _GFXSHADER_H_
#include "gfx/gfxShader.h"
#endif
#ifndef _GFXOCCLUSIONQUERY_H_
#include "gfx/gfxOcclusionQuery.h"
#endif
#ifndef _PLATFORM_PLATFORMTIMER_H_
#include "platform/platformTimer.h"
#endif
@ -61,7 +64,6 @@ struct SceneData;
class GFXShaderConstBuffer;
class GFXShaderConstHandle;
class GFXShader;
class GFXOcclusionQuery;
class LightManager;
class RenderPassManager;
@ -169,12 +171,6 @@ public:
bool isViewDependent() const { return mIsViewDependent; }
bool wasOccluded() const { return mWasOccluded; }
void preLightRender();
void postLightRender();
void updatePriority( const SceneRenderState *state, U32 currTimeMs );
F32 getLastScreenSize() const { return mLastScreenSize; }
@ -257,15 +253,6 @@ protected:
/// The time this shadow was last culled and prioritized.
U32 mLastCull;
/// The shadow occlusion query used when the light is
/// rendered to determine if any pixel of it is visible.
GFXOcclusionQuery *mVizQuery;
/// If true the light was occluded by geometry the
/// last frame it was updated.
//the last frame.
bool mWasOccluded;
F32 mLastScreenSize;
F32 mLastPriority;
@ -325,6 +312,8 @@ public:
bool hasCookieTex() const { return cookie.isNotEmpty(); }
GFXOcclusionQuery* getOcclusionQuery() const { return mQuery; }
GFXTextureObject* getCookieTex();
GFXCubemap* getCookieCubeTex();
@ -339,6 +328,7 @@ protected:
///
LightShadowMap *mShadowMap;
LightShadowMap *mDynamicShadowMap;
GFXOcclusionQuery* mQuery;
LightInfo *mLight;

View file

@ -174,12 +174,12 @@ void ShadowMapPass::render( SceneManager *sceneManager,
continue;
// --- Static Shadow Map ---
LightShadowMap *lsm = params->getOrCreateShadowMap();
LightShadowMap *dlsm = params->getOrCreateShadowMap(true);
LightShadowMap *lsm = params->getOrCreateShadowMap();
LightShadowMap *dlsm = params->getOrCreateShadowMap(true);
// First check the visiblity query... if it wasn't
// visible skip it.
if (lsm->wasOccluded() || dlsm->wasOccluded())
if(params->getOcclusionQuery()->getStatus(true) == GFXOcclusionQuery::Occluded)
continue;
// Any shadow that is visible is counted as being
@ -187,9 +187,9 @@ void ShadowMapPass::render( SceneManager *sceneManager,
++smActiveShadowMaps;
// Do a priority update for this shadow.
lsm->updatePriority(diffuseState, currTime);
lsm->updatePriority(diffuseState, currTime);
shadowMaps.push_back(lsm);
shadowMaps.push_back(lsm);
// --- Dynamic Shadow Map ---
@ -198,7 +198,7 @@ void ShadowMapPass::render( SceneManager *sceneManager,
++smActiveShadowMaps;
// Do a priority update for this shadow.
dlsm->updatePriority(diffuseState, currTime);
dlsm->updatePriority(diffuseState, currTime);
shadowMaps.push_back( dlsm );
}
@ -306,4 +306,4 @@ void DynamicShadowRenderPassManager::addInst( RenderInst *inst )
}
Parent::addInst(inst);
}
}