Merge "removal of shader inheritance, renderable actors now have shaders and there...
[platform/core/uifw/dali-core.git] / dali / public-api / actors / renderable-actor.cpp
1 /*
2  * Copyright (c) 2014 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 <dali/public-api/actors/renderable-actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/actors/renderable-actor-impl.h>
23 #include <dali/internal/event/effects/shader-effect-impl.h>
24
25 namespace Dali
26 {
27
28 const BlendingMode::Type RenderableActor::DEFAULT_BLENDING_MODE = BlendingMode::AUTO;
29
30 RenderableActor::RenderableActor()
31 {
32 }
33
34 RenderableActor RenderableActor::DownCast( BaseHandle handle )
35 {
36   return RenderableActor( dynamic_cast<Dali::Internal::RenderableActor*>(handle.GetObjectPtr()) );
37 }
38
39 RenderableActor::~RenderableActor()
40 {
41 }
42
43 RenderableActor::RenderableActor(const RenderableActor& copy)
44 : Actor(copy)
45 {
46 }
47
48 RenderableActor& RenderableActor::operator=(const RenderableActor& rhs)
49 {
50   BaseHandle::operator=(rhs);
51   return *this;
52 }
53
54 RenderableActor& RenderableActor::operator=(BaseHandle::NullType* rhs)
55 {
56   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
57   Reset();
58   return *this;
59 }
60
61 void RenderableActor::SetSortModifier(float modifier)
62 {
63   GetImplementation(*this).SetSortModifier(modifier);
64 }
65
66 float RenderableActor::GetSortModifier() const
67 {
68   return GetImplementation(*this).GetSortModifier();
69 }
70
71 void RenderableActor::SetCullFace(const CullFaceMode mode)
72 {
73   GetImplementation(*this).SetCullFace(mode);
74 }
75
76 CullFaceMode RenderableActor::GetCullFace() const
77 {
78   return GetImplementation(*this).GetCullFace();
79 }
80
81 void RenderableActor::SetBlendMode( BlendingMode::Type mode )
82 {
83   GetImplementation(*this).SetBlendMode( mode );
84 }
85
86 BlendingMode::Type RenderableActor::GetBlendMode() const
87 {
88   return GetImplementation(*this).GetBlendMode();
89 }
90
91 void RenderableActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
92 {
93   GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
94 }
95
96 void RenderableActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
97                                     BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
98 {
99   GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
100 }
101
102 void RenderableActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
103                                     BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
104 {
105   GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
106 }
107
108 void RenderableActor::SetBlendEquation( BlendingEquation::Type equationRgba )
109 {
110   GetImplementation(*this).SetBlendEquation( equationRgba );
111 }
112
113 void RenderableActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
114 {
115   GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
116 }
117
118 void RenderableActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
119 {
120   GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
121 }
122
123 void RenderableActor::SetBlendColor( const Vector4& color )
124 {
125   GetImplementation(*this).SetBlendColor( color );
126 }
127
128 const Vector4& RenderableActor::GetBlendColor() const
129 {
130   return GetImplementation(*this).GetBlendColor();
131 }
132
133 void RenderableActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
134 {
135   GetImplementation(*this).SetFilterMode( minFilter, magFilter );
136 }
137
138 void RenderableActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
139 {
140   GetImplementation(*this).GetFilterMode( minFilter, magFilter );
141 }
142
143 void RenderableActor::SetShaderEffect(ShaderEffect effect)
144 {
145   GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
146 }
147
148 ShaderEffect RenderableActor::GetShaderEffect() const
149 {
150   Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
151
152   return ShaderEffect(internal.Get());
153 }
154
155 void RenderableActor::RemoveShaderEffect()
156 {
157   GetImplementation(*this).RemoveShaderEffect();
158 }
159
160 RenderableActor::RenderableActor(Internal::RenderableActor* internal)
161 : Actor(internal)
162 {
163 }
164
165 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
166 {
167   // only do something if the actor and effect are valid
168   if( actor && effect )
169   {
170     // first remove from this actor
171     RenderableActor renderable = RenderableActor::DownCast( actor );
172     if( renderable )
173     {
174       renderable.SetShaderEffect( effect );
175     }
176     // then all children recursively
177     const unsigned int count = actor.GetChildCount();
178     for( unsigned int index = 0; index < count; ++index )
179     {
180       Actor child( actor.GetChildAt( index ) );
181       SetShaderEffectRecursively( child, effect );
182     }
183   }
184 }
185
186 void RemoveShaderEffectRecursively( Actor actor )
187 {
188   // only do something if the actor is valid
189   if( actor )
190   {
191     // first remove from this actor
192     RenderableActor renderable = RenderableActor::DownCast( actor );
193     if( renderable )
194     {
195       renderable.RemoveShaderEffect();
196     }
197     // then all children recursively
198     const unsigned int count = actor.GetChildCount();
199     for( unsigned int index = 0; index < count; ++index )
200     {
201       Actor child( actor.GetChildAt( index ) );
202       RemoveShaderEffectRecursively( child );
203     }
204   }
205 }
206
207 } // namespace Dali