diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 097b68be01..5377522a25 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -54,7 +54,8 @@ void Actor::Reset() m_bTextureWrapping = false; m_BlendMode = BLEND_NORMAL; m_bClearZBuffer = false; - m_bUseZBuffer = false; + m_bZTest = false; + m_bZWrite = false; m_bUseBackfaceCull = false; } @@ -204,7 +205,8 @@ void Actor::SetRenderStates() // set Actor-defined render states DISPLAY->SetTextureWrapping( m_bTextureWrapping ); DISPLAY->SetBlendMode( m_BlendMode ); - DISPLAY->SetZBuffer( m_bUseZBuffer ); + DISPLAY->SetZWrite( m_bZWrite ); + DISPLAY->SetZTest( m_bZTest ); if( m_bClearZBuffer ) DISPLAY->ClearZBuffer(); DISPLAY->SetBackfaceCull( m_bUseBackfaceCull ); @@ -821,6 +823,8 @@ void Actor::HandleCommand( const CStringArray &asTokens ) else if( sName=="additiveblend" ) SetBlendMode( bParam(1) ? BLEND_ADD : BLEND_NORMAL ); else if( sName=="blend" ) SetBlendMode( sParam(1) ); else if( sName=="zbuffer" ) SetUseZBuffer( bParam(1) ); + else if( sName=="ztest" ) SetZTest( bParam(1) ); + else if( sName=="zwrite" ) SetZWrite( bParam(1) ); else if( sName=="clearzbuffer" ) SetClearZBuffer( bParam(1) ); else if( sName=="hidden" ) SetHidden( bParam(1) ); else if( sName=="playcommand" ) sParam(1); /* nop: only BGAnimation handles this but everyone receives it */ diff --git a/stepmania/src/Actor.h b/stepmania/src/Actor.h index 80ec7067ec..adae159353 100644 --- a/stepmania/src/Actor.h +++ b/stepmania/src/Actor.h @@ -272,7 +272,9 @@ public: virtual void SetBlendMode( CString ); virtual void SetTextureWrapping( bool b ) { m_bTextureWrapping = b; } virtual void SetClearZBuffer( bool b ) { m_bClearZBuffer = b; } - virtual void SetUseZBuffer( bool b ) { m_bUseZBuffer = b; } + virtual void SetUseZBuffer( bool b ) { SetZTest(b); SetZWrite(b); } + virtual void SetZTest( bool b ) { m_bZTest = b; } + virtual void SetZWrite( bool b ) { m_bZWrite = b; } virtual void SetUseBackfaceCull( bool b ) { m_bUseBackfaceCull = b; } // @@ -352,7 +354,7 @@ protected: bool m_bTextureWrapping; BlendMode m_BlendMode; bool m_bClearZBuffer; - bool m_bUseZBuffer; + bool m_bZTest, m_bZWrite; bool m_bUseBackfaceCull; }; diff --git a/stepmania/src/ActorFrame.cpp b/stepmania/src/ActorFrame.cpp index a49f0e724a..01200d17e7 100644 --- a/stepmania/src/ActorFrame.cpp +++ b/stepmania/src/ActorFrame.cpp @@ -87,13 +87,22 @@ void ActorFrame::SetDiffuse( RageColor c ) m_SubActors[i]->SetDiffuse(c ); } -void ActorFrame::SetUseZBuffer( bool b ) +void ActorFrame::SetZTest( bool b ) { - Actor::SetUseZBuffer( b ); + Actor::SetZTest( b ); // set all sub-Actors for( unsigned i=0; iSetUseZBuffer( b ); + m_SubActors[i]->SetZTest( b ); +} + +void ActorFrame::SetZWrite( bool b ) +{ + Actor::SetZWrite( b ); + + // set all sub-Actors + for( unsigned i=0; iSetZWrite( b ); } void ActorFrame::FinishTweening() diff --git a/stepmania/src/ActorFrame.h b/stepmania/src/ActorFrame.h index fad0a85720..efb0ae7db2 100644 --- a/stepmania/src/ActorFrame.h +++ b/stepmania/src/ActorFrame.h @@ -28,7 +28,8 @@ public: virtual void SetDiffuse( RageColor c ); - virtual void SetUseZBuffer( bool b ); + virtual void SetZTest( bool b ); + virtual void SetZWrite( bool b ); virtual void FinishTweening(); virtual void HurryTweening( float factor ); diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 5f5e7ee1f7..f967f3e202 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -27,7 +27,7 @@ Model::Model () { m_pBones = NULL; m_bTextureWrapping = true; - m_bUseZBuffer = true; + SetUseZBuffer( true ); m_pCurAnimation = NULL; m_bRevertToDefaultAnimation = false; m_fDefaultAnimationRate = 1; diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 5ed3ecf44d..ee3c1b46dd 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -166,9 +166,12 @@ public: virtual int GetMaxTextureSize() const = 0; virtual void SetTextureFiltering( bool b ) = 0; - virtual bool IsZBufferEnabled() const = 0; - virtual void SetZBuffer( bool b ) = 0; + virtual bool IsZTestEnabled() const = 0; + virtual bool IsZWriteEnabled() const = 0; + virtual void SetZWrite( bool b ) = 0; + virtual void SetZTest( bool b ) = 0; virtual void ClearZBuffer() = 0; + void SetZBuffer( bool b ) { SetZWrite(b); SetZTest(b); } // shortcut virtual void SetBackfaceCull( bool b ) = 0; diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index 0d001cf6c6..5bffecaeaa 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -884,19 +884,31 @@ void RageDisplay_D3D::SetBlendMode( BlendMode mode ) } } -bool RageDisplay_D3D::IsZBufferEnabled() const +bool RageDisplay_D3D::IsZWriteEnabled() const { DWORD b; - g_pd3dDevice->GetRenderState( D3DRS_ZENABLE, &b ); + g_pd3dDevice->GetRenderState( D3DRS_ZWRITEENABLE, &b ); return b!=0; } -void RageDisplay_D3D::SetZBuffer( bool b ) +bool RageDisplay_D3D::IsZTestEnabled() const +{ + DWORD b; + g_pd3dDevice->GetRenderState( D3DRS_ZFUNC, &b ); + return b!=D3DCMP_ALWAYS; +} + +void RageDisplay_D3D::SetZWrite( bool b ) { - g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, b ? D3DZB_TRUE : D3DZB_FALSE ); - g_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL ); g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, b ); } + +void RageDisplay_D3D::SetZTest( bool b ) +{ + g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); + g_pd3dDevice->SetRenderState( D3DRS_ZFUNC, b ? D3DCMP_LESSEQUAL : D3DCMP_ALWAYS ); +} + void RageDisplay_D3D::ClearZBuffer() { g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0x00000000 ); diff --git a/stepmania/src/RageDisplay_D3D.h b/stepmania/src/RageDisplay_D3D.h index 5845f07599..fb4f683dce 100644 --- a/stepmania/src/RageDisplay_D3D.h +++ b/stepmania/src/RageDisplay_D3D.h @@ -45,8 +45,10 @@ public: void SetTextureWrapping( bool b ); int GetMaxTextureSize() const; void SetTextureFiltering( bool b); - bool IsZBufferEnabled() const; - void SetZBuffer( bool b ); + bool IsZWriteEnabled() const; + bool IsZTestEnabled() const; + void SetZWrite( bool b ); + void SetZTest( bool b ); void ClearZBuffer(); void SetBackfaceCull( bool b ); void SetAlphaTest( bool b ); diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 5834247ae9..57e6de05a6 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -683,6 +683,7 @@ int RageDisplay_OGL::GetMaxTextureSize() const void RageDisplay_OGL::BeginFrame() { glClearColor( 0,0,0,1 ); + SetZWrite( true ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } @@ -1033,6 +1034,7 @@ void RageDisplay_OGL::SetBlendMode( BlendMode mode ) glBlendFunc( GL_SRC_ALPHA, GL_ONE ); break; 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 @@ -1044,24 +1046,40 @@ void RageDisplay_OGL::SetBlendMode( BlendMode mode ) } } -bool RageDisplay_OGL::IsZBufferEnabled() const +bool RageDisplay_OGL::IsZWriteEnabled() const { bool a; - glGetBooleanv( GL_DEPTH_TEST, (unsigned char*)&a ); + glGetBooleanv( GL_DEPTH_WRITEMASK, (unsigned char*)&a ); return a; } -void RageDisplay_OGL::SetZBuffer( bool b ) +bool RageDisplay_OGL::IsZTestEnabled() const { - glDepthFunc(GL_LEQUAL); - if( b ) - glEnable( GL_DEPTH_TEST ); - else - glDisable( GL_DEPTH_TEST ); + GLenum a; + glGetIntegerv( GL_DEPTH_FUNC, (int*)&a ); + return a != GL_ALWAYS; } + void RageDisplay_OGL::ClearZBuffer() { + bool write = IsZWriteEnabled(); + SetZWrite( true ); glClear( GL_DEPTH_BUFFER_BIT ); + SetZWrite( write ); +} + +void RageDisplay_OGL::SetZWrite( bool b ) +{ + glDepthMask( b ); +} + +void RageDisplay_OGL::SetZTest( bool b ) +{ + glEnable( GL_DEPTH_TEST ); + if( b ) + glDepthFunc( GL_LEQUAL ); + else + glDepthFunc( GL_ALWAYS ); } void RageDisplay_OGL::SetTextureWrapping( bool b ) diff --git a/stepmania/src/RageDisplay_OGL.h b/stepmania/src/RageDisplay_OGL.h index 6c73781dc3..2f66684d23 100644 --- a/stepmania/src/RageDisplay_OGL.h +++ b/stepmania/src/RageDisplay_OGL.h @@ -31,8 +31,10 @@ public: void SetTextureWrapping( bool b ); int GetMaxTextureSize() const; void SetTextureFiltering( bool b); - bool IsZBufferEnabled() const; - void SetZBuffer( bool b ); + bool IsZWriteEnabled() const; + bool IsZTestEnabled() const; + void SetZWrite( bool b ); + void SetZTest( bool b ); void ClearZBuffer(); void SetBackfaceCull( bool b ); void SetAlphaTest( bool b );