Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_RendererLightingParameters.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiEffects_RendererLightingParameters.h
19  * @brief               This is the header file for the LightingParameters class
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_LIGHTINGPARAMETERS_H_
23 #define _FUI_EFFECTS_INTERNAL_RENDERER_LIGHTINGPARAMETERS_H_
24
25 #include <FBaseSysLog.h>
26 #include <FUiEffects_EffectErrorMessages.h>
27 #include <renderer/engine-model/FUiEffects_RendererEngineModelIntPropertyHolder.h>
28 #include <renderer/engine-model/FUiEffects_RendererEngineModelVector3fPropertyHolder.h>
29 #include <utils/FUiEffects_Utils.h>
30
31 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer
32 {
33
34 /**
35  * @class       LightingParameters
36  * @brief       This class contains data for ambient light in scene
37  *
38  */
39 class LightingParameters
40 {
41 public:
42
43         /**
44          * Constructor
45          *
46          * @remark              Sets default values for members
47          */
48         LightingParameters(void)
49         {
50                 result r = GetLastResult();
51                 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
52
53                 __ambientColorI = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
54                 __attenuation = System::FloatPtr(new (std::nothrow) float);
55
56                 r = GetLastResult();
57                 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
58                 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__ambientColorI) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
59                 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__attenuation) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
60
61                 __ambientColor.set(1.f, 0.f, 0.f);
62                 __ambientIntensity = 1.f;
63                 *__attenuation = 0.08f;
64
65                 UpdateAmbientColorI();
66         }
67
68         /**
69         * Sets ambient color value
70         *
71         * @param [in]   color                           New color ambient color value
72         *
73         * @return               void
74         */
75         void SetAmbientColor(const Tizen::Ui::Effects::_Utils::Vec3f& ambientColor)
76         {
77                 __ambientColor = ambientColor;
78                 UpdateAmbientColorI();
79
80                 return;
81         }
82
83         /**
84         * Sets ambient intensity value
85         *
86         * @param [in]   intensity                               New ambient intensity value
87         *
88         * @return               void
89         */
90         void SetAmbientIntensity(float ambientIntensity)
91         {
92                 __ambientIntensity = ambientIntensity;
93                 UpdateAmbientColorI();
94
95                 return;
96         }
97
98         void SetAttenuation(float attenuation)
99         {
100                 *__attenuation = attenuation;
101
102                 return;
103         }
104
105         /**
106         * Gets ambient color*intensity value property
107         *
108         * @return               ambient color*intensity value property
109         */
110         EngineModel::Vector3fPropertyHolderPtr GetAmbientColorIHolder(void) const
111         {
112                 return __ambientColorI;
113         }
114
115         System::FloatPtr GetAttenuation(void) const
116         {
117                 return __attenuation;
118         }
119
120 private:
121
122         /**
123          * Hidden copy constructor
124          */
125         LightingParameters(const LightingParameters &rhs);
126
127
128         /**
129          * Hidden assignment operator
130          */
131         LightingParameters& operator=(const LightingParameters &rhs);
132
133         /**
134         * Sets ambient colorI property which is premultiplied color x intensity for use in shader
135         *
136         * @return               void
137         */
138         void UpdateAmbientColorI(void)
139         {
140                 __ambientColorI->Set(__ambientColor.x * __ambientIntensity, __ambientColor.y * __ambientIntensity, __ambientColor.z * __ambientIntensity);
141
142                 return;
143         }
144
145 private:
146         _Utils::Vec3f __ambientColor;
147         float __ambientIntensity;
148
149         EngineModel::Vector3fPropertyHolderPtr __ambientColorI;         /**<  __ambientColor * __ambientIntensity */
150         System::FloatPtr __attenuation;
151 }; // LightingParameters
152
153 typedef System::SmartPtr<LightingParameters> LightingParametersPtr;
154
155 } } } } // Tizen::Ui::Effects::_EffectRenderer
156
157 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_LIGHTINGPARAMETERS_H_