Implemented custom shader in ImageRenderer and changed Dissolve-effect to utilise...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / control-renderer-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "control-renderer-impl.h"
20
21 // EXTERNAL HEADER
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
24
25 //INTERNAL HEARDER
26 #include <dali-toolkit/internal/controls/renderers/control-renderer-data-impl.h>
27
28 namespace
29 {
30 //custom shader
31 const char * const CUSTOM_SHADER( "shader" );
32 const char * const CUSTOM_VERTEX_SHADER( "vertex-shader" );
33 const char * const CUSTOM_FRAGMENT_SHADER( "fragment-shader" );
34 const char * const CUSTOM_SUBDIVIDE_GRID_X( "subdivide-grid-x" );
35 const char * const CUSTOM_SUBDIVIDE_GRID_Y( "subdivide-grid-y" );
36 const char * const CUSTOM_SHADER_HINTS( "hints" ); ///< type INTEGER; (bitfield) values from enum Shader::Hints
37 }
38
39 namespace Dali
40 {
41
42 namespace Toolkit
43 {
44
45 namespace Internal
46 {
47
48 ControlRenderer::ControlRenderer()
49 : mImpl( new Impl() )
50 {
51 }
52
53 ControlRenderer::~ControlRenderer()
54 {
55   delete mImpl;
56 }
57
58 void ControlRenderer::Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap )
59 {
60   if( mImpl->mCustomShader )
61   {
62     mImpl->mCustomShader->SetPropertyMap( propertyMap );
63   }
64   else
65   {
66     Property::Value* customShaderValue = propertyMap.Find( CUSTOM_SHADER );
67     if( customShaderValue )
68     {
69       Property::Map customShader;
70       if( customShaderValue->Get( customShader ) )
71       {
72         mImpl->mCustomShader = new Impl::CustomShader( propertyMap );
73       }
74     }
75   }
76   DoInitialize( factoryCache, propertyMap );
77 }
78
79 void ControlRenderer::SetSize( const Vector2& size )
80 {
81   mImpl->mSize = size;
82 }
83
84 const Vector2& ControlRenderer::GetSize() const
85 {
86   return mImpl->mSize;
87 }
88
89 void ControlRenderer::GetNaturalSize( Vector2& naturalSize ) const
90 {
91   naturalSize = Vector2::ZERO;
92 }
93
94 void ControlRenderer::SetClipRect( const Rect<int>& clipRect )
95 {
96   mImpl->mClipRect = clipRect;
97 }
98
99 void ControlRenderer::SetOffset( const Vector2& offset )
100 {
101   mImpl->mOffset = offset;
102 }
103
104 void ControlRenderer::SetDepthIndex( float index )
105 {
106   mImpl->mDepthIndex = index;
107   if( mImpl->mRenderer )
108   {
109     mImpl->mRenderer.SetDepthIndex( mImpl->mDepthIndex );
110   }
111 }
112
113 float ControlRenderer::GetDepthIndex() const
114 {
115   return mImpl->mDepthIndex;
116 }
117
118 void ControlRenderer::SetOnStage( Actor& actor )
119 {
120   Material material = Material::New( mImpl->mShader );
121   mImpl->mRenderer = Renderer::New( mImpl->mGeometry, material );
122   mImpl->mRenderer.SetDepthIndex( mImpl->mDepthIndex );
123   actor.AddRenderer( mImpl->mRenderer );
124   mImpl->mIsOnStage = true;
125
126   DoSetOnStage( actor );
127 }
128
129 void ControlRenderer::SetOffStage( Actor& actor )
130 {
131   if( mImpl->mIsOnStage )
132   {
133     DoSetOffStage( actor );
134
135     actor.RemoveRenderer( mImpl->mRenderer );
136     mImpl->mRenderer.Reset();
137
138     mImpl->mIsOnStage = false;
139   }
140 }
141
142 void ControlRenderer::DoSetOnStage( Actor& actor )
143 {
144 }
145
146 void ControlRenderer::DoSetOffStage( Actor& actor )
147 {
148 }
149
150 void ControlRenderer::CreatePropertyMap( Property::Map& map ) const
151 {
152   if( mImpl->mCustomShader )
153   {
154     mImpl->mCustomShader->CreatePropertyMap( map );
155   }
156   DoCreatePropertyMap( map );
157 }
158
159 } // namespace Internal
160
161 } // namespace Toolkit
162
163 } // namespace Dali