X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fgl-resources%2Fcontext.cpp;h=ead1be3ad6b423611743311f27958970cf803d08;hb=79881246746f65474b24ea4fe14151ccef8df3f4;hp=ace0e959cd783afc1d261f9212297376b3336d04;hpb=e49d514ff63c9ab428af8fdaac028b6d29bbc995;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/gl-resources/context.cpp b/dali/internal/render/gl-resources/context.cpp index ace0e95..ead1be3 100644 --- a/dali/internal/render/gl-resources/context.cpp +++ b/dali/internal/render/gl-resources/context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,15 @@ // EXTERNAL INCLUDES #include +#include +#include // INTERNAL INCLUDES #include -#include +#include #include -#include #include +#include namespace Dali { @@ -37,7 +39,7 @@ namespace Internal namespace // unnamed namespace { -DALI_COMPILE_TIME_ASSERT( TEXTURE_UNIT_LAST <= Context::MAX_TEXTURE_UNITS ); +static_assert( TEXTURE_UNIT_LAST <= Context::MAX_TEXTURE_UNITS, "TEXTURE_UNIT_LAST is greater than Context::MAX_TEXTURE_UNITS" ); /** * GL error strings @@ -62,39 +64,50 @@ errorStrings errors[] = Debug::Filter* gContextLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_CONTEXT_STATE"); #endif -Context::Context(Integration::GlAbstraction& glAbstraction) +Context::Context( Integration::GlAbstraction& glAbstraction ) +: Context( glAbstraction, nullptr ) +{ +} + +Context::Context( Integration::GlAbstraction& glAbstraction, std::vector< Context* >* contexts ) : mGlAbstraction(glAbstraction), mGlContextCreated(false), mColorMask(true), mStencilMask(0xFF), mBlendEnabled(false), - mDepthTestEnabled(false), + mDepthBufferEnabled(false), mDepthMaskEnabled(false), mDitherEnabled(true), // This the only GL capability which defaults to true mPolygonOffsetFillEnabled(false), mSampleAlphaToCoverageEnabled(false), mSampleCoverageEnabled(false), mScissorTestEnabled(false), - mStencilTestEnabled(false), + mStencilBufferEnabled(false), mClearColorSet(false), + mUsingDefaultBlendColor(true), mBoundArrayBufferId(0), mBoundElementArrayBufferId(0), mBoundTransformFeedbackBufferId(0), mActiveTextureUnit( TEXTURE_UNIT_LAST ), - mUsingDefaultBlendColor(true), + mBlendColor(Color::TRANSPARENT), mBlendFuncSeparateSrcRGB(GL_ONE), mBlendFuncSeparateDstRGB(GL_ZERO), mBlendFuncSeparateSrcAlpha(GL_ONE), 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 - mCullFaceMode(CullNone), + mCullFaceMode( FaceCullingMode::NONE ), mViewPort( 0, 0, 0, 0 ), - mFrameCount( 0 ), - mCulledCount( 0 ), - mRendererCount( 0 ) + mSceneContexts( contexts ) { } @@ -111,7 +124,7 @@ void Context::GlContextCreated() mGlContextCreated = true; // Set the initial GL state, and check it. - ResetGlState(); + InitializeGlState(); #ifdef DEBUG_ENABLED PrintCurrentState(); @@ -192,107 +205,42 @@ void Context::SetVertexAttributeLocation(unsigned int location, bool state) } } -void Context::ResetVertexAttributeState() -{ - // reset attribute cache - for( unsigned int i=0; i < MAX_ATTRIBUTE_CACHE_SIZE; ++i ) - { - mVertexAttributeCachedState[ i ] = false; - mVertexAttributeCurrentState[ i ] = false; - - LOG_GL("DisableVertexAttribArray %d\n", i); - CHECK_GL( mGlAbstraction, mGlAbstraction.DisableVertexAttribArray( i ) ); - } -} - -void Context::ResetGlState() +void Context::InitializeGlState() { - DALI_LOG_INFO(gContextLogFilter, Debug::Verbose, "Context::ResetGlState()\n"); + DALI_LOG_INFO(gContextLogFilter, Debug::Verbose, "Context::InitializeGlState()\n"); DALI_ASSERT_DEBUG(mGlContextCreated); mClearColorSet = false; - // Render manager will call clear in next render - - // Reset internal state and Synchronize it with real OpenGL context. - // This may seem like overkill, but the GL context is not owned by dali-core, - // and no assumptions should be made about the initial state. mColorMask = true; - mGlAbstraction.ColorMask( true, true, true, true ); - mStencilMask = 0xFF; - mGlAbstraction.StencilMask( 0xFF ); - mBlendEnabled = false; - mGlAbstraction.Disable(GL_BLEND); - - mDepthTestEnabled = false; - mGlAbstraction.Disable(GL_DEPTH_TEST); - + mDepthBufferEnabled = false; mDepthMaskEnabled = false; - mGlAbstraction.DepthMask(GL_FALSE); - - mDitherEnabled = false; // This the only GL capability which defaults to true - mGlAbstraction.Disable(GL_DITHER); - mPolygonOffsetFillEnabled = false; - mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL); - mSampleAlphaToCoverageEnabled = false; - mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE); - mSampleCoverageEnabled = false; - mGlAbstraction.Disable(GL_SAMPLE_COVERAGE); - mScissorTestEnabled = false; - mGlAbstraction.Disable(GL_SCISSOR_TEST); - - mStencilTestEnabled = false; - mGlAbstraction.Disable(GL_STENCIL_TEST); + mStencilBufferEnabled = false; + mDitherEnabled = false; // This and GL_MULTISAMPLE are the only GL capability which defaults to true + mGlAbstraction.Disable(GL_DITHER); mBoundArrayBufferId = 0; - LOG_GL("BindBuffer GL_ARRAY_BUFFER 0\n"); - mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, mBoundArrayBufferId); - mBoundElementArrayBufferId = 0; - LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER 0\n"); - mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBoundElementArrayBufferId); - -#ifndef EMSCRIPTEN // not in WebGL mBoundTransformFeedbackBufferId = 0; - LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER 0\n"); - mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mBoundTransformFeedbackBufferId); -#endif + mActiveTextureUnit = TEXTURE_UNIT_IMAGE; - mActiveTextureUnit = TEXTURE_UNIT_LAST; - - mUsingDefaultBlendColor = true; - mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ); + mUsingDefaultBlendColor = true; //Default blend color is (0,0,0,0) mBlendFuncSeparateSrcRGB = GL_ONE; mBlendFuncSeparateDstRGB = GL_ZERO; mBlendFuncSeparateSrcAlpha = GL_ONE; mBlendFuncSeparateDstAlpha = GL_ZERO; - mGlAbstraction.BlendFuncSeparate( mBlendFuncSeparateSrcRGB, mBlendFuncSeparateDstRGB, - mBlendFuncSeparateSrcAlpha, mBlendFuncSeparateDstAlpha ); // initial state is GL_FUNC_ADD for both RGB and Alpha blend modes mBlendEquationSeparateModeRGB = GL_FUNC_ADD; mBlendEquationSeparateModeAlpha = GL_FUNC_ADD; - mGlAbstraction.BlendEquationSeparate( mBlendEquationSeparateModeRGB, mBlendEquationSeparateModeAlpha); - - mCullFaceMode = CullNone; - mGlAbstraction.Disable(GL_CULL_FACE); - mGlAbstraction.FrontFace(GL_CCW); - mGlAbstraction.CullFace(GL_BACK); - // rebind texture units to 0 - for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i ) - { - mBound2dTextureId[ i ] = 0; - // set active texture - mGlAbstraction.ActiveTexture( GL_TEXTURE0 + i ); - mGlAbstraction.BindTexture(GL_TEXTURE_2D, mBound2dTextureId[ i ] ); - } + mCullFaceMode = FaceCullingMode::NONE; //By default cullface is disabled, front face is set to CCW and cull face is set to back // get maximum texture size mGlAbstraction.GetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); @@ -300,7 +248,14 @@ void Context::ResetGlState() // reset viewport, this will be set to something useful when rendering mViewPort.x = mViewPort.y = mViewPort.width = mViewPort.height = 0; - ResetVertexAttributeState(); + //Initialze vertex attribute cache + memset( &mVertexAttributeCachedState, 0, sizeof(mVertexAttributeCachedState) ); + memset( &mVertexAttributeCurrentState, 0, sizeof(mVertexAttributeCurrentState) ); + + //Initialize bound 2d texture cache + memset( &mBoundTextureId, 0, sizeof(mBoundTextureId) ); + + mFrameBufferStateCache.Reset(); } #ifdef DEBUG_ENABLED @@ -323,14 +278,14 @@ void Context::PrintCurrentState() "----------------- Context State END -----------------\n", mBlendEnabled ? "Enabled" : "Disabled", cullFaceModes[ mCullFaceMode ], - mDepthTestEnabled ? "Enabled" : "Disabled", + mDepthBufferEnabled ? "Enabled" : "Disabled", mDepthMaskEnabled ? "Enabled" : "Disabled", mDitherEnabled ? "Enabled" : "Disabled", mPolygonOffsetFillEnabled ? "Enabled" : "Disabled", mSampleAlphaToCoverageEnabled ? "Enabled" : "Disabled", mSampleCoverageEnabled ? "Enabled" : "Disabled", mScissorTestEnabled ? "Enabled" : "Disabled", - mStencilTestEnabled ? "Enabled" : "Disabled"); + mStencilBufferEnabled ? "Enabled" : "Disabled"); } #endif // DALI_CONTEXT_LOGGING