diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index d4ff7f5ba6..33baf6cd96 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -76,6 +76,7 @@ void Actor::Reset() m_bTextureWrapping = false; m_BlendMode = BLEND_NORMAL; + m_bZBias = false; m_bClearZBuffer = false; m_ZTestMode = ZTEST_OFF; m_bZWrite = false; @@ -385,6 +386,11 @@ void Actor::SetGlobalRenderStates() DISPLAY->SetBlendMode( m_BlendMode ); DISPLAY->SetZWrite( m_bZWrite ); DISPLAY->SetZTestMode( m_ZTestMode ); + + // BLEND_NO_EFFECT is used to draw masks to the Z-buffer, which always wants + // Z-bias enabled. + DISPLAY->SetZBias( m_bZBias || m_BlendMode == BLEND_NO_EFFECT ); + if( m_bClearZBuffer ) DISPLAY->ClearZBuffer(); DISPLAY->SetCullMode( m_CullMode ); diff --git a/stepmania/src/Actor.h b/stepmania/src/Actor.h index d686c964e2..8ba73fd1ce 100644 --- a/stepmania/src/Actor.h +++ b/stepmania/src/Actor.h @@ -342,6 +342,7 @@ public: virtual void SetZTestMode( ZTestMode mode ) { m_ZTestMode = mode; } void SetZTestModeString( const CString &s ); // convenience virtual void SetZWrite( bool b ) { m_bZWrite = b; } + void SetZBias( bool b ) { m_bZBias = b; } virtual void SetCullMode( CullMode mode ) { m_CullMode = mode; } void SetCullModeString( const CString &s ); // convenience @@ -463,6 +464,7 @@ protected: bool m_bClearZBuffer; ZTestMode m_ZTestMode; bool m_bZWrite; + bool m_bZBias; // if true, always wins z-test against a coplanar actor CullMode m_CullMode; // @@ -576,6 +578,7 @@ public: static int ztest( T* p, lua_State *L ) { p->SetZTestMode((!!IArg(1))?ZTEST_WRITE_ON_PASS:ZTEST_OFF); return 0; } static int ztestmode( T* p, lua_State *L ) { p->SetZTestModeString(SArg(1)); return 0; } static int zwrite( T* p, lua_State *L ) { p->SetZWrite(!!IArg(1)); return 0; } + static int zbias( T* p, lua_State *L ) { p->SetZBias(!!IArg(1)); return 0; } static int clearzbuffer( T* p, lua_State *L ) { p->SetClearZBuffer(!!IArg(1)); return 0; } static int backfacecull( T* p, lua_State *L ) { p->SetCullMode((!!IArg(1)) ? CULL_BACK : CULL_NONE); return 0; } static int cullmode( T* p, lua_State *L ) { p->SetCullModeString(SArg(1)); return 0; } @@ -694,6 +697,7 @@ public: ADD_METHOD( ztest ) ADD_METHOD( ztestmode ) ADD_METHOD( zwrite ) + ADD_METHOD( zbias ) ADD_METHOD( clearzbuffer ) ADD_METHOD( backfacecull ) ADD_METHOD( cullmode ) diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 0dc05b27cd..3e340c3f7c 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -172,6 +172,7 @@ public: virtual bool IsZWriteEnabled() const = 0; virtual void SetZWrite( bool b ) = 0; virtual void SetZTestMode( ZTestMode mode ) = 0; + virtual void SetZBias( bool b ) = 0; virtual void ClearZBuffer() = 0; virtual void SetCullMode( CullMode mode ) = 0; diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index 1ecfc908ac..5282d0e76a 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -1035,7 +1035,6 @@ void RageDisplay_D3D::SetTextureFiltering( bool b ) void RageDisplay_D3D::SetBlendMode( BlendMode mode ) { g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); - g_pd3dDevice->SetRenderState( D3DRS_ZBIAS, 0 ); switch( mode ) { case BLEND_NORMAL: @@ -1049,11 +1048,6 @@ void RageDisplay_D3D::SetBlendMode( BlendMode mode ) case BLEND_NO_EFFECT: g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO ); g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); - - /* This is almost exclusively used to draw masks to the Z-buffer. Make sure - * masks always win the depth test when drawn at the same position. */ - g_pd3dDevice->SetRenderState( D3DRS_ZBIAS, 30 ); // this bias is bigger than it needs to be to handle the coplanar case - break; default: ASSERT(0); @@ -1067,6 +1061,15 @@ bool RageDisplay_D3D::IsZWriteEnabled() const return b!=0; } +void RageDisplay_D3D::SetZBias( bool b ) +{ + if( b ) + g_pd3dDevice->SetRenderState( D3DRS_ZBIAS, 30 ); + else + g_pd3dDevice->SetRenderState( D3DRS_ZBIAS, 0 ); +} + + bool RageDisplay_D3D::IsZTestEnabled() const { DWORD b; diff --git a/stepmania/src/RageDisplay_D3D.h b/stepmania/src/RageDisplay_D3D.h index 5ec776b42d..5c72dca4c3 100644 --- a/stepmania/src/RageDisplay_D3D.h +++ b/stepmania/src/RageDisplay_D3D.h @@ -41,6 +41,7 @@ public: bool IsZWriteEnabled() const; bool IsZTestEnabled() const; void SetZWrite( bool b ); + void SetZBias( bool b ); void SetZTestMode( ZTestMode mode ); void ClearZBuffer(); void SetCullMode( CullMode mode ); diff --git a/stepmania/src/RageDisplay_Null.h b/stepmania/src/RageDisplay_Null.h index c9e6e02113..1e4238ea40 100644 --- a/stepmania/src/RageDisplay_Null.h +++ b/stepmania/src/RageDisplay_Null.h @@ -39,6 +39,7 @@ public: bool IsZWriteEnabled() const { return false; } bool IsZTestEnabled() const { return false; } void SetZWrite( bool b ) { } + void SetZBias( bool b ) { } void SetZTestMode( ZTestMode mode ) { } void ClearZBuffer() { } void SetCullMode( CullMode mode ) { } diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 7d19afad28..4131ac24ba 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -349,6 +349,7 @@ RageDisplay_OGL::RageDisplay_OGL() InitStringMap(); wind = NULL; + g_bTextureMatrixShader = NULL; } CString GetInfoLog( GLhandleARB h ) @@ -1472,7 +1473,6 @@ void RageDisplay_OGL::SetBlendMode( BlendMode mode ) { glEnable(GL_BLEND); - glDepthRange( 0.05, 1.0 ); switch( mode ) { case BLEND_NORMAL: @@ -1484,10 +1484,6 @@ void RageDisplay_OGL::SetBlendMode( BlendMode mode ) case BLEND_NO_EFFECT: /* XXX: Would it be faster and have the same effect to say glDisable(GL_COLOR_WRITEMASK)? */ glBlendFunc( GL_ZERO, GL_ONE ); - - /* This is almost exclusively used to draw masks to the Z-buffer. Make sure - * masks always win the depth test when drawn at the same position. */ - glDepthRange( 0.0, 0.95 ); // this bias is bigger than it needs to be to handle the coplanar case break; default: ASSERT(0); @@ -1521,6 +1517,14 @@ void RageDisplay_OGL::SetZWrite( bool b ) glDepthMask( b ); } +void RageDisplay_OGL::SetZBias( bool b ) +{ + if( b ) + glDepthRange( 0.0, 0.95 ); + else + glDepthRange( 0.05, 1.0 ); +} + void RageDisplay_OGL::SetZTestMode( ZTestMode mode ) { glEnable( GL_DEPTH_TEST ); diff --git a/stepmania/src/RageDisplay_OGL.h b/stepmania/src/RageDisplay_OGL.h index b9c6044c5b..b3f3e56bb8 100644 --- a/stepmania/src/RageDisplay_OGL.h +++ b/stepmania/src/RageDisplay_OGL.h @@ -42,6 +42,7 @@ public: bool IsZWriteEnabled() const; bool IsZTestEnabled() const; void SetZWrite( bool b ); + void SetZBias( bool b ); void SetZTestMode( ZTestMode mode ); void ClearZBuffer(); void SetCullMode( CullMode mode );