Skip to content

Commit

Permalink
prepare refactor for haxe 4-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Mar 9, 2019
1 parent 20261ae commit 471e161
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
18 changes: 8 additions & 10 deletions h3d/impl/GlDriver.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import h3d.mat.Data;
#if (js||cpp||hlsdl||usegl)

#if js
import js.html.Uint16Array;
import js.html.Uint8Array;
import js.html.Float32Array;
import hxd.impl.TypedArray;
private typedef GL = js.html.webgl.GL;
private extern class GL2 extends js.html.webgl.GL {
// webgl2
Expand Down Expand Up @@ -1134,9 +1132,9 @@ class GlDriver extends Driver {
gl.texImage2D(face, mipLevel, t.t.internalFmt, pixels.width, pixels.height, 0, getChannels(t.t), t.t.pixelFmt, bytesToUint8Array(pixels.bytes));
#elseif js
var buffer = switch( t.format ) {
case RGBA32F, R32F, RG32F, RGB32F: new js.html.Float32Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset);
case RGBA16F, R16F, RG16F, RGB16F: new js.html.Uint16Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset);
case RGB10A2, RG11B10UF: new js.html.Uint32Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset);
case RGBA32F, R32F, RG32F, RGB32F: new Float32Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset);
case RGBA16F, R16F, RG16F, RGB16F: new Uint16Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset);
case RGB10A2, RG11B10UF: new Uint32Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset);
default: bytesToUint8Array(pixels.bytes,pixels.offset);
}
if( t.format.match(S3TC(_)) )
Expand Down Expand Up @@ -1611,11 +1609,11 @@ class GlDriver extends Driver {
throw "Can't capture main render buffer in GL";
discardError();
#if js
var buffer : js.html.ArrayBufferView = @:privateAccess pixels.bytes.b;
var buffer : ArrayBufferView = @:privateAccess pixels.bytes.b;
switch( curTarget.format ) {
case RGBA32F, R32F, RG32F, RGB32F: buffer = new js.html.Float32Array(buffer.buffer);
case RGBA16F, R16F, RG16F, RGB16F: buffer = new js.html.Uint16Array(buffer.buffer);
case RGB10A2, RG11B10UF: buffer = new js.html.Uint32Array(buffer.buffer);
case RGBA32F, R32F, RG32F, RGB32F: buffer = new Float32Array(buffer.buffer);
case RGBA16F, R16F, RG16F, RGB16F: buffer = new Uint16Array(buffer.buffer);
case RGB10A2, RG11B10UF: buffer = new Uint32Array(buffer.buffer);
default:
}
#else
Expand Down
2 changes: 1 addition & 1 deletion h3d/shader/Buffers.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package h3d.shader;
public var Buffers = 3;
}

typedef ShaderBufferData = #if js js.html.Float32Array #else haxe.ds.Vector<hxd.impl.Float32> #end;
typedef ShaderBufferData = hxd.impl.TypedArray.Float32Array;

class ShaderBuffers {

Expand Down
9 changes: 5 additions & 4 deletions hxd/FloatBuffer.hx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package hxd;
import hxd.impl.TypedArray;

private typedef InnerData = #if flash flash.Vector<Float> #elseif js Float32Expand #else Array<hxd.impl.Float32> #end

#if js
private abstract Float32Expand({ pos : Int, array : js.html.Float32Array }) {
private abstract Float32Expand({ pos : Int, array : hxd.impl.TypedArray.Float32Array }) {

public var length(get, set) : Int;

public function new(length) {
this = { pos : 0, array : new js.html.Float32Array(new js.html.ArrayBuffer(length<<2)) };
this = { pos : 0, array : new Float32Array(new ArrayBuffer(length<<2)) };
}

inline function get_length() return this.pos;
inline function set_length(v:Int) {
if( length != v ) {
var newArray = new js.html.Float32Array(v);
var newArray = new Float32Array(v);
newArray.set(this.array);
this.array = newArray;
}
Expand All @@ -26,7 +27,7 @@ private abstract Float32Expand({ pos : Int, array : js.html.Float32Array }) {
if( this.pos == this.array.length ) {
var newSize = this.array.length << 1;
if( newSize < 128 ) newSize = 128;
var newArray = new js.html.Float32Array(newSize);
var newArray = new Float32Array(newSize);
newArray.set(this.array);
this.array = newArray;
}
Expand Down
2 changes: 1 addition & 1 deletion hxd/fmt/fbx/HMDOut.hx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class HMDOut extends BaseLibrary {
for( _ in skin.splitJoints ) ibufs.push(new hxd.IndexBuffer());

g.bounds = new h3d.col.Bounds();
var tmpBuf = #if js new js.html.Float32Array(stride) #else new haxe.ds.Vector<hxd.impl.Float32>(stride) #end;
var tmpBuf = new hxd.impl.TypedArray.Float32Array(stride);
var vertexRemap = new Array<Int>();
var index = geom.getPolygons();
var count = 0, matPos = 0, stri = 0;
Expand Down
14 changes: 14 additions & 0 deletions hxd/impl/TypedArray.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hxd.impl;

#if js

typedef Float32Array = js.html.Float32Array;
typedef Uint16Array = js.html.Uint16Array;
typedef Uint8Array = js.html.Uint8Array;
typedef ArrayBuffer = js.html.ArrayBuffer;
typedef Uint32Array = js.html.Uint32Array;
typedef ArrayBufferView = js.html.ArrayBufferView;

#else
typedef Float32Array = haxe.ds.Vector<Float32>;
#end
2 changes: 1 addition & 1 deletion hxd/impl/UncheckedBytes.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hxd.impl;

private typedef InnerData = #if hl hl.Bytes #elseif js js.html.Uint8Array #else haxe.io.BytesData #end
private typedef InnerData = #if hl hl.Bytes #elseif js TypedArray.Uint8Array #else haxe.io.BytesData #end

abstract UncheckedBytes(InnerData) {

Expand Down
2 changes: 1 addition & 1 deletion hxd/snd/Mp3Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Mp3Data extends Data {
}

var right = buf.numberOfChannels < 2 ? left : buf.getChannelData(1);
var join = new js.html.Float32Array(left.length * 2);
var join = new hxd.impl.TypedArray.Float32Array(left.length * 2);
var w = 0;
for( i in 0...buf.length ) {
join[w++] = left[i];
Expand Down

0 comments on commit 471e161

Please sign in to comment.