/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
std::ostringstream depthTestStr;
depthTestStr << GL_DEPTH_TEST;
- //OFF
- {
- renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::OFF);
- glEnableDisableStack.Reset();
- glDepthFunctionStack.Reset();
- application.SendNotification();
- application.Render();
-
- //Depth testing should be disabled
- DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", depthTestStr.str().c_str() ) );
- }
-
//GL_NEVER
{
renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
tet_infoline("Testing Dali::Layer::SetDepthTestDisabled() ");
Layer actor = Layer::New();
+ // Note that IsDepthTestDisabled does not depend on layer behavior,
+ // as 2D layers can still have depth tests performed on a per-renderer basis.
+ // Check default.
DALI_TEST_CHECK( actor.IsDepthTestDisabled() );
- actor.SetBehavior( Layer::LAYER_3D );
-
- Property::Value behavior = actor.GetProperty(Layer::Property::BEHAVIOR);
- DALI_TEST_EQUALS(behavior.Get<std::string>().c_str(), "LAYER_3D", TEST_LOCATION );
+ // Check Set / Unset.
+ actor.SetDepthTestDisabled( false );
DALI_TEST_CHECK( !actor.IsDepthTestDisabled() );
-
actor.SetDepthTestDisabled( true );
DALI_TEST_CHECK( actor.IsDepthTestDisabled() );
+
END_TEST;
}
} // namespace DepthWriteMode
+namespace DepthTestMode
+{
+
+/**
+ * @brief Depth buffer test (reading) modes.
+ */
+enum Type
+{
+ OFF, ///< Renderer does not read from the depth buffer @SINCE_1_1.38
+ AUTO, ///< Renderer only reads from the depth buffer if in a 3D layer @SINCE_1_1.38
+ ON ///< Renderer reads from the depth buffer based on the DepthFunction @SINCE_1_1.38
+};
+
+} // namespace DepthTestMode
+
namespace DepthFunction
{
*/
enum Type
{
- OFF, ///< Depth test is disabled
NEVER, ///< Depth test never passes
ALWAYS, ///< Depth test always passes
LESS, ///< Depth test passes if the incoming depth value is less than the stored depth value
* @see DepthFunction
* @note The default value is DepthFunction::LESS
*/
- DEPTH_FUNCTION
+ DEPTH_FUNCTION,
+
+ /**
+ * @brief name "depthTestMode", type INTEGER
+ * @see DepthTestMode
+ * @note The default value is DepthTestMode::AUTO
+ * @SINCE_1_1.38
+ */
+ DEPTH_TEST_MODE
};
};
#define __DALI_INTERNAL_TYPE_ABSTRACTION_ENUMS_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
template <> struct ParameterType< Dali::FaceCullingMode::Type > : public BasicType< Dali::FaceCullingMode::Type > {};
template <> struct ParameterType< Dali::BlendMode::Type > : public BasicType< Dali::BlendMode::Type > {};
template <> struct ParameterType< Dali::DepthWriteMode::Type > : public BasicType< Dali::DepthWriteMode::Type > {};
+template <> struct ParameterType< Dali::DepthTestMode::Type > : public BasicType< Dali::DepthTestMode::Type > {};
template <> struct ParameterType< Dali::DepthFunction::Type > : public BasicType< Dali::DepthFunction::Type > {};
} //namespace Internal
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
Layer::Layer( Actor::DerivedType type )
: Actor( type ),
- mLayerList(NULL),
- mClippingBox(0,0,0,0),
- mSortFunction(Layer::ZValue),
- mBehavior(Dali::Layer::LAYER_2D),
- mIsClipping(false),
- mDepthTestDisabled(false),
- mTouchConsumed(false),
- mHoverConsumed(false)
+ mLayerList( NULL ),
+ mClippingBox( 0, 0, 0, 0 ),
+ mSortFunction( Layer::ZValue ),
+ mBehavior( Dali::Layer::LAYER_2D ),
+ mIsClipping( false ),
+ mDepthTestDisabled( true ),
+ mTouchConsumed( false ),
+ mHoverConsumed( false )
{
}
{
mBehavior = behavior;
- // notify update side object
+ // Notify update side object.
SetBehaviorMessage( GetEventThreadServices(), GetSceneLayerOnStage(), behavior );
+ // By default, disable depth test for LAYER_2D, and enable for LAYER_3D.
+ SetDepthTestDisabled( mBehavior == Dali::Layer::LAYER_2D );
}
void Layer::SetClipping(bool enabled)
{
mDepthTestDisabled = disable;
- // Send message .....
+ // Send message.
// layerNode is being used in a separate thread; queue a message to set the value
SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
}
bool Layer::IsDepthTestDisabled() const
{
- return mDepthTestDisabled || (mBehavior == Dali::Layer::LAYER_2D);
+ return mDepthTestDisabled;
}
void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
+DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
mDepthWriteMode = mode;
SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, mode );
}
-
break;
}
case Dali::Renderer::Property::DEPTH_FUNCTION:
mDepthFunction = depthFunction;
SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, depthFunction );
}
-
+ break;
+ }
+ case Dali::Renderer::Property::DEPTH_TEST_MODE:
+ {
+ int value;
+ propertyValue.Get( value );
+ DepthTestMode::Type mode = static_cast<DepthTestMode::Type>(value);
+ if( mode != mDepthTestMode )
+ {
+ mDepthTestMode = mode;
+ SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, mode );
+ }
break;
}
}
value = mDepthFunction;
break;
}
+ case Dali::Renderer::Property::DEPTH_TEST_MODE:
+ {
+ value = mDepthTestMode;
+ break;
+ }
}
return value;
}
mBlendingOptions(),
mDepthWriteMode( DepthWriteMode::AUTO ),
mDepthFunction( DepthFunction::LESS ),
+ mDepthTestMode( DepthTestMode::AUTO ),
mPremultipledAlphaEnabled( false )
{
}
BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
Dali::DepthWriteMode::Type mDepthWriteMode; ///< Local copy of depth write mode
Dali::DepthFunction::Type mDepthFunction; ///< Local copy of depth function
+ Dali::DepthTestMode::Type mDepthTestMode; ///< Local copy of depth test mode
bool mPremultipledAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
};
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
#include <dali/internal/render/common/render-instruction.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/renderers/render-renderer.h>
+#include <dali/internal/update/nodes/scene-graph-layer.h>
using Dali::Internal::SceneGraph::RenderItem;
using Dali::Internal::SceneGraph::RenderList;
namespace Render
{
-/**
- * Helper to set the depth function
- * @param[in] context The GL context
- * @param[in] depthFunction The depth function
- */
-inline void SetDepthFunction( Context& context, DepthFunction::Type depthFunction )
+namespace
{
- switch( depthFunction )
- {
- case DepthFunction::OFF:
- {
- context.EnableDepthBuffer( false );
- break;
- }
- case DepthFunction::NEVER:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_NEVER );
- break;
- }
- case DepthFunction::ALWAYS:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_ALWAYS );
- break;
- }
- case DepthFunction::LESS:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_LESS );
- break;
- }
- case DepthFunction::GREATER:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_GREATER );
- break;
- }
- case DepthFunction::EQUAL:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_EQUAL );
- break;
- }
- case DepthFunction::NOT_EQUAL:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_NOTEQUAL );
- break;
- }
- case DepthFunction::LESS_EQUAL:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_LEQUAL );
- break;
- }
- case DepthFunction::GREATER_EQUAL:
- {
- context.EnableDepthBuffer( true );
- context.DepthFunc( GL_GEQUAL );
- break;
- }
- }
-}
+// Table for fast look-up of Dali::DepthFunction enum to a GL depth function.
+// Note: These MUST be in the same order as Dali::DepthFunction enum.
+const short DaliDepthToGLDepthTable[] = { GL_NEVER, GL_ALWAYS, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_LEQUAL, GL_GEQUAL };
+} // Unnamed namespace
/**
* Sets up the scissor test if required.
}
/**
- * Sets the render flags for depth testing and stencil buffer
- *
+ * Sets the render flags for the stencil buffer and clears all required buffers (depth and stencil if required).
* @param[in] renderList The render list from which to get the render flags
* @param[in] context The context
+ * @param[in] depthTestEnabled True if depth test is enabled for the layer
+ * @param[in] isLayer3D True if the layer is a 3D layer
*/
-inline void SetRenderFlags( const RenderList& renderList, Context& context )
+inline void SetRenderFlags( const RenderList& renderList, Context& context, bool depthTestEnabled, bool isLayer3D )
{
const unsigned int renderFlags = renderList.GetFlags();
-
- if( ( renderFlags & RenderList::DEPTH_BUFFER_ENABLED ) != 0u )
- {
- //Enable depth testing
- context.EnableDepthBuffer( true );
- }
- else
- {
- //Disable depth test and depth write
- context.EnableDepthBuffer( false );
- context.DepthMask( false );
- }
-
- GLbitfield clearMask = ( renderFlags & RenderList::DEPTH_CLEAR ) ? GL_DEPTH_BUFFER_BIT : 0u;
+ GLbitfield clearMask = 0u;
// Stencil enabled, writing, and clearing...
const bool enableStencilBuffer( renderFlags & RenderList::STENCIL_BUFFER_ENABLED );
context.EnableStencilBuffer( enableStencilBuffer );
if( enableStencilBuffer )
{
- context.StencilFunc( (enableStencilWrite ? GL_ALWAYS : GL_EQUAL), 1, 0xFF );
- context.StencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
+ context.StencilFunc( ( enableStencilWrite ? GL_ALWAYS : GL_EQUAL ), 1, 0xFF );
+ context.StencilOp( GL_KEEP, GL_REPLACE, GL_REPLACE );
- clearMask |= (renderFlags & RenderList::STENCIL_CLEAR) ? GL_STENCIL_BUFFER_BIT : 0u;
+ clearMask |= ( renderFlags & RenderList::STENCIL_CLEAR ) ? GL_STENCIL_BUFFER_BIT : 0u;
}
// Write to stencil buffer or color buffer, but not both
context.StencilMask( enableStencilWrite ? 0xFF : 0x00 );
context.ColorMask( !enableStencilWrite );
- // Clear depth and/or stencil buffer.
- if( clearMask )
+ // Enable and Clear the depth buffer if required.
+ // DepthTest must be enabled for the layer, else testing is turned off.
+ if( !depthTestEnabled )
+ {
+ context.EnableDepthBuffer( false );
+ }
+ else if( renderList.HasColorRenderItems() || isLayer3D ) // Also, within the context of this if(), depth test is enabled.
{
- // only clear if the depth and/or stencil buffer have been written to after a previous clear
- context.Clear( clearMask, Context::CHECK_CACHED_VALUES );
+
+ clearMask |= GL_DEPTH_BUFFER_BIT;
+ // We need to enable the depth buffer to clear it.
+ // Subsequently it is enabled and disabled on a per-RenderItem basis.
+ // If we do not have color renderers, this is only done for 3D layers.
+ context.EnableDepthBuffer( true );
}
+
+ // Clear Depth and/or stencil buffers as required.
+ // Note: The buffers will only be cleared if written to since a previous clear.
+ context.Clear( clearMask, Context::CHECK_CACHED_VALUES );
}
+/**
+ * Sets up the depth buffer for reading and writing based on the current render item.
+ * The items read and write mode are used if specified.
+ * If AUTO is selected for reading, the decision will be based on the Layer Behavior.
+ * If AUTO is selected for writing, the decision will be based on the items opacity.
+ * @param item The RenderItem to set up the depth buffer for
+ * @param context The context used to execute GL commands.
+ * @param isLayer3D True if the layer behavior is set to LAYER_3D
+ */
+inline void SetupDepthBuffer( const RenderItem& item, Context& context, bool isLayer3D )
+{
+ // Set up whether or not to write to the depth buffer.
+ const DepthWriteMode::Type depthWriteMode = item.mRenderer->GetDepthWriteMode();
+ // Most common mode (AUTO) is tested first.
+ bool enableDepthWrite = ( ( depthWriteMode == DepthWriteMode::AUTO ) && item.mIsOpaque ) ||
+ ( depthWriteMode == DepthWriteMode::ON );
+ context.DepthMask( enableDepthWrite );
+
+ // Set up whether or not to read from (test) the depth buffer.
+ const DepthTestMode::Type depthTestMode = item.mRenderer->GetDepthTestMode();
+ // Most common mode (AUTO) is tested first.
+ bool enableDepthTest = ( ( depthTestMode == DepthTestMode::AUTO ) && isLayer3D ) ||
+ ( depthTestMode == DepthTestMode::ON );
+ // Look-up the GL depth function from the Dali::DepthFunction enum, and set it.
+ context.DepthFunc( DaliDepthToGLDepthTable[ item.mRenderer->GetDepthFunction() ] );
+
+ // The depth buffer must be enabled if either reading or writing.
+ context.EnableDepthBuffer( enableDepthWrite || enableDepthTest );
+}
/**
* Process a render-list.
{
DALI_PRINT_RENDER_LIST( renderList );
+ bool depthTestEnabled = !( renderList.GetSourceLayer()->IsDepthTestDisabled() );
+ bool isLayer3D = renderList.GetSourceLayer()->GetBehavior() == Dali::Layer::LAYER_3D;
+
SetScissorTest( renderList, context );
- SetRenderFlags( renderList, context );
+ SetRenderFlags( renderList, context, depthTestEnabled, isLayer3D );
- if( renderList.HasColorRenderItems() )
+ // The Layers depth enabled flag overrides the per-renderer depth flags.
+ // So if depth test is disabled at the layer level, we ignore per-render flags.
+ // Note: Overlay renderers will not read or write from the depth buffer.
+ if( DALI_LIKELY( !renderList.HasColorRenderItems() || !depthTestEnabled ) )
{
- bool depthBufferEnabled = ( ( renderList.GetFlags() & RenderList::DEPTH_BUFFER_ENABLED ) != 0u );
size_t count = renderList.Count();
-
- if( depthBufferEnabled )
+ for ( size_t index = 0; index < count; ++index )
{
- for ( size_t index = 0; index < count; ++index )
- {
- const RenderItem& item = renderList.GetItem( index );
- DALI_PRINT_RENDER_ITEM( item );
-
- DepthWriteMode::Type depthWriteMode = item.mRenderer->GetDepthWriteMode();
- context.DepthMask( ( depthWriteMode == DepthWriteMode::AUTO && item.mIsOpaque ) ||
- ( depthWriteMode == DepthWriteMode::ON ) );
+ const RenderItem& item = renderList.GetItem( index );
+ DALI_PRINT_RENDER_ITEM( item );
- SetDepthFunction( context, item.mRenderer->GetDepthFunction() );
- item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
- item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
- }
- }
- else
- {
- for ( size_t index = 0; index < count; ++index )
- {
- const RenderItem& item = renderList.GetItem( index );
- DALI_PRINT_RENDER_ITEM( item );
- item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
- item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
- }
+ item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
+ item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
}
}
else
const RenderItem& item = renderList.GetItem( index );
DALI_PRINT_RENDER_ITEM( item );
+ // Set up the depth buffer based on per-renderer flags.
+ SetupDepthBuffer( item, context, isLayer3D );
+
item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
}
-
}
}
{
debugStream << " with:";
- if( flags & RenderList::DEPTH_BUFFER_ENABLED )
- {
- debugStream << " DEPTH_TEST";
- }
-
- if( flags & RenderList::DEPTH_WRITE )
- {
- debugStream << " DEPTH_WRITE";
- }
-
- if( flags & RenderList::DEPTH_CLEAR )
- {
- debugStream << " DEPTH_CLEAR";
- }
-
if( flags & RenderList::STENCIL_BUFFER_ENABLED )
{
debugStream << " STENCIL_TEST";
}
else
{
- debugStream << " without any DEPTH_TEST, DEPTH_WRITE etc";
+ debugStream << " without any STENCIL settings";
}
if( list.IsClipping() )
public:
/**
- * The RenderFlags describe how the objects are rendered using the depth and stencil buffer.
- *
- * The flags which relate to GL_DEPTH_TEST and GL_STENCIL_TEST are called
- * DEPTH_BUFFER_ENABLED and STENCIL_BUFFER_ENABLED to avoid any confusion.
- * E.g. if GL_DEPTH_TEST is not enabled you can't write to the depth buffer, which can cause confusion.
- *
+ * The RenderFlags describe how the objects are rendered using the stencil buffer.
*/
enum RenderFlags
{
- DEPTH_BUFFER_ENABLED = 1 << 0, ///< If depth buffer should be used for writing / test operations
- DEPTH_WRITE = 1 << 1, ///< If the depth buffer is writable
- DEPTH_CLEAR = 1 << 2, ///< If the depth buffer should first be cleared
- STENCIL_BUFFER_ENABLED = 1 << 3, ///< If stencil buffer should be used for writing / test operation
- STENCIL_WRITE = 1 << 4, ///< If the stencil buffer is writable
- STENCIL_CLEAR = 1 << 5, ///< If the stencil buffer should first be cleared
-
+ STENCIL_BUFFER_ENABLED = 1 << 0, ///< If stencil buffer should be used for writing / test operation
+ STENCIL_WRITE = 1 << 1, ///< If the stencil buffer is writable
+ STENCIL_CLEAR = 1 << 2, ///< If the stencil buffer should first be cleared
};
/**
/**
* @return the source layer these renderitems originate from
*/
- Layer* GetSourceLayer()
+ Layer* GetSourceLayer() const
{
return mSourceLayer;
}
/**
- * @param layer these renderitems originate from
+ * @param layer The layer these RenderItems originate from
*/
void SetSourceLayer( Layer* layer )
{
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
DepthFunction::Type depthFunction )
{
- return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthFunction );
+ return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction );
}
Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
DepthFunction::Type depthFunction )
: mRenderDataProvider( dataProvider ),
mContext(NULL),
mUniformIndexMap(),
mAttributesLocation(),
mBlendingOptions(),
- mFaceCullingMode( faceCullingMode ),
- mDepthWriteMode( depthWriteMode ),
+ mFaceCullingMode( faceCullingMode ),
mDepthFunction( depthFunction ),
mIndexedDrawFirstElement( 0 ),
mIndexedDrawElementsCount( 0 ),
+ mDepthWriteMode( depthWriteMode ),
+ mDepthTestMode( depthTestMode ),
mUpdateAttributesLocation( true ),
mPremultipledAlphaEnabled( preMultipliedAlphaEnabled )
{
mDepthWriteMode = depthWriteMode;
}
+void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode )
+{
+ mDepthTestMode = depthTestMode;
+}
+
DepthWriteMode::Type Renderer::GetDepthWriteMode() const
{
return mDepthWriteMode;
}
+DepthTestMode::Type Renderer::GetDepthTestMode() const
+{
+ return mDepthTestMode;
+}
+
void Renderer::SetDepthFunction( DepthFunction::Type depthFunction )
{
mDepthFunction = depthFunction;
* @param[in] faceCullingMode The face-culling mode.
* @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
* @param[in] depthWriteMode Depth buffer write mode
+ * @param[in] depthTestMode Depth buffer test mode
* @param[in] depthFunction Depth function
*/
static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
DepthFunction::Type depthFunction );
/**
* @param[in] faceCullingMode The face-culling mode.
* @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
* @param[in] depthWriteMode Depth buffer write mode
+ * @param[in] depthTestMode Depth buffer test mode
* @param[in] depthFunction Depth function
*/
Renderer( SceneGraph::RenderDataProvider* dataProviders,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
DepthFunction::Type depthFunction );
/**
*/
DepthWriteMode::Type GetDepthWriteMode() const;
+ /**
+ * Sets the depth test mode
+ * @param[in] depthTestMode The depth test mode
+ */
+ void SetDepthTestMode( DepthTestMode::Type depthTestMode );
+
+ /**
+ * Query the Renderer's depth test mode
+ * @return The renderer depth test mode
+ */
+ DepthTestMode::Type GetDepthTestMode() const;
+
/**
* Sets the depth function
* @param[in] depthFunction The depth function
BlendingOptions mBlendingOptions; /// Blending options including blend color, blend func and blend equation
FaceCullingMode::Type mFaceCullingMode; /// Mode of face culling
- DepthWriteMode::Type mDepthWriteMode; /// Depth write mode
DepthFunction::Type mDepthFunction; /// Depth function
- size_t mIndexedDrawFirstElement; /// Offset of first element to draw
- size_t mIndexedDrawElementsCount; /// Number of elements to draw
+ size_t mIndexedDrawFirstElement; /// Offset of first element to draw
+ size_t mIndexedDrawElementsCount; /// Number of elements to draw
+
+ DepthWriteMode::Type mDepthWriteMode:2; /// Depth write mode
+ DepthTestMode::Type mDepthTestMode:2; /// Depth test mode
- bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
- bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
+ bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
+ bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
};
} // namespace SceneGraph
{
RenderList& renderList = instruction.GetNextFreeRenderList( layer.colorRenderables.Size() );
renderList.SetClipping( layer.IsClipping(), layer.GetClippingBox() );
+ renderList.SetSourceLayer( &layer );
renderList.SetHasColorRenderItems( true );
// try to reuse cached renderitems from last time around
AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, viewMatrix, camera, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
SortRenderItems( updateBufferIndex, renderList, layer, sortingHelper );
- //Set render flags
- unsigned int flags = 0u;
+ // Setup the render flags for stencil.
+ renderList.ClearFlags();
if( stencilRenderablesExist )
{
- flags = RenderList::STENCIL_BUFFER_ENABLED;
- }
-
- // Special optimization. If this layer has got exactly one renderer
- // and this renderer is not writing to the depth buffer there is no point on enabling
- // depth buffering
- if ( ( renderList.Count() == 1 ) &&
- (( renderList.GetRenderer( 0 ).GetDepthWriteMode() == DepthWriteMode::OFF ) ||
- ( renderList.GetRenderer( 0 ).GetDepthWriteMode() == DepthWriteMode::AUTO && !renderList.GetItem(0).mIsOpaque )))
- {
- //Nothing to do here
+ // Note: SetFlags does not overwrite, it ORs, so ClearFlags() is also required.
+ renderList.SetFlags( RenderList::STENCIL_BUFFER_ENABLED );
}
- else if( !layer.IsDepthTestDisabled())
- {
- flags |= RenderList::DEPTH_BUFFER_ENABLED;
- flags |= RenderList::DEPTH_CLEAR;
- }
-
- renderList.ClearFlags();
- renderList.SetFlags( flags );
}
/**
{
RenderList& overlayRenderList = instruction.GetNextFreeRenderList( layer.overlayRenderables.Size() );
overlayRenderList.SetClipping( layer.IsClipping(), layer.GetClippingBox() );
+ overlayRenderList.SetSourceLayer( &layer );
overlayRenderList.SetHasColorRenderItems( false );
//Set render flags
{
RenderList& stencilRenderList = instruction.GetNextFreeRenderList( layer.stencilRenderables.Size() );
stencilRenderList.SetClipping( layer.IsClipping(), layer.GetClippingBox() );
+ stencilRenderList.SetSourceLayer( &layer );
stencilRenderList.SetHasColorRenderItems( false );
//Set render flags
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
mLastCamera( NULL ),
mBehavior( Dali::Layer::LAYER_2D ),
mIsClipping( false ),
- mDepthTestDisabled( false ),
+ mDepthTestDisabled( true ),
mIsDefaultSortFunction( true )
{
// layer starts off dirty
bool Layer::IsDepthTestDisabled() const
{
- return ( mBehavior == Dali::Layer::LAYER_2D ) || mDepthTestDisabled;
+ return mDepthTestDisabled;
}
void Layer::ClearRenderables()
// flags for resending data to renderer
enum Flags
{
- RESEND_DATA_PROVIDER = 1,
- RESEND_GEOMETRY = 1 << 1,
- RESEND_FACE_CULLING_MODE = 1 << 2,
- RESEND_BLEND_COLOR = 1 << 3,
- RESEND_BLEND_BIT_MASK = 1 << 4,
- RESEND_PREMULTIPLIED_ALPHA = 1 << 5,
- RESEND_INDEXED_DRAW_FIRST_ELEMENT = 1 << 6,
+ RESEND_DATA_PROVIDER = 1,
+ RESEND_GEOMETRY = 1 << 1,
+ RESEND_FACE_CULLING_MODE = 1 << 2,
+ RESEND_BLEND_COLOR = 1 << 3,
+ RESEND_BLEND_BIT_MASK = 1 << 4,
+ RESEND_PREMULTIPLIED_ALPHA = 1 << 5,
+ RESEND_INDEXED_DRAW_FIRST_ELEMENT = 1 << 6,
RESEND_INDEXED_DRAW_ELEMENTS_COUNT = 1 << 7,
- RESEND_DEPTH_WRITE_MODE = 1 << 8,
- RESEND_DEPTH_FUNCTION = 1 << 9,
+ RESEND_DEPTH_WRITE_MODE = 1 << 8,
+ RESEND_DEPTH_TEST_MODE = 1 << 9,
+ RESEND_DEPTH_FUNCTION = 1 << 10,
};
}
}
Renderer::Renderer()
-:mSceneController( 0 ),
- mRenderer( NULL ),
- mTextureSet( NULL ),
- mGeometry( NULL ),
- mShader( NULL ),
- mBlendColor( NULL ),
- mBlendBitmask( 0u ),
- mFaceCullingMode( FaceCullingMode::NONE ),
- mBlendMode( BlendMode::AUTO ),
- mDepthWriteMode( DepthWriteMode::AUTO ),
- mDepthFunction( DepthFunction::LESS ),
- mIndexedDrawFirstElement( 0 ),
- mIndexedDrawElementsCount( 0 ),
- mReferenceCount( 0 ),
- mRegenerateUniformMap( 0 ),
- mResendFlag( 0 ),
- mResourcesReady( false ),
- mFinishedResourceAcquisition( false ),
- mPremultipledAlphaEnabled(false),
- mDepthIndex( 0 )
+: mSceneController( 0 ),
+ mRenderer( NULL ),
+ mTextureSet( NULL ),
+ mGeometry( NULL ),
+ mShader( NULL ),
+ mBlendColor( NULL ),
+ mIndexedDrawFirstElement( 0u ),
+ mIndexedDrawElementsCount( 0u ),
+ mBlendBitmask( 0u ),
+ mReferenceCount( 0u ),
+ mRegenerateUniformMap( 0u ),
+ mResendFlag( 0u ),
+ mDepthFunction( DepthFunction::LESS ),
+ mFaceCullingMode( FaceCullingMode::NONE ),
+ mBlendMode( BlendMode::AUTO ),
+ mDepthWriteMode( DepthWriteMode::AUTO ),
+ mDepthTestMode( DepthTestMode::AUTO ),
+ mResourcesReady( false ),
+ mFinishedResourceAcquisition( false ),
+ mPremultipledAlphaEnabled( false ),
+ mDepthIndex( 0 )
{
mUniformMapChanged[0] = false;
mUniformMapChanged[1] = false;
new (slot) DerivedType( mRenderer, &Render::Renderer::SetDepthWriteMode, mDepthWriteMode );
}
+ if( mResendFlag & RESEND_DEPTH_TEST_MODE )
+ {
+ typedef MessageValue1< Render::Renderer, DepthTestMode::Type > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::SetDepthTestMode, mDepthTestMode );
+ }
+
if( mResendFlag & RESEND_DEPTH_FUNCTION )
{
typedef MessageValue1< Render::Renderer, DepthFunction::Type > DerivedType;
mResendFlag |= RESEND_DEPTH_WRITE_MODE;
}
+void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode )
+{
+ mDepthTestMode = depthTestMode;
+ mResendFlag |= RESEND_DEPTH_TEST_MODE;
+}
+
void Renderer::SetDepthFunction( DepthFunction::Type depthFunction )
{
mDepthFunction = depthFunction;
static_cast< FaceCullingMode::Type >( mFaceCullingMode ),
mPremultipledAlphaEnabled,
mDepthWriteMode,
+ mDepthTestMode,
mDepthFunction );
mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer );
*/
void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode );
+ /**
+ * Sets the depth buffer test mode
+ * @param[in] depthTestMode The depth buffer test mode
+ */
+ void SetDepthTestMode( DepthTestMode::Type depthTestMode );
+
/**
* Sets the depth function
* @param[in] depthFunction The depth function
private:
- SceneController* mSceneController; ///< Used for initializing renderers
- Render::Renderer* mRenderer; ///< Raw pointer to the renderer (that's owned by RenderManager)
- TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
- Render::Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
- Shader* mShader;
-
- Vector4* mBlendColor; ///< The blend color for blending operation
- unsigned int mBlendBitmask; ///< The bitmask of blending options
- FaceCullingMode::Type mFaceCullingMode; ///< The mode of face culling
- BlendMode::Type mBlendMode; ///< The mode of blending
- DepthWriteMode::Type mDepthWriteMode; ///< The depth write mode
- DepthFunction::Type mDepthFunction; ///< The depth function
-
- CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
-
- size_t mIndexedDrawFirstElement; ///< first element index to be drawn using indexed draw
- size_t mIndexedDrawElementsCount; ///< number of elements to be drawn using indexed draw
- unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
- unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
- unsigned short mResendFlag; ///< Indicate whether data should be resent to the renderer
- bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
- bool mResourcesReady; ///< Set during the Update algorithm; true if the renderer has resources ready for the current frame.
- bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
- bool mPremultipledAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
-
+ CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
+ SceneController* mSceneController; ///< Used for initializing renderers
+ Render::Renderer* mRenderer; ///< Raw pointer to the renderer (that's owned by RenderManager)
+ TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
+ Render::Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
+ Shader* mShader; ///< The shader this renderer uses. (Not owned)
+ Vector4* mBlendColor; ///< The blend color for blending operation
+
+ size_t mIndexedDrawFirstElement; ///< first element index to be drawn using indexed draw
+ size_t mIndexedDrawElementsCount; ///< number of elements to be drawn using indexed draw
+ unsigned int mBlendBitmask; ///< The bitmask of blending options
+ unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
+ unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
+ unsigned short mResendFlag; ///< Indicate whether data should be resent to the renderer
+
+ DepthFunction::Type mDepthFunction:3; ///< The depth function
+ FaceCullingMode::Type mFaceCullingMode:2; ///< The mode of face culling
+ BlendMode::Type mBlendMode:2; ///< The mode of blending
+ DepthWriteMode::Type mDepthWriteMode:2; ///< The depth write mode
+ DepthTestMode::Type mDepthTestMode:2; ///< The depth test mode
+
+ bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
+ bool mResourcesReady; ///< Set during the Update algorithm; true if the renderer has resources ready for the current frame.
+ bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
+ bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
public:
- int mDepthIndex; ///< Used only in PrepareRenderInstructions
+
+ int mDepthIndex; ///< Used only in PrepareRenderInstructions
};
new (slot) LocalType( &renderer, &Renderer::SetDepthWriteMode, depthWriteMode );
}
+inline void SetDepthTestModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, DepthTestMode::Type depthTestMode )
+{
+ typedef MessageValue1< Renderer, DepthTestMode::Type > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ new (slot) LocalType( &renderer, &Renderer::SetDepthTestMode, depthTestMode );
+}
+
inline void SetDepthFunctionMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, DepthFunction::Type depthFunction )
{
typedef MessageValue1< Renderer, DepthFunction::Type > LocalType;