License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / renderable-attachment-impl.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/internal/event/actor-attachments/renderable-attachment-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/common/stage-impl.h>
23 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
24 #include <dali/internal/render/renderers/scene-graph-renderer.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 RenderableAttachment::RenderableAttachment( Stage& stage )
33 : ActorAttachment( stage ),
34   mSortModifier( 0.0f ),
35   mCullFaceMode( CullNone ),
36   mBlendingMode( BlendingMode::AUTO )
37 {
38 }
39
40 RenderableAttachment::~RenderableAttachment()
41 {
42 }
43
44 void RenderableAttachment::SetSortModifier(float modifier)
45 {
46   // Cache for actor-side getters
47   mSortModifier = modifier;
48
49   // attachment is being used in a separate thread; queue a message to set the value & base value
50   SetSortModifierMessage( mStage->GetUpdateInterface(), GetSceneObject(), modifier );
51 }
52
53 float RenderableAttachment::GetSortModifier() const
54 {
55   // mSortModifier is not animatable; this is the most up-to-date value.
56   return mSortModifier;
57 }
58
59 void RenderableAttachment::SetCullFace( CullFaceMode mode )
60 {
61   // Cache for actor-side getters
62   mCullFaceMode = mode;
63
64   // attachment is being used in a separate thread; queue a message to set the value
65   SetCullFaceMessage( mStage->GetUpdateInterface(), GetSceneObject(), mode );
66 }
67
68 CullFaceMode RenderableAttachment::GetCullFace() const
69 {
70   // mCullFaceMode is not animatable; this is the most up-to-date value.
71   return mCullFaceMode;
72 }
73
74 void RenderableAttachment::SetBlendMode( BlendingMode::Type mode )
75 {
76   mBlendingMode = mode;
77
78   // attachment is being used in a separate thread; queue a message to set the value
79   SetBlendingModeMessage( mStage->GetUpdateInterface(), GetSceneObject(), mode );
80 }
81
82 BlendingMode::Type RenderableAttachment::GetBlendMode() const
83 {
84   return mBlendingMode;
85 }
86
87 void RenderableAttachment::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
88                                          BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
89 {
90   // Cache for actor-side getters
91   mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
92
93   // attachment is being used in a separate thread; queue a message to set the value
94   SetBlendingOptionsMessage( mStage->GetUpdateInterface(), GetSceneObject(), mBlendingOptions.GetBitmask() );
95 }
96
97 void RenderableAttachment::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
98                                          BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
99 {
100   // These are not animatable, the cached values are up-to-date.
101   srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
102   destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
103   srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
104   destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
105 }
106
107 void RenderableAttachment::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
108 {
109   mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
110
111   // attachment is being used in a separate thread; queue a message to set the value
112   SetBlendingOptionsMessage( mStage->GetUpdateInterface(), GetSceneObject(), mBlendingOptions.GetBitmask() );
113 }
114
115 void RenderableAttachment::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
116 {
117   // These are not animatable, the cached values are up-to-date.
118   equationRgb   = mBlendingOptions.GetBlendEquationRgb();
119   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
120 }
121
122 void RenderableAttachment::SetBlendColor( const Vector4& color )
123 {
124   if( mBlendingOptions.SetBlendColor( color ) )
125   {
126     // attachment is being used in a separate thread; queue a message to set the value
127     SetBlendColorMessage( mStage->GetUpdateInterface(), GetSceneObject(), color );
128   }
129 }
130
131 const Vector4& RenderableAttachment::GetBlendColor() const
132 {
133   const Vector4* optionalColor = mBlendingOptions.GetBlendColor();
134   if( optionalColor )
135   {
136     return *optionalColor;
137   }
138
139   return Vector4::ZERO;
140 }
141
142 void RenderableAttachment::OnStageConnection()
143 {
144   // For derived classes
145   OnStageConnection2();
146 }
147
148 void RenderableAttachment::OnStageDisconnection()
149 {
150   // For derived classes
151   OnStageDisconnection2();
152 }
153
154 } // namespace Internal
155
156 } // namespace Dali