'<(DALI_JS_DIR)/image/resource-image-api.cpp',
'<(DALI_JS_DIR)/image/nine-patch-image-api.cpp',
'<(DALI_JS_DIR)/object/handle-wrapper.cpp',
+ '<(DALI_JS_DIR)/object/property-buffer-api.cpp',
+ '<(DALI_JS_DIR)/object/property-buffer-wrapper.cpp',
'<(DALI_JS_DIR)/object/property-value-wrapper.cpp',
'<(DALI_JS_DIR)/signals/signal-manager.cpp',
'<(DALI_JS_DIR)/render-tasks/render-task-list-api.cpp',
'<(DALI_JS_DIR)/render-tasks/render-task-list-wrapper.cpp',
'<(DALI_JS_DIR)/render-tasks/render-task-api.cpp',
'<(DALI_JS_DIR)/render-tasks/render-task-wrapper.cpp',
+ '<(DALI_JS_DIR)/rendering/geometry-api.cpp',
+ '<(DALI_JS_DIR)/rendering/geometry-wrapper.cpp',
+ '<(DALI_JS_DIR)/rendering/material-api.cpp',
+ '<(DALI_JS_DIR)/rendering/material-wrapper.cpp',
+ '<(DALI_JS_DIR)/rendering/renderer-api.cpp',
+ '<(DALI_JS_DIR)/rendering/renderer-wrapper.cpp',
+ '<(DALI_JS_DIR)/rendering/sampler-api.cpp',
+ '<(DALI_JS_DIR)/rendering/sampler-wrapper.cpp',
+ '<(DALI_JS_DIR)/rendering/shader-api.cpp',
+ '<(DALI_JS_DIR)/rendering/shader-wrapper.cpp',
'<(DALI_JS_DIR)/toolkit/builder/builder-api.cpp',
'<(DALI_JS_DIR)/toolkit/builder/builder-wrapper.cpp',
'<(DALI_JS_DIR)/toolkit/focus-manager/keyboard-focus-manager-api.cpp',
--- /dev/null
+ var window= {
+ x:0,
+ y:0,
+ width:1920,
+ height: 1080,
+ transparent: false,
+ name:'line-mesh-app'
+ };
+
+ var viewMode={
+ 'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced,
+ 'stereo-base': 65 // Distance in millimeters between left/right cameras typically between (50-70mm)
+ };
+
+ var options= {
+ 'window': window,
+ 'view-mode': viewMode,
+ }
+
+var dali = require('./build/Release/dali')( options );
+
+var daliApp = {};
+
+daliApp.createMeshActor = function() {
+
+ // Create shader
+ var vertShader =
+ "attribute mediump vec2 aPosition1;\
+ attribute mediump vec2 aPosition2;\
+ uniform mediump mat4 uMvpMatrix;\
+ uniform mediump vec3 uSize;\
+ uniform mediump float uMorphAmount;\
+ void main()\
+ {\
+ mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount);\
+ mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0);\
+ vertexPosition.xyz *= uSize;\
+ vertexPosition = uMvpMatrix * vertexPosition;\
+ gl_Position = vertexPosition;\
+ }";
+
+ var fragShader =
+ "uniform lowp vec4 uColor;\
+ uniform sampler2D sTexture;\
+ void main()\
+ {\
+ gl_FragColor = uColor;\
+ }";
+
+ var shaderOptions = {
+ vertexShader : vertShader,
+ fragmentShader: fragShader
+ };
+
+ var shader = new dali.Shader(shaderOptions);
+
+ var material = new dali.Material( shader );
+
+ // Create vertex buffer
+ var pentagonVertexFormat ={ "aPosition1" : dali.PROPERTY_VECTOR2 };
+
+ var pentagonVertexData = [ 0, 1,
+ -0.95, 0.31,
+ -0.59, -0.81,
+ 0.59, -0.81,
+ 0.95, 0.31];
+
+ var pentagonVertexDataArray = new Float32Array(pentagonVertexData.length);
+ pentagonVertexDataArray.set(pentagonVertexData, 0);
+ var pentagonVertices = new dali.PropertyBuffer(pentagonVertexFormat, 5);
+ pentagonVertices.setData(pentagonVertexDataArray);
+
+ var pentacleVertexFormat ={ "aPosition2" : dali.PROPERTY_VECTOR2};
+
+ var pentacleVertexData = [ 0, -1,
+ 0.59, 0.81,
+ -0.95, -0.31,
+ 0.95, -0.31,
+ -0.59, 0.81];
+
+ var pentacleVertexDataArray = new Float32Array(pentacleVertexData.length);
+ pentacleVertexDataArray.set(pentacleVertexData, 0);
+ var pentacleVertices = new dali.PropertyBuffer(pentacleVertexFormat, 5);
+ pentacleVertices.setData(pentacleVertexDataArray);
+
+ var indexFormat ={ "indices" : dali.PROPERTY_INTEGER };
+
+ var indexData = [0, 1, 1, 2, 2, 3, 3, 4, 4, 0];
+
+ var indexDataArray = new Uint32Array(indexData.length);
+ indexDataArray.set(indexData, 0);
+ var indices = new dali.PropertyBuffer(indexFormat, 10);
+ indices.setData(indexDataArray);
+
+ // Create geometry
+ var geometry = new dali.Geometry();
+ geometry.addVertexBuffer( pentagonVertices );
+ geometry.addVertexBuffer( pentacleVertices );
+ geometry.setIndexBuffer( indices );
+ geometry.setGeometryType( dali.GEOMETRY_LINES );
+
+ var renderer = new dali.Renderer(geometry, material);
+ renderer.depthIndex = 0;
+
+ // Create mesh actor
+ var meshActor = new dali.Actor();
+ meshActor.addRenderer( renderer );
+ meshActor.size = [300, 300, 0];
+ meshActor.parentOrigin = dali.CENTER;
+ meshActor.anchorPoint = dali.CENTER;
+ meshActor.registerAnimatableProperty("uMorphAmount", 0.0);
+
+ dali.stage.add( meshActor );
+
+ // Animate the mesh actor
+ var animation = new dali.Animation(5);
+
+ var keyFramesIndex = [{progress:0.0, value: 0.0}, {progress:1.0, value:1.0}];
+ var animOptions = { alpha:"sin", delay:0, duration:5};
+
+ animation.animateBetween( meshActor, "uMorphAmount", keyFramesIndex, animOptions );
+ animation.setLooping(true);
+ animation.play();
+}
+
+function startup()
+{
+ daliApp.init();
+}
+
+daliApp.init = function()
+{
+ daliApp.createMeshActor();
+}
+
+
+startup();
+
--- /dev/null
+ var window= {
+ x:0,
+ y:0,
+ width:1920,
+ height: 1080,
+ transparent: false,
+ name:'mesh-morph-app'
+ };
+
+ var viewMode={
+ 'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced,
+ 'stereo-base': 65 // Distance in millimeters between left/right cameras typically between (50-70mm)
+ };
+
+ var options= {
+ 'window': window,
+ 'view-mode': viewMode,
+ }
+
+var dali = require('./build/Release/dali')( options );
+
+var daliApp = {};
+
+daliApp.createMeshActor = function() {
+
+ // Create shader
+ var vertShader =
+ "attribute mediump vec2 aInitPos;\
+ attribute mediump vec2 aFinalPos;\
+ attribute mediump vec3 aColor;\
+ uniform mediump mat4 uMvpMatrix;\
+ uniform mediump vec3 uSize;\
+ uniform mediump float uDelta;\
+ uniform lowp vec4 uColor;\
+ varying lowp vec4 vColor;\
+ void main()\
+ {\
+ mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0);\
+ vertexPosition.xyz *= uSize;\
+ vertexPosition = uMvpMatrix * vertexPosition;\
+ gl_Position = vertexPosition;\
+ vColor = vec4(aColor, 0.) * uColor;\
+ }";
+
+ var fragShader =
+ "varying lowp vec4 vColor;\
+ void main()\
+ {\
+ gl_FragColor = vColor;\
+ }";
+
+ var shaderOptions = {
+ vertexShader : vertShader,
+ fragmentShader : fragShader
+ };
+
+ var shader = new dali.Shader(shaderOptions);
+
+ var material = new dali.Material( shader );
+
+ // Create vertex buffer for initial positions
+ var initialPositionVertexFormat = { "aInitPos" : dali.PROPERTY_VECTOR2 };
+
+ var initialPositionVertexData = [
+ // yellow
+ -0.50, -0.50,
+ 0.0, 0.0,
+ -0.50, 0.50,
+
+ // green
+ -0.50, -0.50,
+ 0.50, -0.50,
+ 0.0, 0.0,
+
+ // blue
+ 0.50, -0.50,
+ 0.50, 0.0,
+ 0.25, -0.25,
+
+ // red
+ 0.25, -0.25,
+ 0.50, 0.0,
+ 0.25, 0.25,
+ 0.25, 0.25,
+ 0.0, 0.0,
+ 0.25, -0.25,
+
+ // cyan
+ 0.0, 0.0,
+ 0.25, 0.25,
+ -0.25, 0.25,
+
+ // magenta
+ -0.25, 0.25,
+ 0.25, 0.25,
+ 0.0, 0.50,
+ 0.0, 0.50,
+ -0.50, 0.50,
+ -0.25, 0.25,
+
+ // orange
+ 0.50, 0.0,
+ 0.50, 0.50,
+ 0.0, 0.50
+ ];
+
+ var initialPositionVertexDataArray = new Float32Array(initialPositionVertexData.length);
+ initialPositionVertexDataArray.set(initialPositionVertexData, 0);
+ var initialPositionVertices = new dali.PropertyBuffer(initialPositionVertexFormat, 27);
+ initialPositionVertices.setData(initialPositionVertexDataArray);
+
+ // Create vertex buffer for final positions
+ var finalPositionVertexFormat = { "aFinalPos" : dali.PROPERTY_VECTOR2 };
+
+ var bigSide = 0.707106781;
+ var side = bigSide * 0.5;
+
+ var finalPositionVertexData = [
+ // yellow
+ side, 0.25, // pA
+ side, 0.25 + bigSide, // pB
+ side - bigSide, 0.25 + bigSide, // pC
+
+ // green
+ side - 0.50, -0.25, // pD
+ side, 0.25, // pA
+ side - 0.50, 0.75, // pE
+
+ // blue
+ side - 0.50, -0.75, // pJ
+ side - 0.50, -0.25, // pD
+ side - 0.75, -0.50, // pI
+
+ // red
+ side - 0.75, -0.50, // pI
+ side - 0.50, -0.25, // pD
+ side - 0.75, 0.0, // pG
+ side - 0.75, 0.0, // pG
+ side - 1.0, -0.25, // pH
+ side - 0.75, -0.50, // pI
+
+ // cyan
+ side - 0.75, -0.50, // pI
+ side - 1.0, -0.25, // pH
+ side - 1.0, -0.75, // pK
+
+ // magenta
+ side, 0.25 + bigSide - side, // pL
+ side * 2.0, 0.25 + bigSide - side * 2.0, // pM
+ side * 2.0, 0.25 + bigSide - side, // pN
+ side * 2.0, 0.25 + bigSide - side, // pN
+ side, 0.25 + bigSide, // pB
+ side, 0.25 + bigSide - side, // pL
+
+ // orange
+ side - 0.50, -0.25, // pD
+ side - 0.50, -0.25 + bigSide, // pF2
+ - 0.50, -0.25 + side // pF
+ ];
+
+ var finalPositionVertexDataArray = new Float32Array(finalPositionVertexData.length);
+ finalPositionVertexDataArray.set(finalPositionVertexData, 0);
+ var finalPositionVertices = new dali.PropertyBuffer(finalPositionVertexFormat, 27);
+ finalPositionVertices.setData(finalPositionVertexDataArray);
+
+ // Create vertex buffer for color
+ var colorVertexFormat = { "aColor" : dali.PROPERTY_VECTOR3 };
+
+ var colorVertexData = [
+ // yellow
+ 1.0, 1.0, 0.0,
+ 1.0, 1.0, 0.0,
+ 1.0, 1.0, 0.0,
+
+ // green
+ 0.0, 1.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 1.0, 0.0,
+
+ // blue
+ 0.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0,
+
+ // red
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+
+ // cyan
+ 0.0, 1.0, 1.0,
+ 0.0, 1.0, 1.0,
+ 0.0, 1.0, 1.0,
+
+ // magenta
+ 1.0, 0.0, 1.0,
+ 1.0, 0.0, 1.0,
+ 1.0, 0.0, 1.0,
+ 1.0, 0.0, 1.0,
+ 1.0, 0.0, 1.0,
+ 1.0, 0.0, 1.0,
+
+ // orange
+ 1.0, 0.5, 0.0,
+ 1.0, 0.5, 0.0,
+ 1.0, 0.5, 0.0
+ ];
+
+ var colorVertexDataArray = new Float32Array(colorVertexData.length);
+ colorVertexDataArray.set(colorVertexData, 0);
+ var colorVertices = new dali.PropertyBuffer(colorVertexFormat, 27);
+ colorVertices.setData(colorVertexDataArray);
+
+ // Create geometry
+ var geometry = new dali.Geometry();
+ geometry.addVertexBuffer( initialPositionVertices );
+ geometry.addVertexBuffer( finalPositionVertices );
+ geometry.addVertexBuffer( colorVertices );
+
+ var renderer = new dali.Renderer(geometry, material);
+ renderer.depthIndex = 0;
+
+ // Create mesh actor
+ var meshActor = new dali.Actor();
+ meshActor.addRenderer( renderer );
+ meshActor.size = [400, 400, 0];
+ meshActor.parentOrigin = dali.CENTER;
+ meshActor.anchorPoint = dali.CENTER;
+ meshActor.registerAnimatableProperty("uDelta", 0.0);
+
+ dali.stage.add( meshActor );
+
+ // Animate the mesh actor
+ var animation = new dali.Animation(5);
+
+ var animOptions = { alpha:"sin", delay:0, duration:5};
+
+ animation.animateTo( meshActor, "uDelta", 1.0, animOptions );
+ animation.setLooping(true);
+ animation.play();
+}
+
+function startup()
+{
+ daliApp.init();
+}
+
+daliApp.init = function()
+{
+ daliApp.createMeshActor();
+}
+
+
+startup();
+
--- /dev/null
+ var window= {
+ x:0,
+ y:0,
+ width:1920,
+ height: 1080,
+ transparent: false,
+ name:'line-mesh-app'
+ };
+
+ var viewMode={
+ 'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced,
+ 'stereo-base': 65 // Distance in millimeters between left/right cameras typically between (50-70mm)
+ };
+
+ var options= {
+ 'window': window,
+ 'view-mode': viewMode,
+ }
+
+var imageDir = "./";
+
+var dali = require('./build/Release/dali')( options );
+
+var daliApp = {};
+
+daliApp.createMeshActor = function() {
+
+ // Create shader
+ var vertShader =
+ "attribute mediump vec2 aPosition;\
+ attribute highp float aHue;\
+ varying mediump vec2 vTexCoord;\
+ uniform mediump mat4 uMvpMatrix;\
+ uniform mediump vec3 uSize;\
+ uniform mediump float uPointSize;\
+ uniform lowp vec4 uFadeColor;\
+ varying mediump vec3 vVertexColor;\
+ varying mediump float vHue;\
+ vec3 hsv2rgb(vec3 c)\
+ {\
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\
+ }\
+ void main()\
+ {\
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\
+ vertexPosition.xyz *= (uSize-uPointSize);\
+ vertexPosition = uMvpMatrix * vertexPosition;\
+ vVertexColor = hsv2rgb( vec3( aHue, 0.7, 1.0 ) );\
+ vHue = aHue;\
+ gl_PointSize = uPointSize;\
+ gl_Position = vertexPosition;\
+ }";
+
+ var fragShader =
+ "varying mediump vec3 vVertexColor;\
+ varying mediump float vHue;\
+ uniform lowp vec4 uColor;\
+ uniform sampler2D sTexture1;\
+ uniform sampler2D sTexture2;\
+ uniform lowp vec4 uFadeColor;\
+ void main()\
+ {\
+ mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord);\
+ mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord);\
+ gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1*vHue) + (texCol2*(1.0-vHue)));\
+ }";
+
+ var shaderOptions = {
+ vertexShader : vertShader,
+ fragmentShader: fragShader
+ };
+
+ var shader = new dali.Shader(shaderOptions);
+
+ var material = new dali.Material( shader );
+ var image = new dali.ResourceImage( {url: imageDir + "image-1.jpg"} );
+ material.addTexture(image, "sTexture");
+
+ // Create vertex buffer
+ var polyhedraVertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2,
+ "aHue" : dali.PROPERTY_FLOAT };
+
+ var numSides = 20;
+ var angle = 0;
+ var sectorAngle = 2.0 * Math.PI / numSides;
+
+ var polyhedraVertexData = [];
+ for(i=0; i<numSides; ++i)
+ {
+ var positionX = Math.sin(angle) * 0.5;
+ var positionY = Math.cos(angle) * 0.5;
+ var hue = angle / ( 2.0 * Math.PI);
+
+ polyhedraVertexData[i*3+0] = positionX;
+ polyhedraVertexData[i*3+1] = positionY;
+ polyhedraVertexData[i*3+2] = hue;
+
+ angle += sectorAngle;
+ }
+
+ var polyhedraVertexDataArray = new Float32Array(polyhedraVertexData.length);
+ polyhedraVertexDataArray.set(polyhedraVertexData, 0);
+ var polyhedraVertices = new dali.PropertyBuffer(polyhedraVertexFormat, numSides);
+ polyhedraVertices.setData(polyhedraVertexDataArray);
+
+ // Create geometry
+ var geometry = new dali.Geometry();
+ geometry.addVertexBuffer( polyhedraVertices );
+ geometry.setGeometryType( dali.GEOMETRY_POINTS );
+
+ var renderer = new dali.Renderer(geometry, material);
+ renderer.registerAnimatableProperty("uFadeColor", [1.0, 0.0, 1.0, 1.0]); // Green
+ renderer.registerAnimatableProperty("uPointSize", 80.0);
+ renderer.depthIndex = 0;
+
+ // Create mesh actor
+ var meshActor = new dali.Actor();
+ meshActor.addRenderer( renderer );
+ meshActor.size = [400, 400, 0];
+ meshActor.parentOrigin = dali.CENTER;
+ meshActor.anchorPoint = dali.CENTER;
+ meshActor.registerAnimatableProperty("uFadeColor", [0.0, 1.0, 0.0, 1.0]); // Magenta
+
+ dali.stage.add( meshActor );
+
+ // Animate the mesh actor
+ var animation = new dali.Animation(5);
+ var animOptions = { alpha:"linear", delay:0, duration:5};
+ var rotation = new dali.Rotation(360,0,0,1);
+ animation.animateBy( meshActor, "orientation", rotation, animOptions );
+ animation.setLooping(true);
+ animation.play();
+}
+
+function startup()
+{
+ daliApp.init();
+}
+
+daliApp.init = function()
+{
+ daliApp.createMeshActor();
+}
+
+
+startup();
+
--- /dev/null
+ var window= {
+ x:0,
+ y:0,
+ width:1920,
+ height: 1080,
+ transparent: false,
+ name:'texture-mesh-app'
+ };
+
+ var viewMode={
+ 'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced,
+ 'stereo-base': 65 // Distance in millimeters between left/right cameras typically between (50-70mm)
+ };
+
+ var options= {
+ 'window': window,
+ 'view-mode': viewMode,
+ }
+
+var imageDir = "./";
+
+var dali = require('./build/Release/dali')( options );
+
+var daliApp = {};
+
+daliApp.createMeshActor = function() {
+
+ // Create shader
+ var vertShader =
+ "attribute mediump vec2 aPosition;\
+ attribute highp vec2 aTexCoord;\
+ varying mediump vec2 vTexCoord;\
+ uniform mediump mat4 uMvpMatrix;\
+ uniform mediump vec3 uSize;\
+ uniform lowp vec4 uFadeColor;\
+ void main()\
+ {\
+ mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\
+ vertexPosition.xyz *= uSize;\
+ vertexPosition = uMvpMatrix * vertexPosition;\
+ vTexCoord = aTexCoord;\
+ gl_Position = vertexPosition;\
+ }";
+
+ var fragShader =
+ "varying mediump vec2 vTexCoord;\
+ uniform lowp vec4 uColor;\
+ uniform sampler2D sTexture;\
+ uniform lowp vec4 uFadeColor;\
+ void main()\
+ {\
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * uFadeColor;\
+ }";
+
+ var shaderOptions = {
+ vertexShader : vertShader,
+ fragmentShader: fragShader
+ };
+
+ var shader = new dali.Shader(shaderOptions);
+
+ var material = new dali.Material( shader );
+ var image = new dali.ResourceImage( {url: imageDir + "image-1.jpg"} );
+ material.addTexture(image, "sTexture");
+
+ var material2 = new dali.Material( shader );
+ var image2 = new dali.ResourceImage( {url: imageDir + "image-2.jpg"} );
+ material2.addTexture(image2, "sTexture");
+
+ // Create vertex buffer
+ var texturedQuadVertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2,
+ "aTexCoord" : dali.PROPERTY_VECTOR2 };
+
+ var halfQuadSize = 0.5;
+ var texturedQuadVertexData = [ -halfQuadSize, -halfQuadSize, 0.0, 0.0,
+ halfQuadSize, -halfQuadSize, 1.0, 0.0,
+ -halfQuadSize, halfQuadSize, 0.0, 1.0,
+ halfQuadSize, halfQuadSize, 1.0, 1.0 ];
+
+ var texturedQuadVertexDataArray = new Float32Array(texturedQuadVertexData.length);
+ texturedQuadVertexDataArray.set(texturedQuadVertexData, 0);
+ var texturedQuadVertices = new dali.PropertyBuffer(texturedQuadVertexFormat, 4);
+ texturedQuadVertices.setData(texturedQuadVertexDataArray);
+
+ var indexFormat ={ "indices" : dali.PROPERTY_INTEGER };
+
+ var indexData = [0, 3, 1, 0, 2, 3];
+
+ var indexDataArray = new Uint32Array(indexData.length);
+ indexDataArray.set(indexData, 0);
+ var indices = new dali.PropertyBuffer(indexFormat, 6);
+ indices.setData(indexDataArray);
+
+ // Create geometry
+ var geometry = new dali.Geometry();
+ geometry.addVertexBuffer( texturedQuadVertices );
+ geometry.setIndexBuffer( indices );
+
+ var renderer = new dali.Renderer(geometry, material);
+ renderer.depthIndex = 0;
+
+ var meshActor = new dali.Actor();
+ meshActor.addRenderer( renderer );
+ meshActor.size = [530, 530, 0];
+ meshActor.parentOrigin = dali.TOP_CENTER;
+ meshActor.anchorPoint = dali.TOP_CENTER;
+ meshActor.registerAnimatableProperty("uFadeColor", [1.0, 0.0, 1.0, 1.0]);
+
+ dali.stage.add( meshActor );
+
+ var renderer2 = new dali.Renderer(geometry, material2);
+ renderer2.depthIndex = 0;
+
+ var meshActor2 = new dali.Actor();
+ meshActor2.addRenderer( renderer2 );
+ meshActor2.size = [530, 530, 0];
+ meshActor2.parentOrigin = dali.BOTTOM_CENTER;
+ meshActor2.anchorPoint = dali.BOTTOM_CENTER;
+ meshActor2.registerAnimatableProperty("uFadeColor", [0.0, 0.0, 1.0, 1.0]);
+
+ dali.stage.add( meshActor2 );
+
+ // Animate the mesh actors
+ var animation = new dali.Animation(5);
+
+ var keyFramesIndex = [{progress:0.0, value: [0.0, 0.0, 0.0, 0.0]}, {progress:1.0, value:[0.0, 1.0, 0.0, 1.0]}];
+ var animOptions = { alpha:"sin", delay:0, duration:5};
+
+ var keyFramesIndex2 = [{progress:0.0, value: [0.0, 0.0, 0.0, 0.0]}, {progress:1.0, value:[1.0, 0.0, 1.0, 1.0]}];
+ var animOptions2 = { alpha:"sin", delay:0, duration:5};
+
+ animation.animateBetween( meshActor, "uFadeColor", keyFramesIndex, animOptions );
+ animation.animateBetween( meshActor2, "uFadeColor", keyFramesIndex2, animOptions2 );
+ animation.setLooping(true);
+ animation.play();
+}
+
+function startup()
+{
+ daliApp.init();
+}
+
+daliApp.init = function()
+{
+ daliApp.createMeshActor();
+}
+
+
+startup();
+
* @class Actor
+ * @extends Handle
*/
| PIXEL_FORMAT_COMPRESSED_RGB8_ETC1 | integer value |
| PIXEL_FORMAT_COMPRESSED_RGB_PVRTC_4BPPV1 | integer value |
+|**Texture filtering mode ** | |
+|FILTER_MODE_NONE | integer value |
+|FILTER_MODE_DEFAULT | integer value |
+|FILTER_MODE_NEAREST | integer value |
+|FILTER_MODE_LINEAR | integer value |
+
+|**Sampler wrap mode ** | |
+|WRAP_MODE_DEFAULT | integer value |
+|WRAP_MODE_CLAMP_TO_EDGE | integer value |
+|WRAP_MODE_REPEAT | integer value |
+|WRAP_MODE_MIRRORED_REPEAT | integer value |
+
+|**Material face culling mode ** | |
+|MATERIAL_NONE | integer value |
+|MATERIAL_CULL_BACK | integer value |
+|MATERIAL_CULL_FRONT | integer value |
+|MATERIAL_CULL_BACK_AND_FRONT | integer value |
+
+|**Geometry primitives type ** | |
+|GEOMETRY_POINTS | integer value |
+|GEOMETRY_LINES | integer value |
+|GEOMETRY_LINE_LOOP | integer value |
+|GEOMETRY_LINE_STRIP | integer value |
+|GEOMETRY_TRIANGLES | integer value |
+|GEOMETRY_TRIANGLE_FAN | integer value |
+|GEOMETRY_TRIANGLE_STRIP | integer value |
+
+|**Property type ** | |
+|PROPERTY_NONE | integer value |
+|PROPERTY_BOOLEAN | integer value |
+|PROPERTY_FLOAT | integer value |
+|PROPERTY_INTEGER | integer value |
+|PROPERTY_VECTOR2 | integer value |
+|PROPERTY_VECTOR3 | integer value |
+|PROPERTY_VECTOR4 | integer value |
+|PROPERTY_MATRIX3 | integer value |
+|PROPERTY_MATRIX | integer value |
+|PROPERTY_RECTANGLE | integer value |
+|PROPERTY_ROTATION | integer value |
+|PROPERTY_STRING | integer value |
+|PROPERTY_ARRAY | integer value |
+|PROPERTY_MAP | integer value |
+|PROPERTY_INVALID_INDEX | integer value |
+
* @class Constants
*/
$(v8_plugin_dir)/image/resource-image-api.cpp \
$(v8_plugin_dir)/image/nine-patch-image-api.cpp \
$(v8_plugin_dir)/object/handle-wrapper.cpp \
+ $(v8_plugin_dir)/object/property-buffer-api.cpp \
+ $(v8_plugin_dir)/object/property-buffer-wrapper.cpp \
$(v8_plugin_dir)/object/property-value-wrapper.cpp \
$(v8_plugin_dir)/signals/signal-manager.cpp \
$(v8_plugin_dir)/render-tasks/render-task-list-api.cpp \
$(v8_plugin_dir)/render-tasks/render-task-list-wrapper.cpp \
$(v8_plugin_dir)/render-tasks/render-task-api.cpp \
$(v8_plugin_dir)/render-tasks/render-task-wrapper.cpp \
+ $(v8_plugin_dir)/rendering/geometry-api.cpp \
+ $(v8_plugin_dir)/rendering/geometry-wrapper.cpp \
+ $(v8_plugin_dir)/rendering/material-api.cpp \
+ $(v8_plugin_dir)/rendering/material-wrapper.cpp \
+ $(v8_plugin_dir)/rendering/renderer-api.cpp \
+ $(v8_plugin_dir)/rendering/renderer-wrapper.cpp \
+ $(v8_plugin_dir)/rendering/sampler-api.cpp \
+ $(v8_plugin_dir)/rendering/sampler-wrapper.cpp \
+ $(v8_plugin_dir)/rendering/shader-api.cpp \
+ $(v8_plugin_dir)/rendering/shader-wrapper.cpp \
$(v8_plugin_dir)/toolkit/builder/builder-api.cpp \
$(v8_plugin_dir)/toolkit/builder/builder-wrapper.cpp \
$(v8_plugin_dir)/toolkit/focus-manager/keyboard-focus-manager-api.cpp \
#include <v8-utils.h>
#include <actors/actor-wrapper.h>
#include <animation/path-constrainer-wrapper.h>
+#include <rendering/renderer-wrapper.h>
+#include <rendering/renderer-api.h>
namespace Dali
{
actor.ScaleBy( vector );
}
+/**
+ * Add a renderer to this actor.
+ * @example
+ *
+ * var renderer = new dali.Renderer( geometry, material );
+ * actor.addRenderer( renderer );
+ *
+ * @for Actor
+ * @method addRenderer
+ * @param {object} renderer Renderer to add to the actor
+ * @return {integer} The index of the Renderer that was added
+ */
+void ActorApi::AddRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ unsigned int index = 0;
+
+ bool found( false );
+ Renderer renderer = RendererApi::GetRendererFromParams( 0, found, isolate, args );
+ if( found )
+ {
+ index = actor.AddRenderer(renderer);
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Renderer parameter missing" );
+ return;
+ }
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, index ) );
+}
+
+/**
+ * Get the number of renderers on this actor.
+ * @example
+ *
+ * var count = actor.getRendererCount();
+ *
+ * @for Actor
+ * @method getRendererCount
+ * @return {integer} the number of renderers on this actor
+ */
+void ActorApi::GetRendererCount( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Actor actor = GetActor( isolate, args );
+ args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetRendererCount() ) );
+}
+
+/**
+ * Get a Renderer by index.
+ * @example
+ *
+ * var renderer = actor.getRendererAt( 0 );
+ *
+ * @for Actor
+ * @method getRendererAt
+ * @param {integer} index The index of the renderer to fetch, which must be between 0 and getRendererCount()-1
+ * @return {object} The renderer at the specified index
+ */
+void ActorApi::GetRendererAt( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ Renderer renderer;
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ return;
+ }
+ else
+ {
+ renderer = actor.GetRendererAt(static_cast<unsigned int>(index));
+ if( !renderer )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "renderer not found" );
+ return;
+ }
+ }
+
+ // Wrap the renderer
+ v8::Local<v8::Object> localObject = RendererWrapper::WrapRenderer( isolate, renderer );
+ args.GetReturnValue().Set( localObject );
+}
+
+/**
+ * Remove an renderer from the actor by index.
+ * @example
+ *
+ * actor.removeRenderer( 0 );
+ *
+ * @for Actor
+ * @method removeRenderer
+ * @param {integer} index Index of the renderer to be removed, which must be between 0 and getRendererCount()-1
+ */
+void ActorApi::RemoveRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+ Actor actor = GetActor( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ }
+ else
+ {
+ actor.RemoveRenderer(static_cast<unsigned int>(index));
+ }
+}
+
+
} // namespace V8Plugin
} // namespace Dali
void TranslateBy( const v8::FunctionCallbackInfo< v8::Value >& args );
void RotateBy( const v8::FunctionCallbackInfo< v8::Value >& args );
void ScaleBy( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AddRenderer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetRendererCount( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetRendererAt( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RemoveRenderer( const v8::FunctionCallbackInfo< v8::Value >& args );
// new function just for JavaScript API, to help developers know what type of actor
// they're dealing with, returns actor name as a string
{ "SetKeyboardFocusable", ActorApi::SetKeyboardFocusable, ACTOR_API }, //-- should this be a property???
{ "IsKeyboardFocusable" , ActorApi::IsKeyboardFocusable, ACTOR_API }, //-- should this be a property???
+ { "AddRenderer", ActorApi::AddRenderer, ACTOR_API },
+ { "GetRendererCount", ActorApi::GetRendererCount, ACTOR_API },
+ { "GetRendererAt" , ActorApi::GetRendererAt, ACTOR_API },
+ { "RemoveRenderer" , ActorApi::RemoveRenderer, ACTOR_API },
+
/**************************************
* Layer API (in order of layer.h)
**************************************/
#include <dali/public-api/actors/image-actor.h>
#include <dali/public-api/actors/blending.h>
#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/actors/sampling.h>
#include <dali/public-api/render-tasks/render-task.h>
#include <dali/public-api/common/loading-state.h>
-
+#include <dali/devel-api/rendering/material.h>
+#include <dali/devel-api/rendering/geometry.h>
namespace Dali
{
{"IMAGE_ACTOR_STYLE_QUAD", ImageActor::STYLE_QUAD},
{"IMAGE_ACTOR_STYLE_NINE_PATCH", ImageActor::STYLE_NINE_PATCH},
- {"IMAGE_ACTOR_STYLE_NINE_PATCH_NO_CENTER",ImageActor::STYLE_NINE_PATCH_NO_CENTER }
-
+ {"IMAGE_ACTOR_STYLE_NINE_PATCH_NO_CENTER",ImageActor::STYLE_NINE_PATCH_NO_CENTER },
+
+ { "FILTER_MODE_NONE", FilterMode::NONE },
+ { "FILTER_MODE_DEFAULT", FilterMode::DEFAULT },
+ { "FILTER_MODE_NEAREST", FilterMode::NEAREST },
+ { "FILTER_MODE_LINEAR", FilterMode::LINEAR },
+
+ { "WRAP_MODE_DEFAULT", WrapMode::DEFAULT },
+ { "WRAP_MODE_CLAMP_TO_EDGE", WrapMode::CLAMP_TO_EDGE },
+ { "WRAP_MODE_REPEAT", WrapMode::REPEAT },
+ { "WRAP_MODE_MIRRORED_REPEAT", WrapMode::MIRRORED_REPEAT },
+
+ { "MATERIAL_NONE", Material::NONE },
+ { "MATERIAL_CULL_BACK", Material::CULL_BACK },
+ { "MATERIAL_CULL_FRONT", Material::CULL_FRONT },
+ { "MATERIAL_CULL_BACK_AND_FRONT", Material::CULL_BACK_AND_FRONT },
+
+ { "GEOMETRY_POINTS", Geometry::POINTS },
+ { "GEOMETRY_LINES", Geometry::LINES },
+ { "GEOMETRY_LINE_LOOP", Geometry::LINE_LOOP },
+ { "GEOMETRY_LINE_STRIP", Geometry::LINE_STRIP },
+ { "GEOMETRY_TRIANGLES", Geometry::TRIANGLES },
+ { "GEOMETRY_TRIANGLE_FAN", Geometry::TRIANGLE_FAN },
+ { "GEOMETRY_TRIANGLE_STRIP", Geometry::TRIANGLE_STRIP },
+
+ { "PROPERTY_NONE", Property::NONE },
+ { "PROPERTY_BOOLEAN", Property::BOOLEAN },
+ { "PROPERTY_FLOAT", Property::FLOAT },
+ { "PROPERTY_INTEGER", Property::INTEGER },
+ { "PROPERTY_VECTOR2", Property::VECTOR2 },
+ { "PROPERTY_VECTOR3", Property::VECTOR3 },
+ { "PROPERTY_VECTOR4", Property::VECTOR4 },
+ { "PROPERTY_MATRIX3", Property::MATRIX3 },
+ { "PROPERTY_MATRIX", Property::MATRIX },
+ { "PROPERTY_RECTANGLE", Property::RECTANGLE },
+ { "PROPERTY_ROTATION", Property::ROTATION },
+ { "PROPERTY_STRING", Property::STRING },
+ { "PROPERTY_ARRAY", Property::ARRAY },
+ { "PROPERTY_MAP", Property::MAP },
+ { "PROPERTY_INVALID_INDEX", Property::INVALID_INDEX },
};
const unsigned int EnumTableCount = sizeof(EnumTable)/sizeof(EnumTable[0]);
#include <animation/animation-wrapper.h>
#include <events/pan-gesture-detector-wrapper.h>
#include <shader-effects/shader-effect-wrapper.h>
+#include <object/property-buffer-wrapper.h>
+#include <rendering/geometry-wrapper.h>
+#include <rendering/material-wrapper.h>
+#include <rendering/renderer-wrapper.h>
+#include <rendering/shader-wrapper.h>
+#include <rendering/sampler-wrapper.h>
#include <shared/object-template-helper.h>
#include <constants/constants-wrapper.h>
#include <toolkit/builder/builder-wrapper.h>
{ "FrameBufferImage", ImageWrapper::NewImage },
{ "Animation", AnimationWrapper::NewAnimation},
{ "ShaderEffect", ShaderEffectWrapper::NewShaderEffect},
+ { "Shader", ShaderWrapper::NewShader},
+ { "Sampler", SamplerWrapper::NewSampler},
+ { "Material", MaterialWrapper::NewMaterial},
+ { "Geometry", GeometryWrapper::NewGeometry},
+ { "Renderer", RendererWrapper::NewRenderer},
+ { "PropertyBuffer", PropertyBufferWrapper::NewPropertyBuffer},
{ "Builder", BuilderWrapper::NewBuilder},
{ "PanGestureDetector", PanGestureDetectorWrapper::NewPanGestureDetector},
namespace V8Plugin
{
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction HandleFunctionTable[]=
+{
+ { "RegisterAnimatableProperty", HandleWrapper::RegisterAnimatableProperty },
+};
+
+const unsigned int HandleFunctionTableCount = sizeof(HandleFunctionTable)/sizeof(HandleFunctionTable[0]);
+} //un-named space
+
+/**
+ * @class Handle
+ */
+
HandleWrapper::HandleWrapper( BaseWrappedObject::Type type,
Handle handle,
GarbageCollectorInterface& gc ) :
objTemplate->SetNamedPropertyHandler( HandleWrapper::PropertyGet, HandleWrapper::PropertySet);
+ // add function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, HandleFunctionTable, HandleFunctionTableCount );
+
ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
}
+/**
+ * Register a new animatable property.
+ *
+ * The object should support dynamic properties.
+ * Property names are expected to be unique, but this is not enforced.
+ * Property indices are unique to each registered custom property in a given object.
+ * returns dali.PROPERTY_INVALID_INDEX if registration failed. This can happen if you try
+ * to register animatable property on an object that does not have scene graph object.
+ *
+ * @method registerAnimatableProperty
+ * @for Handle
+ * @param {string} name The name of the property.
+ * @param {Object} propertyValue The new value of the property.
+ * @return {integer} The index of the property or dali.PROPERTY_INVALID_INDEX if registration failed
+ * @example
+ *
+ * var morphPropertyIdex = actor.registerAnimatableProperty("uMorphAmount", 0.0f);
+ * var fadeColorPropertyIdex = handle.registerAnimatableProperty("uFadeColor", [1.0, 0.0, 0.0, 1.0]);
+ *
+ */
+void HandleWrapper::RegisterAnimatableProperty( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ // unwrap the object
+ HandleWrapper* handleWrapper = Unwrap( isolate, args.This() );
+ if( !handleWrapper )
+ {
+ return;
+ }
+
+ Handle handle = handleWrapper->mHandle;
+
+ bool found( false );
+ std::string propertyName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad property name parameter" );
+ return;
+ }
+
+ found = false;
+ Dali::Property::Value daliPropertyValue = V8Utils::GetPropertyValueParameter(PARAMETER_1, found, isolate, args );
+ if( !found || Dali::Property::NONE == daliPropertyValue.GetType() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "bad property value parameter" );
+ return;
+ }
+ else
+ {
+ args.GetReturnValue().Set( v8::Integer::New( isolate, handle.RegisterProperty(propertyName, daliPropertyValue) ) );
+ }
+}
} // namespace V8Plugin
*/
static void AddInterceptsToTemplate( v8::Isolate* isolate, v8::Local<v8::ObjectTemplate>& objTemplate );
+ /**
+ * @brief Register an animatable property for a JavaScript object that
+ * contains a Dali Handle.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void RegisterAnimatableProperty( const v8::FunctionCallbackInfo< v8::Value >& args );
Handle GetHandle() { return mHandle; }
Handle mHandle;
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "property-buffer-api.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/property-buffer-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // unnamed namespace
+{
+
+struct PropertyBufferParameters
+{
+ PropertyBufferParameters()
+ : mSize( 0 )
+ {
+ }
+
+ PropertyBuffer NewPropertyBuffer()
+ {
+ return PropertyBuffer::New( mBufferFormat,
+ mSize);
+ }
+
+ Property::Map mBufferFormat;
+ std::size_t mSize;
+};
+
+} // unnamed space
+
+/**
+ * ## PropertyBuffer API
+ *
+ * PropertyBuffer is a handle to an object that contains a buffer of structured properties.
+ * It can be used to provide data to Geometry objects.
+ *
+ * ### Simple example
+ *
+ *```
+ * var vertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2 };
+ * var vertexData = [ 0, 1,
+ * -0.95, 0.31,
+ * -0.59, -0.81,
+ * 0.59, -0.81,
+ * 0.95, 0.31];
+ *
+ * var vertexDataArray = new Float32Array(vertexData.length);
+ * vertexDataArray.set(vertexData, 0);
+ * var vertices = new dali.PropertyBuffer(vertexFormat, 5);
+ * vertices.setData(vertexDataArray);
+ *
+ * var geometry = new dali.Geometry();
+ * geometry.addVertexBuffer( vertices );
+ *```
+ * @class PropertyBuffer
+ */
+
+PropertyBuffer PropertyBufferApi::GetPropertyBuffer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ PropertyBufferWrapper* wrapper = static_cast< PropertyBufferWrapper *>(ptr);
+ return wrapper->GetPropertyBuffer();
+}
+
+PropertyBuffer PropertyBufferApi::GetPropertyBufferFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::PROPERTY_BUFFER, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ PropertyBufferWrapper* wrapper = static_cast< PropertyBufferWrapper *>(wrappedObject);
+ return wrapper->GetPropertyBuffer();
+ }
+ else
+ {
+ return PropertyBuffer();
+ }
+}
+
+/**
+ * Create a new PropertyBuffer
+ *
+ * PropertyBuffers contains a buffer of structured properties and can be
+ * used to provide data to Geometry objects.
+ *
+ * @constructor
+ * @for PropertyBuffer
+ * @method PropertyBuffer
+ * @param {Object} bufferFormat
+ * @param {integer} size
+ * @return {Object} PropertyBuffer
+ * @example
+ *```
+ * var bufferFormat = {
+ * "aPosition" : dali.PROPERTY_VECTOR2,
+ * "aTexCoord" : dali.PROPERTY_VECTOR2,
+ * "aHue" : dali.PROPERTY_FLOAT,
+ * };
+ *
+ * var buffer = new dali.PropertyBuffer(bufferFormat, 5);
+ *```
+ */
+PropertyBuffer PropertyBufferApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Dali::Property::Map bufferFormat = V8Utils::GetPropertyMapParameter( PARAMETER_0, found, isolate, args);
+ if( !found || bufferFormat.Empty() )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid property map parameter" );
+ return PropertyBuffer();
+ }
+
+ found = false;
+ int size = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing buffer size from param 1" );
+ return PropertyBuffer();
+ }
+
+ return PropertyBuffer::New(bufferFormat, static_cast<std::size_t>(size));
+}
+
+/**
+ * Update the whole buffer information
+ *
+ * This function expects an array of data with the same format that was given
+ * in the construction, and the number of elements to be the same as the size
+ * of the buffer.
+ *
+ * @method setData
+ * @for PropertyBuffer
+ * @param {Object} data The data that will be copied to the buffer.
+ * @example
+ *```
+ * var vertexData = [ 0, 1,
+ * -0.95, 0.31,
+ * -0.59, -0.81,
+ * 0.59, -0.81,
+ * 0.95, 0.31];
+ *
+ * var vertexDataArray = new Float32Array(vertexData.length);
+ * vertexDataArray.set(vertexData, 0);
+ *
+ * propertyBuffer.setData( vertexDataArray );
+ *```
+ */
+void PropertyBufferApi::SetData( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ PropertyBuffer buffer = GetPropertyBuffer( isolate, args );
+
+ bool found( false );
+ void* data = V8Utils::GetArrayBufferViewParameter( PARAMETER_0, found, isolate, args);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid data parameter" );
+ }
+ else
+ {
+ buffer.SetData( data );
+ }
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PROPERTY_BUFFER_API_H__
+#define __DALI_V8PLUGIN_PROPERTY_BUFFER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/object/property-buffer.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace PropertyBufferApi
+{
+
+ /**
+ * @brief Helper to get property buffer from args.This()
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ PropertyBuffer GetPropertyBuffer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * @brief Helper to get property buffer from the JavaScript object held in the given function argument
+ * @param[in] paramIndex Argument index the object is held in
+ * @param[in] found Whether property buffer is found in the given function parameter
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ PropertyBuffer GetPropertyBufferFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ PropertyBuffer New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * PropertyBuffer API see property-buffer.h for a description
+ */
+ void SetData( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace PropertyBufferApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_PROPERTY_BUFFER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "property-buffer-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <object/property-buffer-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> PropertyBufferWrapper::mPropertyBufferTemplate;
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction PropertyBufferFunctionTable[]=
+{
+ /**************************************
+ * PropertyBuffer API (in order of property-buffer.h)
+ **************************************/
+
+ { "SetData" , PropertyBufferApi::SetData },
+};
+
+const unsigned int PropertyBufferFunctionTableCount = sizeof(PropertyBufferFunctionTable)/sizeof(PropertyBufferFunctionTable[0]);
+} //un-named space
+
+
+PropertyBufferWrapper::PropertyBufferWrapper( const Dali::PropertyBuffer& buffer, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::PROPERTY_BUFFER , gc )
+{
+ mPropertyBuffer = buffer;
+}
+
+v8::Handle<v8::Object> PropertyBufferWrapper::WrapPropertyBuffer(v8::Isolate* isolate, const Dali::PropertyBuffer& buffer )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetPropertyBufferTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the PropertyBuffer wrapper
+ PropertyBufferWrapper* pointer = new PropertyBufferWrapper( buffer, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> PropertyBufferWrapper::GetPropertyBufferTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mPropertyBufferTemplate.IsEmpty() )
+ {
+ objectTemplate = MakePropertyBufferTemplate( isolate );
+ mPropertyBufferTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mPropertyBufferTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> PropertyBufferWrapper::MakePropertyBufferTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, PropertyBufferFunctionTable, PropertyBufferFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void PropertyBufferWrapper::NewPropertyBuffer( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "PropertyBuffer constructor called without 'new'");
+ return;
+ }
+ Dali::PropertyBuffer buffer = PropertyBufferApi::New( isolate, args );
+
+ if(buffer)
+ {
+ v8::Local<v8::Object> localObject = WrapPropertyBuffer( isolate, buffer );
+ args.GetReturnValue().Set( localObject );
+ }
+}
+
+
+PropertyBuffer PropertyBufferWrapper::GetPropertyBuffer()
+{
+ return mPropertyBuffer;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_PROPERTY_BUFFER_WRAPPER_H__
+#define __DALI_V8PLUGIN_PROPERTY_BUFFER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/object/property-buffer.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * A PropertyBuffer wrapper.
+ * Provides access to PropertyBuffer specific functionality and V8 memory handling.
+ */
+class PropertyBufferWrapper : public BaseWrappedObject
+{
+
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] propertyBuffer DALi property buffer
+ * @param[in] gc garbage collection interface
+ */
+ PropertyBufferWrapper( const PropertyBuffer& propertyBuffer,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~PropertyBufferWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new PropertyBuffer wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewPropertyBuffer( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a property buffer
+ */
+ static v8::Handle<v8::Object> WrapPropertyBuffer(v8::Isolate* isolate, const Dali::PropertyBuffer& );
+
+
+ // The PropertyBufferAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create a PropertyBuffer
+ static v8::Persistent<v8::ObjectTemplate> mPropertyBufferTemplate;
+
+ /**
+ * @brief Gets the handle of property buffer
+ */
+ PropertyBuffer GetPropertyBuffer();
+
+
+private:
+
+ // PropertyBuffer
+ PropertyBuffer mPropertyBuffer;
+
+ static v8::Handle<v8::ObjectTemplate> MakePropertyBufferTemplate( v8::Isolate* isolate );
+ static v8::Local<v8::ObjectTemplate> GetPropertyBufferTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_PROPERTY_BUFFER_WRAPPER_H__
daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
break;
}
+ case Dali::Property::MAP:
+ {
+ if( v8Value->IsObject() )
+ {
+ v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(v8Value);
+ Dali::Property::Map propertyMap = V8Utils::GetPropertyMapFromObject(isolate, object);
+ daliPropertyValue = Dali::Property::Value( propertyMap );
+ }
+ break;
+ }
case Dali::Property::NONE:
default:
{
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// CLASS HEADER
+#include "geometry-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/geometry-wrapper.h>
+#include <object/property-buffer-api.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * ## Geometry API
+ *
+ * Geometry is handle to an object that can be used to define a geometric elements.
+ *
+ * @class Geometry
+ * @extends Handle
+ */
+
+Geometry GeometryApi::GetGeometry( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ GeometryWrapper* wrapper = static_cast< GeometryWrapper *>(ptr);
+ return wrapper->GetGeometry();
+}
+
+Geometry GeometryApi::GetGeometryFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::GEOMETRY, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ GeometryWrapper* wrapper = static_cast< GeometryWrapper *>(wrappedObject);
+ return wrapper->GetGeometry();
+ }
+ else
+ {
+ return Geometry();
+ }
+}
+
+/**
+ * Create a new geometry object.
+ *
+ * @constructor
+ * @method Geometry
+ * @for Geometry
+ * @return {Object} Geometry
+ */
+Geometry GeometryApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ return Geometry::New();
+}
+
+/**
+ * Add a PropertyBuffer to be used as source of geometry vertices
+ *
+ * @method addVertexBuffer
+ * @for Geometry
+ * @param {Object} vertexBuffer PropertyBuffer to be used as source of geometry vertices
+ * @return {interger} Index of the newly added buffer, can be used with RemoveVertexBuffer
+ * to remove this buffer if no longer required
+ * @example
+ *```
+ * var vertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2 };
+ * var vertexData = [ 0, 1,
+ * -0.95, 0.31,
+ * -0.59, -0.81,
+ * 0.59, -0.81,
+ * 0.95, 0.31];
+ *
+ * var vertexDataArray = new Float32Array(vertexData.length);
+ * vertexDataArray.set(vertexData, 0);
+ * var vertices = new dali.PropertyBuffer(vertexFormat, 5);
+ * vertices.setData(vertexDataArray);
+ *
+ * var geometry = new dali.Geometry();
+ * geometry.addVertexBuffer( vertices );
+ *```
+ */
+void GeometryApi::AddVertexBuffer( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Geometry geometry = GetGeometry( isolate, args );
+
+ bool found( false );
+ PropertyBuffer vertexBuffer = PropertyBufferApi::GetPropertyBufferFromParams( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid property buffer parameter" );
+ }
+ else
+ {
+ args.GetReturnValue().Set( v8::Integer::New( isolate, geometry.AddVertexBuffer(vertexBuffer) ) );
+ }
+}
+
+/**
+ * Retrieve the number of vertex buffers that have been added to this geometry
+ *
+ * @method getNumberOfVertexBuffers
+ * @for Geometry
+ * @return {integer} Number of vertex buffers that have been added to this geometry
+ */
+void GeometryApi::GetNumberOfVertexBuffers( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Geometry geometry = GetGeometry( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, geometry.GetNumberOfVertexBuffers() ) );
+}
+
+/**
+ * Remove a vertex buffer
+ *
+ * @method removeVertexBuffer
+ * @for Geometry
+ * @param {integer} index Index to the vertex buffer to remove,
+ * which must be between 0 and getNumberOfVertexBuffers()
+ */
+void GeometryApi::RemoveVertexBuffer( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Geometry geometry = GetGeometry( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing index from param 0" );
+ }
+ else
+ {
+ geometry.RemoveVertexBuffer(static_cast<std::size_t>(index));
+ }
+}
+
+/**
+ * Set a PropertyBuffer to be used as a source of indices for the geometry
+ *
+ * This buffer is required to have exactly one component and it must be of the
+ * type dali.PROPERTY_INTEGER
+ *
+ * By setting this buffer it will cause the geometry to be rendered using indices.
+ * To unset call SetIndexBuffer with an empty handle.
+ *
+ * @method setIndexBuffer
+ * @for Geometry
+ * @param {Object} indexBuffer PropertyBuffer to be used as a source of indices
+ * for the geometry
+ */
+void GeometryApi::SetIndexBuffer( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Geometry geometry = GetGeometry( isolate, args );
+
+ bool found( false );
+ PropertyBuffer indexBuffer = PropertyBufferApi::GetPropertyBufferFromParams( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid property buffer parameter" );
+ }
+ else
+ {
+ geometry.SetIndexBuffer(indexBuffer);
+ }
+}
+
+/**
+ * Set the type of primitives this geometry contains
+ *
+ * @method setGeometryType
+ * @for Geometry
+ * @param {integer} geometryType Type of primitives this geometry contains
+ * @example
+ * // geometry type is one of the following
+ * dali.GEOMETRY_POINTS
+ * dali.GEOMETRY_LINES
+ * dali.GEOMETRY_LINE_LOOP
+ * dali.GEOMETRY_LINE_STRIP
+ * dali.GEOMETRY_TRIANGLES
+ * dali.GEOMETRY_TRIANGLE_FAN
+ * dali.GEOMETRY_TRIANGLE_STRIP
+ *
+ * geometry.SetGeometryType( dali.GEOMETRY_LINES );
+ */
+void GeometryApi::SetGeometryType( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Geometry geometry = GetGeometry( isolate, args );
+
+ bool found( false );
+ int geometryType = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing geometryType from param 0" );
+ }
+ else
+ {
+ geometry.SetGeometryType(static_cast<Geometry::GeometryType>(geometryType));
+ }
+}
+
+/**
+ * Get the type of primitives this geometry contains
+ *
+ * @method getGeometryType
+ * @for Geometry
+ * @return {integer} Type of primitives this geometry contains
+ * @example
+ * // returns one of the following
+ * dali.GEOMETRY_POINTS
+ * dali.GEOMETRY_LINES
+ * dali.GEOMETRY_LINE_LOOP
+ * dali.GEOMETRY_LINE_STRIP
+ * dali.GEOMETRY_TRIANGLES
+ * dali.GEOMETRY_TRIANGLE_FAN
+ * dali.GEOMETRY_TRIANGLE_STRIP
+ */
+void GeometryApi::GetGeometryType( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Geometry geometry = GetGeometry( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, geometry.GetGeometryType() ) );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_GEOMETRY_API_H__
+#define __DALI_V8PLUGIN_GEOMETRY_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/geometry.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace GeometryApi
+{
+
+ /**
+ * Helper to get geometry from args.This()
+ */
+ Geometry GetGeometry( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * @brief Helper to get geometry from the JavaScript object held in the given function argument
+ * @param[in] paramIndex Argument index the object is held in
+ * @param[in] found Whether geometry is found in the given function parameter
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ Geometry GetGeometryFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ Geometry New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Geometry API see geometry.h for a description
+ */
+ void AddVertexBuffer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetNumberOfVertexBuffers( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RemoveVertexBuffer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetIndexBuffer( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetGeometryType( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetGeometryType( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace GeometryApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_GEOMETRY_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "geometry-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/geometry-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> GeometryWrapper::mGeometryTemplate;
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction GeometryFunctionTable[]=
+{
+ /**************************************
+ * Geometry API (in order of Geometry.h)
+ **************************************/
+
+ { "AddVertexBuffer" , GeometryApi::AddVertexBuffer },
+ { "GetNumberOfVertexBuffers" , GeometryApi::GetNumberOfVertexBuffers },
+ { "RemoveVertexBuffer" , GeometryApi::RemoveVertexBuffer },
+ { "SetIndexBuffer" , GeometryApi::SetIndexBuffer },
+ { "SetGeometryType" , GeometryApi::SetGeometryType },
+ { "GetGeometryType" , GeometryApi::GetGeometryType },
+};
+
+const unsigned int GeometryFunctionTableCount = sizeof(GeometryFunctionTable)/sizeof(GeometryFunctionTable[0]);
+} //un-named space
+
+
+GeometryWrapper::GeometryWrapper( const Dali::Geometry& geometry, GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::GEOMETRY , geometry, gc )
+{
+ mGeometry = geometry;
+}
+
+v8::Handle<v8::Object> GeometryWrapper::WrapGeometry(v8::Isolate* isolate, const Dali::Geometry& geometry )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetGeometryTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Geometry wrapper
+ GeometryWrapper* pointer = new GeometryWrapper( geometry, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> GeometryWrapper::GetGeometryTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mGeometryTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeGeometryTemplate( isolate );
+ mGeometryTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mGeometryTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> GeometryWrapper::MakeGeometryTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, GeometryFunctionTable, GeometryFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void GeometryWrapper::NewGeometry( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Geometry constructor called without 'new'");
+ return;
+ }
+ Dali::Geometry geometry = GeometryApi::New( args );
+
+ if(geometry)
+ {
+ v8::Local<v8::Object> localObject = WrapGeometry( isolate, geometry );
+ args.GetReturnValue().Set( localObject );
+ }
+}
+
+
+Geometry GeometryWrapper::GetGeometry()
+{
+ return mGeometry;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_GEOMETRY_WRAPPER_H__
+#define __DALI_V8PLUGIN_GEOMETRY_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/geometry.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * A Geometry wrapper.
+ * Provides access to Geometry specific functionality and V8 memory handling.
+ */
+class GeometryWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] propertyBuffer DALi geometry
+ * @param[in] gc garbage collection interface
+ */
+ GeometryWrapper( const Geometry& geometry,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~GeometryWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Geometry wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewGeometry( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a geometry
+ */
+ static v8::Handle<v8::Object> WrapGeometry(v8::Isolate* isolate, const Dali::Geometry& );
+
+
+ // The GeometryAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create a Geometry
+ static v8::Persistent<v8::ObjectTemplate> mGeometryTemplate;
+
+ /**
+ * @brief Gets the handle of geometry
+ * @return the handle of geometry
+ */
+ Geometry GetGeometry();
+
+
+private:
+
+ // Geometry
+ Geometry mGeometry;
+
+ /**
+ * @brief Creates the object template that used to create geometry at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeGeometryTemplate( v8::Isolate* isolate );
+
+ /**
+ * @brief Gets the object template that used to create geometry at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Local<v8::ObjectTemplate> GetGeometryTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_GEOMETRY_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// CLASS HEADER
+#include "material-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/material-wrapper.h>
+#include <rendering/shader-wrapper.h>
+#include <rendering/shader-api.h>
+#include <rendering/sampler-wrapper.h>
+#include <rendering/sampler-api.h>
+#include <image/image-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * ## Material API
+ *
+ * Material is a handle to an object that specifies the visual properties of the renderer.
+ *
+ * @class Material
+ * @extends Handle
+ */
+
+Material MaterialApi::GetMaterial( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ MaterialWrapper* wrapper = static_cast< MaterialWrapper *>(ptr);
+ return wrapper->GetMaterial();
+}
+
+Material MaterialApi::GetMaterialFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::MATERIAL, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ MaterialWrapper* wrapper = static_cast< MaterialWrapper *>(wrappedObject);
+ return wrapper->GetMaterial();
+ }
+ else
+ {
+ return Material();
+ }
+}
+
+/**
+ * Create a new material object.
+ *
+ * @constructor
+ * @method Material
+ * @for Material
+ * @param {Object} shader The shader used by the material
+ * @return {Object} Material
+ */
+Material MaterialApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Shader shader = ShaderApi::GetShaderFromParams( 0, found, isolate, args );
+ if( found )
+ {
+ return Material::New( shader );
+ }
+ else
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing shader from param 0" );
+ return Material();
+ }
+}
+
+/**
+ * Set the Shader used by this material
+ *
+ * @method setShader
+ * @for Material
+ * @param {Object} shader Handle to the shader
+ */
+void MaterialApi::SetShader( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ Shader shader = ShaderApi::GetShaderFromParams( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid shader parameter" );
+ }
+ else
+ {
+ return material.SetShader( shader );
+ }
+}
+
+/**
+ * Get the Shader used by this material
+ *
+ * @method getShader
+ * @for Material
+ * @return {Object} Shader
+ */
+void MaterialApi::GetShader( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+ Shader shader = material.GetShader();
+
+ // Wrap the shader
+ v8::Local<v8::Object> localObject = ShaderWrapper::WrapShader( isolate, shader );
+ args.GetReturnValue().Set( localObject );
+}
+
+/**
+ * Add a new texture to be used by the material
+ *
+ * @method addTexture
+ * @for Material
+ * @param {Object} image The image used by this sampler
+ * @param {String} uniformName The string with the name of the uniform
+ * @param {Object} sampler The sampler to add to this material
+ * @return {integer} The index of the texture in the array of textures or -1 if texture can not be added
+ */
+void MaterialApi::AddTexture( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ Image image = V8Utils::GetImageParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing image from param 0" );
+ return;
+ }
+
+ found = false;
+ std::string uniformName = V8Utils::GetStringParameter( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing uniform name from param 1" );
+ return;
+ }
+
+ found = false;
+ Sampler sampler = SamplerApi::GetSamplerFromParams( PARAMETER_2, found, isolate, args );
+ if( !found )
+ {
+ args.GetReturnValue().Set( v8::Integer::New( isolate, material.AddTexture( image, uniformName ) ) );
+ }
+ else
+ {
+ args.GetReturnValue().Set( v8::Integer::New( isolate, material.AddTexture( image, uniformName, sampler ) ) );
+ }
+}
+
+/**
+ * Removes a texture from the material
+ *
+ * @method removeTexture
+ * @for Material
+ * @param {integer} index The index of the texture in the array of textures
+ */
+void MaterialApi::RemoveTexture( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ }
+ else
+ {
+ material.RemoveTexture( index );
+ }
+}
+
+/**
+ * Sets the image to be used by a given texture
+ * @method setTextureImage
+ * @for Material
+ * @param {integer} index The index of the texture in the array of textures
+ * @param {Object} image The image used by this sampler
+ */
+void MaterialApi::SetTextureImage( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ return;
+ }
+
+ found = false;
+ Image image = V8Utils::GetImageParameter( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing image from param 1" );
+ }
+ else
+ {
+ material.SetTextureImage(index, image);
+ }
+}
+
+/**
+ * Set the sampler used by a given texture
+ * @method setTextureSampler
+ * @for Material
+ * @param {integer} index The index of the texture in the array of textures
+ * @param {Object} sampler The new sampler
+ */
+void MaterialApi::SetTextureSampler( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ return;
+ }
+
+ found = false;
+ Sampler sampler = SamplerApi::GetSamplerFromParams( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing sampler from param 1" );
+ }
+ else
+ {
+ material.SetTextureSampler(index, sampler);
+ }
+}
+
+/**
+ * Set the uniform name of a given texture
+ * @method setTextureUniformName
+ * @for Material
+ * @param {integer} index The index of the texture in the array of textures
+ * @param {string} uniformName The new uniform name
+ */
+void MaterialApi::SetTextureUniformName( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ return;
+ }
+
+ found = false;
+ std::string uniformName = V8Utils::GetStringParameter( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid uniform name parameter" );
+ }
+ else
+ {
+ material.SetTextureUniformName(index, uniformName);
+ }
+}
+
+/**
+ * Establish if a given texture will affect the transparency of the material ( true by default )
+ * @method setTextureAffectsTransparency
+ * @for Material
+ * @param {integer} index The index of the texture in the array of textures
+ * @param {string} affectsTransparency True if the texture affects transparency, false otherwise
+ */
+void MaterialApi::SetTextureAffectsTransparency( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
+ return;
+ }
+
+ found = false;
+ bool affectsTransparency = V8Utils::GetBooleanParameter( PARAMETER_1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid affectsTransparency parameter" );
+ }
+ else
+ {
+ material.SetTextureAffectsTransparency(index, affectsTransparency);
+ }
+}
+
+/**
+ * Retrive the index of a texture given its uniform name
+ * @method getTextureIndex
+ * @for Material
+ * @param {string} uniformName The uniform name
+ * @return {integer} The index in the array of textures or -1 if the texture is not found
+ */
+void MaterialApi::GetTextureIndex( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ std::string uniformName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid uniform name parameter" );
+ }
+ else
+ {
+ args.GetReturnValue().Set( v8::Integer::New( isolate, material.GetTextureIndex(uniformName) ) );
+ }
+}
+
+/**
+ * Retrieve the number of textures used by the material
+ *
+ * @method getNumberOfTextures
+ * @for Material
+ * @return {integer} The number of textures
+ */
+void MaterialApi::GetNumberOfTextures( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, material.GetNumberOfTextures() ) );
+}
+
+/**
+ * Set the culling mode for this material
+ *
+ * @method setFaceCullingMode
+ * @for Material
+ * @param {integer} cullingMode The culling mode for this material
+ * @example
+ * // face culling mode is one of the following
+ * dali.MATERIAL_NONE // None of the faces should be culled
+ * dali.MATERIAL_CULL_BACK // Cull back face, back face should never be shown
+ * dali.MATERIAL_CULL_FRONT // Cull front face, back face should never be shown
+ * dali.MATERIAL_CULL_BACK_AND_FRONT // Cull back and front faces, if the geometry is composed of triangles none of the faces will be shown
+ *
+ * material.setFaceCullingMode( dali.MATERIAL_NONE );
+ */
+void MaterialApi::SetFaceCullingMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid cullingMode parameter" );
+ }
+ else
+ {
+ material.SetFaceCullingMode( static_cast<Material::FaceCullingMode>(mode) );
+ }
+}
+
+/**
+ * Set the blending mode.
+ *
+ * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work.
+ *
+ * @for Material
+ * @method setBlendMode
+ * @param { integer } mode The blending mode.
+ * @example
+ * // blend mode is one of the following
+ * dali.BLENDING_OFF // Blending is disabled.
+ * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
+ * dali.BLENDING_ON // Blending is enabled.
+ *
+ * material.setBlendMode( dali.BLENDING_AUTO );
+ */
+void MaterialApi::SetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ bool found( false );
+ int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "invalid blendMode parameter" );
+ }
+ else
+ {
+ material.SetBlendMode( static_cast<Dali::BlendingMode::Type>( mode ) );
+ }
+}
+
+/**
+ * Retrieves the blending mode.
+ *
+ * @for Material
+ * @method getBlendMode
+ * @return { integer } blendMode
+ * @example returns one of the following:
+ *
+ * dali.BLENDING_OFF // Blending is disabled.
+ * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel.
+ * dali.BLENDING_ON // Blending is enabled.
+ */
+void MaterialApi::GetBlendMode( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ args.GetReturnValue().Set( v8::Integer::New( isolate, material.GetBlendMode() ) );
+}
+
+/**
+ * Specify the pixel arithmetic used when the actor is blended.
+ *
+ * @for Material
+ * @method setBlendFunc
+ * @param {integer} srcFactorRgb Source Blending RGB
+ * @param {integer} destFactorRgb Destination Blending RGB
+ * @param {integer} srcFactorAlpha Source Blending Alpha
+ * @param {integer} destFactorAlpha Destinatino 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
+ *
+ * material.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 MaterialApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ int params[4];
+ bool foundAllParams(false);
+ V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args, 0 );
+ if( foundAllParams )
+ {
+ material.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 Material
+ * @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 MaterialApi::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 );
+
+ Material material = GetMaterial( isolate, args );
+
+ material.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 Material
+ * @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
+ *
+ * material.setBlendEquation( dali.BLEND_EQUATION_ADD, dali.BLEND_EQUATION_REVERSE_SUBTRACT );
+ */
+void MaterialApi::SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Material material = GetMaterial( isolate, args );
+
+ int params[2];
+ bool foundAllParams(false);
+ V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 2, args, 0 );
+ if( foundAllParams )
+ {
+ material.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 Material
+ * @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 MaterialApi::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 );
+
+ Material material = GetMaterial( isolate, args );
+
+ material.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
--- /dev/null
+#ifndef __DALI_V8PLUGIN_MATERIAL_API_H__
+#define __DALI_V8PLUGIN_MATERIAL_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/material.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace MaterialApi
+{
+
+ /**
+ * Helper to get material from args.This()
+ */
+ Material GetMaterial( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * @brief Helper to get material from the JavaScript object held in the given function argument
+ * @param[in] paramIndex Argument index the object is held in
+ * @param[in] found Whether material is found in the given function parameter
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ Material GetMaterialFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ Material New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Material API see material.h for a description
+ */
+ void SetShader( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetShader( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void AddTexture( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void RemoveTexture( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetTextureImage( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetTextureSampler( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetTextureUniformName( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetTextureAffectsTransparency( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetTextureIndex( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetNumberOfTextures( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetFaceCullingMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace MaterialApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_MATERIAL_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "material-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/material-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> MaterialWrapper::mMaterialTemplate;
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction MaterialFunctionTable[]=
+{
+ /**************************************
+ * Material API (in order of Material.h)
+ **************************************/
+
+ { "SetShader" , MaterialApi::SetShader },
+ { "GetShader" , MaterialApi::GetShader },
+ { "AddTexture" , MaterialApi::AddTexture },
+ { "RemoveTexture" , MaterialApi::RemoveTexture },
+ { "SetTextureImage" , MaterialApi::SetTextureImage },
+ { "SetTextureSampler" , MaterialApi::SetTextureSampler },
+ { "SetTextureUniformName" , MaterialApi::SetTextureUniformName },
+ { "SetTextureAffectsTransparency" , MaterialApi::SetTextureAffectsTransparency },
+ { "GetTextureIndex" , MaterialApi::GetTextureIndex },
+ { "GetNumberOfTextures" , MaterialApi::GetNumberOfTextures },
+ { "SetFaceCullingMode" , MaterialApi::SetFaceCullingMode },
+ { "SetBlendMode" , MaterialApi::SetBlendMode },
+ { "GetBlendMode" , MaterialApi::GetBlendMode },
+ { "SetBlendFunc" , MaterialApi::SetBlendFunc },
+ { "GetBlendFunc" , MaterialApi::GetBlendFunc },
+ { "SetBlendEquation" , MaterialApi::SetBlendEquation },
+ { "GetBlendEquation" , MaterialApi::GetBlendEquation },
+};
+
+const unsigned int MaterialFunctionTableCount = sizeof(MaterialFunctionTable)/sizeof(MaterialFunctionTable[0]);
+} //un-named space
+
+
+MaterialWrapper::MaterialWrapper( const Dali::Material& material, GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::MATERIAL , material, gc )
+{
+ mMaterial = material;
+}
+
+v8::Handle<v8::Object> MaterialWrapper::WrapMaterial(v8::Isolate* isolate, const Dali::Material& material )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetMaterialTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Material wrapper
+ MaterialWrapper* pointer = new MaterialWrapper( material, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> MaterialWrapper::GetMaterialTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mMaterialTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeMaterialTemplate( isolate );
+ mMaterialTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mMaterialTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> MaterialWrapper::MakeMaterialTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, MaterialFunctionTable, MaterialFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void MaterialWrapper::NewMaterial( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Material constructor called without 'new'");
+ return;
+ }
+ Dali::Material material = MaterialApi::New( args );
+
+ if(material)
+ {
+ v8::Local<v8::Object> localObject = WrapMaterial( isolate, material );
+ args.GetReturnValue().Set( localObject );
+ }
+}
+
+
+Material MaterialWrapper::GetMaterial()
+{
+ return mMaterial;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_MATERIAL_WRAPPER_H__
+#define __DALI_V8PLUGIN_MATERIAL_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/material.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * A Material wrapper.
+ * Provides access to Material specific functionality and V8 memory handling.
+ */
+class MaterialWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] material DALi material
+ * @param[in] gc garbage collection interface
+ */
+ MaterialWrapper( const Material& material,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~MaterialWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Material wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewMaterial( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a sampler
+ */
+ static v8::Handle<v8::Object> WrapMaterial(v8::Isolate* isolate, const Dali::Material& );
+
+
+ // The MaterialAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create a Material
+ static v8::Persistent<v8::ObjectTemplate> mMaterialTemplate;
+
+ /**
+ * @brief Gets the handle of material
+ * @return the handle of material
+ */
+ Material GetMaterial();
+
+
+private:
+
+ // Material
+ Material mMaterial;
+
+ /**
+ * @brief Creates the object template that used to create material at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeMaterialTemplate( v8::Isolate* isolate );
+
+ /**
+ * @brief Gets the object template that used to create material at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Local<v8::ObjectTemplate> GetMaterialTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_MATERIAL_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// CLASS HEADER
+#include "renderer-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#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>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * ## Renderer API
+ *
+ * Renderer is a handle to an object that can be used to provide an image to a material.
+ *
+ * @class Renderer
+ * @extends Handle
+ */
+
+Renderer RendererApi::GetRenderer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ RendererWrapper* wrapper = static_cast< RendererWrapper *>(ptr);
+ return wrapper->GetRenderer();
+}
+
+Renderer RendererApi::GetRendererFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::RENDERER, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ RendererWrapper* wrapper = static_cast< RendererWrapper *>(wrappedObject);
+ return wrapper->GetRenderer();
+ }
+ else
+ {
+ return Renderer();
+ }
+}
+
+/**
+ * Create a new renderer object.
+ *
+ * @constructor
+ * @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
+ * @return {Object} Renderer
+ */
+Renderer RendererApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ bool found( false );
+ Geometry geometry = GeometryApi::GetGeometryFromParams( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing geometry from param 0" );
+ return Renderer();
+ }
+
+ found = false;
+ Material material = MaterialApi::GetMaterialFromParams( 1, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing material from param 0" );
+ return Renderer();
+ }
+
+ return Renderer::New(geometry, material);
+}
+
+/**
+ * Sets the geometry to be used by this renderer
+ *
+ * @method setGeometry
+ * @for Renderer
+ * @param {Object} geometry The geometry to be used by this renderer
+ */
+void RendererApi::SetGeometry( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Renderer renderer = GetRenderer( isolate, args );
+
+ bool found( false );
+ Geometry geometry = GeometryApi::GetGeometryFromParams( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing geometry from param 0" );
+ }
+ else
+ {
+ renderer.SetGeometry(geometry);
+ }
+}
+
+/**
+ * Gets the geometry used by this renderer
+ *
+ * @method getGeometry
+ * @for Renderer
+ * @return {Object} The geometry used by this renderer
+ */
+void RendererApi::GetGeometry( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Renderer renderer = GetRenderer( isolate, args );
+ Geometry geometry = renderer.GetGeometry();
+
+ // Wrap the geometry
+ v8::Local<v8::Object> localObject = GeometryWrapper::WrapGeometry( isolate, geometry );
+ args.GetReturnValue().Set( localObject );
+}
+
+/**
+ * Sets the material to be used by this renderer
+ *
+ * @method setMaterial
+ * @for Renderer
+ * @param {Object} material The material to be used by this renderer
+ */
+void RendererApi::SetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Renderer renderer = GetRenderer( isolate, args );
+
+ bool found( false );
+ Material material = MaterialApi::GetMaterialFromParams( 0, found, isolate, args );
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing material from param 0" );
+ }
+ else
+ {
+ renderer.SetMaterial(material);
+ }
+}
+
+/**
+ * Gets the material used by this renderer
+ *
+ * @method getMaterial
+ * @for Renderer
+ * @return {Object} The material used by this renderer
+ */
+void RendererApi::GetMaterial( const v8::FunctionCallbackInfo<v8::Value>& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Renderer renderer = GetRenderer( isolate, args );
+ Material material = renderer.GetMaterial();
+
+ // Wrap the material
+ v8::Local<v8::Object> localObject = MaterialWrapper::WrapMaterial( isolate, material );
+ args.GetReturnValue().Set( localObject );
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RENDERER_API_H__
+#define __DALI_V8PLUGIN_RENDERER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/renderer.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace RendererApi
+{
+
+ /**
+ * Helper to get renderer from args.This()
+ */
+ Renderer GetRenderer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * @brief Helper to get renderer from the JavaScript object held in the given function argument
+ * @param[in] paramIndex Argument index the object is held in
+ * @param[in] found Whether renderer is found in the given function parameter
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ Renderer GetRendererFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ Renderer New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Renderer API see renderer.h for a description
+ */
+ void SetGeometry( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetGeometry( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void GetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace RendererApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_RENDERER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "renderer-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/renderer-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> RendererWrapper::mRendererTemplate;
+
+namespace // un-named name space
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction RendererFunctionTable[]=
+{
+ /**************************************
+ * Renderer API (in order of Renderer.h)
+ **************************************/
+
+ { "SetGeometry" , RendererApi::SetGeometry },
+ { "GetGeometry" , RendererApi::GetGeometry },
+ { "SetMaterial" , RendererApi::SetMaterial },
+ { "GetMaterial" , RendererApi::GetMaterial },
+};
+
+const unsigned int RendererFunctionTableCount = sizeof(RendererFunctionTable)/sizeof(RendererFunctionTable[0]);
+} //un-named space
+
+
+RendererWrapper::RendererWrapper( const Dali::Renderer& renderer, GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::RENDERER , renderer, gc )
+{
+ mRenderer = renderer;
+}
+
+v8::Handle<v8::Object> RendererWrapper::WrapRenderer(v8::Isolate* isolate, const Dali::Renderer& renderer )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetRendererTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Renderer wrapper
+ RendererWrapper* pointer = new RendererWrapper( renderer, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> RendererWrapper::GetRendererTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mRendererTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeRendererTemplate( isolate );
+ mRendererTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mRendererTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> RendererWrapper::MakeRendererTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, RendererFunctionTable, RendererFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void RendererWrapper::NewRenderer( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Renderer constructor called without 'new'");
+ return;
+ }
+ Dali::Renderer renderer = RendererApi::New( args );
+
+ if(renderer)
+ {
+ v8::Local<v8::Object> localObject = WrapRenderer( isolate, renderer );
+ args.GetReturnValue().Set( localObject );
+ }
+}
+
+
+Renderer RendererWrapper::GetRenderer()
+{
+ return mRenderer;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_RENDERER_WRAPPER_H__
+#define __DALI_V8PLUGIN_RENDERER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/renderer.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * A Renderer wrapper.
+ * Provides access to Renderer specific functionality and V8 memory handling.
+ */
+class RendererWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] renderer DALi renderer
+ * @param[in] gc garbage collection interface
+ */
+ RendererWrapper( const Renderer& renderer,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~RendererWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Renderer wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewRenderer( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a renderer
+ */
+ static v8::Handle<v8::Object> WrapRenderer(v8::Isolate* isolate, const Dali::Renderer& );
+
+
+ // The RendererAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create a Renderer
+ static v8::Persistent<v8::ObjectTemplate> mRendererTemplate;
+
+ /**
+ * @brief Gets the handle of renderer
+ * @return the handle of renderer
+ */
+ Renderer GetRenderer();
+
+
+private:
+
+ // Renderer
+ Renderer mRenderer;
+
+ /**
+ * @brief Creates the object template that used to create renderer at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeRendererTemplate( v8::Isolate* isolate );
+
+ /**
+ * @brief Gets the object template that used to create renderer at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Local<v8::ObjectTemplate> GetRendererTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_RENDERER_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "sampler-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/sampler-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * ## Sampler API
+ *
+ * Sampler is a handle to an object that can be used to provide the sampling parameters to sample textures
+ *
+ * @class Sampler
+ */
+
+Sampler SamplerApi::GetSampler( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ SamplerWrapper* wrapper = static_cast< SamplerWrapper *>(ptr);
+ return wrapper->GetSampler();
+}
+
+Sampler SamplerApi::GetSamplerFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::SAMPLER, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ SamplerWrapper* wrapper = static_cast< SamplerWrapper *>(wrappedObject);
+ return wrapper->GetSampler();
+ }
+ else
+ {
+ return Sampler();
+ }
+}
+
+/**
+ * Create a new sampler object.
+ *
+ * @constructor
+ * @method Sampler
+ * @for Sampler
+ * @return {Object} Sampler
+ */
+Sampler SamplerApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ return Sampler::New();
+}
+
+/**
+ * Set the filter modes for this sampler
+ * @method setFilterMode
+ * @for Sampler
+ * @param {integer} minFilter The minification filter that will be used
+ * @param {integer} magFilter The magnification filter that will be used
+ * @example
+ * // filter mode is one of the following
+ * dali.FILTER_MODE_NONE // Use GL system defaults (minification NEAREST_MIPMAP_LINEAR, magnification LINEAR)
+ * dali.FILTER_MODE_DEFAULT // Use dali defaults (minification LINEAR, magnification LINEAR)
+ * dali.FILTER_MODE_NEAREST // Filter nearest
+ * dali.FILTER_MODE_LINEAR // Filter linear
+ *
+ * sampler.setFilterMode( dali.FILTER_MODE_DEFAULT, dali.FILTER_MODE_LINEAR );
+ */
+void SamplerApi::SetFilterMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Sampler sampler = GetSampler( isolate, args );
+
+ bool found( false );
+ int minFilter = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing minification filter from param 0" );
+ return;
+ }
+
+ found = false;
+ int magFilter = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing magnification filter from param 1" );
+ }
+ else
+ {
+ sampler.SetFilterMode(static_cast<FilterMode::Type>(minFilter), static_cast<FilterMode::Type>(magFilter));
+ }
+}
+
+/**
+ * Set the wrap modes for this sampler
+ * @method setWrapMode
+ * @for Sampler
+ * @param {integer} uWrap Wrap mode for u coordinates
+ * @param {integer} vWrap Wrap mode for v coordinates
+ * @example
+ * // wrap mode is one of the following
+ * dali.WRAP_MODE_DEFAULT
+ * dali.WRAP_MODE_CLAMP_TO_EDGE
+ * dali.WRAP_MODE_REPEAT
+ * dali.WRAP_MODE_MIRRORED_REPEAT
+ *
+ * sampler.setWrapMode( dali.WRAP_MODE_CLAMP_TO_EDGE, dali.WRAP_MODE_REPEAT );
+ */
+void SamplerApi::SetWrapMode( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate );
+
+ Sampler sampler = GetSampler( isolate, args );
+
+ bool found( false );
+ int uWrap = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing wrap mode for u coordinates from param 0" );
+ return;
+ }
+
+ found = false;
+ int vWrap = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0 /* default */);
+ if( !found )
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "missing wrap mode for v coordinates from param 1" );
+ }
+ else
+ {
+ sampler.SetWrapMode(static_cast<WrapMode::Type>(uWrap), static_cast<WrapMode::Type>(vWrap));
+ }
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SAMPLER_API_H__
+#define __DALI_V8PLUGIN_SAMPLER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/sampler.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace SamplerApi
+{
+ /**
+ * Helper to get sampler from args.This()
+ */
+ Sampler GetSampler( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * @brief Helper to get sampler from the JavaScript object held in the given function argument
+ * @param[in] paramIndex Argument index the object is held in
+ * @param[in] found Whether sampler is found in the given function parameter
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ Sampler GetSamplerFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Constructor
+ */
+ Sampler New( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * Sampler API see sampler.h for a description
+ */
+ void SetFilterMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+ void SetWrapMode( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace SamplerApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_SAMPLER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "sampler-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <dali-wrapper.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <rendering/sampler-api.h>
+
+namespace Dali
+{
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> SamplerWrapper::mSamplerTemplate;
+
+namespace
+{
+
+/**
+ * Contains a list of all functions that can be called
+ */
+const ApiFunction SamplerFunctionTable[]=
+{
+ /**************************************
+ * Sampler API (in order of sampler.h)
+ **************************************/
+
+ { "SetFilterMode", SamplerApi::SetFilterMode },
+ { "SetWrapMode", SamplerApi::SetWrapMode },
+};
+
+const unsigned int SamplerFunctionTableCount = sizeof(SamplerFunctionTable)/sizeof(SamplerFunctionTable[0]);
+} //un-named space
+
+
+SamplerWrapper::SamplerWrapper( const Sampler& sampler, GarbageCollectorInterface& gc )
+: BaseWrappedObject( BaseWrappedObject::SAMPLER , gc )
+{
+ mSampler = sampler;
+}
+
+v8::Handle<v8::Object> SamplerWrapper::WrapSampler(v8::Isolate* isolate, const Sampler& sampler )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetSamplerTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Sampler wrapper
+ SamplerWrapper* pointer = new SamplerWrapper( sampler, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> SamplerWrapper::GetSamplerTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mSamplerTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeSamplerTemplate( isolate );
+ mSamplerTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mSamplerTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> SamplerWrapper::MakeSamplerTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ // add our function properties
+ ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, SamplerFunctionTable, SamplerFunctionTableCount );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void SamplerWrapper::NewSampler( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Sampler constructor called without 'new'");
+ return;
+ }
+ Dali::Sampler sampler = SamplerApi::New( args );
+
+ if(sampler)
+ {
+ v8::Local<v8::Object> localObject = WrapSampler( isolate, sampler );
+ args.GetReturnValue().Set( localObject );
+ }
+}
+
+Sampler SamplerWrapper::GetSampler()
+{
+ return mSampler;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SAMPLER_WRAPPER_H__
+#define __DALI_V8PLUGIN_SAMPLER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/sampler.h>
+
+// INTERNAL INCLUDES
+#include <shared/base-wrapped-object.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * A Sampler wrapper.
+ * Provides access to Sampler specific functionality and V8 memory handling.
+ */
+class SamplerWrapper : public BaseWrappedObject
+{
+
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] sampler DALi sampler
+ * @param[in] gc garbage collection interface
+ */
+ SamplerWrapper( const Sampler& sampler,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~SamplerWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Sampler wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewSampler( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a sampler
+ */
+ static v8::Handle<v8::Object> WrapSampler(v8::Isolate* isolate, const Sampler& );
+
+ // The SamplerAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create a Sampler
+ static v8::Persistent<v8::ObjectTemplate> mSamplerTemplate;
+
+ /**
+ * @brief Gets the handle of sampler
+ * @return the handle of sampler
+ */
+ Sampler GetSampler();
+
+private:
+
+ // Sampler
+ Sampler mSampler;
+
+ /**
+ * @brief Creates the object template that used to create sampler at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeSamplerTemplate( v8::Isolate* isolate );
+
+ /**
+ * @brief Gets the object template that used to create sampler at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Local<v8::ObjectTemplate> GetSamplerTemplate( v8::Isolate* isolate );
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_SAMPLER_WRAPPER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// CLASS HEADER
+#include "shader-api.h"
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/shader-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * ## Shader API
+ *
+ * Shaders allows custom vertex and color transformations in the GPU
+ *
+ * ### Simple example
+ *
+ *```
+ * // this will match the default shaders for image
+ * var vertexShader = " void main() \
+ * { \
+ * gl_Position = uProjection * uModelView * vec4(aPosition, 1.0); \
+ * vTexCoord = aTexCoord; \
+ * }; "
+ * var fragShader = " void main() \
+ * { \
+ * gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\
+ * }; "
+ * var shaderOptions = {
+ * vertexShader: vertexShader,
+ * fragmentShader: fragShader
+ * };
+ *
+ * var shader = new dali.Shader(shaderOptions);
+ *```
+ * @class Shader
+ * @extends Handle
+ */
+
+namespace // unnamed namespace
+{
+
+typedef std::vector< std::string > HintsArray;
+
+struct ShaderHintPair
+{
+ const char* name;
+ Shader::ShaderHints hint;
+};
+
+const ShaderHintPair ShaderHintTable[]=
+{
+ {"requiresSelfDepthTest", Shader::HINT_REQUIRES_SELF_DEPTH_TEST },
+ {"outputIsTransparent", Shader::HINT_OUTPUT_IS_TRANSPARENT },
+ {"outputIsOpaque", Shader::HINT_OUTPUT_IS_OPAQUE },
+ {"modifiesGeometry", Shader::HINT_MODIFIES_GEOMETRY },
+};
+
+const unsigned int ShaderHintTableCount = sizeof(ShaderHintTable)/sizeof(ShaderHintTable[0]);
+
+struct ShaderParameters
+{
+ ShaderParameters()
+ : mHints( Shader::HINT_NONE )
+ {
+ }
+
+ Shader::ShaderHints GetShaderHint( const std::string& hint )
+ {
+ for( unsigned int i = 0 ; i < ShaderHintTableCount; ++i )
+ {
+ if( hint == ShaderHintTable[i].name )
+ {
+ return ShaderHintTable[i].hint;
+ }
+ }
+ return Shader::HINT_NONE;
+ }
+
+ void ProcessHintsArray( const HintsArray& hintsArray )
+ {
+ for( HintsArray::const_iterator iter = hintsArray.begin(); iter != hintsArray.end() ; ++iter )
+ {
+ mHints= static_cast<Shader::ShaderHints>( mHints | GetShaderHint( *iter ) );
+ }
+ }
+
+ Shader NewShader()
+ {
+ return Shader::New( mVertex,
+ mFragment,
+ mHints);
+ }
+
+ std::string mVertex;
+ std::string mFragment;
+ Shader::ShaderHints mHints;
+};
+
+Shader GetShader( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ v8::Local<v8::Object> object = args.This();
+ v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
+ void* ptr = field->Value();
+
+ ShaderWrapper* wrapper = static_cast< ShaderWrapper *>(ptr);
+ return wrapper->GetShader();
+}
+
+} // unnamed space
+
+/**
+ * Create a new Shader
+ * @constructor
+ * @for Shader
+ * @method Shader
+ * @param {Object} shaderOptions
+ * @param {String} [shaderOptions.vertexShader] VertexShader code for the shader. If not defined, the default version will be used
+ * @param {String} [shaderOptions.fragmentShader] FragmentShader code for the shader. If not defined, the default version will be used
+ * @param {Array} [shaderOptions.shaderHints] Hints for rendering/subdividing geometry, e.g. [ "requiresSelfDepthTest", "outputIsTransparent", "outputIsOpaque","modifiesGeometry" ]
+ * @return {Object} Shader
+ * @example
+
+ // this will match the default shaders for image
+ var vertexShader = " void main() \
+ { \
+ gl_Position = uProjection * uModelView * vec4(aPosition, 1.0); \
+ vTexCoord = aTexCoord; \
+ }; "
+
+ var fragShader = " void main() \
+ { \
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\
+ }; "
+
+ var shaderOptions = {
+ vertexShader: vertexShader,
+ fragmentShader: fragShader
+ };
+
+ var shader = new dali.Shader(shaderOptions);
+ *
+ */
+Shader ShaderApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ v8::HandleScope handleScope( isolate );
+
+ ShaderParameters shaderParams;
+
+ if( args[0]->IsObject() )
+ {
+ v8::Local<v8::Object > obj = args[0]->ToObject();
+
+ v8::Local<v8::Value> vertexValue = obj->Get(v8::String::NewFromUtf8( isolate, "vertexShader"));
+ if( vertexValue->IsString() )
+ {
+ shaderParams.mVertex = V8Utils::v8StringToStdString( vertexValue );
+ }
+
+ v8::Local<v8::Value> fragmentValue = obj->Get(v8::String::NewFromUtf8( isolate, "fragmentShader"));
+ if( fragmentValue->IsString() )
+ {
+ shaderParams.mFragment = V8Utils::v8StringToStdString( fragmentValue );
+ }
+ // Get any hints
+ v8::Local<v8::Value> hints = obj->Get(v8::String::NewFromUtf8( isolate, "shaderHints"));
+ if( hints->IsArray() )
+ {
+ HintsArray hintsArray;
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( hints );
+ for( uint32_t i=0; i < array->Length(); ++i)
+ {
+ v8::Handle<v8::Value> entry = array->Get( v8::Integer::New( isolate, i) );
+ if( entry->IsString() )
+ {
+ std::string entryString = V8Utils::v8StringToStdString( entry );
+ hintsArray.push_back( entryString );
+ }
+ }
+ shaderParams.ProcessHintsArray( hintsArray );
+ }
+ }
+
+ return shaderParams.NewShader();
+}
+
+Shader ShaderApi::GetShaderFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+
+ v8::HandleScope handleScope( isolate );
+ BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::SHADER, isolate, args );
+ if( wrappedObject )
+ {
+ found = true;
+ ShaderWrapper* wrapper = static_cast< ShaderWrapper *>(wrappedObject);
+ return wrapper->GetShader();
+ }
+ else
+ {
+ return Shader();
+ }
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SHADER_API_H__
+#define __DALI_V8PLUGIN_SHADER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/shader.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ShaderApi
+{
+
+ /**
+ * Constructor
+ */
+ Shader New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+ /**
+ * @brief Helper to get shader from the JavaScript object held in the given function argument
+ * @param[in] paramIndex Argument index the object is held in
+ * @param[in] found Whether shader is found in the given function parameter
+ * @param[in] isolate v8 isolated instance
+ * @param[in] args v8 function call arguments interpreted
+ */
+ Shader GetShaderFromParams( int paramIndex,
+ bool& found,
+ v8::Isolate* isolate,
+ const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace ShaderApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_SHADER_API_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "shader-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <v8-utils.h>
+#include <rendering/shader-api.h>
+#include <shared/api-function.h>
+#include <shared/object-template-helper.h>
+#include <dali-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+v8::Persistent<v8::ObjectTemplate> ShaderWrapper::mShaderTemplate;
+
+ShaderWrapper::ShaderWrapper( const Dali::Shader& shader, GarbageCollectorInterface& gc )
+: HandleWrapper( BaseWrappedObject::SHADER , shader, gc )
+{
+ mShader = shader;
+}
+
+v8::Handle<v8::Object> ShaderWrapper::WrapShader(v8::Isolate* isolate, const Dali::Shader& shader )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ objectTemplate = GetShaderTemplate( isolate);
+
+ // create an instance of the template
+ v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+ // create the Shader wrapper
+ ShaderWrapper* pointer = new ShaderWrapper( shader, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+ // assign the JavaScript object to the wrapper.
+ pointer->SetJavascriptObject( isolate, localObject );
+
+ return handleScope.Escape( localObject );
+}
+
+v8::Local<v8::ObjectTemplate> ShaderWrapper::GetShaderTemplate( v8::Isolate* isolate)
+{
+ v8::EscapableHandleScope handleScope( isolate );
+ v8::Local<v8::ObjectTemplate> objectTemplate;
+
+ if( mShaderTemplate.IsEmpty() )
+ {
+ objectTemplate = MakeShaderTemplate( isolate );
+ mShaderTemplate.Reset( isolate, objectTemplate );
+ }
+ else
+ {
+ // get the object template
+ objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mShaderTemplate );
+ }
+ return handleScope.Escape( objectTemplate );
+}
+
+v8::Handle<v8::ObjectTemplate> ShaderWrapper::MakeShaderTemplate( v8::Isolate* isolate )
+{
+ v8::EscapableHandleScope handleScope( isolate );
+
+ v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+
+ // property handle intercepts property getters and setters and signals
+ HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+ objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+ return handleScope.Escape( objTemplate );
+}
+
+void ShaderWrapper::NewShader( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::HandleScope handleScope( isolate);
+
+ if(!args.IsConstructCall())
+ {
+ DALI_SCRIPT_EXCEPTION( isolate, "Shader constructor called without 'new'");
+ return;
+ }
+ Dali::Shader shader = ShaderApi::New( isolate, args );
+
+ if(shader)
+ {
+ v8::Local<v8::Object> localObject = WrapShader( isolate, shader );
+ args.GetReturnValue().Set( localObject );
+ }
+}
+
+
+Shader ShaderWrapper::GetShader()
+{
+ return mShader;
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_V8PLUGIN_SHADER_WRAPPER_H__
+#define __DALI_V8PLUGIN_SHADER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+#include <dali/devel-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+
+/**
+ * A Shader wrapper.
+ * Provides access to Shader specific functionality and V8 memory handling.
+ */
+class ShaderWrapper : public HandleWrapper
+{
+
+public:
+
+ /**
+ * @brief Constructor
+ * @param[in] shader DALi shader
+ * @param[in] gc garbage collection interface
+ */
+ ShaderWrapper( const Shader& shader,
+ GarbageCollectorInterface& gc );
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~ShaderWrapper()
+ {
+ };
+
+ /**
+ * @brief Creates a new Shader wrapped inside a Javascript Object.
+ * @param[in] args v8 function call arguments interpreted
+ */
+ static void NewShader( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+ /**
+ * Wraps a shader
+ */
+ static v8::Handle<v8::Object> WrapShader(v8::Isolate* isolate, const Dali::Shader& );
+
+
+ // The ShaderAttribute ObjectTemplate, we cache templates so we don't have
+ // keep generating them everytime we want to create a Shader
+ static v8::Persistent<v8::ObjectTemplate> mShaderTemplate;
+
+ /**
+ * @brief Gets the handle of shader
+ * @return the handle of shader
+ */
+ Shader GetShader();
+
+
+private:
+
+ // Shader
+ Shader mShader;
+
+ /**
+ * @brief Creates the object template that used to create shader at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Handle<v8::ObjectTemplate> MakeShaderTemplate( v8::Isolate* isolate );
+
+ /**
+ * @brief Gets the object template that used to create shader at runtime
+ * @param[in] isolate v8 isolated instance
+ * @return the object template
+ */
+ static v8::Local<v8::ObjectTemplate> GetShaderTemplate( v8::Isolate* isolate );
+
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // __DALI_V8PLUGIN_SHADER_WRAPPER_H__
RENDER_TASK,
RENDER_TASK_LIST,
TIMER,
+ SHADER,
+ SAMPLER,
+ MATERIAL,
+ GEOMETRY,
+ RENDERER,
+ PROPERTY_BUFFER,
TAP_GESTURE,
SHADER_EFFECT,
PAN_GESTURE,
#include <image/image-wrapper.h>
#include <animation/animation-wrapper.h>
#include <shader-effects/shader-effect-wrapper.h>
+#include <rendering/shader-wrapper.h>
namespace Dali
v8::Local<v8::Object> image = ImageWrapper::WrapImage(isolate, Image::DownCast(handle) );
args.GetReturnValue().Set( image );
}
+ if( typeName == "ShaderEffect")
+ {
+ v8::Local<v8::Object> shaderEffect = ShaderEffectWrapper::WrapShaderEffect(isolate, ShaderEffect::DownCast( handle ));
+ args.GetReturnValue().Set( shaderEffect );
+ }
if( typeName == "Shader")
{
- v8::Local<v8::Object> shader = ShaderEffectWrapper::WrapShaderEffect(isolate, ShaderEffect::DownCast( handle ));
+ v8::Local<v8::Object> shader = ShaderWrapper::WrapShader(isolate, Shader::DownCast( handle ));
args.GetReturnValue().Set( shader );
}
-
}
void BuilderApi::ApplyStyle( const v8::FunctionCallbackInfo< v8::Value >& args )
{
{
v8::HandleScope handleScope( isolate);
- Property::Value daliPropertyValue;// creates a property with Property::INVALID
+ Property::Value daliPropertyValue;// creates a property with Property::NONE
found = false;
// Get the value
v8::Local<v8::Value> value = object->Get( key );
- std::string valueString = V8Utils::v8StringToStdString( value );
-
- propertyMap[ keyString ] = valueString.c_str();
+ if( value->IsBoolean() )
+ {
+ v8::Local<v8::Boolean> v = value->ToBoolean();
+ propertyMap[ keyString ] = v->Value();
+ }
+ else if( value->IsNumber() )
+ {
+ v8::Local<v8::Number> v = value->ToNumber();
+ propertyMap[ keyString ] = static_cast<float>(v->Value());
+ }
+ else if( value->IsInt32() || value->IsUint32() )
+ {
+ v8::Local<v8::Int32> v = value->ToInt32();
+ propertyMap[ keyString ] = static_cast<int>(v->Value());
+ }
+ else if( value->IsString() )
+ {
+ std::string valueString = V8Utils::v8StringToStdString( value );
+ propertyMap[ keyString ] = valueString.c_str();
+ }
+ else if( value->IsArray() )
+ {
+ propertyMap[ keyString ] = PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, value);
+ }
}
+
return propertyMap;
}
found = true;
return args[ index ]->Int32Value();
}
+ else
{
return defaultValue;
}
found = true;
return args[ index ]->NumberValue();
}
+ else
{
return defaultValue;
}
}
}
+void* GetArrayBufferViewParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+ found = false;
+ unsigned int length = args.Length();
+ if( index < length && args[index]->IsArrayBufferView() )
+ {
+ found = true;
+ v8::ArrayBufferView* bufferView = v8::ArrayBufferView::Cast(*(args[index]));
+ v8::Handle<v8::ArrayBuffer> buffer = bufferView->Buffer();
+ v8::ArrayBuffer::Contents contents = buffer->Externalize();
+ return contents.Data();
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
{
v8::HandleScope handleScope( isolate);
}
}
+
RenderTask GetRenderTaskParameter( unsigned int paramIndex, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
{
found = false;
}
}
-
BaseWrappedObject* GetWrappedDaliObjectParameter( unsigned int index, BaseWrappedObject::Type type, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
{
v8::HandleScope handleScope( isolate);
/**
* Given a JavaScript object with
* @param [in] object JavaScrript object
- * @return DALi ProperyMap from the JavaScript object
+ * @return DALi ProperyMap from the JavaScript object
*/
Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::Local<v8::Object>& object);
/**
* @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
* @param[out] found whether the parameter was found
+ * @return ArrayBufferView from the JavaScript function arguments
+ */
+void* GetArrayBufferViewParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );
+
+/**
+ * @param [in] index parameter index, e.g. callMyFunc( index0, index1, index2).
+ * @param[out] found whether the parameter was found
* @return DALi Handle value from the JavaScript function arguments
*/
Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args );