From 3630f97ab14867887acb196283ee3c09fc73efed Mon Sep 17 00:00:00 2001 From: irei1as Date: Tue, 22 Sep 2015 19:37:42 +0200 Subject: [PATCH 01/12] mQuat.h change to fix QuatF::angleBetween The old version doesn't have that 2.0f in the return that seems to be needed. Also added normalizing inside so it can be used for not-normalized quaternions too. --- Engine/source/math/mQuat.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Engine/source/math/mQuat.h b/Engine/source/math/mQuat.h index 2ea1b94c1..c167e4e18 100644 --- a/Engine/source/math/mQuat.h +++ b/Engine/source/math/mQuat.h @@ -227,8 +227,13 @@ inline F32 QuatF::dot( const QuatF &q ) const inline F32 QuatF::angleBetween( const QuatF & q ) { - // angle between to quaternions - return mAcos(x * q.x + y * q.y + z * q.z + w * q.w); + // angle between two quaternions + QuatF base(x,y,z,w); + base=base.normalize(); + QuatF q_norm=q; + q_norm=q_norm.normalize(); + return 2.0f*mAcos(base.dot(q_norm)); } + #endif // _MQUAT_H_ From f128b451702782edbdd6b04664286b2bae79b6f0 Mon Sep 17 00:00:00 2001 From: rextimmy Date: Fri, 25 Sep 2015 22:40:24 +1000 Subject: [PATCH 02/12] Changed order of fmodex library unload. --- Engine/source/sfx/fmod/sfxFMODDevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/sfx/fmod/sfxFMODDevice.h b/Engine/source/sfx/fmod/sfxFMODDevice.h index f710faa20..fc15041e9 100644 --- a/Engine/source/sfx/fmod/sfxFMODDevice.h +++ b/Engine/source/sfx/fmod/sfxFMODDevice.h @@ -105,8 +105,8 @@ struct FModFNTable } ~FModFNTable() { - eventDllRef = NULL; dllRef = NULL; + eventDllRef = NULL; delete mutex; } From 1733ecc315197cab5b3f2873a619980d36895c61 Mon Sep 17 00:00:00 2001 From: irei1as Date: Tue, 29 Sep 2015 16:13:01 +0200 Subject: [PATCH 03/12] Updated normalize() It seems normalize() already changes the quaternion so the asignation is not needed. --- Engine/source/math/mQuat.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Engine/source/math/mQuat.h b/Engine/source/math/mQuat.h index c167e4e18..628e298ba 100644 --- a/Engine/source/math/mQuat.h +++ b/Engine/source/math/mQuat.h @@ -229,11 +229,10 @@ inline F32 QuatF::angleBetween( const QuatF & q ) { // angle between two quaternions QuatF base(x,y,z,w); - base=base.normalize(); + base.normalize(); QuatF q_norm=q; - q_norm=q_norm.normalize(); + q_norm.normalize(); return 2.0f*mAcos(base.dot(q_norm)); } - #endif // _MQUAT_H_ From 58a604d363cac4cabf9148d402e3a17c44e28008 Mon Sep 17 00:00:00 2001 From: Anis Date: Mon, 18 Jan 2016 05:49:05 +0100 Subject: [PATCH 04/12] Update gfxGLCircularVolatileBuffer.h --- Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h b/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h index c291cb229..6d7d0e4b1 100644 --- a/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h +++ b/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h @@ -143,6 +143,11 @@ public: init(); } + ~GLCircularVolatileBuffer() + { + glDeleteBuffers(1, &mBufferName); + } + void init() { glGenBuffers(1, &mBufferName); @@ -290,4 +295,4 @@ protected: }; -#endif \ No newline at end of file +#endif From 07282822870c6a86de7da7f42a1de4e85c15c402 Mon Sep 17 00:00:00 2001 From: Anis Date: Mon, 18 Jan 2016 05:55:36 +0100 Subject: [PATCH 05/12] Update gfxGLTextureTarget.cpp --- Engine/source/gfx/gl/gfxGLTextureTarget.cpp | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp index 1569b9a85..202265107 100644 --- a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp @@ -163,6 +163,10 @@ void _GFXGLTextureTargetFBOImpl::applyState() PRESERVE_FRAMEBUFFER(); glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); + bool drawbufs[16]; + int bufsize = 0; + for (int i = 0; i < 16; i++) + drawbufs[i] = false; bool hasColor = false; for(int i = 0; i < GFXGL->getNumRenderTargets(); ++i) { @@ -200,6 +204,20 @@ void _GFXGLTextureTargetFBOImpl::applyState() glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); } + GLenum *buf = new GLenum[bufsize]; + int count = 0; + for (int i = 0; i < bufsize; i++) + { + if (drawbufs[i]) + { + buf[count] = GL_COLOR_ATTACHMENT0 + i; + count++; + } + } + + glDrawBuffers(bufsize, buf); + + delete[] buf; CHECK_FRAMEBUFFER_STATUS(); } @@ -260,7 +278,10 @@ GFXGLTextureTarget::GFXGLTextureTarget() : mCopyFboSrc(0), mCopyFboDst(0) GFXGLTextureTarget::~GFXGLTextureTarget() { - GFXTextureManager::removeEventDelegate( this, &GFXGLTextureTarget::_onTextureEvent ); + GFXTextureManager::removeEventDelegate(this, &GFXGLTextureTarget::_onTextureEvent); + + glDeleteFramebuffers(1, &mCopyFboSrc); + glDeleteFramebuffers(1, &mCopyFboDst); } const Point2I GFXGLTextureTarget::getSize() From c3ef59e39c9784812810d7c24c17b775a91f0e48 Mon Sep 17 00:00:00 2001 From: Anis Date: Mon, 18 Jan 2016 05:55:48 +0100 Subject: [PATCH 06/12] Update gfxGLWindowTarget.cpp --- Engine/source/gfx/gl/gfxGLWindowTarget.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp index c02ff1bc3..5f8808cae 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp @@ -42,6 +42,14 @@ GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d) win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal); } +GFXGLWindowTarget::~GFXGLWindowTarget() +{ + if(glIsFramebuffer(mCopyFBO)) + { + glDeleteFramebuffers(1, &mCopyFBO); + } +} + void GFXGLWindowTarget::resetMode() { if(mWindow->getVideoMode().fullScreen != mWindow->isFullscreen()) @@ -49,6 +57,7 @@ void GFXGLWindowTarget::resetMode() _teardownCurrentMode(); _setupNewMode(); } + GFX->beginReset(); } void GFXGLWindowTarget::_onAppSignal(WindowId wnd, S32 event) From 500a237892db6fa6a445aa646815f20cec7ccbfa Mon Sep 17 00:00:00 2001 From: Anis Date: Mon, 18 Jan 2016 05:56:00 +0100 Subject: [PATCH 07/12] Update gfxGLWindowTarget.h --- Engine/source/gfx/gl/gfxGLWindowTarget.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.h b/Engine/source/gfx/gl/gfxGLWindowTarget.h index 4baa6a53f..af368e192 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.h +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.h @@ -30,6 +30,8 @@ class GFXGLWindowTarget : public GFXWindowTarget public: GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d); + ~GFXGLWindowTarget(); + const Point2I getSize() { return mWindow->getClientExtent(); @@ -64,4 +66,4 @@ private: void _WindowPresent(); }; -#endif \ No newline at end of file +#endif From ca31ef3f1aef7c3f0643246c788beeb980474b43 Mon Sep 17 00:00:00 2001 From: Anis Date: Mon, 18 Jan 2016 06:15:07 +0100 Subject: [PATCH 08/12] Update gfxGLWindowTarget.cpp --- Engine/source/gfx/gl/gfxGLWindowTarget.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp index 5f8808cae..c00506835 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp @@ -57,7 +57,6 @@ void GFXGLWindowTarget::resetMode() _teardownCurrentMode(); _setupNewMode(); } - GFX->beginReset(); } void GFXGLWindowTarget::_onAppSignal(WindowId wnd, S32 event) From e2d789e87de69d1b525763ca99aa5daef15b8e74 Mon Sep 17 00:00:00 2001 From: Anis Date: Mon, 18 Jan 2016 06:17:20 +0100 Subject: [PATCH 09/12] Update gfxGLTextureTarget.cpp --- Engine/source/gfx/gl/gfxGLTextureTarget.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp index 202265107..ddb308adc 100644 --- a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp @@ -163,10 +163,6 @@ void _GFXGLTextureTargetFBOImpl::applyState() PRESERVE_FRAMEBUFFER(); glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); - bool drawbufs[16]; - int bufsize = 0; - for (int i = 0; i < 16; i++) - drawbufs[i] = false; bool hasColor = false; for(int i = 0; i < GFXGL->getNumRenderTargets(); ++i) { @@ -204,20 +200,6 @@ void _GFXGLTextureTargetFBOImpl::applyState() glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); } - GLenum *buf = new GLenum[bufsize]; - int count = 0; - for (int i = 0; i < bufsize; i++) - { - if (drawbufs[i]) - { - buf[count] = GL_COLOR_ATTACHMENT0 + i; - count++; - } - } - - glDrawBuffers(bufsize, buf); - - delete[] buf; CHECK_FRAMEBUFFER_STATUS(); } From 23c4b52e1f69fbec2594ffde6bd2952e55bb2e3b Mon Sep 17 00:00:00 2001 From: Azaezel Date: Mon, 18 Jan 2016 00:28:09 -0600 Subject: [PATCH 10/12] courtessy @Lopuska: opengl occlusion query fix --- .../advanced/advancedLightBinManager.cpp | 14 +++------ .../lighting/shadowMap/lightShadowMap.cpp | 31 +++++-------------- .../lighting/shadowMap/lightShadowMap.h | 22 ++++--------- .../lighting/shadowMap/shadowMapPass.cpp | 14 ++++----- 4 files changed, 25 insertions(+), 56 deletions(-) diff --git a/Engine/source/lighting/advanced/advancedLightBinManager.cpp b/Engine/source/lighting/advanced/advancedLightBinManager.cpp index dd71afeb0..98330a5de 100644 --- a/Engine/source/lighting/advanced/advancedLightBinManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightBinManager.cpp @@ -318,6 +318,8 @@ void AdvancedLightBinManager::render( SceneRenderState *state ) const U32 numPrims = curEntry.numPrims; const U32 numVerts = curEntry.vertBuffer->mNumVerts; + ShadowMapParams *lsp = curLightInfo->getExtended(); + // 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) diff --git a/Engine/source/lighting/shadowMap/lightShadowMap.cpp b/Engine/source/lighting/shadowMap/lightShadowMap.cpp index 53a6f4e8d..984f6cbc6 100644 --- a/Engine/source/lighting/shadowMap/lightShadowMap.cpp +++ b/Engine/source/lighting/shadowMap/lightShadowMap.cpp @@ -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 ); } diff --git a/Engine/source/lighting/shadowMap/lightShadowMap.h b/Engine/source/lighting/shadowMap/lightShadowMap.h index 2cbb2ca5e..d96481192 100644 --- a/Engine/source/lighting/shadowMap/lightShadowMap.h +++ b/Engine/source/lighting/shadowMap/lightShadowMap.h @@ -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; diff --git a/Engine/source/lighting/shadowMap/shadowMapPass.cpp b/Engine/source/lighting/shadowMap/shadowMapPass.cpp index 7c17046e1..dea7305b5 100644 --- a/Engine/source/lighting/shadowMap/shadowMapPass.cpp +++ b/Engine/source/lighting/shadowMap/shadowMapPass.cpp @@ -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); -} \ No newline at end of file +} From 39613c0d87ace06e9648b3fb0d886f3c7758475c Mon Sep 17 00:00:00 2001 From: irei1as Date: Mon, 15 Feb 2016 18:43:56 +0100 Subject: [PATCH 11/12] Optimized You're right. If the normalized quaternions are in a variable or something for normal uses it's just a waste to force the change hidden inside again. --- Engine/source/math/mQuat.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Engine/source/math/mQuat.h b/Engine/source/math/mQuat.h index 628e298ba..10efb0619 100644 --- a/Engine/source/math/mQuat.h +++ b/Engine/source/math/mQuat.h @@ -227,12 +227,8 @@ inline F32 QuatF::dot( const QuatF &q ) const inline F32 QuatF::angleBetween( const QuatF & q ) { - // angle between two quaternions - QuatF base(x,y,z,w); - base.normalize(); - QuatF q_norm=q; - q_norm.normalize(); - return 2.0f*mAcos(base.dot(q_norm)); + // angle between two quaternions. + return mAcos(q.dot(*this)) * 2.0f; } #endif // _MQUAT_H_ From 6891d348af015f5695d568aac6976c77b0890212 Mon Sep 17 00:00:00 2001 From: irei1as Date: Mon, 15 Feb 2016 18:50:18 +0100 Subject: [PATCH 12/12] Update mQuat.h --- Engine/source/math/mQuat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/math/mQuat.h b/Engine/source/math/mQuat.h index 10efb0619..ca6ed5d82 100644 --- a/Engine/source/math/mQuat.h +++ b/Engine/source/math/mQuat.h @@ -227,7 +227,7 @@ inline F32 QuatF::dot( const QuatF &q ) const inline F32 QuatF::angleBetween( const QuatF & q ) { - // angle between two quaternions. + // angle between two normalized quaternions. return mAcos(q.dot(*this)) * 2.0f; }