2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "renderable-actor-api.h"
22 #include <object/handle-wrapper.h>
24 #include <object/property-value-wrapper.h>
25 #include <shader-effects/shader-effect-api.h>
26 #include <shader-effects/shader-effect-wrapper.h>
34 namespace //unnamed name space
36 RenderableActor GetRenderableActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
38 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
39 return RenderableActor::DownCast( handleWrapper->mHandle );
42 /***************************************
43 * RENDERABLE ACTOR FUNCTIONS
45 ****************************************/
47 * Allows modification of an actors position in the depth sort algorithm.
49 * The offset can be altered for each coplanar actor hence allowing an order of painting.
50 * @param { Number } depthOffset the offset to be given to the actor. Positive values pushing it further back.
51 * @for RenderableActor
52 * @method setSortModifier
54 void RenderableActorApi::SetSortModifier( const v8::FunctionCallbackInfo<v8::Value>& args )
56 v8::Isolate* isolate = args.GetIsolate();
57 v8::HandleScope handleScope( isolate );
58 RenderableActor actor = GetRenderableActor( isolate, args );
61 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
64 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
67 actor.SetSortModifier( value );
71 * Retrieves the offset used to modify an actors position in the depth sort algorithm.
72 * @for RenderableActor
73 * @method getSortModifier .
74 * @return { Number} the offset that has been given to the actor. Positive values pushing it further back
76 void RenderableActorApi::GetSortModifier( const v8::FunctionCallbackInfo<v8::Value>& args )
78 v8::Isolate* isolate = args.GetIsolate();
79 v8::HandleScope handleScope( isolate );
80 RenderableActor actor = GetRenderableActor( isolate, args );
82 args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetSortModifier() ) );
87 * Set the face-culling mode for this actor.
88 * @for RenderableActor
90 * @param {Number} cullMode
92 * // cull mode should be one of the following constants
93 * dali.CULL_FACE_DISABLE // Face culling disabled
94 * dali.CULL_FRONT_FACE // Cull front facing polygons
95 * dali.CULL_BACK_FACE // Cull back facing polygons
96 * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygons
97 * actor.SetCullFace( dali.CULL_FRONT_FACE );
99 void RenderableActorApi::SetCullFace( const v8::FunctionCallbackInfo<v8::Value>& args )
101 v8::Isolate* isolate = args.GetIsolate();
102 v8::HandleScope handleScope( isolate );
103 RenderableActor actor = GetRenderableActor( isolate, args );
106 int cullMode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
109 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
113 actor.SetCullFace( static_cast<Dali::CullFaceMode>( cullMode ) );
118 * Retrieve the face-culling mode for this actor.
119 * @for RenderableActor
120 * @method getCullFace
121 * @return {Number} cullMode
123 * // cull mode is one of the following
124 * dali.CULL_FACE_DISABLE // Face culling disabled
125 * dali.CULL_FRONT_FACE // Cull front facing polygons
126 * dali.CULL_BACK_FACE // Cull back facing polygons
127 * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygon
129 void RenderableActorApi::GetCullFace( const v8::FunctionCallbackInfo<v8::Value>& args )
131 v8::Isolate* isolate = args.GetIsolate();
132 v8::HandleScope handleScope( isolate );
133 RenderableActor actor = GetRenderableActor( isolate, args );
135 args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetCullFace() ) );
140 * Sets the blending mode.
142 * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work.
145 * // blend mode is one of the following
146 * dali.BLENDING_OFF // Blending is disabled.
147 * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
148 * dali.BLENDING_ON // Blending is enabled.
149 * actor.SetBlendMode( dali.BLENDING_AUTO );
151 * @for RenderableActor
152 * @method setBlendMode
153 * @param { Number } blendMode
155 void RenderableActorApi::SetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
157 v8::Isolate* isolate = args.GetIsolate();
158 v8::HandleScope handleScope( isolate );
159 RenderableActor actor = GetRenderableActor( isolate, args );
162 int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
165 DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter" );
168 actor.SetBlendMode( static_cast<Dali::BlendingMode::Type>( mode ) );
173 * @for RenderableActor
174 * @method getBlendMode
175 * @return { Number } blendMode
176 * @example returns one of the following:
178 * dali.BLENDING_OFF // Blending is disabled.
179 * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
180 * dali.BLENDING_ON // Blending is enabled.
183 void RenderableActorApi::GetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
185 v8::Isolate* isolate = args.GetIsolate();
186 v8::HandleScope handleScope( isolate );
187 RenderableActor actor = GetRenderableActor( isolate, args );
189 args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetBlendMode() ) );
194 * @for RenderableActor
195 * @method setBlendFunc
196 * @param {Number} SourceBlending RGB
197 * @param {Number} DestinationBlending RGB
198 * @param {Number} SourceBlending Alpha
199 * @param {Number} DestinatinoBlending Alpha
201 * //blending constants
202 dali.BLEND_FACTOR_ZERO
203 dali.BLEND_FACTOR_ONE
204 dali.BLEND_FACTOR_SRC_COLOR
205 dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR
206 dali.BLEND_FACTOR_SRC_ALPHA
207 dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
208 dali.BLEND_FACTOR_DST_ALPHA
209 dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA
210 dali.BLEND_FACTOR_DST_COLOR
211 dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR
212 dali.BLEND_FACTOR_SRC_ALPHA_SATURATE
213 dali.BLEND_FACTOR_CONSTANT_COLOR
214 dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
215 dali.BLEND_FACTOR_CONSTANT_ALPHA
216 dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
218 actor.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
219 dali.BLEND_FACTOR_CONSTANT_ALPHA, BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA);
223 void RenderableActorApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
225 v8::Isolate* isolate = args.GetIsolate();
226 v8::HandleScope handleScope( isolate );
227 RenderableActor actor = GetRenderableActor( isolate, args );
230 bool foundAllParams(false);
231 V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args,0 );
234 actor.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]),
235 static_cast< Dali::BlendingFactor::Type>(params[1]),
236 static_cast< Dali::BlendingFactor::Type>(params[2]),
237 static_cast< Dali::BlendingFactor::Type>(params[3]));
241 DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter");
247 * @for RenderableActor
248 * @method GetBlendFunc
249 * @return {Object} BlendProperties
250 * @example Blend properties object has 4 fields
252 * blendProperties.sourceRgb // source rgb enum
253 * blendProperties.destinationRgb // destination rgb enum
254 * blendProperties.sourceAlpha source // alpha enum
255 * blendProperties.destinationAlpha // destination alpha enum
257 void RenderableActorApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
259 // @todo pass by reference doesn't work in Javascript so need to decide what to return
260 // for now just return a vector 4...
262 BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
263 v8::Isolate* isolate = args.GetIsolate();
264 v8::HandleScope handleScope( isolate );
265 RenderableActor actor = GetRenderableActor( isolate, args );
267 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
269 v8::Local<v8::Object> blendInfo = v8::Object::New( isolate );
271 blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) );
272 blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) );
273 blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) );
274 blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) );
276 args.GetReturnValue().Set( blendInfo );
281 * @for RenderableActor
282 * @method getShaderEffect
283 * @return {Object} ShaderEffect object
285 * Retrieve the shader effect for the Actor.
288 * var shaderEffect = actor.getShaderEffect();
291 void RenderableActorApi::GetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
293 v8::Isolate* isolate = args.GetIsolate();
294 v8::HandleScope handleScope( isolate );
295 RenderableActor actor = GetRenderableActor( isolate, args );
297 v8::Local < v8::Object > object = ShaderEffectWrapper::WrapShaderEffect( isolate, actor.GetShaderEffect() );
298 args.GetReturnValue().Set( object );
303 * @for RenderableActor
304 * @method setShaderEffect
305 * @param {Object} shaderEffect The shader effect.
307 * Sets the shader effect for the Actor.
309 * Shader effects provide special effects like rippling and bending.
310 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
312 * // first create the shaderOptions, then the shaderEffect
313 * var shader = new dali.ShaderEffect( shaderOptions );
314 * actor.setShaderEffect( shader );
317 void RenderableActorApi::SetShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
319 v8::Isolate* isolate = args.GetIsolate();
320 v8::HandleScope handleScope( isolate );
321 RenderableActor actor = GetRenderableActor( isolate, args );
324 ShaderEffect effect = ShaderEffectApi::GetShaderEffectFromParams( 0, found, isolate, args );
327 actor.SetShaderEffect( effect );
331 DALI_SCRIPT_EXCEPTION( isolate, "shader effect parameter missing" );
337 * Removes the current shader effect
340 * actor.removeShaderEffect();
342 * @for RenderableActor
343 * @method removeShaderEffect
345 void RenderableActorApi::RemoveShaderEffect( const v8::FunctionCallbackInfo<v8::Value>& args )
347 v8::Isolate* isolate = args.GetIsolate();
348 v8::HandleScope handleScope( isolate );
349 RenderableActor actor = GetRenderableActor( isolate, args );
350 actor.RemoveShaderEffect();
355 } // namespace V8Plugin