From fae4c3195f5e80557a505ab8836034ad7a785558 Mon Sep 17 00:00:00 2001 From: Duncan Tebbs Date: Wed, 27 May 2015 11:49:20 +0900 Subject: [PATCH] tslib: give TechniqueParameterBuffer its own prototype. turbulenz/turbulenz_engine#43 --- tslib/webgl/graphicsdevice.ts | 127 +++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 50 deletions(-) diff --git a/tslib/webgl/graphicsdevice.ts b/tslib/webgl/graphicsdevice.ts index 44b5c737..5258b2e9 100644 --- a/tslib/webgl/graphicsdevice.ts +++ b/tslib/webgl/graphicsdevice.ts @@ -4911,65 +4911,95 @@ class WebGLTechniqueParameters implements TechniqueParameters // TechniqueParameterBuffer // var techniqueParameterBufferCreate = - function techniqueParameterBufferCreateFn(params): Float32Array + function techniqueParameterBufferCreateFn(gd: GraphicsDevice, + params: any) +: TechniqueParameterBuffer { - if (Float32Array.prototype.map === undefined) + var tpbProto = (gd).tpbProto; + if (!tpbProto) { - Float32Array.prototype.map = function techniqueParameterBufferMap(offset, numFloats) { - if (offset === undefined) - { - offset = 0; - } - var buffer = this; - if (numFloats === undefined) - { - numFloats = this.length; - } - function techniqueParameterBufferWriter() + var tpbProtoConstructor = function () + { + this.map = function techniqueParameterBufferMap(offset, numFloats) { - var numArguments = arguments.length; - for (var a = 0; a < numArguments; a += 1) + if (offset === undefined) { - var value = arguments[a]; - if (typeof value === 'number') - { - buffer[offset] = value; - offset += 1; - } - else + offset = 0; + } + var buffer = this; + if (numFloats === undefined) + { + numFloats = this.length; + } + function techniqueParameterBufferWriter() + { + var numArguments = arguments.length; + for (var a = 0; a < numArguments; a += 1) { - buffer.setData(value, offset, value.length); - offset += value.length; + var value = arguments[a]; + if (typeof value === 'number') + { + buffer[offset] = value; + offset += 1; + } + else + { + buffer.setData(value, offset, value.length); + offset += value.length; + } } } - } - return techniqueParameterBufferWriter; - }; - - /* tslint:disable:no-empty */ - Float32Array.prototype.unmap = function techniqueParameterBufferUnmap(writer) { - }; - /* tslint:enable:no-empty */ + return techniqueParameterBufferWriter; + }; - Float32Array.prototype.setData = function techniqueParameterBufferSetData(data, - offset?: number, - numValues?: number) { - if (offset === undefined) - { - offset = 0; - } - if (numValues === undefined) + /* tslint:disable:no-empty */ + this.unmap = function techniqueParameterBufferUnmap(writer) { - numValues = this.length; - } - for (var n = 0; n < numValues; n += 1, offset += 1) + }; + /* tslint:enable:no-empty */ + + this.setData = + function techniqueParameterBufferSetData(data, + offset?: number, + numValues?: number) { - this[offset] = data[n]; - } + if (offset === undefined) + { + offset = 0; + } + if (numValues === undefined) + { + numValues = this.length; + } + for (var n = 0; n < numValues; n += 1, offset += 1) + { + this[offset] = data[n]; + } + }; + + Object.defineProperty(this, "data", { + get: function techniqueParameterBufferDataGet() + { + return this; + }, + enumerable: true + }); + + Object.defineProperty(this, "numFloats", { + get: function techniqueParameterBufferDataGet() + { + return this.length; + }, + enumerable: true + }); }; + tpbProtoConstructor.prototype = Float32Array.prototype; + (gd).tpbProto = tpbProto = new tpbProtoConstructor(); } - return new Float32Array(params.numFloats); + var tpb = new Float32Array(params.numFloats); + (tpb).__proto__ = tpbProto; + return (tpb); }; // @@ -7246,10 +7276,7 @@ class WebGLGraphicsDevice implements GraphicsDevice createTechniqueParameterBuffer(params): TechniqueParameterBuffer { - // TOOD: We're returning a float array, which doesn't have all - // the proprties that are expected. - return - techniqueParameterBufferCreate(params); + return techniqueParameterBufferCreate(this, params); } createRenderBuffer(params): WebGLRenderBuffer