@@ -276,18 +276,51 @@ Handle<Value> GLESglDrawElementsCallback(const Arguments& args) {
276
276
return res;
277
277
}
278
278
279
+ static int _ExternalArrayTypeToElementSize (ExternalArrayType type) {
280
+ switch (type) {
281
+ case kExternalByteArray : return sizeof (int8_t );
282
+ case kExternalUnsignedByteArray : return sizeof (uint8_t );
283
+ case kExternalShortArray : return sizeof (int16_t );
284
+ case kExternalUnsignedShortArray : return sizeof (uint16_t );
285
+ case kExternalIntArray : return sizeof (int32_t );
286
+ case kExternalUnsignedIntArray : return sizeof (uint32_t );
287
+ case kExternalFloatArray : return sizeof (float );
288
+ case kExternalDoubleArray : return sizeof (double );
289
+ case kExternalPixelArray : return sizeof (uint8_t );
290
+ default : return 0 ;
291
+ }
292
+ }
293
+
279
294
// Accepts GL_UNSIGNED_SHORT and GL_FLOAT as types
280
295
// TODO(nico): deal with interleaved data
281
296
Handle<Value> GLESglBufferDataCallback (const Arguments& args) {
282
- if (args.Length () != 4 || !args[1 ]->IsArray ())
283
- return v8::Undefined ( );
297
+ if (args.Length () != 4 || !args[1 ]->IsObject ())
298
+ return ThrowException ( String::New ( " Bad arguments to bufferData " ) );
284
299
285
300
unsigned int target = args[0 ]->Uint32Value ();
286
301
unsigned int type = args[2 ]->Uint32Value ();
287
302
unsigned int usage = args[3 ]->Uint32Value ();
288
- Handle<Array> data = Handle<Array>::Cast (args[1 ]);
289
- unsigned int len = data->Length ();
303
+ Handle<Object> source = Handle<Object>::Cast (args[1 ]);
304
+
305
+ if (source->HasIndexedPropertiesInExternalArrayData ()) {
306
+ const void *data = source->GetIndexedPropertiesExternalArrayData ();
307
+ int len = source->GetIndexedPropertiesExternalArrayDataLength ();
308
+ int element_size= _ExternalArrayTypeToElementSize
309
+ (source->GetIndexedPropertiesExternalArrayDataType ());
310
+ if (element_size==0 )
311
+ return ThrowException (String::New (" unknown array type" ));
290
312
313
+ glBufferData ((GLenum)target, (GLsizeiptr) (len * element_size),
314
+ data, (GLenum)usage);
315
+
316
+ Handle<Object> res (GlesFactory::self_);
317
+ return res;
318
+ }
319
+
320
+ if (!source->IsArray ())
321
+ return ThrowException (String::New (" Second argument not an array" ));
322
+ Handle<Array> data = Handle<Array>::Cast (source);
323
+ unsigned int len = data->Length ();
291
324
if (type == GL_FLOAT) {
292
325
GLfloat* arg1 = new GLfloat[len];
293
326
for (unsigned j = 0 ; j < len; j++) {
@@ -310,6 +343,8 @@ Handle<Value> GLESglBufferDataCallback(const Arguments& args) {
310
343
(const void *)arg1,
311
344
(GLenum)usage);
312
345
delete[] arg1;
346
+ } else {
347
+ return ThrowException (String::New (" Unsupported type" ));
313
348
}
314
349
315
350
Handle<Object> res (GlesFactory::self_);
0 commit comments