6
6
#import " EJConvertWebGL.h"
7
7
#import " EJJavaScriptView.h"
8
8
9
- #import < JavaScriptCore/JSTypedArray.h >
9
+ #import " EJConvertTypedArray.h "
10
10
11
11
12
12
@implementation EJBindingCanvasContextWebGL
@@ -365,10 +365,10 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
365
365
glBufferData (target, psize, NULL , usage);
366
366
}
367
367
else if ( JSValueIsObject (ctx, argv[1 ]) ) {
368
- size_t size ;
369
- GLvoid *buffer = JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)argv[ 1 ], &size);
370
- if ( buffer ) {
371
- glBufferData (target, size , buffer, usage);
368
+ NSData *data = JSObjectGetTypedArrayData (ctx, (JSObjectRef)argv[ 1 ]) ;
369
+ if ( data ) {
370
+ const GLvoid * buffer = data. bytes ;
371
+ glBufferData (target, data. length , buffer, usage);
372
372
}
373
373
}
374
374
@@ -383,10 +383,10 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
383
383
GLenum target = JSValueToNumberFast (ctx, argv[0 ]);
384
384
GLintptr offset = JSValueToNumberFast (ctx, argv[1 ]);
385
385
386
- size_t size ;
387
- GLvoid *buffer = JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)argv[ 2 ], &size);
388
- if ( buffer ) {
389
- glBufferSubData (target, offset, size , buffer);
386
+ NSData *data = JSObjectGetTypedArrayData (ctx, (JSObjectRef)argv[ 2 ]) ;
387
+ if ( data ) {
388
+ const GLvoid * buffer = data. bytes ;
389
+ glBufferSubData (target, offset, data. length , buffer);
390
390
}
391
391
return NULL ;
392
392
}
@@ -726,6 +726,7 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
726
726
int intbuffer[4 ];
727
727
float floatvalue;
728
728
JSValueRef arrayArgs[4 ];
729
+ NSMutableData *data;
729
730
730
731
switch ( pname ) {
731
732
// Float32Array (with 0 elements)
@@ -737,28 +738,40 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
737
738
case GL_ALIASED_LINE_WIDTH_RANGE:
738
739
case GL_ALIASED_POINT_SIZE_RANGE:
739
740
case GL_DEPTH_RANGE:
741
+ data = [[NSMutableData alloc ] initWithLength: 2 * sizeof (GLfloat)];
742
+ glGetFloatv (pname, data.mutableBytes );
740
743
ret = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeFloat32Array , 2 );
741
- glGetFloatv (pname, JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)ret, NULL ));
744
+ JSObjectSetTypedArrayData (ctx, (JSObjectRef)ret, data);
745
+ [data release ];
742
746
break ;
743
747
744
748
// Float32Array (with 4 values)
745
749
case GL_BLEND_COLOR:
746
750
case GL_COLOR_CLEAR_VALUE:
751
+ data = [[NSMutableData alloc ] initWithLength: 4 * sizeof (GLfloat)];
752
+ glGetFloatv (pname, data.mutableBytes );
747
753
ret = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeFloat32Array , 4 );
748
- glGetFloatv (pname, JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)ret, NULL ));
754
+ JSObjectSetTypedArrayData (ctx, (JSObjectRef)ret, data);
755
+ [data release ];
749
756
break ;
750
757
751
758
// Int32Array (with 2 values)
752
759
case GL_MAX_VIEWPORT_DIMS:
760
+ data = [[NSMutableData alloc ] initWithLength: 2 * sizeof (GLint)];
761
+ glGetIntegerv (pname, data.mutableBytes );
753
762
ret = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeInt32Array , 2 );
754
- glGetIntegerv (pname, JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)ret, NULL ));
763
+ JSObjectSetTypedArrayData (ctx, (JSObjectRef)ret, data);
764
+ [data release ];
755
765
break ;
756
766
757
767
// Int32Array (with 4 values)
758
768
case GL_SCISSOR_BOX:
759
769
case GL_VIEWPORT:
770
+ data = [[NSMutableData alloc ] initWithLength: 4 * sizeof (GLint)];
771
+ glGetIntegerv (pname, data.mutableBytes );
760
772
ret = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeInt32Array , 4 );
761
- glGetIntegerv (pname, JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)ret, NULL ));
773
+ JSObjectSetTypedArrayData (ctx, (JSObjectRef)ret, data);
774
+ [data release ];
762
775
break ;
763
776
764
777
// boolean[] (with 4 values)
@@ -1147,15 +1160,21 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
1147
1160
// Float32Array
1148
1161
if ( type == GL_FLOAT ) {
1149
1162
array = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeFloat32Array , size);
1150
- void *buffer = JSObjectGetTypedArrayDataPtr (ctx, array, NULL );
1151
- glGetUniformfv (program, uniform, buffer);
1163
+ NSMutableData *data = [[NSMutableData alloc ] initWithLength: size * sizeof (GLfloat)];
1164
+ glGetUniformfv (program, uniform, data.mutableBytes );
1165
+
1166
+ JSObjectSetTypedArrayData (ctx, array, data);
1167
+ [data release ];
1152
1168
}
1153
1169
1154
1170
// Int32Array
1155
1171
else if ( type == GL_INT ) {
1156
1172
array = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeInt32Array , size);
1157
- void *buffer = JSObjectGetTypedArrayDataPtr (ctx, array, NULL );
1158
- glGetUniformiv (program, uniform, buffer);
1173
+ NSMutableData *data = [[NSMutableData alloc ] initWithLength: size * sizeof (GLint)];
1174
+ glGetUniformiv (program, uniform, data.mutableBytes );
1175
+
1176
+ JSObjectSetTypedArrayData (ctx, array, data);
1177
+ [data release ];
1159
1178
}
1160
1179
1161
1180
// boolean[]
@@ -1202,8 +1221,10 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
1202
1221
}
1203
1222
else if ( pname == GL_CURRENT_VERTEX_ATTRIB ) {
1204
1223
JSObjectRef array = JSObjectMakeTypedArray (ctx, kJSTypedArrayTypeFloat32Array , 4 );
1205
- GLint *values = JSObjectGetTypedArrayDataPtr (ctx, array, NULL );
1206
- glGetVertexAttribiv (index , pname, values);
1224
+ NSMutableData *data = [[NSMutableData alloc ] initWithLength: 4 * sizeof (GLfloat)];
1225
+ glGetVertexAttribiv (index , pname, data.mutableBytes );
1226
+ JSObjectSetTypedArrayData (ctx, array, data);
1227
+ [data release ];
1207
1228
return array;
1208
1229
}
1209
1230
else {
@@ -1302,13 +1323,11 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
1302
1323
1303
1324
scriptView.currentRenderingContext = renderingContext;
1304
1325
1305
- size_t size;
1306
- void *pixels = JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)argv[6 ], &size);
1307
-
1308
1326
GLuint bytesPerPixel = EJGetBytesPerPixel (type, format);
1309
- if ( bytesPerPixel && size >= width * height * bytesPerPixel ) {
1310
- glReadPixels (x, y, width, height, format, type, pixels);
1311
- }
1327
+ NSMutableData *data = [[NSMutableData alloc ] initWithLength: width*height*bytesPerPixel];
1328
+ glReadPixels (x, y, width, height, format, type, data.mutableBytes );
1329
+ JSObjectSetTypedArrayData (ctx, (JSObjectRef)argv[6 ], data);
1330
+ [data release ];
1312
1331
1313
1332
return NULL ;
1314
1333
}
@@ -1463,10 +1482,10 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
1463
1482
if ( border == 0 && EJ_ARRAY_MATCHES_TYPE (arrayType, type) ) {
1464
1483
int bytesPerPixel = EJGetBytesPerPixel (type, format);
1465
1484
1466
- size_t byteLength ;
1467
- void *pixels = JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)argv[ 8 ], &byteLength) ;
1485
+ NSMutableData *data = JSObjectGetTypedArrayData (ctx, (JSObjectRef)argv[ 8 ]) ;
1486
+ void *pixels = data. mutableBytes ;
1468
1487
1469
- if ( bytesPerPixel && byteLength >= width * height * bytesPerPixel ) {
1488
+ if ( bytesPerPixel && data. length >= width * height * bytesPerPixel ) {
1470
1489
if ( unpackFlipY ) {
1471
1490
[EJTexture flipPixelsY: pixels bytesPerRow: (width * bytesPerPixel) rows: height];
1472
1491
}
@@ -1595,10 +1614,10 @@ - (void)deleteVertexArray:(GLuint)vertexArray {
1595
1614
if ( EJ_ARRAY_MATCHES_TYPE (arrayType, type) ) {
1596
1615
int bytesPerPixel = EJGetBytesPerPixel (type, format);
1597
1616
1598
- size_t byteLength ;
1599
- void *pixels = JSObjectGetTypedArrayDataPtr (ctx, (JSObjectRef)argv[ 8 ], &byteLength) ;
1617
+ NSMutableData *data = JSObjectGetTypedArrayData (ctx, (JSObjectRef)argv[ 8 ]) ;
1618
+ void *pixels = data. mutableBytes ;
1600
1619
1601
- if ( bytesPerPixel && byteLength >= width * height * bytesPerPixel ) {
1620
+ if ( bytesPerPixel && data. length >= width * height * bytesPerPixel ) {
1602
1621
if ( unpackFlipY ) {
1603
1622
[EJTexture flipPixelsY: pixels bytesPerRow: (width * bytesPerPixel) rows: height];
1604
1623
}
0 commit comments