mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 23:24:41 +00:00
Merge pull request #1505 from Azaezel/OcclusionQueryFixGL_Clean
courtessy @Lopuska: opengl occlusion query fix
This commit is contained in:
commit
b009d678fa
4 changed files with 25 additions and 56 deletions
|
|
@ -318,6 +318,8 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
|
||||||
const U32 numPrims = curEntry.numPrims;
|
const U32 numPrims = curEntry.numPrims;
|
||||||
const U32 numVerts = curEntry.vertBuffer->mNumVerts;
|
const U32 numVerts = curEntry.vertBuffer->mNumVerts;
|
||||||
|
|
||||||
|
ShadowMapParams *lsp = curLightInfo->getExtended<ShadowMapParams>();
|
||||||
|
|
||||||
// Skip lights which won't affect the scene.
|
// Skip lights which won't affect the scene.
|
||||||
if ( !curLightMat || curLightInfo->getBrightness() <= 0.001f )
|
if ( !curLightMat || curLightInfo->getBrightness() <= 0.001f )
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -329,15 +331,12 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
|
||||||
mShadowManager->setLightShadowMap( curEntry.shadowMap );
|
mShadowManager->setLightShadowMap( curEntry.shadowMap );
|
||||||
mShadowManager->setLightDynamicShadowMap( curEntry.dynamicShadowMap );
|
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
|
// Set geometry
|
||||||
GFX->setVertexBuffer( curEntry.vertBuffer );
|
GFX->setVertexBuffer( curEntry.vertBuffer );
|
||||||
GFX->setPrimitiveBuffer( curEntry.primBuffer );
|
GFX->setPrimitiveBuffer( curEntry.primBuffer );
|
||||||
|
|
||||||
|
lsp->getOcclusionQuery()->begin();
|
||||||
|
|
||||||
// Render the material passes
|
// Render the material passes
|
||||||
while( curLightMat->matInstance->setupPass( state, sgData ) )
|
while( curLightMat->matInstance->setupPass( state, sgData ) )
|
||||||
{
|
{
|
||||||
|
|
@ -352,10 +351,7 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
|
||||||
GFX->drawPrimitive(GFXTriangleList, 0, numPrims);
|
GFX->drawPrimitive(GFXTriangleList, 0, numPrims);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell it we're done rendering.
|
lsp->getOcclusionQuery()->end();
|
||||||
if ( curEntry.shadowMap )
|
|
||||||
curEntry.shadowMap->postLightRender();
|
|
||||||
if ( curEntry.dynamicShadowMap ) curEntry.dynamicShadowMap->postLightRender();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set NULL for active shadow map (so nothing gets confused)
|
// Set NULL for active shadow map (so nothing gets confused)
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,6 @@ LightShadowMap::LightShadowMap( LightInfo *light )
|
||||||
mLastUpdate( 0 ),
|
mLastUpdate( 0 ),
|
||||||
mLastCull( 0 ),
|
mLastCull( 0 ),
|
||||||
mIsViewDependent( false ),
|
mIsViewDependent( false ),
|
||||||
mVizQuery( NULL ),
|
|
||||||
mWasOccluded( false ),
|
|
||||||
mLastScreenSize( 0.0f ),
|
mLastScreenSize( 0.0f ),
|
||||||
mLastPriority( 0.0f ),
|
mLastPriority( 0.0f ),
|
||||||
mIsDynamic( false )
|
mIsDynamic( false )
|
||||||
|
|
@ -98,9 +96,7 @@ LightShadowMap::LightShadowMap( LightInfo *light )
|
||||||
GFXTextureManager::addEventDelegate( this, &LightShadowMap::_onTextureEvent );
|
GFXTextureManager::addEventDelegate( this, &LightShadowMap::_onTextureEvent );
|
||||||
|
|
||||||
mTarget = GFX->allocRenderToTextureTarget();
|
mTarget = GFX->allocRenderToTextureTarget();
|
||||||
mVizQuery = GFX->createOcclusionQuery();
|
smShadowMaps.push_back( this );
|
||||||
|
|
||||||
smShadowMaps.push_back(this);
|
|
||||||
mStaticRefreshTimer = PlatformTimer::create();
|
mStaticRefreshTimer = PlatformTimer::create();
|
||||||
mDynamicRefreshTimer = PlatformTimer::create();
|
mDynamicRefreshTimer = PlatformTimer::create();
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +104,8 @@ LightShadowMap::LightShadowMap( LightInfo *light )
|
||||||
LightShadowMap::~LightShadowMap()
|
LightShadowMap::~LightShadowMap()
|
||||||
{
|
{
|
||||||
mTarget = NULL;
|
mTarget = NULL;
|
||||||
SAFE_DELETE( mVizQuery );
|
SAFE_DELETE(mStaticRefreshTimer);
|
||||||
|
SAFE_DELETE(mDynamicRefreshTimer);
|
||||||
|
|
||||||
releaseTextures();
|
releaseTextures();
|
||||||
|
|
||||||
|
|
@ -334,23 +331,6 @@ void LightShadowMap::render( RenderPassManager* renderPass,
|
||||||
mLastUpdate = Sim::getCurrentTime();
|
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
|
BaseMatInstance* LightShadowMap::getShadowMaterial( BaseMatInstance *inMat ) const
|
||||||
{
|
{
|
||||||
// See if we have an existing material hook.
|
// See if we have an existing material hook.
|
||||||
|
|
@ -610,11 +590,14 @@ ShadowMapParams::ShadowMapParams( LightInfo *light )
|
||||||
shadowSoftness = 0.15f;
|
shadowSoftness = 0.15f;
|
||||||
fadeStartDist = 0.0f;
|
fadeStartDist = 0.0f;
|
||||||
lastSplitTerrainOnly = false;
|
lastSplitTerrainOnly = false;
|
||||||
|
mQuery = GFX->createOcclusionQuery();
|
||||||
|
|
||||||
_validate();
|
_validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
ShadowMapParams::~ShadowMapParams()
|
ShadowMapParams::~ShadowMapParams()
|
||||||
{
|
{
|
||||||
|
SAFE_DELETE( mQuery );
|
||||||
SAFE_DELETE( mShadowMap );
|
SAFE_DELETE( mShadowMap );
|
||||||
SAFE_DELETE( mDynamicShadowMap );
|
SAFE_DELETE( mDynamicShadowMap );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@
|
||||||
#ifndef _GFXSHADER_H_
|
#ifndef _GFXSHADER_H_
|
||||||
#include "gfx/gfxShader.h"
|
#include "gfx/gfxShader.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef _GFXOCCLUSIONQUERY_H_
|
||||||
|
#include "gfx/gfxOcclusionQuery.h"
|
||||||
|
#endif
|
||||||
#ifndef _PLATFORM_PLATFORMTIMER_H_
|
#ifndef _PLATFORM_PLATFORMTIMER_H_
|
||||||
#include "platform/platformTimer.h"
|
#include "platform/platformTimer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -61,7 +64,6 @@ struct SceneData;
|
||||||
class GFXShaderConstBuffer;
|
class GFXShaderConstBuffer;
|
||||||
class GFXShaderConstHandle;
|
class GFXShaderConstHandle;
|
||||||
class GFXShader;
|
class GFXShader;
|
||||||
class GFXOcclusionQuery;
|
|
||||||
class LightManager;
|
class LightManager;
|
||||||
class RenderPassManager;
|
class RenderPassManager;
|
||||||
|
|
||||||
|
|
@ -169,12 +171,6 @@ public:
|
||||||
|
|
||||||
bool isViewDependent() const { return mIsViewDependent; }
|
bool isViewDependent() const { return mIsViewDependent; }
|
||||||
|
|
||||||
bool wasOccluded() const { return mWasOccluded; }
|
|
||||||
|
|
||||||
void preLightRender();
|
|
||||||
|
|
||||||
void postLightRender();
|
|
||||||
|
|
||||||
void updatePriority( const SceneRenderState *state, U32 currTimeMs );
|
void updatePriority( const SceneRenderState *state, U32 currTimeMs );
|
||||||
|
|
||||||
F32 getLastScreenSize() const { return mLastScreenSize; }
|
F32 getLastScreenSize() const { return mLastScreenSize; }
|
||||||
|
|
@ -257,15 +253,6 @@ protected:
|
||||||
/// The time this shadow was last culled and prioritized.
|
/// The time this shadow was last culled and prioritized.
|
||||||
U32 mLastCull;
|
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 mLastScreenSize;
|
||||||
|
|
||||||
F32 mLastPriority;
|
F32 mLastPriority;
|
||||||
|
|
@ -325,6 +312,8 @@ public:
|
||||||
|
|
||||||
bool hasCookieTex() const { return cookie.isNotEmpty(); }
|
bool hasCookieTex() const { return cookie.isNotEmpty(); }
|
||||||
|
|
||||||
|
GFXOcclusionQuery* getOcclusionQuery() const { return mQuery; }
|
||||||
|
|
||||||
GFXTextureObject* getCookieTex();
|
GFXTextureObject* getCookieTex();
|
||||||
|
|
||||||
GFXCubemap* getCookieCubeTex();
|
GFXCubemap* getCookieCubeTex();
|
||||||
|
|
@ -339,6 +328,7 @@ protected:
|
||||||
///
|
///
|
||||||
LightShadowMap *mShadowMap;
|
LightShadowMap *mShadowMap;
|
||||||
LightShadowMap *mDynamicShadowMap;
|
LightShadowMap *mDynamicShadowMap;
|
||||||
|
GFXOcclusionQuery* mQuery;
|
||||||
|
|
||||||
LightInfo *mLight;
|
LightInfo *mLight;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,12 @@ void ShadowMapPass::render( SceneManager *sceneManager,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// --- Static Shadow Map ---
|
// --- Static Shadow Map ---
|
||||||
LightShadowMap *lsm = params->getOrCreateShadowMap();
|
LightShadowMap *lsm = params->getOrCreateShadowMap();
|
||||||
LightShadowMap *dlsm = params->getOrCreateShadowMap(true);
|
LightShadowMap *dlsm = params->getOrCreateShadowMap(true);
|
||||||
|
|
||||||
// First check the visiblity query... if it wasn't
|
// First check the visiblity query... if it wasn't
|
||||||
// visible skip it.
|
// visible skip it.
|
||||||
if (lsm->wasOccluded() || dlsm->wasOccluded())
|
if(params->getOcclusionQuery()->getStatus(true) == GFXOcclusionQuery::Occluded)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Any shadow that is visible is counted as being
|
// Any shadow that is visible is counted as being
|
||||||
|
|
@ -187,9 +187,9 @@ void ShadowMapPass::render( SceneManager *sceneManager,
|
||||||
++smActiveShadowMaps;
|
++smActiveShadowMaps;
|
||||||
|
|
||||||
// Do a priority update for this shadow.
|
// 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 ---
|
// --- Dynamic Shadow Map ---
|
||||||
|
|
||||||
|
|
@ -198,7 +198,7 @@ void ShadowMapPass::render( SceneManager *sceneManager,
|
||||||
++smActiveShadowMaps;
|
++smActiveShadowMaps;
|
||||||
|
|
||||||
// Do a priority update for this shadow.
|
// Do a priority update for this shadow.
|
||||||
dlsm->updatePriority(diffuseState, currTime);
|
dlsm->updatePriority(diffuseState, currTime);
|
||||||
|
|
||||||
shadowMaps.push_back( dlsm );
|
shadowMaps.push_back( dlsm );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue