Glue glue and more glue
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / 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/actors/renderer-impl.h> // Dali::Internal::Renderer
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/renderer.h> // Dali::Renderer
23 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
24 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
25 #include <dali/internal/event/common/stage-impl.h>
26 #include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32
33 namespace
34 {
35
36 /**
37  *            |name          |type     |writable|animatable|constraint-input|enum for index-checking|
38  */
39 DALI_PROPERTY_TABLE_BEGIN
40 DALI_PROPERTY( "depth-index", INTEGER,  true, true, true, Dali::Renderer::Property::DEPTH_INDEX )
41 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX )
42
43 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
44
45 } // unnamed namespace
46
47 RendererPtr Renderer::New()
48 {
49   RendererPtr rendererPtr( new Renderer() );
50   rendererPtr->Initialize();
51   return rendererPtr;
52 }
53
54 void Renderer::SetGeometry( Geometry& geometry )
55 {
56   mGeometryConnector.Set( geometry, OnStage() );
57   const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
58   SetGeometryMessage( Stage::GetCurrent()->GetUpdateInterface(), *mSceneObject, *geometrySceneObject );
59 }
60
61 void Renderer::SetMaterial( Material& material )
62 {
63   mMaterialConnector.Set( material, OnStage() );
64   const SceneGraph::Material* materialSceneObject = material.GetMaterialSceneObject();
65   SetMaterialMessage( Stage::GetCurrent()->GetUpdateInterface(), *mSceneObject, *materialSceneObject );
66 }
67
68 void Renderer::SetDepthIndex( int depthIndex )
69 {
70   //SceneGraph::NodePropertyMessage<Vector3>::Send( mStage->GetUpdateManager(), mNode, &mNode->mPosition, &AnimatableProperty<Vector3>::Bake, position );
71   // TODO: MESH_REWORK
72   DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
73 }
74
75 SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
76 {
77   return mSceneObject;
78 }
79
80 unsigned int Renderer::GetDefaultPropertyCount() const
81 {
82   return RENDERER_IMPL.GetDefaultPropertyCount();
83 }
84
85 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
86 {
87   RENDERER_IMPL.GetDefaultPropertyIndices( indices );
88 }
89
90 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
91 {
92   return RENDERER_IMPL.GetDefaultPropertyName( index );
93 }
94
95 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
96 {
97   return RENDERER_IMPL.GetDefaultPropertyIndex( name );
98 }
99
100 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
101 {
102   return RENDERER_IMPL.IsDefaultPropertyWritable( index );
103 }
104
105 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
106 {
107   return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
108 }
109
110 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
111 {
112   return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
113 }
114
115 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
116 {
117   return RENDERER_IMPL.GetDefaultPropertyType( index );
118 }
119
120 void Renderer::SetDefaultProperty( Property::Index index,
121                                    const Property::Value& propertyValue )
122 {
123   RENDERER_IMPL.SetDefaultProperty( index, propertyValue );
124 }
125
126 void Renderer::SetSceneGraphProperty( Property::Index index,
127                                       const CustomProperty& entry,
128                                       const Property::Value& value )
129 {
130   RENDERER_IMPL.SetSceneGraphProperty( index, entry, value );
131 }
132
133 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
134 {
135   return RENDERER_IMPL.GetDefaultProperty( index );
136 }
137
138 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
139 {
140   return RENDERER_IMPL.GetPropertyOwner();
141 }
142
143 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
144 {
145   return mSceneObject;
146 }
147
148 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
149 {
150   return RENDERER_IMPL.GetSceneObjectAnimatableProperty( index );
151 }
152
153 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
154 {
155   return RENDERER_IMPL.GetSceneObjectInputProperty( index );
156 }
157
158 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
159 {
160   return RENDERER_IMPL.GetPropertyComponentIndex( index );
161 }
162
163 bool Renderer::OnStage() const
164 {
165   // TODO: MESH_REWORK
166   //DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
167   return mOnStage;
168 }
169
170 void Renderer::Connect()
171 {
172   // TODO: MESH_REWORK : check this
173   mGeometryConnector.OnStageConnect();
174   mMaterialConnector.OnStageConnect();
175   mOnStage = true;
176 }
177
178 void Renderer::Disconnect()
179 {
180   // TODO: MESH_REWORK : check this
181   mGeometryConnector.OnStageDisconnect();
182   mMaterialConnector.OnStageDisconnect();
183   mOnStage = false;
184 }
185
186 Renderer::Renderer()
187 : mSceneObject(NULL),
188   mOnStage(false)
189 {
190 }
191
192 void Renderer::Initialize()
193 {
194   // Transfer object ownership of scene-object to message
195   mSceneObject = SceneGraph::RendererAttachment::New();
196
197   // Send message to update to connect to scene graph:
198   AttachToSceneGraphMessage( Stage::GetCurrent()->GetUpdateManager(), mSceneObject );
199 }
200
201
202 } // namespace Internal
203 } // namespace Dali