2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/render/common/render-algorithms.h>
22 #include <dali/internal/render/common/render-debug.h>
23 #include <dali/internal/render/common/render-list.h>
24 #include <dali/internal/render/common/render-instruction.h>
25 #include <dali/internal/render/gl-resources/context.h>
26 #include <dali/internal/render/renderers/scene-graph-renderer.h>
28 using Dali::Internal::SceneGraph::RenderItem;
29 using Dali::Internal::SceneGraph::RenderList;
30 using Dali::Internal::SceneGraph::RenderListContainer;
31 using Dali::Internal::SceneGraph::RenderInstruction;
43 * Process a render-list.
44 * @param[in] renderList The render-list to process.
45 * @param[in] context The GL context.
46 * @param[in] buffer The current render buffer index (previous update buffer)
47 * @param[in] frameTime The elapsed time between the last two updates.
48 * @param[in] viewMatrix The view matrix from the appropriate camera.
49 * @param[in] projectionMatrix The projection matrix from the appropriate camera.
51 inline void ProcessRenderList( const RenderList& renderList,
53 BufferIndex bufferIndex,
55 const Matrix& viewMatrix,
56 const Matrix& projectionMatrix )
58 DALI_PRINT_RENDER_LIST( renderList );
61 if( renderList.IsClipping() )
63 context.SetScissorTest( true );
65 const Dali::ClippingBox& clip = renderList.GetClippingBox();
66 context.Scissor(clip.x, clip.y, clip.width, clip.height);
70 context.SetScissorTest( false );
73 const unsigned int renderFlags = renderList.GetFlags();
75 bool setDepthTest = ( ( renderFlags & RenderList::DEPTH_TEST ) != 0u );
76 bool depthMask = ( ( renderFlags & RenderList::DEPTH_WRITE ) != 0u );
78 GLbitfield clearMask = ( renderFlags & RenderList::DEPTH_CLEAR ) ? GL_DEPTH_BUFFER_BIT : 0u;
80 context.SetDepthTest( setDepthTest );
81 context.DepthMask( depthMask );
83 // Stencil testing, writing, and clearing...
84 const bool enableStencilTest( renderFlags & RenderList::STENCIL_TEST );
85 const bool enableStencilWrite( renderFlags & RenderList::STENCIL_WRITE );
87 context.SetStencilTest( enableStencilTest );
89 if( enableStencilTest )
91 context.StencilFunc( (enableStencilWrite ? GL_ALWAYS : GL_EQUAL), 1, 0xFF );
92 context.StencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
94 clearMask |= (renderFlags & RenderList::STENCIL_CLEAR) ? GL_STENCIL_BUFFER_BIT : 0u;
97 // Write to stencil buffer or color buffer, but not both
98 context.StencilMask( enableStencilWrite ? 0xFF : 0x00 );
99 context.ColorMask( !enableStencilWrite );
101 // Clear depth and/or stencil buffer.
104 context.Clear( clearMask );
107 size_t count = renderList.Count();
108 for ( size_t index = 0; index < count; ++index )
110 const RenderItem& item = renderList.GetItem( index );
112 DALI_PRINT_RENDER_ITEM( item );
114 SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( item.GetRenderer() );
115 const Matrix& modelViewMatrix = item.GetModelViewMatrix();
117 renderer->Render( bufferIndex, modelViewMatrix, viewMatrix, projectionMatrix, frameTime );
121 void ProcessRenderInstruction( const RenderInstruction& instruction,
123 BufferIndex bufferIndex,
126 DALI_PRINT_RENDER_INSTRUCTION( instruction );
128 const Matrix* viewMatrix = instruction.mViewMatrix;
129 const Matrix* projectionMatrix = instruction.mProjectionMatrix;
131 DALI_ASSERT_DEBUG( NULL != viewMatrix );
132 DALI_ASSERT_DEBUG( NULL != projectionMatrix );
134 if( NULL != viewMatrix &&
135 NULL != projectionMatrix )
137 const RenderListContainer::SizeType count = instruction.RenderListCount();
138 for( RenderListContainer::SizeType index = 0; index < count; ++index )
140 const RenderList* renderList = instruction.GetRenderList( index );
143 !renderList->IsEmpty() )
145 ProcessRenderList( *renderList, context, bufferIndex, frameTime, *viewMatrix, *projectionMatrix );
151 } // namespace Render
153 } // namespace Internal