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()
41 PropertyBuffer NewPropertyBuffer()
43 return PropertyBuffer::New( mBufferFormat,
47 Property::Map mBufferFormat;
54 * ## PropertyBuffer API
56 * PropertyBuffer is a handle to an object that contains a buffer of structured properties.
57 * It can be used to provide data to Geometry objects.
62 * var vertexFormat ={ "aPosition" : dali.PROPERTY_VECTOR2 };
63 * var vertexData = [ 0, 1,
69 * var vertexDataArray = new Float32Array(vertexData.length);
70 * vertexDataArray.set(vertexData, 0);
71 * var vertices = new dali.PropertyBuffer(vertexFormat, 5);
72 * vertices.setData(vertexDataArray);
74 * var geometry = new dali.Geometry();
75 * geometry.addVertexBuffer( vertices );
77 * @class PropertyBuffer
80 PropertyBuffer PropertyBufferApi::GetPropertyBuffer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
82 v8::HandleScope handleScope( isolate );
84 v8::Local<v8::Object> object = args.This();
85 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
86 void* ptr = field->Value();
88 PropertyBufferWrapper* wrapper = static_cast< PropertyBufferWrapper *>(ptr);
89 return wrapper->GetPropertyBuffer();
92 PropertyBuffer PropertyBufferApi::GetPropertyBufferFromParams( int paramIndex,
95 const v8::FunctionCallbackInfo< v8::Value >& args )
99 v8::HandleScope handleScope( isolate );
100 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::PROPERTY_BUFFER, isolate, args );
104 PropertyBufferWrapper* wrapper = static_cast< PropertyBufferWrapper *>(wrappedObject);
105 return wrapper->GetPropertyBuffer();
109 return PropertyBuffer();
114 * Create a new PropertyBuffer
116 * PropertyBuffers contains a buffer of structured properties and can be
117 * used to provide data to Geometry objects.
120 * @for PropertyBuffer
121 * @method PropertyBuffer
122 * @param {Object} bufferFormat
123 * @param {integer} size
124 * @return {Object} PropertyBuffer
127 * var bufferFormat = {
128 * "aPosition" : dali.PROPERTY_VECTOR2,
129 * "aTexCoord" : dali.PROPERTY_VECTOR2,
130 * "aHue" : dali.PROPERTY_FLOAT,
133 * var buffer = new dali.PropertyBuffer(bufferFormat, 5);
136 PropertyBuffer PropertyBufferApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
138 v8::HandleScope handleScope( isolate );
141 Dali::Property::Map bufferFormat = V8Utils::GetPropertyMapParameter( PARAMETER_0, found, isolate, args);
142 if( !found || bufferFormat.Empty() )
144 DALI_SCRIPT_EXCEPTION( isolate, "invalid property map parameter" );
145 return PropertyBuffer();
149 int size = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0);
152 DALI_SCRIPT_EXCEPTION( isolate, "missing buffer size from param 1" );
153 return PropertyBuffer();
156 return PropertyBuffer::New(bufferFormat, static_cast<std::size_t>(size));
160 * Update the whole buffer information
162 * This function expects an array of data with the same format that was given
163 * in the construction, and the number of elements to be the same as the size
167 * @for PropertyBuffer
168 * @param {Object} data The data that will be copied to the buffer.
171 * var vertexData = [ 0, 1,
177 * var vertexDataArray = new Float32Array(vertexData.length);
178 * vertexDataArray.set(vertexData, 0);
180 * propertyBuffer.setData( vertexDataArray );
183 void PropertyBufferApi::SetData( const v8::FunctionCallbackInfo< v8::Value >& args )
185 v8::Isolate* isolate = args.GetIsolate();
186 v8::HandleScope handleScope( isolate );
188 PropertyBuffer buffer = GetPropertyBuffer( isolate, args );
191 void* data = V8Utils::GetArrayBufferViewParameter( PARAMETER_0, found, isolate, args);
194 DALI_SCRIPT_EXCEPTION( isolate, "invalid data parameter" );
198 buffer.SetData( data );
202 } // namespace V8Plugin