2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiEffects_RendererPointLight.h
19 * @brief This is the header file for the PointLight class
22 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_POINTLIGHT_H_
23 #define _FUI_EFFECTS_INTERNAL_RENDERER_POINTLIGHT_H_
25 #include <FBaseSysLog.h>
29 #include <renderer/engine-model/FUiEffects_RendererEngineModelIntPropertyHolder.h>
30 #include <renderer/engine-model/FUiEffects_RendererEngineModelFloatPropertyHolder.h>
31 #include <renderer/engine-model/FUiEffects_RendererEngineModelVector3fPropertyHolder.h>
32 #include <utils/FUiEffects_Utils.h>
34 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer
39 * @brief This class contains data for point light in scene
49 * @param [in] attenuation Global attenuation pointer
51 * @remark Sets default values for members
53 PointLight(System::FloatPtr attenuation)
55 result r = GetLastResult();
56 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
57 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(attenuation) != null, E_INVALID_ARG, "[E_INVALID_ARG] PointLight attenuation equals null");
59 __position = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
60 __colorI = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
61 __Rk = EngineModel::FloatPropertyHolderPtr(new (std::nothrow) EngineModel::FloatPropertyHolder);
64 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
65 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__position) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
66 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__colorI) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
67 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__Rk) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
69 __position->Set(0.f, 0.f, 0.f);
70 __color.set(1.f, 0.f, 0.f);
73 __attenuation = attenuation;
80 * Sets position property
82 * @param [in] position New position
86 void SetPosition(const Tizen::Ui::Effects::_Utils::Vec3f& position)
88 __position->Set(position.x, position.y, position.z);
96 * @param [in] color New color value
100 void SetColor(const Tizen::Ui::Effects::_Utils::Vec3f& color)
109 * Sets intensity property
111 * @param [in] intensity New intensity value
115 void SetIntensity(float intensity)
117 __intensity = intensity;
126 * @param [in] enabled New enabled value
130 void SetEnabled(bool enabled)
138 * Gets position property
140 * @return position property
142 EngineModel::Vector3fPropertyHolderPtr GetPositionHolder(void) const
148 * Gets color*intensity value property
150 * @return color*intensity value property
152 EngineModel::Vector3fPropertyHolderPtr GetColorIHolder(void) const
159 * Gets Rk value holder
161 * @return Rk value holder
163 EngineModel::FloatPropertyHolderPtr GetRkHolder(void) const
171 * @return enabled value
173 bool GetEnabled(void) const
179 * Does source emitt any light?
181 * @return true if color*intensity = 0
183 bool IsBlack(void) const
185 return __maxCi <= std::numeric_limits<float>::epsilon() || __Rk->Get() <= std::numeric_limits<float>::epsilon();
189 * Updates precalculated values related to Attenuation
193 void UpdateAttenuation(void)
201 * Hidden copy constructor
203 PointLight(const PointLight &rhs);
207 * Hidden assignment operator
209 PointLight& operator=(const PointLight &rhs);
212 * Sets colorI property which is premultiplied color x intensity for use in shader. @n
213 * Also calculates 1 / Rmax, where Rmax is maxim distance light value is >= 1/255
217 void UpdateColorI(void)
219 __colorI->Set(__color.x * __intensity, __color.y * __intensity, __color.z * __intensity);
220 __maxCi = Math::EffectsAbs((float)__intensity * Math::EffectsMax(__color.x, Math::EffectsMax(__color.y, __color.z)));
228 * Updates precalculated values related to light emission radius
234 if(__maxCi > std::numeric_limits<float>::epsilon())
236 __Rk->Set(Math::EffectsSqrt(*__attenuation * (1.0f/255.f) / __maxCi));
241 _Utils::Vec3f __color;
246 EngineModel::Vector3fPropertyHolderPtr __position;
247 EngineModel::Vector3fPropertyHolderPtr __colorI; /**< __color * __intensity */
248 EngineModel::FloatPropertyHolderPtr __Rk;
249 System::FloatPtr __attenuation;
252 typedef System::SmartPtr<PointLight> PointLightPtr;
254 } } } } // Tizen::Ui::Effects::_EffectRenderer
256 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_POINTLIGHT_H_