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/renderers/scene-graph-renderer.h>
20 #include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
23 #include <dali/internal/render/gl-resources/context.h>
24 #include <dali/internal/render/shaders/shader.h>
25 #include <dali/internal/render/renderers/render-data-provider.h>
26 #include <dali/public-api/actors/blending.h>
37 void Renderer::Initialize( Context& context, TextureCache& textureCache )
40 mTextureCache = &textureCache;
47 void Renderer::SetShader( Shader* shader )
52 void Renderer::SetUseBlend( bool useBlend )
57 void Renderer::SetBlendingOptions( unsigned int options )
59 mBlendingOptions.SetBitmask( options );
62 void Renderer::SetBlendColor( const Vector4& color )
64 mBlendingOptions.SetBlendColor( color );
67 void Renderer::SetCullFace( CullFaceMode mode )
69 DALI_ASSERT_DEBUG(mode >= CullNone && mode <= CullFrontAndBack);
73 void Renderer::Render( BufferIndex bufferIndex,
74 const Matrix& modelViewMatrix,
75 const Matrix& viewMatrix,
76 const Matrix& projectionMatrix,
79 DALI_ASSERT_DEBUG( mContext && "Renderer::Render. Renderer not initialised!! (mContext == NULL)." );
80 DALI_ASSERT_DEBUG( mShader && "Renderer::Render. Shader not set!!" );
82 if( !CheckResources() )
84 // CheckResources() is overriden in derived classes.
85 // Prevents modify the GL state if resources are not ready and nothing is to be rendered.
89 // Enables/disables blending mode.
90 mContext->SetBlend( mUseBlend );
92 // Set face culling mode
93 mContext->CullFace( mCullFaceMode );
95 // Set the blend color
96 const Vector4* const customColor = mBlendingOptions.GetBlendColor();
99 mContext->SetCustomBlendColor( *customColor );
103 mContext->SetDefaultBlendColor();
106 // Set blend source & destination factors
107 mContext->BlendFuncSeparate( mBlendingOptions.GetBlendSrcFactorRgb(),
108 mBlendingOptions.GetBlendDestFactorRgb(),
109 mBlendingOptions.GetBlendSrcFactorAlpha(),
110 mBlendingOptions.GetBlendDestFactorAlpha() );
112 // Set blend equations
113 mContext->BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
114 mBlendingOptions.GetBlendEquationAlpha() );
116 mShader->SetFrameTime( frametime );
118 const Matrix& modelMatrix = mDataProvider.GetModelMatrix( bufferIndex );
119 const Vector4& color = mDataProvider.GetRenderColor( bufferIndex );
121 // Call to over ridden method in the child class
122 // TODO, once MeshRenderer is fixed to render only one mesh, move mShader.Apply here
123 // and we can greatly reduce these parameters. Also then derived renderers can be passed the Program&
124 DoRender( bufferIndex, modelViewMatrix, modelMatrix, viewMatrix, projectionMatrix, color );
127 Renderer::Renderer( RenderDataProvider& dataprovider )
128 : mDataProvider( dataprovider ),
130 mTextureCache( NULL ),
133 mCullFaceMode( CullNone )
137 } // namespace SceneGraph
139 } // namespace Internal