Rendering API clean-up
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / rendering / renderer-api.cpp
index fb2c0a8..5efcd94 100644 (file)
@@ -27,8 +27,9 @@
 #include <rendering/renderer-wrapper.h>
 #include <rendering/geometry-api.h>
 #include <rendering/geometry-wrapper.h>
-#include <rendering/material-api.h>
-#include <rendering/material-wrapper.h>
+#include <rendering/texture-set-api.h>
+#include <rendering/texture-set-wrapper.h>
+#include <rendering/shader-api.h>
 
 namespace Dali
 {
@@ -85,7 +86,7 @@ Renderer RendererApi::GetRendererFromParams( int paramIndex,
  * @method Renderer
  * @for Renderer
  * @param {Object} geometry The geometry to be used by this renderer
- * @param {Object} material The material to be used by this renderer
+ * @param {Object} shader The shader to be used by this renderer
  * @return {Object} Renderer
  */
 Renderer RendererApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
@@ -102,14 +103,14 @@ Renderer RendererApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
   }
 
   found = false;
-  Material material = MaterialApi::GetMaterialFromParams( 1, found, isolate, args );
+  Shader shader = ShaderApi::GetShaderFromParams( 1, found, isolate, args );
   if( !found )
   {
-    DALI_SCRIPT_EXCEPTION( isolate, "missing material from param 0" );
+    DALI_SCRIPT_EXCEPTION( isolate, "missing shader from param 0" );
     return Renderer();
   }
 
-  return Renderer::New(geometry, material);
+  return Renderer::New(geometry, shader);
 }
 
 /**
@@ -159,13 +160,13 @@ void RendererApi::GetGeometry( const v8::FunctionCallbackInfo<v8::Value>& args )
 }
 
 /**
- * Sets the material to be used by this renderer
+ * Sets the texture set to be used by this renderer
  *
- * @method setMaterial
+ * @method setTextures
  * @for Renderer
- * @param {Object} material The material to be used by this renderer
+ * @param {Object} textureSet The TextureSet to be used by this renderer
  */
-void RendererApi::SetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args )
+void RendererApi::SetTextures( const v8::FunctionCallbackInfo< v8::Value >& args )
 {
   v8::Isolate* isolate = args.GetIsolate();
   v8::HandleScope handleScope( isolate );
@@ -173,37 +174,193 @@ void RendererApi::SetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args
   Renderer renderer = GetRenderer( isolate, args );
 
   bool found( false );
-  Material material = MaterialApi::GetMaterialFromParams( 0, found, isolate, args );
+  TextureSet textureSet = TextureSetApi::GetTextureSetFromParams( 0, found, isolate, args );
   if( !found )
   {
-    DALI_SCRIPT_EXCEPTION( isolate, "missing material from param 0" );
+    DALI_SCRIPT_EXCEPTION( isolate, "missing texture set from param 0" );
   }
   else
   {
-    renderer.SetMaterial(material);
+    renderer.SetTextures(textureSet);
   }
 }
 
 /**
- * Gets the material used by this renderer
+ * Gets the texture set used by this renderer
  *
- * @method getMaterial
+ * @method getTextures
  * @for Renderer
- * @return {Object} The material used by this renderer
+ * @return {Object} The texture set used by this renderer
  */
-void RendererApi::GetMaterial( const v8::FunctionCallbackInfo<v8::Value>& args )
+void RendererApi::GetTextures( const v8::FunctionCallbackInfo<v8::Value>& args )
 {
   v8::Isolate* isolate = args.GetIsolate();
   v8::HandleScope handleScope( isolate );
 
   Renderer renderer = GetRenderer( isolate, args );
-  Material material = renderer.GetMaterial();
+  TextureSet textureSet = renderer.GetTextures();
 
-  // Wrap the material
-  v8::Local<v8::Object> localObject = MaterialWrapper::WrapMaterial( isolate, material );
+  // Wrap the textureset
+  v8::Local<v8::Object> localObject = TextureSetWrapper::WrapTextureSet( isolate, textureSet );
   args.GetReturnValue().Set( localObject );
 }
 
