2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "property-buffer-api.h"
23 #include <object/property-buffer-wrapper.h>
31 namespace // unnamed namespace
34 struct PropertyBufferParameters
36 PropertyBufferParameters()
40 PropertyBuffer NewPropertyBuffer()
42 return PropertyBuffer::New( mBufferFormat );
45 Property::Map mBufferFormat;
51 * ## PropertyBuffer API
53 * PropertyBuffer is a handle to an object that contains a buffer of structured properties.
54 * It can be used to provide data to Geometry objects.
59 * var vertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2 };
60 * var vertexData = [ 0, 1,
66 * var vertexDataArray = new Float32Array(vertexData.length);
67 * vertexDataArray.set(vertexData, 0);
68 * var vertices = new dali.PropertyBuffer(vertexFormat, 5);
69 * vertices.setData(vertexDataArray);
71 * var geometry = new dali.Geometry();
72 * geometry.addVertexBuffer( vertices );
74 * @class PropertyBuffer
77 PropertyBuffer PropertyBufferApi::GetPropertyBuffer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
79 v8::HandleScope handleScope( isolate );
81 v8::Local<v8::Object> object = args.This();
82 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
83 void* ptr = field->Value();
85 PropertyBufferWrapper* wrapper = static_cast< PropertyBufferWrapper *>(ptr);
86 return wrapper->GetPropertyBuffer();
89 PropertyBuffer PropertyBufferApi::GetPropertyBufferFromParams( int paramIndex,
92 const v8::FunctionCallbackInfo< v8::Value >& args )
96 v8::HandleScope handleScope( isolate );
97 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::PROPERTY_BUFFER, isolate, args );
101 PropertyBufferWrapper* wrapper = static_cast< PropertyBufferWrapper *>(wrappedObject);
102 return wrapper->GetPropertyBuffer();
106 return PropertyBuffer();
111 * Create a new PropertyBuffer
113 * PropertyBuffers contains a buffer of structured properties and can be
114 * used to provide data to Geometry objects.
117 * @for PropertyBuffer
118 * @method PropertyBuffer
119 * @param {Object} bufferFormat Map of names and types that describes the components of the buffer
120 * @param {integer} size The number of elements in the property buffer
121 * @return {Object} PropertyBuffer
124 * var bufferFormat = {
125 * "aPosition" : dali.PROPERTY_VECTOR2,
126 * "aTexCoord" : dali.PROPERTY_VECTOR2,
127 * "aHue" : dali.PROPERTY_FLOAT,
130 * var buffer = new dali.PropertyBuffer(bufferFormat, 5);
133 PropertyBuffer PropertyBufferApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
135 v8::HandleScope handleScope( isolate );
138 Dali::Property::Map bufferFormat = V8Utils::GetPropertyMapParameter( PARAMETER_0, found, isolate, args);
139 if( !found || bufferFormat.Empty() )
141 DALI_SCRIPT_EXCEPTION( isolate, "invalid property map parameter" );
142 return PropertyBuffer();
145 return PropertyBuffer::New( bufferFormat );
149 * Update the whole buffer information
151 * This function expects an array of data with the same format that was given
152 * in the construction, and the number of elements to be the same as the size
156 * @for PropertyBuffer
157 * @param {Float32Array} data The data that will be copied to the buffer.
160 * var vertexData = [ 0, 1,
166 * var vertexDataArray = new Float32Array(vertexData.length);
167 * vertexDataArray.set(vertexData, 0);
169 * propertyBuffer.setData( vertexDataArray, vertexData.length );
172 void PropertyBufferApi::SetData( const v8::FunctionCallbackInfo< v8::Value >& args )
174 v8::Isolate* isolate = args.GetIsolate();
175 v8::HandleScope handleScope( isolate );
177 PropertyBuffer buffer = GetPropertyBuffer( isolate, args );
180 void* data = V8Utils::GetArrayBufferViewParameter( PARAMETER_0, found, isolate, args);
184 DALI_SCRIPT_EXCEPTION( isolate, "invalid data parameter" );
188 int size = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0);
191 DALI_SCRIPT_EXCEPTION( isolate, "missing buffer size from param 1" );
195 buffer.SetData( data, size );
200 } // namespace V8Plugin