From 7be08e80bae1e586e9d7de3f15728f3e13c7e104 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Wed, 8 Nov 2017 11:01:41 +0000 Subject: [PATCH] [4.0] Caches stencil glStencilFunc() and glStencilOp() calls. Change-Id: I970ec25b1a6ab39c284c561bf96c81a1515b9434 Signed-off-by: Victor Cebollada (cherry picked from commit 83e7fd6820cdb9d16d91377912f85bdbbdf84eb4) --- automated-tests/src/dali/utc-Dali-Renderer.cpp | 64 +++++++++++++++----------- dali/internal/render/gl-resources/context.cpp | 6 +++ dali/internal/render/gl-resources/context.h | 30 ++++++++++-- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Renderer.cpp b/automated-tests/src/dali/utc-Dali-Renderer.cpp index a8164eb..9ea907d 100644 --- a/automated-tests/src/dali/utc-Dali-Renderer.cpp +++ b/automated-tests/src/dali/utc-Dali-Renderer.cpp @@ -2278,6 +2278,8 @@ int UtcDaliRendererSetRenderModeToUseStencilBuffer(void) renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR ); ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL ); + // Set a different stencil function as the last one is cached. + renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS ); ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) ); @@ -2443,7 +2445,7 @@ int UtcDaliRendererSetStencilOperation(void) }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] ); // Set all 3 StencilOperation properties to a default. - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO ); + renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP ); renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO ); renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO ); @@ -2459,40 +2461,48 @@ int UtcDaliRendererSetStencilOperation(void) * - Checks the correct parameters to "glStencilFunc" were used * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass ) */ - int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS }; std::string methodString( "StencilOp" ); - for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex ) + for( int i = 0; i < StencilOperationLookupTableCount; ++i ) { - for( int i = 0; i < StencilOperationLookupTableCount; ++i ) + for( int j = 0; j < StencilOperationLookupTableCount; ++j ) { - // Set the property (outer loop causes all 3 different properties to be set separately). - renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast( i ) ); - - // Check GetProperty returns the same value. - DALI_TEST_EQUALS( static_cast( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get() ), i, TEST_LOCATION ); - - // Reset the trace debug. - ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); - - // Check the function is called and the parameters are correct. - // Set the expected parameter value at its correct index (only) - parameters[ parameterIndex ] = StencilOperationLookupTable[ i ]; - - // Build the parameter list. - std::stringstream parameterStream; - for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild ) + for( int k = 0; k < StencilOperationLookupTableCount; ++k ) { - parameterStream << parameters[ parameterBuild ]; - // Comma-separate the parameters. - if( parameterBuild < 2 ) + // Set the property (outer loop causes all 3 different properties to be set separately). + renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast( i ) ); + renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast( j ) ); + renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast( k ) ); + + // Check GetProperty returns the same value. + DALI_TEST_EQUALS( static_cast( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get() ), i, TEST_LOCATION ); + DALI_TEST_EQUALS( static_cast( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get() ), j, TEST_LOCATION ); + DALI_TEST_EQUALS( static_cast( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get() ), k, TEST_LOCATION ); + + // Reset the trace debug. + ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); + + // Check the function is called and the parameters are correct. + // Set the expected parameter value at its correct index (only) + parameters[ 0u ] = StencilOperationLookupTable[ i ]; + parameters[ 1u ] = StencilOperationLookupTable[ j ]; + parameters[ 2u ] = StencilOperationLookupTable[ k ]; + + // Build the parameter list. + std::stringstream parameterStream; + for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild ) { - parameterStream << ", "; + parameterStream << parameters[ parameterBuild ]; + // Comma-separate the parameters. + if( parameterBuild < 2 ) + { + parameterStream << ", "; + } } - } - // Check the function was called and the parameters were correct. - DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) ); + // Check the function was called and the parameters were correct. + DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) ); + } } } diff --git a/dali/internal/render/gl-resources/context.cpp b/dali/internal/render/gl-resources/context.cpp index 2d883bc..0819de8 100644 --- a/dali/internal/render/gl-resources/context.cpp +++ b/dali/internal/render/gl-resources/context.cpp @@ -91,6 +91,12 @@ Context::Context(Integration::GlAbstraction& glAbstraction) mBlendFuncSeparateDstAlpha(GL_ZERO), mBlendEquationSeparateModeRGB( GL_FUNC_ADD ), mBlendEquationSeparateModeAlpha( GL_FUNC_ADD ), + mStencilFunc( GL_ALWAYS ), + mStencilFuncRef( 0 ), + mStencilFuncMask( 0xFFFFFFFF ), + mStencilOpFail( GL_KEEP ), + mStencilOpDepthFail( GL_KEEP ), + mStencilOpDepthPass( GL_KEEP ), mDepthFunction( GL_LESS ), mMaxTextureSize(0), mClearColor(Color::WHITE), // initial color, never used until it's been set by the user diff --git a/dali/internal/render/gl-resources/context.h b/dali/internal/render/gl-resources/context.h index 59ed396..fdd9a8e 100644 --- a/dali/internal/render/gl-resources/context.h +++ b/dali/internal/render/gl-resources/context.h @@ -1497,10 +1497,15 @@ public: */ void StencilFunc(GLenum func, GLint ref, GLuint mask) { + if( ( func != mStencilFunc ) || ( ref != mStencilFuncRef ) || ( mask != mStencilFuncMask ) ) + { + mStencilFunc = func; + mStencilFuncRef = ref; + mStencilFuncMask = mask; - - LOG_GL("StencilFunc %x %d %d\n", func, ref, mask); - CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) ); + LOG_GL("StencilFunc %x %d %d\n", func, ref, mask); + CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) ); + } } /** @@ -1540,8 +1545,15 @@ public: */ void StencilOp(GLenum fail, GLenum zfail, GLenum zpass) { - LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass); - CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) ); + if( ( fail != mStencilOpFail ) || ( zfail != mStencilOpDepthFail ) || ( zpass != mStencilOpDepthPass ) ) + { + mStencilOpFail = fail; + mStencilOpDepthFail = zfail; + mStencilOpDepthPass = zpass; + + LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass); + CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) ); + } } /** @@ -1749,6 +1761,14 @@ private: // Data GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode + // glStencilFunc() and glStencilOp() state. + GLenum mStencilFunc; + GLint mStencilFuncRef; + GLuint mStencilFuncMask; + GLenum mStencilOpFail; + GLenum mStencilOpDepthFail; + GLenum mStencilOpDepthPass; + GLenum mDepthFunction; ///The depth function GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE) -- 2.7.4