+/**
+ * Specify the pixel arithmetic used when the actor is blended.
+ *
+ * @for Renderer
+ * @method setBlendFunc
+ * @param {integer} srcFactorRgb Source Blending RGB
+ * @param {integer} destFactorRgb Destination Blending RGB
+ * @param {integer} srcFactorAlpha Source Blending Alpha
+ * @param {integer} destFactorAlpha Destination Blending Alpha
+ * @example
+ *    //blending constants
+ *    dali.BLEND_FACTOR_ZERO
+ *    dali.BLEND_FACTOR_ONE
+ *    dali.BLEND_FACTOR_SRC_COLOR
+ *    dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR
+ *    dali.BLEND_FACTOR_SRC_ALPHA
+ *    dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
+ *    dali.BLEND_FACTOR_DST_ALPHA
+ *    dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA
+ *    dali.BLEND_FACTOR_DST_COLOR
+ *    dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR
+ *    dali.BLEND_FACTOR_SRC_ALPHA_SATURATE
+ *    dali.BLEND_FACTOR_CONSTANT_COLOR
+ *    dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
+ *    dali.BLEND_FACTOR_CONSTANT_ALPHA
+ *    dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
+ *
+ *    renderer.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
+ *                           dali.BLEND_FACTOR_CONSTANT_ALPHA, dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA );
+ */
+void RendererApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  Renderer renderer = GetRenderer( isolate, args );
+
+  int params[4];
+  bool foundAllParams(false);
+  V8Utils::ReadIntegerArguments( foundAllParams, &params[0], 4, args, 0 );
+  if( foundAllParams )
+  {
+    renderer.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]),
+                           static_cast< Dali::BlendingFactor::Type>(params[1]),
+                           static_cast< Dali::BlendingFactor::Type>(params[2]),
+                           static_cast< Dali::BlendingFactor::Type>(params[3]) );
+  }
+  else
+  {
+    DALI_SCRIPT_EXCEPTION( isolate, "invalid blendFunc parameter");
+  }
+}
+
+/**
+ * Query the pixel arithmetic used when the actor is blended.
+ *
+ * @for Renderer
+ * @method getBlendFunc
+ * @return {Object} Blend properties
+ * @example Blend properties object has 4 fields
+ *
+ *      blendProperties.sourceRgb // source rgb enum
+ *      blendProperties.destinationRgb // destination rgb enum
+ *      blendProperties.sourceAlpha source // alpha enum
+ *      blendProperties.destinationAlpha // destination alpha enum
+ */
+void RendererApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  // Pass by reference doesn't work in Javascript
+  // For now just return a vector 4...
+
+  BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha;
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  Renderer renderer = GetRenderer( isolate, args );
+
+  renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+
+  v8::Local<v8::Object> blendProperties = v8::Object::New( isolate );
+
+  blendProperties->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ),        v8::Integer::New( isolate, srcFactorRgb) );
+  blendProperties->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ),   v8::Integer::New( isolate, destFactorRgb ) );
+  blendProperties->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ),      v8::Integer::New( isolate, srcFactorAlpha  ) );
+  blendProperties->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) );
+
+  args.GetReturnValue().Set( blendProperties );
+}
+
+/**
+ * Specify the equation used when the actor is blended.
+ *
+ * @for Renderer
+ * @method setBlendEquation
+ * @param { integer } equationRgb The equation used for combining red, green, and blue components.
+ * @param { integer } equationAlpha The equation used for combining the alpha component.
+ * @example
+ *      // blend equation is one of the following
+ *      dali.BLEND_EQUATION_ADD
+ *      dali.BLEND_EQUATION_SUBTRACT
+ *      dali.BLEND_EQUATION_REVERSE_SUBTRACT
+ *
+ *      renderer.setBlendEquation( dali.BLEND_EQUATION_ADD, dali.BLEND_EQUATION_REVERSE_SUBTRACT );
+ */
+void RendererApi::SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  Renderer renderer = GetRenderer( isolate, args );
+
+  int params[2];
+  bool foundAllParams(false);
+  V8Utils::ReadIntegerArguments( foundAllParams, &params[0], 2, args, 0 );
+  if( foundAllParams )
+  {
+    renderer.SetBlendEquation( static_cast< BlendingEquation::Type>(params[0]), static_cast< BlendingEquation::Type>(params[1]) );
+  }
+  else
+  {
+    DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendEquation parameter");
+  }
+}
+
+/**
+ * Query the equation used when the actor is blended.
+ *
+ * @for Renderer
+ * @method getBlendEquation
+ * @return {Object} Blend equations
+ * @example Blend equations object has 2 fields
+ *
+ *      blendEquations.equationRgb // equation used for combining rgb components
+ *      blendEquations.equationAlpha // equation used for combining alpha components
+ */
+void RendererApi::GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  // Pass by reference doesn't work in Javascript
+  // For now just return a vector 2...
+
+  BlendingEquation::Type equationRgb, equationAlpha;
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  Renderer renderer = GetRenderer( isolate, args );
+
+  renderer.GetBlendEquation( equationRgb, equationAlpha );
+
+  v8::Local<v8::Object> blendEquations = v8::Object::New( isolate );
+
+  blendEquations->Set( v8::String::NewFromUtf8( isolate, "equationRgb" ),   v8::Integer::New( isolate, equationRgb) );
+  blendEquations->Set( v8::String::NewFromUtf8( isolate, "equationAlpha" ), v8::Integer::New( isolate, equationAlpha ) );
+
+  args.GetReturnValue().Set( blendEquations );
+}
+
 } // namespace V8Plugin
 
 } // namespace Dali