Merge "Remove API to set if a geometry requires writing to the depth buffer" into...
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / 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 <dali/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
25 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
26 #include <dali/internal/event/common/property-input-impl.h>
27 #include <dali/internal/update/rendering/scene-graph-renderer.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/render/renderers/render-geometry.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 /**
40  *            |name                              |type     |writable|animatable|constraint-input|enum for index-checking|
41  */
42 DALI_PROPERTY_TABLE_BEGIN
43 DALI_PROPERTY( "depthIndex",                      INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_INDEX )
44 DALI_PROPERTY( "faceCullingMode",                 INTEGER,   true, false,  false, Dali::Renderer::Property::FACE_CULLING_MODE )
45 DALI_PROPERTY( "blendingMode",                    INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_MODE )
46 DALI_PROPERTY( "blendEquationRgb",                INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
47 DALI_PROPERTY( "blendEquationAlpha",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
48 DALI_PROPERTY( "sourceBlendFactorRgb",            INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB )
49 DALI_PROPERTY( "destinationBlendFactorRgb",       INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB )
50 DALI_PROPERTY( "sourceBlendFactorAlpha",          INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA )
51 DALI_PROPERTY( "destinationBlendFactorAlpha",     INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA )
52 DALI_PROPERTY( "blendingColor",                   VECTOR4,   true, false,  false, Dali::Renderer::Property::BLENDING_COLOR )
53 DALI_PROPERTY( "blendPreMultipliedAlpha",         BOOLEAN,   true, false,  false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
54 DALI_PROPERTY( "indexRangeFirst",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
55 DALI_PROPERTY( "indexRangeCount",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
56 DALI_PROPERTY( "depthWriteMode",                  INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
57 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
58
59 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
60
61 BaseHandle Create()
62 {
63   return Dali::BaseHandle();
64 }
65
66 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
67
68 } // unnamed namespace
69
70 RendererPtr Renderer::New()
71 {
72   RendererPtr rendererPtr( new Renderer() );
73   rendererPtr->Initialize();
74   return rendererPtr;
75 }
76
77 void Renderer::SetGeometry( Geometry& geometry )
78 {
79   mGeometry = &geometry;
80
81   const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
82   SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
83 }
84
85 Geometry* Renderer::GetGeometry() const
86 {
87   return mGeometry.Get();
88 }
89
90 void Renderer::SetTextures( TextureSet& textureSet )
91 {
92   mTextureSetConnector.Set( textureSet, OnStage() );
93   const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
94   SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
95 }
96
97 TextureSet* Renderer::GetTextures() const
98 {
99   return mTextureSetConnector.Get().Get();
100 }
101
102 void Renderer::SetShader( Shader& shader )
103 {
104   mShader = &shader;
105   SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
106   SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
107 }
108
109 Shader* Renderer::GetShader() const
110 {
111   return mShader.Get();
112 }
113
114 void Renderer::SetDepthIndex( int depthIndex )
115 {
116   if ( mDepthIndex != depthIndex )
117   {
118     mDepthIndex = depthIndex;
119     SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
120   }
121 }
122
123 int Renderer::GetDepthIndex() const
124 {
125   return mDepthIndex;
126 }
127
128 void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode )
129 {
130   if( mFaceCullingMode != cullingMode )
131   {
132     mFaceCullingMode = cullingMode;
133
134     SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
135   }
136 }
137
138 Dali::Renderer::FaceCullingMode Renderer::GetFaceCullingMode()
139 {
140   return mFaceCullingMode;
141 }
142
143 void Renderer::SetBlendMode( BlendingMode::Type mode )
144 {
145   if( mBlendingMode != mode )
146   {
147     mBlendingMode = mode;
148
149     SetBlendingModeMessage( GetEventThreadServices(), *mSceneObject, mBlendingMode );
150   }
151 }
152
153 BlendingMode::Type Renderer::GetBlendMode() const
154 {
155   return mBlendingMode;
156 }
157
158 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
159 {
160   mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
161   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
162 }
163
164 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
165                              BlendingFactor::Type destFactorRgb,
166                              BlendingFactor::Type srcFactorAlpha,
167                              BlendingFactor::Type destFactorAlpha )
168 {
169   mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
170   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
171 }
172
173 void Renderer::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
174                              BlendingFactor::Type& destFactorRgb,
175                              BlendingFactor::Type& srcFactorAlpha,
176                              BlendingFactor::Type& destFactorAlpha ) const
177 {
178   srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
179   destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
180   srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
181   destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
182 }
183
184 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgba )
185 {
186   mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
187   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
188 }
189
190 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgb,
191                                  BlendingEquation::Type equationAlpha )
192 {
193   mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
194   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
195 }
196
197 void Renderer::GetBlendEquation( BlendingEquation::Type& equationRgb,
198                                  BlendingEquation::Type& equationAlpha ) const
199 {
200   // These are not animatable, the cached values are up-to-date.
201   equationRgb   = mBlendingOptions.GetBlendEquationRgb();
202   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
203 }
204
205 void Renderer::SetBlendColor( const Vector4& color )
206 {
207   if( !mBlendColor )
208   {
209     mBlendColor = new Vector4();
210   }
211   if( *mBlendColor != color )
212   {
213     *mBlendColor = color;
214     SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
215   }
216 }
217
218 Vector4 Renderer::GetBlendColor() const
219 {
220   if( mBlendColor )
221   {
222     return *mBlendColor;
223   }
224   return Color::TRANSPARENT; // GL default
225 }
226
227 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
228 {
229   if( firstElement != mIndexedDrawFirstElement )
230   {
231     mIndexedDrawFirstElement = firstElement;
232     SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
233   }
234 }
235
236 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
237 {
238   if( elementsCount != mIndexedDrawElementCount )
239   {
240     mIndexedDrawElementCount = elementsCount;
241     SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
242   }
243 }
244
245
246 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
247 {
248   if(  mPremultipledAlphaEnabled != preMultipled )
249   {
250     if( preMultipled )
251     {
252       SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA, BlendingFactor::ONE, BlendingFactor::ONE );
253     }
254     mPremultipledAlphaEnabled = preMultipled;
255     SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
256   }
257 }
258
259 bool Renderer::IsPreMultipliedAlphaEnabled() const
260 {
261   return mPremultipledAlphaEnabled;
262 }
263
264 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
265 {
266   return mSceneObject;
267 }
268
269 unsigned int Renderer::GetDefaultPropertyCount() const
270 {
271   return RENDERER_IMPL.GetDefaultPropertyCount();
272 }
273
274 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
275 {
276   RENDERER_IMPL.GetDefaultPropertyIndices( indices );
277 }
278
279 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
280 {
281   return RENDERER_IMPL.GetDefaultPropertyName( index );
282 }
283
284 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
285 {
286   return RENDERER_IMPL.GetDefaultPropertyIndex( name );
287 }
288
289 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
290 {
291   return RENDERER_IMPL.IsDefaultPropertyWritable( index );
292 }
293
294 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
295 {
296   return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
297 }
298
299 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
300 {
301   return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
302 }
303
304 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
305 {
306   return RENDERER_IMPL.GetDefaultPropertyType( index );
307 }
308
309 void Renderer::SetDefaultProperty( Property::Index index,
310                                    const Property::Value& propertyValue )
311 {
312   switch( index )
313   {
314     case Dali::Renderer::Property::DEPTH_INDEX:
315     {
316       SetDepthIndex( propertyValue.Get<int>() );
317       break;
318     }
319     case Dali::Renderer::Property::FACE_CULLING_MODE:
320     {
321       int faceCullingMode;
322       if( propertyValue.Get( faceCullingMode ) )
323       {
324         SetFaceCullingMode( Dali::Renderer::FaceCullingMode( faceCullingMode ) );
325       }
326       break;
327     }
328     case Dali::Renderer::Property::BLENDING_MODE:
329     {
330       int blendingMode;
331       if( propertyValue.Get( blendingMode ) )
332       {
333         SetBlendMode( BlendingMode::Type( blendingMode ) );
334       }
335       break;
336     }
337     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
338     {
339       int blendingEquation;
340       if( propertyValue.Get( blendingEquation ) )
341       {
342         BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
343         mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>( blendingEquation ), alphaEquation );
344         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
345       }
346       break;
347     }
348     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
349     {
350       int blendingEquation;
351       if( propertyValue.Get( blendingEquation ) )
352       {
353         BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
354         mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>( blendingEquation ) );
355         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
356       }
357       break;
358     }
359     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
360     {
361       int blendingFactor;
362       if( propertyValue.Get( blendingFactor ) )
363       {
364         BlendingFactor::Type srcFactorRgb;
365         BlendingFactor::Type destFactorRgb;
366         BlendingFactor::Type srcFactorAlpha;
367         BlendingFactor::Type destFactorAlpha;
368         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
369         SetBlendFunc( static_cast<BlendingFactor::Type>( blendingFactor ),
370             destFactorRgb,
371             srcFactorAlpha,
372             destFactorAlpha );
373       }
374       break;
375     }
376     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
377     {
378       int blendingFactor;
379       if( propertyValue.Get( blendingFactor ) )
380       {
381         BlendingFactor::Type srcFactorRgb;
382         BlendingFactor::Type destFactorRgb;
383         BlendingFactor::Type srcFactorAlpha;
384         BlendingFactor::Type destFactorAlpha;
385         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
386         SetBlendFunc( srcFactorRgb,
387             static_cast<BlendingFactor::Type>( blendingFactor ),
388             srcFactorAlpha,
389             destFactorAlpha );
390       }
391       break;
392     }
393     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
394     {
395       int blendingFactor;
396       if( propertyValue.Get( blendingFactor ) )
397       {
398         BlendingFactor::Type srcFactorRgb;
399         BlendingFactor::Type destFactorRgb;
400         BlendingFactor::Type srcFactorAlpha;
401         BlendingFactor::Type destFactorAlpha;
402         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
403         SetBlendFunc( srcFactorRgb,
404             destFactorRgb,
405             static_cast<BlendingFactor::Type>( blendingFactor ),
406             destFactorAlpha );
407       }
408       break;
409     }
410     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
411     {
412       int blendingFactor;
413       if( propertyValue.Get( blendingFactor ) )
414       {
415         BlendingFactor::Type srcFactorRgb;
416         BlendingFactor::Type destFactorRgb;
417         BlendingFactor::Type srcFactorAlpha;
418         BlendingFactor::Type destFactorAlpha;
419         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
420         SetBlendFunc( srcFactorRgb,
421             destFactorRgb,
422             srcFactorAlpha,
423             static_cast<BlendingFactor::Type>( blendingFactor ) );
424       }
425       break;
426     }
427     case Dali::Renderer::Property::BLENDING_COLOR:
428     {
429       Vector4 blendColor;
430       if( propertyValue.Get( blendColor ) )
431       {
432         SetBlendColor( blendColor );
433       }
434       break;
435     }
436     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
437     {
438       bool preMultipled;
439       if( propertyValue.Get( preMultipled ) )
440       {
441         EnablePreMultipliedAlpha( preMultipled );
442       }
443       break;
444     }
445     case Dali::Renderer::Property::INDEX_RANGE_FIRST:
446     {
447       int firstElement;
448       if( propertyValue.Get( firstElement ) )
449       {
450         SetIndexedDrawFirstElement( firstElement );
451       }
452       break;
453     }
454     case Dali::Renderer::Property::INDEX_RANGE_COUNT:
455     {
456       int elementsCount;
457       if( propertyValue.Get( elementsCount ) )
458       {
459         SetIndexedDrawElementsCount( elementsCount );
460       }
461       break;
462     }
463     case Dali::Renderer::Property::DEPTH_WRITE_MODE:
464     {
465       int value;
466       propertyValue.Get( value );
467       Dali::Renderer::DepthWriteMode mode = static_cast<Dali::Renderer::DepthWriteMode>(value);
468       if( mode != mDepthWriteMode )
469       {
470         mDepthWriteMode = mode;
471         SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, mode );
472       }
473
474       break;
475     }
476   }
477 }
478
479 void Renderer::SetSceneGraphProperty( Property::Index index,
480                                       const PropertyMetadata& entry,
481                                       const Property::Value& value )
482 {
483   RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
484   OnPropertySet(index, value);
485 }
486
487 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
488 {
489   Property::Value value;
490   switch( index )
491   {
492     case Dali::Renderer::Property::DEPTH_INDEX:
493     {
494       value = GetDepthIndex();
495       break;
496     }
497     case Dali::Renderer::Property::FACE_CULLING_MODE:
498     {
499       value = mFaceCullingMode;
500       break;
501     }
502     case Dali::Renderer::Property::BLENDING_MODE:
503     {
504       value = mBlendingMode;
505       break;
506     }
507     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
508     {
509       value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
510       break;
511     }
512     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
513     {
514       value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
515       break;
516     }
517     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
518     {
519       BlendingFactor::Type srcFactorRgb;
520       BlendingFactor::Type destFactorRgb;
521       BlendingFactor::Type srcFactorAlpha;
522       BlendingFactor::Type destFactorAlpha;
523       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
524       value = static_cast<int>( srcFactorRgb );
525       break;
526     }
527     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
528     {
529       BlendingFactor::Type srcFactorRgb;
530       BlendingFactor::Type destFactorRgb;
531       BlendingFactor::Type srcFactorAlpha;
532       BlendingFactor::Type destFactorAlpha;
533       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
534       value = static_cast<int>( destFactorRgb );
535       break;
536     }
537     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
538     {
539       BlendingFactor::Type srcFactorRgb;
540       BlendingFactor::Type destFactorRgb;
541       BlendingFactor::Type srcFactorAlpha;
542       BlendingFactor::Type destFactorAlpha;
543       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
544       value = static_cast<int>( srcFactorAlpha );
545       break;
546     }
547     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
548     {
549       BlendingFactor::Type srcFactorRgb;
550       BlendingFactor::Type destFactorRgb;
551       BlendingFactor::Type srcFactorAlpha;
552       BlendingFactor::Type destFactorAlpha;
553       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
554       value = static_cast<int>( destFactorAlpha );
555       break;
556     }
557     case Dali::Renderer::Property::BLENDING_COLOR:
558     {
559       if( mBlendColor )
560       {
561         value = *mBlendColor;
562       }
563       else
564       {
565         value = Color::TRANSPARENT;
566       }
567       break;
568     }
569     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
570     {
571       value = IsPreMultipliedAlphaEnabled();
572       break;
573     }
574     case Dali::Renderer::Property::INDEX_RANGE_FIRST:
575     {
576       value = static_cast<int>( mIndexedDrawFirstElement );
577       break;
578     }
579     case Dali::Renderer::Property::INDEX_RANGE_COUNT:
580     {
581       value = static_cast<int>( mIndexedDrawElementCount );
582       break;
583     }
584     case Dali::Renderer::Property::DEPTH_WRITE_MODE:
585     {
586       value = mDepthWriteMode;
587       break;
588     }
589   }
590   return value;
591 }
592
593 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
594 {
595   return mSceneObject;
596 }
597
598 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
599 {
600   return mSceneObject;
601 }
602
603 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
604 {
605   DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
606   const SceneGraph::PropertyBase* property = NULL;
607
608   if( OnStage() )
609   {
610     property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
611       this,
612       &Renderer::FindAnimatableProperty,
613       &Renderer::FindCustomProperty,
614       index );
615   }
616
617   return property;
618 }
619
620 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
621 {
622   const PropertyInputImpl* property = NULL;
623
624   if( OnStage() )
625   {
626     const SceneGraph::PropertyBase* baseProperty =
627       RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
628                                                      &Renderer::FindAnimatableProperty,
629                                                      &Renderer::FindCustomProperty,
630                                                      index );
631     property = static_cast<const PropertyInputImpl*>( baseProperty );
632   }
633
634   return property;
635 }
636
637 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
638 {
639   return Property::INVALID_COMPONENT_INDEX;
640 }
641
642 bool Renderer::OnStage() const
643 {
644   return mOnStageCount > 0;
645 }
646
647 void Renderer::Connect()
648 {
649   if( mOnStageCount == 0 )
650   {
651     OnStageConnectMessage( GetEventThreadServices(), *mSceneObject );
652     mTextureSetConnector.OnStageConnect();
653   }
654   ++mOnStageCount;
655 }
656
657 void Renderer::Disconnect()
658 {
659   --mOnStageCount;
660   if( mOnStageCount == 0 )
661   {
662     OnStageDisconnectMessage( GetEventThreadServices(), *mSceneObject);
663     mTextureSetConnector.OnStageDisconnect();
664   }
665 }
666
667 Renderer::Renderer()
668 : mSceneObject (NULL ),
669   mBlendColor( NULL ),
670   mDepthIndex( 0 ),
671   mOnStageCount( 0 ),
672   mIndexedDrawFirstElement( 0 ),
673   mIndexedDrawElementCount( 0 ),
674   mFaceCullingMode( Dali::Renderer::CULL_NONE ),
675   mBlendingMode( Dali::BlendingMode::AUTO ),
676   mBlendingOptions(),
677   mDepthWriteMode( Dali::Renderer::DEPTH_WRITE_AUTO ),
678   mPremultipledAlphaEnabled( false )
679 {
680 }
681
682 void Renderer::Initialize()
683 {
684   EventThreadServices& eventThreadServices = GetEventThreadServices();
685   SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
686
687   mSceneObject = SceneGraph::Renderer::New();
688   AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
689
690   eventThreadServices.RegisterObject( this );
691 }
692
693 Renderer::~Renderer()
694 {
695   if( EventThreadServices::IsCoreRunning() )
696   {
697     EventThreadServices& eventThreadServices = GetEventThreadServices();
698     SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
699     RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
700
701     eventThreadServices.UnregisterObject( this );
702   }
703 }
704
705 } // namespace Internal
706 } // namespace Dali