Force the DataPointer type to be numeric on HTML5
This commit is contained in:
@@ -2458,7 +2458,7 @@ class GL
|
||||
context.vertexAttrib1f(index, v0);
|
||||
}
|
||||
|
||||
public static inline function vertexAttrib1fv(index:Int, v:DataPointer):Void
|
||||
public static inline function vertexAttrib1fv(index:Int, v:#if (!js || !html5 || doc_gen) DataPointer #else Dynamic #end):Void
|
||||
{
|
||||
#if !doc_gen
|
||||
context.vertexAttrib1fv(index, v);
|
||||
@@ -2477,7 +2477,7 @@ class GL
|
||||
context.vertexAttrib2f(index, v0, v1);
|
||||
}
|
||||
|
||||
public static inline function vertexAttrib2fv(index:Int, v:DataPointer):Void
|
||||
public static inline function vertexAttrib2fv(index:Int, v:#if (!js || !html5 || doc_gen) DataPointer #else Dynamic #end):Void
|
||||
{
|
||||
#if !doc_gen
|
||||
context.vertexAttrib2fv(index, v);
|
||||
@@ -2496,7 +2496,7 @@ class GL
|
||||
context.vertexAttrib3f(index, v0, v1, v2);
|
||||
}
|
||||
|
||||
public static inline function vertexAttrib3fv(index:Int, v:DataPointer):Void
|
||||
public static inline function vertexAttrib3fv(index:Int, v:#if (!js || !html5 || doc_gen) DataPointer #else Dynamic #end):Void
|
||||
{
|
||||
#if !doc_gen
|
||||
context.vertexAttrib3fv(index, v);
|
||||
@@ -2515,7 +2515,7 @@ class GL
|
||||
context.vertexAttrib4f(index, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
public static inline function vertexAttrib4fv(index:Int, v:DataPointer):Void
|
||||
public static inline function vertexAttrib4fv(index:Int, v:#if (!js || !html5 || doc_gen) DataPointer #else Dynamic #end):Void
|
||||
{
|
||||
#if !doc_gen
|
||||
context.vertexAttrib4fv(index, v);
|
||||
@@ -2539,7 +2539,7 @@ class GL
|
||||
context.vertexAttribI4i(index, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
public static inline function vertexAttribI4iv(index:Int, v:DataPointer):Void
|
||||
public static inline function vertexAttribI4iv(index:Int, v:#if (!js || !html5 || doc_gen) DataPointer #else Dynamic #end):Void
|
||||
{
|
||||
#if !doc_gen
|
||||
context.vertexAttribI4iv(index, v);
|
||||
@@ -2558,7 +2558,7 @@ class GL
|
||||
context.vertexAttribI4ui(index, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
public static inline function vertexAttribI4uiv(index:Int, v:DataPointer):Void
|
||||
public static inline function vertexAttribI4uiv(index:Int, v:#if (!js || !html5 || doc_gen) DataPointer #else Dynamic #end):Void
|
||||
{
|
||||
#if !doc_gen
|
||||
context.vertexAttribI4uiv(index, v);
|
||||
|
||||
@@ -22,28 +22,22 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
this = data;
|
||||
}
|
||||
|
||||
#if (lime_cffi && !js)
|
||||
@:from @:noCompletion private static function fromInt(value:Int):DataPointer
|
||||
{
|
||||
#if (lime_cffi && !macro)
|
||||
var float:Float = value;
|
||||
return new DataPointer(float);
|
||||
#elseif (js && !doc_gen)
|
||||
return new DataPointer(new DataPointerObject(value));
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
#else
|
||||
@:from @:noCompletion private static function fromFloat(value:Float):DataPointer
|
||||
{
|
||||
#if (lime_cffi && !macro)
|
||||
return new DataPointer(value);
|
||||
#elseif (js && !doc_gen)
|
||||
return new DataPointer(new DataPointerObject(Std.int(value)));
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
return cast value;
|
||||
}
|
||||
#end
|
||||
|
||||
#if (cpp && !cppia && !doc_gen)
|
||||
#if (haxe_ver < 4)
|
||||
@@ -73,10 +67,8 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
if (pointer == null || pointer.bytes == null) return cast 0;
|
||||
var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset(pointer.bytes, pointer.offset);
|
||||
return new DataPointer(data);
|
||||
#elseif (js && !doc_gen)
|
||||
return new DataPointer(new DataPointerObject(null, pointer.bytes.getData(), pointer.offset));
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -89,10 +81,8 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
if (arrayBufferView == null) return cast 0;
|
||||
var data:Float = NativeCFFI.lime_bytes_get_data_pointer_offset(arrayBufferView.buffer, arrayBufferView.byteOffset);
|
||||
return new DataPointer(data);
|
||||
#elseif (js && !doc_gen)
|
||||
return new DataPointer(new DataPointerObject(arrayBufferView));
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -101,10 +91,8 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
#if (lime_cffi && !macro)
|
||||
if (buffer == null) return cast 0;
|
||||
return fromBytes(buffer);
|
||||
#elseif (js && !doc_gen)
|
||||
return new DataPointer(new DataPointerObject(buffer));
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -117,10 +105,8 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
if (bytes == null) return cast 0;
|
||||
var data:Float = NativeCFFI.lime_bytes_get_data_pointer(bytes);
|
||||
return new DataPointer(data);
|
||||
#elseif (js && !doc_gen)
|
||||
return fromArrayBuffer(bytes.getData());
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -129,10 +115,8 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
#if (lime_cffi && !macro)
|
||||
if (bytesData == null) return cast 0;
|
||||
return fromBytes(Bytes.ofData(bytesData));
|
||||
#elseif (js && !doc_gen)
|
||||
return fromArrayBuffer(bytesData);
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -148,7 +132,7 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
if (pointer == null) return cast 0;
|
||||
return new DataPointer(pointer.get());
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
@@ -158,209 +142,10 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
#if (lime_cffi && !macro)
|
||||
return fromBytes(LimeBytes.fromFile(path));
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
#if (js && html5 && !doc_gen)
|
||||
@:dox(hide) @:noCompletion public function toBufferOrBufferView(?length:Int):Dynamic
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return null");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case BUFFER_VIEW:
|
||||
if (length == null) length = data.bufferView.byteLength;
|
||||
|
||||
if (data.offset == 0 && length == data.bufferView.byteLength)
|
||||
{
|
||||
return data.bufferView;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UInt8Array(data.bufferView.buffer, data.bufferView.byteOffset + data.offset, length);
|
||||
}
|
||||
|
||||
case BUFFER:
|
||||
if (length == null) length = data.buffer.byteLength;
|
||||
|
||||
if (data.offset == 0 && length == data.buffer.byteLength)
|
||||
{
|
||||
return data.buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UInt8Array(data.buffer, data.offset, length);
|
||||
}
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) @:noCompletion public function toBufferView(?length:Int):Dynamic
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return null");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case BUFFER_VIEW:
|
||||
if (length == null) length = data.bufferView.byteLength;
|
||||
|
||||
if (data.offset == 0 && length == data.bufferView.byteLength)
|
||||
{
|
||||
return data.bufferView;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UInt8Array(data.bufferView.buffer, data.bufferView.byteOffset + data.offset, length);
|
||||
}
|
||||
|
||||
case BUFFER:
|
||||
if (length == null) length = data.buffer.byteLength;
|
||||
return new UInt8Array(data.buffer, data.offset, length);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) @:noCompletion public function toFloat32Array(?length:Int):Float32Array
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return null");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case BUFFER_VIEW:
|
||||
if (length == null) length = data.bufferView.byteLength;
|
||||
if (data.offset == 0
|
||||
&& length == data.bufferView.byteLength
|
||||
&& untyped __js__("data.bufferView.constructor == Float32Array"))
|
||||
{
|
||||
return cast data.bufferView;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (length > data.bufferView.byteLength) length = data.bufferView.byteLength;
|
||||
return new Float32Array(data.bufferView.buffer, data.bufferView.byteOffset + data.offset, Std.int(length / Float32Array.BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
case BUFFER:
|
||||
if (length == null) length = data.buffer.byteLength;
|
||||
return new Float32Array(data.buffer, data.offset, Std.int(length / Float32Array.BYTES_PER_ELEMENT));
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) @:noCompletion public function toInt32Array(?length:Int):Int32Array
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return null");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case BUFFER_VIEW:
|
||||
if (length == null) length = data.bufferView.byteLength;
|
||||
if (data.offset == 0
|
||||
&& length == data.bufferView.byteLength
|
||||
&& untyped __js__("data.bufferView.constructor == Int32Array"))
|
||||
{
|
||||
return cast data.bufferView;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Int32Array(data.bufferView.buffer, data.bufferView.byteOffset + data.offset, Std.int(length / Int32Array.BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
case BUFFER:
|
||||
if (length == null) length = data.buffer.byteLength;
|
||||
return new Int32Array(data.buffer, data.offset, Std.int(length / Int32Array.BYTES_PER_ELEMENT));
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) @:noCompletion public function toUInt8Array(?length:Int):UInt8Array
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return null");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case BUFFER_VIEW:
|
||||
if (length == null) length = data.bufferView.byteLength;
|
||||
if (data.offset == 0
|
||||
&& length == data.bufferView.byteLength
|
||||
&& untyped __js__("data.bufferView.constructor == Uint8Array"))
|
||||
{
|
||||
return cast data.bufferView;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UInt8Array(data.bufferView.buffer, data.bufferView.byteOffset + data.offset, length);
|
||||
}
|
||||
|
||||
case BUFFER:
|
||||
if (length == null) length = data.buffer.byteLength;
|
||||
return new UInt8Array(data.buffer, data.offset, length);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) @:noCompletion public function toUInt32Array(?length:Int):UInt32Array
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return null");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case BUFFER_VIEW:
|
||||
if (length == null) length = data.bufferView.byteLength;
|
||||
if (data.offset == 0
|
||||
&& length == data.bufferView.byteLength
|
||||
&& untyped __js__("data.bufferView.constructor == Uint32Array"))
|
||||
{
|
||||
return cast data.bufferView;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UInt32Array(data.bufferView.buffer, data.bufferView.byteOffset + data.offset, Std.int(length / UInt32Array.BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
case BUFFER:
|
||||
if (length == null) length = data.buffer.byteLength;
|
||||
return new UInt32Array(data.buffer, data.offset, Std.int(length / UInt32Array.BYTES_PER_ELEMENT));
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) @:noCompletion public function toValue():Int
|
||||
{
|
||||
var data:DataPointerObject = this;
|
||||
untyped __js__("if (!data) return 0");
|
||||
untyped __js__("if (typeof data === 'number') return data");
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case VALUE:
|
||||
return data.offset;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
private static function __withOffset(data:DataPointer, offset:Int):DataPointer
|
||||
{
|
||||
#if (lime_cffi && !macro)
|
||||
@@ -368,7 +153,7 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
var data:Float = NativeCFFI.lime_data_pointer_offset(data, offset);
|
||||
return new DataPointer(data);
|
||||
#else
|
||||
return null;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -464,40 +249,5 @@ abstract DataPointer(DataPointerType) to DataPointerType
|
||||
#if (lime_cffi && !js)
|
||||
private typedef DataPointerType = Float;
|
||||
#else
|
||||
private typedef DataPointerType = Dynamic;
|
||||
|
||||
@:dox(hide) class DataPointerObject
|
||||
{
|
||||
public var buffer:ArrayBuffer;
|
||||
public var bufferView:ArrayBufferView;
|
||||
public var offset:Int;
|
||||
public var type:DataPointerObjectType;
|
||||
|
||||
public function new(?bufferView:ArrayBufferView, ?buffer:ArrayBuffer, offset:Int = 0)
|
||||
{
|
||||
if (bufferView != null)
|
||||
{
|
||||
this.bufferView = bufferView;
|
||||
type = BUFFER_VIEW;
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this.buffer = buffer;
|
||||
type = BUFFER;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = VALUE;
|
||||
}
|
||||
|
||||
this.offset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
@:dox(hide) enum DataPointerObjectType
|
||||
{
|
||||
BUFFER;
|
||||
BUFFER_VIEW;
|
||||
VALUE;
|
||||
}
|
||||
#end
|
||||
private typedef DataPointerType = Int;
|
||||
#end
|
||||
Reference in New Issue
Block a user