From 6a354de15a72393165c61bf036d12999c9c39881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Mon, 20 Mar 2017 12:53:46 +0300 Subject: [PATCH 01/60] freezeRenderState function added --- Source/Renderer/freezeRenderState.js | 38 ++++++++++++++ Specs/Renderer/freezeRenderStateSpec.js | 66 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 Source/Renderer/freezeRenderState.js create mode 100644 Specs/Renderer/freezeRenderStateSpec.js diff --git a/Source/Renderer/freezeRenderState.js b/Source/Renderer/freezeRenderState.js new file mode 100644 index 000000000000..2dba153ba0ec --- /dev/null +++ b/Source/Renderer/freezeRenderState.js @@ -0,0 +1,38 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/freezeObject' +], function( + defined, + freezeObject) { + 'use strict'; + + /** + * Returns frozen renderState as well as all of the object literal properties. This function is deep object freeze + * function ignoring properties named "_applyFunctions". + * + * @exports freezeRenderState + * + * @param {Object} renderState + * @returns {Object} Returns frozen renderState. + * + */ + function freezeRenderState(renderState) { + if (typeof renderState !== 'object') { + return renderState; + } + + var i, propName, propNames = Object.keys(renderState); + + for (i = 0; i < propNames.length; i++) { + propName = propNames[i]; + if (renderState.hasOwnProperty(propName) && propName !== '_applyFunctions') { + renderState[propName] = freezeRenderState(renderState[propName]); + } + } + + return freezeObject(renderState); + } + + return freezeRenderState; + }); diff --git a/Specs/Renderer/freezeRenderStateSpec.js b/Specs/Renderer/freezeRenderStateSpec.js new file mode 100644 index 000000000000..18d1a4f7ce53 --- /dev/null +++ b/Specs/Renderer/freezeRenderStateSpec.js @@ -0,0 +1,66 @@ +/*global defineSuite*/ +defineSuite([ + 'Renderer/freezeRenderState' +], 'Renderer/freezeRenderState', function( + freezeRenderState +) { + 'use strict'; + + it('works for literals', function() { + var fresh = { + a: 1, + b: 'b', + c: 2.2 + }; + + var frozen = freezeRenderState(fresh); + + expect(function() { + frozen.a = 2; + }).toThrow(); + + expect(function() { + frozen.b = 'c'; + }).toThrow(); + + expect(function() { + frozen.c = 2; + }).toThrow(); + + }); + + it('works for deep objects', function() { + var fresh = { + a: 2, + o: { + b: 2, + c: 'c' + } + }; + + var frozen = freezeRenderState(fresh); + + expect(function() { + frozen.o.b = 3; + frozen.o.c = 'dddd'; + }).toThrow(); + }); + + it('ignores _applyFunctions', function() { + var fresh = { + a: 1, + _applyFunctions: [function() { }] + }; + + var frozen = freezeRenderState(fresh); + + expect(function() { + frozen.a = 0; + }).toThrow(); + + expect(function() { + frozen._applyFunctions.push(function() { }); + }).not.toThrow(); + }); + + }); From 2518e71e87aac940ec83305d2dc2a8de296eb0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Mon, 20 Mar 2017 13:42:03 +0300 Subject: [PATCH 02/60] null check added into freezeRenderState --- Source/Renderer/freezeRenderState.js | 2 +- Specs/Renderer/freezeRenderStateSpec.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Renderer/freezeRenderState.js b/Source/Renderer/freezeRenderState.js index 2dba153ba0ec..2f7b97b9a812 100644 --- a/Source/Renderer/freezeRenderState.js +++ b/Source/Renderer/freezeRenderState.js @@ -18,7 +18,7 @@ define([ * */ function freezeRenderState(renderState) { - if (typeof renderState !== 'object') { + if (typeof renderState !== 'object' || renderState === null) { return renderState; } diff --git a/Specs/Renderer/freezeRenderStateSpec.js b/Specs/Renderer/freezeRenderStateSpec.js index 18d1a4f7ce53..59e64688b1b4 100644 --- a/Specs/Renderer/freezeRenderStateSpec.js +++ b/Specs/Renderer/freezeRenderStateSpec.js @@ -10,7 +10,9 @@ defineSuite([ var fresh = { a: 1, b: 'b', - c: 2.2 + c: 2.2, + u: undefined, + n: null }; var frozen = freezeRenderState(fresh); From 84c87dc3315f795aefaa57afca56dae07bcfb570 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 24 Apr 2017 18:57:15 -0400 Subject: [PATCH 03/60] Add support for copyBufferSubData and getBufferSubData. --- Source/Renderer/Buffer.js | 93 +++++++++ Specs/Renderer/BufferSpec.js | 372 ++++++++++++++++++++++++++++++++++- 2 files changed, 462 insertions(+), 3 deletions(-) diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index edb489e7d313..90b39053a77e 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -70,6 +70,7 @@ define([ gl.bindBuffer(bufferTarget, null); this._gl = gl; + this._webgl2 = options.context._webgl2; this._bufferTarget = bufferTarget; this._sizeInBytes = sizeInBytes; this._usage = usage; @@ -265,6 +266,98 @@ define([ gl.bindBuffer(target, null); }; + Buffer.prototype.copyFromBuffer = function(readBuffer, readOffset, writeOffset, sizeInBytes) { + //>>includeStart('debug', pragmas.debug); + if (!this._webgl2) { + throw new DeveloperError('A WebGL 2 context is required.'); + } + if (!defined(readBuffer)) { + throw new DeveloperError('readBuffer must be defined.'); + } + if (!defined(sizeInBytes) || sizeInBytes <= 0) { + throw new DeveloperError('sizeInBytes must be defined and be greater than zero.'); + } + if (!defined(readOffset) || readOffset < 0 || readOffset + sizeInBytes > readBuffer._sizeInBytes) { + throw new DeveloperError('readOffset must be greater than or equal to zero and readOffset + sizeInBytes must be less than of equal to readBuffer.sizeInBytes.'); + } + if (!defined(writeOffset) || writeOffset < 0 || writeOffset + sizeInBytes > this._sizeInBytes) { + throw new DeveloperError('writeOffset must be greater than or equal to zero and writeOffset + sizeInBytes must be less than of equal to this.sizeInBytes.'); + } + if (this._buffer === readBuffer._buffer && ((writeOffset >= readOffset && writeOffset < readOffset + sizeInBytes) || (readOffset > writeOffset && readOffset < writeOffset + sizeInBytes))) { + throw new DeveloperError('When readBuffer is equal to this, the ranges [readOffset + sizeInBytes) and [writeOffset, writeOffset + sizeInBytes) must not overlap.'); + } + if ((this._bufferTarget === WebGLConstants.ELEMENT_ARRAY_BUFFER && readBuffer._bufferTarget !== WebGLConstants.ELEMENT_ARRAY_BUFFER) || + (this._bufferTarget !== WebGLConstants.ELEMENT_ARRAY_BUFFER && readBuffer._bufferTarget === WebGLConstants.ELEMENT_ARRAY_BUFFER)) { + throw new DeveloperError('Can not copy an index buffer into another buffer type.'); + } + //>>includeEnd('debug'); + + var readTarget = WebGLConstants.COPY_READ_BUFFER; + var writeTarget = WebGLConstants.COPY_WRITE_BUFFER; + + var gl = this._gl; + gl.bindBuffer(writeTarget, this._buffer); + gl.bindBuffer(readTarget, readBuffer._buffer); + gl.copyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, sizeInBytes); + gl.bindBuffer(writeTarget, null); + gl.bindBuffer(readTarget, null); + }; + + Buffer.prototype.getBufferData = function(arrayView, sourceOffset, destinationOffset, length) { + sourceOffset = defaultValue(sourceOffset, 0); + destinationOffset = defaultValue(destinationOffset, 0); + + //>>includeStart('debug', pragmas.debug); + if (!this._webgl2) { + throw new DeveloperError('A WebGL 2 context is required.'); + } + if (!defined(arrayView)) { + throw new DeveloperError('arrayView is required.'); + } + + var copyLength; + var elementSize; + var arrayLength = arrayView.byteLength; + if (!defined(length)) { + if (defined(arrayLength)) { + copyLength = arrayLength - destinationOffset; + elementSize = 1; + } else { + arrayLength = arrayView.length; + copyLength = arrayLength - destinationOffset; + elementSize = arrayView.BYTES_PER_ELEMENT; + } + } else { + copyLength = length; + if (defined(arrayLength)) { + elementSize = 1; + } else { + arrayLength = arrayView.length; + elementSize = arrayView.BYTES_PER_ELEMENT; + } + } + + if (destinationOffset < 0 || destinationOffset > arrayLength) { + throw new DeveloperError('destinationOffset must be greater than zero and less than the arrayView length.'); + } + if (destinationOffset + copyLength > arrayLength) { + throw new DeveloperError('destinationOffset + length must be less than or equal to the arrayViewLength.'); + } + if (sourceOffset < 0 || sourceOffset > this._sizeInBytes) { + throw new DeveloperError('sourceOffset must be greater than zero and less than the buffers size.'); + } + if (sourceOffset + copyLength * elementSize > this._sizeInBytes) { + throw new DeveloperError('sourceOffset + length must be less than the buffers size.'); + } + //>>includeEnd('debug'); + + var gl = this._gl; + var target = WebGLConstants.COPY_READ_BUFFER; + gl.bindBuffer(target, this._buffer); + gl.getBufferSubData(target, sourceOffset, arrayView, destinationOffset, length); + gl.bindBuffer(target, null); + }; + Buffer.prototype.isDestroyed = function() { return false; }; diff --git a/Specs/Renderer/BufferSpec.js b/Specs/Renderer/BufferSpec.js index 11c89f013459..49a01931c68d 100644 --- a/Specs/Renderer/BufferSpec.js +++ b/Specs/Renderer/BufferSpec.js @@ -13,6 +13,7 @@ defineSuite([ var context; var buffer; + var buffer2; beforeAll(function() { context = createContext(); @@ -23,9 +24,12 @@ defineSuite([ }); afterEach(function() { - if (buffer) { + if (buffer && !buffer.isDestroyed()) { buffer = buffer.destroy(); } + if (buffer2 && !buffer2.isDestroyed()) { + buffer2 = buffer2.destroy(); + } }); it('throws when creating a vertex buffer with no context', function() { @@ -115,7 +119,7 @@ defineSuite([ }); it('can create a vertex buffer from a typed array', function() { - var typedArray = new Float32Array(3 * Float32Array.BYTES_PER_ELEMENT); + var typedArray = new Float32Array(3); typedArray[0] = 1.0; typedArray[1] = 2.0; typedArray[2] = 3.0; @@ -249,7 +253,7 @@ defineSuite([ }); it('can create an index buffer from a typed array', function() { - var typedArray = new Uint16Array(3 * Uint16Array.BYTES_PER_ELEMENT); + var typedArray = new Uint16Array(3); typedArray[0] = 1; typedArray[1] = 2; typedArray[2] = 3; @@ -277,6 +281,368 @@ defineSuite([ expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); }); + it('getBufferData throws without WebGL 2', function() { + if (context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws without arrayView', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.getBufferData(undefined); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws with invalid sourceOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array, -1); + }).toThrowDeveloperError(); + expect(function() { + buffer.getBufferData(array, 5); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws with invalid destinationOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array, 0, -1); + }).toThrowDeveloperError(); + expect(function() { + buffer.getBufferData(array, 0, 5); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws with invalid length', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array, 2, 0, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.getBufferData(array, 0, 2, 4); + }).toThrowDeveloperError(); + }); + + it('getBufferData reads from vertex buffer', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Uint8Array(4); + typedArray[0] = 1; + typedArray[1] = 2; + typedArray[2] = 3; + typedArray[3] = 4; + + buffer = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW + }); + + var destArray = new Uint8Array(4); + buffer.getBufferData(destArray); + + expect(destArray).toEqual(typedArray); + }); + + it('getBufferData reads from index buffer', function() { + if (!context.webgl2) { + return; + } + var typedArray = new Uint16Array(3); + typedArray[0] = 1; + typedArray[1] = 2; + typedArray[2] = 3; + + buffer = Buffer.createIndexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + + var destArray = new Uint16Array(3); + buffer.getBufferData(destArray); + + expect(destArray).toEqual(typedArray); + }); + + it('copyFromBuffer throws without WebGL 2', function() { + if (context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws without readBuffer', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(undefined, 0, 0, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with invalid readOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, undefined, 0, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, -1, 0, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 5, 0, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with invalid writeOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, 0, undefined, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, -1, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 5, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with invalid sizeInBytes', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, undefined); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, -1); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, 0); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, 5); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with one index buffer and the other is not an index buffer', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Uint16Array([0, 1, 2, 3, 4]); + buffer = Buffer.createIndexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + var typedArray2 = new Float32Array([5.0, 6.0, 7.0, 8.0, 9.0]); + buffer2 = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray2, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws when readBuffer is the same buffer and copy range overlaps', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer, 0, 1, 2); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer, 1, 0, 2); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer with vertex buffers', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Float32Array([0.0, 1.0, 2.0, 3.0, 4.0]); + buffer = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW + }); + var typedArray2 = new Float32Array([5.0, 6.0, 7.0, 8.0, 9.0]); + buffer2 = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray2, + usage : BufferUsage.STATIC_DRAW + }); + + var destArray = new Float32Array(5); + buffer.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray2); + + buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + }); + + it('copyFromBuffer with index buffers', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Uint16Array([0, 1, 2, 3, 4]); + buffer = Buffer.createIndexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + var typedArray2 = new Uint16Array([5, 6, 7, 8, 9]); + buffer2 = Buffer.createIndexBuffer({ + context : context, + typedArray : typedArray2, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + + var destArray = new Uint16Array(5); + buffer.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray2); + + buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + }); + it('destroys', function() { var b = Buffer.createIndexBuffer({ context : context, From 1337a6921cf5f81cd774fa7dd6e395dc67d4d430 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 26 Apr 2017 14:59:21 -0400 Subject: [PATCH 04/60] Run Buffer tests with both a WebGL 1 and 2 context. --- Source/Renderer/Context.js | 2 +- Specs/Renderer/BufferSpec.js | 1249 +++++++++++++++++----------------- 2 files changed, 628 insertions(+), 623 deletions(-) diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index 3f092b8346fb..f41dafcf4cba 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -195,7 +195,7 @@ define([ webglOptions.alpha = defaultValue(webglOptions.alpha, false); // WebGL default is true webglOptions.stencil = defaultValue(webglOptions.stencil, true); // WebGL default is false - var defaultToWebgl2 = false; + var defaultToWebgl2 = defaultValue(options.defaultToWebgl2, false); var requestWebgl2 = defaultToWebgl2 && (typeof WebGL2RenderingContext !== 'undefined'); var webgl2 = false; diff --git a/Specs/Renderer/BufferSpec.js b/Specs/Renderer/BufferSpec.js index 49a01931c68d..33147b5924f9 100644 --- a/Specs/Renderer/BufferSpec.js +++ b/Specs/Renderer/BufferSpec.js @@ -11,685 +11,690 @@ defineSuite([ createContext) { 'use strict'; - var context; - var buffer; - var buffer2; - - beforeAll(function() { - context = createContext(); - }); - - afterAll(function() { - context.destroyForSpecs(); - }); - - afterEach(function() { - if (buffer && !buffer.isDestroyed()) { - buffer = buffer.destroy(); - } - if (buffer2 && !buffer2.isDestroyed()) { - buffer2 = buffer2.destroy(); - } - }); - - it('throws when creating a vertex buffer with no context', function() { - expect(function() { + createBufferSpecs(); + createBufferSpecs({ defaultToWebgl2 : true }); + + function createBufferSpecs(contextOptions) { + var context; + var buffer; + var buffer2; + + beforeAll(function() { + context = createContext(contextOptions); + }); + + afterAll(function() { + context.destroyForSpecs(); + }); + + afterEach(function() { + if (buffer && !buffer.isDestroyed()) { + buffer = buffer.destroy(); + } + if (buffer2 && !buffer2.isDestroyed()) { + buffer2 = buffer2.destroy(); + } + }); + + it('throws when creating a vertex buffer with no context', function() { + expect(function() { + buffer = Buffer.createVertexBuffer({ + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating a vertex buffer with an invalid typed array', function() { + expect(function() { + buffer = Buffer.createVertexBuffer({ + context : context, + typedArray : {}, + usage : BufferUsage.STATIC_DRAW + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating a vertex buffer with both a typed array and size in bytes', function() { + expect(function() { + buffer = Buffer.createVertexBuffer({ + context : context, + typedArray : new Float32Array([0, 0, 0, 1]), + sizeInBytes : 16, + usage : BufferUsage.STATIC_DRAW + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating a vertex buffer without a typed array or size in bytes', function() { + expect(function() { + buffer = Buffer.createVertexBuffer({ + context : context, + usage : BufferUsage.STATIC_DRAW + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating a vertex buffer with invalid usage', function() { + expect(function() { + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 16, + usage : 0 + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating a vertex buffer with size of zero', function() { + expect(function() { + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 0, + usage : BufferUsage.STATIC_DRAW + }); + }).toThrowDeveloperError(); + }); + + it('creates vertex buffer', function() { buffer = Buffer.createVertexBuffer({ - sizeInBytes : 4, + context : context, + sizeInBytes : 16, usage : BufferUsage.STATIC_DRAW }); - }).toThrowDeveloperError(); - }); - it('throws when creating a vertex buffer with an invalid typed array', function() { - expect(function() { + expect(buffer.sizeInBytes).toEqual(16); + expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); + }); + + it('copies array to a vertex buffer', function() { + var sizeInBytes = 3 * Float32Array.BYTES_PER_ELEMENT; + var vertices = new ArrayBuffer(sizeInBytes); + var positions = new Float32Array(vertices); + positions[0] = 1.0; + positions[1] = 2.0; + positions[2] = 3.0; + buffer = Buffer.createVertexBuffer({ context : context, - typedArray : {}, + sizeInBytes : sizeInBytes, usage : BufferUsage.STATIC_DRAW }); - }).toThrowDeveloperError(); - }); + buffer.copyFromArrayView(vertices); + }); + + it('can create a vertex buffer from a typed array', function() { + var typedArray = new Float32Array(3); + typedArray[0] = 1.0; + typedArray[1] = 2.0; + typedArray[2] = 3.0; - it('throws when creating a vertex buffer with both a typed array and size in bytes', function() { - expect(function() { buffer = Buffer.createVertexBuffer({ context : context, - typedArray : new Float32Array([0, 0, 0, 1]), - sizeInBytes : 16, + typedArray : typedArray, usage : BufferUsage.STATIC_DRAW }); - }).toThrowDeveloperError(); - }); + expect(buffer.sizeInBytes).toEqual(typedArray.byteLength); + expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); + }); - it('throws when creating a vertex buffer without a typed array or size in bytes', function() { - expect(function() { + it('can create a vertex buffer from a size in bytes', function() { buffer = Buffer.createVertexBuffer({ context : context, + sizeInBytes : 4, usage : BufferUsage.STATIC_DRAW }); - }).toThrowDeveloperError(); - }); - - it('throws when creating a vertex buffer with invalid usage', function() { - expect(function() { - buffer = Buffer.createVertexBuffer({ + expect(buffer.sizeInBytes).toEqual(4); + expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); + }); + + it('throws when creating an index buffer with no context', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating an index buffer with an invalid typed array', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + context : context, + typedArray : {}, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating an index buffer with both a typed array and size in bytes', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + context : context, + typedArray : new Uint16Array([0, 1, 2, 0, 2, 3]), + sizeInBytes : 12, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating an index buffer without a typed array or size in bytes', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + context : context, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating an index buffer with invalid usage', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + context : context, + sizeInBytes : 16, + usage : "invalid", + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating an index buffer with invalid index data type', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + context : context, + sizeInBytes : 16, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : 'invalid' + }); + }).toThrowDeveloperError(); + }); + + it('throws when creating an index buffer with size of zero', function() { + expect(function() { + buffer = Buffer.createIndexBuffer({ + context : context, + sizeInBytes : 0, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + }).toThrowDeveloperError(); + }); + + it('creates index buffer', function() { + buffer = Buffer.createIndexBuffer({ context : context, - sizeInBytes : 16, - usage : 0 + sizeInBytes : 6, + usage : BufferUsage.STREAM_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); - it('throws when creating a vertex buffer with size of zero', function() { - expect(function() { - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 0, - usage : BufferUsage.STATIC_DRAW - }); - }).toThrowDeveloperError(); - }); - - it('creates vertex buffer', function() { - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 16, - usage : BufferUsage.STATIC_DRAW - }); - - expect(buffer.sizeInBytes).toEqual(16); - expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); - }); - - it('copies array to a vertex buffer', function() { - var sizeInBytes = 3 * Float32Array.BYTES_PER_ELEMENT; - var vertices = new ArrayBuffer(sizeInBytes); - var positions = new Float32Array(vertices); - positions[0] = 1.0; - positions[1] = 2.0; - positions[2] = 3.0; - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : sizeInBytes, - usage : BufferUsage.STATIC_DRAW - }); - buffer.copyFromArrayView(vertices); - }); - - it('can create a vertex buffer from a typed array', function() { - var typedArray = new Float32Array(3); - typedArray[0] = 1.0; - typedArray[1] = 2.0; - typedArray[2] = 3.0; - - buffer = Buffer.createVertexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW - }); - expect(buffer.sizeInBytes).toEqual(typedArray.byteLength); - expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); - }); - - it('can create a vertex buffer from a size in bytes', function() { - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - expect(buffer.sizeInBytes).toEqual(4); - expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); - }); - - it('throws when creating an index buffer with no context', function() { - expect(function() { + expect(buffer.sizeInBytes).toEqual(6); + expect(buffer.usage).toEqual(BufferUsage.STREAM_DRAW); + + expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); + expect(buffer.bytesPerIndex).toEqual(2); + expect(buffer.numberOfIndices).toEqual(3); + }); + + it('copies array to an index buffer', function() { + var sizeInBytes = 3 * Uint16Array.BYTES_PER_ELEMENT; + var elements = new ArrayBuffer(sizeInBytes); + var indices = new Uint16Array(elements); + indices[0] = 1; + indices[1] = 2; + indices[2] = 3; + buffer = Buffer.createIndexBuffer({ - sizeInBytes : 4, + context : context, + sizeInBytes : sizeInBytes, usage : BufferUsage.STATIC_DRAW, indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); + buffer.copyFromArrayView(elements); + }); + + it('can create an index buffer from a typed array', function() { + var typedArray = new Uint16Array(3); + typedArray[0] = 1; + typedArray[1] = 2; + typedArray[2] = 3; - it('throws when creating an index buffer with an invalid typed array', function() { - expect(function() { buffer = Buffer.createIndexBuffer({ context : context, - typedArray : {}, + typedArray : typedArray, usage : BufferUsage.STATIC_DRAW, indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); + expect(buffer.sizeInBytes).toEqual(typedArray.byteLength); + expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); + expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); + }); - it('throws when creating an index buffer with both a typed array and size in bytes', function() { - expect(function() { + it('can create an index buffer from a size in bytes', function() { buffer = Buffer.createIndexBuffer({ context : context, - typedArray : new Uint16Array([0, 1, 2, 0, 2, 3]), - sizeInBytes : 12, + sizeInBytes : 6, usage : BufferUsage.STATIC_DRAW, indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); + expect(buffer.sizeInBytes).toEqual(6); + expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); + expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); + }); + + it('getBufferData throws without WebGL 2', function() { + if (context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws without arrayView', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.getBufferData(undefined); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws with invalid sourceOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array, -1); + }).toThrowDeveloperError(); + expect(function() { + buffer.getBufferData(array, 5); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws with invalid destinationOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array, 0, -1); + }).toThrowDeveloperError(); + expect(function() { + buffer.getBufferData(array, 0, 5); + }).toThrowDeveloperError(); + }); + + it('getBufferData throws with invalid length', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + var array = new Uint8Array(4); + + expect(function() { + buffer.getBufferData(array, 2, 0, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.getBufferData(array, 0, 2, 4); + }).toThrowDeveloperError(); + }); + + it('getBufferData reads from vertex buffer', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Uint8Array(4); + typedArray[0] = 1; + typedArray[1] = 2; + typedArray[2] = 3; + typedArray[3] = 4; + + buffer = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW + }); + + var destArray = new Uint8Array(4); + buffer.getBufferData(destArray); + + expect(destArray).toEqual(typedArray); + }); + + it('getBufferData reads from index buffer', function() { + if (!context.webgl2) { + return; + } + var typedArray = new Uint16Array(3); + typedArray[0] = 1; + typedArray[1] = 2; + typedArray[2] = 3; - it('throws when creating an index buffer without a typed array or size in bytes', function() { - expect(function() { buffer = Buffer.createIndexBuffer({ context : context, + typedArray : typedArray, usage : BufferUsage.STATIC_DRAW, indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); - it('throws when creating an index buffer with invalid usage', function() { - expect(function() { - buffer = Buffer.createIndexBuffer({ + var destArray = new Uint16Array(3); + buffer.getBufferData(destArray); + + expect(destArray).toEqual(typedArray); + }); + + it('copyFromBuffer throws without WebGL 2', function() { + if (context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ context : context, - sizeInBytes : 16, - usage : "invalid", - indexDatatype : IndexDatatype.UNSIGNED_SHORT + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws without readBuffer', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW }); - }).toThrowDeveloperError(); - }); - it('throws when creating an index buffer with invalid index data type', function() { - expect(function() { + expect(function() { + buffer.copyFromBuffer(undefined, 0, 0, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with invalid readOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, undefined, 0, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, -1, 0, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 5, 0, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with invalid writeOffset', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, 0, undefined, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, -1, 4); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 5, 4); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with invalid sizeInBytes', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + buffer2 = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, undefined); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, -1); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, 0); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer2, 0, 0, 5); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer throws with one index buffer and the other is not an index buffer', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Uint16Array([0, 1, 2, 3, 4]); buffer = Buffer.createIndexBuffer({ context : context, - sizeInBytes : 16, + typedArray : typedArray, usage : BufferUsage.STATIC_DRAW, - indexDatatype : 'invalid' + indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); + var typedArray2 = new Float32Array([5.0, 6.0, 7.0, 8.0, 9.0]); + buffer2 = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray2, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); + }).toThrowDeveloperError(); + }); - it('throws when creating an index buffer with size of zero', function() { - expect(function() { + it('copyFromBuffer throws when readBuffer is the same buffer and copy range overlaps', function() { + if (!context.webgl2) { + return; + } + + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 4, + usage : BufferUsage.STATIC_DRAW + }); + + expect(function() { + buffer.copyFromBuffer(buffer, 0, 1, 2); + }).toThrowDeveloperError(); + expect(function() { + buffer.copyFromBuffer(buffer, 1, 0, 2); + }).toThrowDeveloperError(); + }); + + it('copyFromBuffer with vertex buffers', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Float32Array([0.0, 1.0, 2.0, 3.0, 4.0]); + buffer = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray, + usage : BufferUsage.STATIC_DRAW + }); + var typedArray2 = new Float32Array([5.0, 6.0, 7.0, 8.0, 9.0]); + buffer2 = Buffer.createVertexBuffer({ + context : context, + typedArray : typedArray2, + usage : BufferUsage.STATIC_DRAW + }); + + var destArray = new Float32Array(5); + buffer.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray2); + + buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + }); + + it('copyFromBuffer with index buffers', function() { + if (!context.webgl2) { + return; + } + + var typedArray = new Uint16Array([0, 1, 2, 3, 4]); buffer = Buffer.createIndexBuffer({ context : context, - sizeInBytes : 0, + typedArray : typedArray, usage : BufferUsage.STATIC_DRAW, indexDatatype : IndexDatatype.UNSIGNED_SHORT }); - }).toThrowDeveloperError(); - }); - - it('creates index buffer', function() { - buffer = Buffer.createIndexBuffer({ - context : context, - sizeInBytes : 6, - usage : BufferUsage.STREAM_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - - expect(buffer.sizeInBytes).toEqual(6); - expect(buffer.usage).toEqual(BufferUsage.STREAM_DRAW); - - expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); - expect(buffer.bytesPerIndex).toEqual(2); - expect(buffer.numberOfIndices).toEqual(3); - }); - - it('copies array to an index buffer', function() { - var sizeInBytes = 3 * Uint16Array.BYTES_PER_ELEMENT; - var elements = new ArrayBuffer(sizeInBytes); - var indices = new Uint16Array(elements); - indices[0] = 1; - indices[1] = 2; - indices[2] = 3; - - buffer = Buffer.createIndexBuffer({ - context : context, - sizeInBytes : sizeInBytes, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - buffer.copyFromArrayView(elements); - }); - - it('can create an index buffer from a typed array', function() { - var typedArray = new Uint16Array(3); - typedArray[0] = 1; - typedArray[1] = 2; - typedArray[2] = 3; - - buffer = Buffer.createIndexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - expect(buffer.sizeInBytes).toEqual(typedArray.byteLength); - expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); - expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); - }); - - it('can create an index buffer from a size in bytes', function() { - buffer = Buffer.createIndexBuffer({ - context : context, - sizeInBytes : 6, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - expect(buffer.sizeInBytes).toEqual(6); - expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); - expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); - }); - - it('getBufferData throws without WebGL 2', function() { - if (context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - var array = new Uint8Array(4); - - expect(function() { - buffer.getBufferData(array); - }).toThrowDeveloperError(); - }); - - it('getBufferData throws without arrayView', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.getBufferData(undefined); - }).toThrowDeveloperError(); - }); - - it('getBufferData throws with invalid sourceOffset', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - var array = new Uint8Array(4); - - expect(function() { - buffer.getBufferData(array, -1); - }).toThrowDeveloperError(); - expect(function() { - buffer.getBufferData(array, 5); - }).toThrowDeveloperError(); - }); - - it('getBufferData throws with invalid destinationOffset', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - var array = new Uint8Array(4); - - expect(function() { - buffer.getBufferData(array, 0, -1); - }).toThrowDeveloperError(); - expect(function() { - buffer.getBufferData(array, 0, 5); - }).toThrowDeveloperError(); - }); - - it('getBufferData throws with invalid length', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - var array = new Uint8Array(4); - - expect(function() { - buffer.getBufferData(array, 2, 0, 4); - }).toThrowDeveloperError(); - expect(function() { - buffer.getBufferData(array, 0, 2, 4); - }).toThrowDeveloperError(); - }); - - it('getBufferData reads from vertex buffer', function() { - if (!context.webgl2) { - return; - } - - var typedArray = new Uint8Array(4); - typedArray[0] = 1; - typedArray[1] = 2; - typedArray[2] = 3; - typedArray[3] = 4; - - buffer = Buffer.createVertexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW - }); - - var destArray = new Uint8Array(4); - buffer.getBufferData(destArray); - - expect(destArray).toEqual(typedArray); - }); - - it('getBufferData reads from index buffer', function() { - if (!context.webgl2) { - return; - } - var typedArray = new Uint16Array(3); - typedArray[0] = 1; - typedArray[1] = 2; - typedArray[2] = 3; - - buffer = Buffer.createIndexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - - var destArray = new Uint16Array(3); - buffer.getBufferData(destArray); - - expect(destArray).toEqual(typedArray); - }); - - it('copyFromBuffer throws without WebGL 2', function() { - if (context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - buffer2 = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.copyFromBuffer(buffer2, 0, 0, 4); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer throws without readBuffer', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.copyFromBuffer(undefined, 0, 0, 4); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer throws with invalid readOffset', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - buffer2 = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.copyFromBuffer(buffer2, undefined, 0, 4); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, -1, 0, 4); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, 5, 0, 4); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer throws with invalid writeOffset', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - buffer2 = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.copyFromBuffer(buffer2, 0, undefined, 4); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, 0, -1, 4); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, 0, 5, 4); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer throws with invalid sizeInBytes', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - buffer2 = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.copyFromBuffer(buffer2, 0, 0, undefined); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, 0, 0, -1); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, 0, 0, 0); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer2, 0, 0, 5); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer throws with one index buffer and the other is not an index buffer', function() { - if (!context.webgl2) { - return; - } - - var typedArray = new Uint16Array([0, 1, 2, 3, 4]); - buffer = Buffer.createIndexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - var typedArray2 = new Float32Array([5.0, 6.0, 7.0, 8.0, 9.0]); - buffer2 = Buffer.createVertexBuffer({ - context : context, - typedArray : typedArray2, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { + var typedArray2 = new Uint16Array([5, 6, 7, 8, 9]); + buffer2 = Buffer.createIndexBuffer({ + context : context, + typedArray : typedArray2, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_SHORT + }); + + var destArray = new Uint16Array(5); + buffer.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray2); + buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer throws when readBuffer is the same buffer and copy range overlaps', function() { - if (!context.webgl2) { - return; - } - - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 4, - usage : BufferUsage.STATIC_DRAW - }); - - expect(function() { - buffer.copyFromBuffer(buffer, 0, 1, 2); - }).toThrowDeveloperError(); - expect(function() { - buffer.copyFromBuffer(buffer, 1, 0, 2); - }).toThrowDeveloperError(); - }); - - it('copyFromBuffer with vertex buffers', function() { - if (!context.webgl2) { - return; - } - - var typedArray = new Float32Array([0.0, 1.0, 2.0, 3.0, 4.0]); - buffer = Buffer.createVertexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW - }); - var typedArray2 = new Float32Array([5.0, 6.0, 7.0, 8.0, 9.0]); - buffer2 = Buffer.createVertexBuffer({ - context : context, - typedArray : typedArray2, - usage : BufferUsage.STATIC_DRAW - }); - - var destArray = new Float32Array(5); - buffer.getBufferData(destArray); - expect(destArray).toEqual(typedArray); - buffer2.getBufferData(destArray); - expect(destArray).toEqual(typedArray2); - - buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); - buffer2.getBufferData(destArray); - expect(destArray).toEqual(typedArray); - }); - - it('copyFromBuffer with index buffers', function() { - if (!context.webgl2) { - return; - } - - var typedArray = new Uint16Array([0, 1, 2, 3, 4]); - buffer = Buffer.createIndexBuffer({ - context : context, - typedArray : typedArray, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - var typedArray2 = new Uint16Array([5, 6, 7, 8, 9]); - buffer2 = Buffer.createIndexBuffer({ - context : context, - typedArray : typedArray2, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_SHORT - }); - - var destArray = new Uint16Array(5); - buffer.getBufferData(destArray); - expect(destArray).toEqual(typedArray); - buffer2.getBufferData(destArray); - expect(destArray).toEqual(typedArray2); - - buffer2.copyFromBuffer(buffer, 0, 0, typedArray.byteLength); - buffer2.getBufferData(destArray); - expect(destArray).toEqual(typedArray); - }); - - it('destroys', function() { - var b = Buffer.createIndexBuffer({ - context : context, - sizeInBytes : 3, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_BYTE - }); - expect(b.isDestroyed()).toEqual(false); - b.destroy(); - expect(b.isDestroyed()).toEqual(true); - }); - - it('fails to provide an array view', function() { - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 3, - usage : BufferUsage.STATIC_DRAW - }); - expect(function() { - buffer.copyFromArrayView(); - }).toThrowDeveloperError(); - }); - - it('fails to copy a large array view', function() { - buffer = Buffer.createVertexBuffer({ - context : context, - sizeInBytes : 3, - usage : BufferUsage.STATIC_DRAW - }); - var elements = new ArrayBuffer(3); - - expect(function() { - buffer.copyFromArrayView(elements, 1); - }).toThrowDeveloperError(); - }); - - it('fails to destroy', function() { - var b = Buffer.createIndexBuffer({ - context : context, - sizeInBytes : 3, - usage : BufferUsage.STATIC_DRAW, - indexDatatype : IndexDatatype.UNSIGNED_BYTE - }); - b.destroy(); - - expect(function() { + buffer2.getBufferData(destArray); + expect(destArray).toEqual(typedArray); + }); + + it('destroys', function() { + var b = Buffer.createIndexBuffer({ + context : context, + sizeInBytes : 3, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_BYTE + }); + expect(b.isDestroyed()).toEqual(false); + b.destroy(); + expect(b.isDestroyed()).toEqual(true); + }); + + it('fails to provide an array view', function() { + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 3, + usage : BufferUsage.STATIC_DRAW + }); + expect(function() { + buffer.copyFromArrayView(); + }).toThrowDeveloperError(); + }); + + it('fails to copy a large array view', function() { + buffer = Buffer.createVertexBuffer({ + context : context, + sizeInBytes : 3, + usage : BufferUsage.STATIC_DRAW + }); + var elements = new ArrayBuffer(3); + + expect(function() { + buffer.copyFromArrayView(elements, 1); + }).toThrowDeveloperError(); + }); + + it('fails to destroy', function() { + var b = Buffer.createIndexBuffer({ + context : context, + sizeInBytes : 3, + usage : BufferUsage.STATIC_DRAW, + indexDatatype : IndexDatatype.UNSIGNED_BYTE + }); b.destroy(); - }).toThrowDeveloperError(); - }); + + expect(function() { + b.destroy(); + }).toThrowDeveloperError(); + }); + } }, 'WebGL'); From 7dfb45e534e87403fbd367eec4ad10132a56d685 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 26 Apr 2017 15:20:16 -0400 Subject: [PATCH 05/60] Check if WebGL 2 is supported before creating the tests. --- Source/Renderer/Context.js | 3 +-- Specs/Renderer/BufferSpec.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index f41dafcf4cba..545f4bcf700d 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -195,8 +195,7 @@ define([ webglOptions.alpha = defaultValue(webglOptions.alpha, false); // WebGL default is true webglOptions.stencil = defaultValue(webglOptions.stencil, true); // WebGL default is false - var defaultToWebgl2 = defaultValue(options.defaultToWebgl2, false); - var requestWebgl2 = defaultToWebgl2 && (typeof WebGL2RenderingContext !== 'undefined'); + var requestWebgl2 = defaultValue(options.requestWebgl2, false) && (typeof WebGL2RenderingContext !== 'undefined'); var webgl2 = false; var glContext; diff --git a/Specs/Renderer/BufferSpec.js b/Specs/Renderer/BufferSpec.js index 33147b5924f9..56bb3a0d779e 100644 --- a/Specs/Renderer/BufferSpec.js +++ b/Specs/Renderer/BufferSpec.js @@ -12,7 +12,19 @@ defineSuite([ 'use strict'; createBufferSpecs(); - createBufferSpecs({ defaultToWebgl2 : true }); + + var c; + var supportsWebGL2 = true; + try { + c = createContext({ requestWebgl2 : true }); + } catch (error) { + supportsWebGL2 = false; + } + + if (supportsWebGL2) { + c.destroyForSpecs(); + createBufferSpecs({ requestWebgl2 : true }); + } function createBufferSpecs(contextOptions) { var context; From 57804425d7fbc1511ddf2e09f6ece4d3a9c4050a Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 26 Apr 2017 15:30:36 -0400 Subject: [PATCH 06/60] Fix creating WebGL 2 Buffer tests. --- Specs/Renderer/BufferSpec.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Specs/Renderer/BufferSpec.js b/Specs/Renderer/BufferSpec.js index 56bb3a0d779e..49c5ab1e8578 100644 --- a/Specs/Renderer/BufferSpec.js +++ b/Specs/Renderer/BufferSpec.js @@ -13,18 +13,11 @@ defineSuite([ createBufferSpecs(); - var c; - var supportsWebGL2 = true; - try { - c = createContext({ requestWebgl2 : true }); - } catch (error) { - supportsWebGL2 = false; - } - - if (supportsWebGL2) { - c.destroyForSpecs(); + var c = createContext({ requestWebgl2 : true }); + if (c.webgl2) { createBufferSpecs({ requestWebgl2 : true }); } + c.destroyForSpecs(); function createBufferSpecs(contextOptions) { var context; From 009c3000724ea9afd572fbe56446e9064ce1cfb8 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Wed, 26 Apr 2017 15:55:08 -0400 Subject: [PATCH 07/60] Tweak WebGL 2 tests --- Specs/Renderer/BufferSpec.js | 103 +++++++++++++++++------------------ 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/Specs/Renderer/BufferSpec.js b/Specs/Renderer/BufferSpec.js index 49c5ab1e8578..3419c2930a87 100644 --- a/Specs/Renderer/BufferSpec.js +++ b/Specs/Renderer/BufferSpec.js @@ -11,22 +11,21 @@ defineSuite([ createContext) { 'use strict'; - createBufferSpecs(); - - var c = createContext({ requestWebgl2 : true }); - if (c.webgl2) { - createBufferSpecs({ requestWebgl2 : true }); - } - c.destroyForSpecs(); + createBufferSpecs({}); + createBufferSpecs({ + requestWebgl2 : true + }); function createBufferSpecs(contextOptions) { - var context; var buffer; var buffer2; + var context = createContext(contextOptions); - beforeAll(function() { - context = createContext(contextOptions); - }); + if (contextOptions.requestWebgl2 && !context.webgl2) { + // Don't repeat WebGL 1 tests + return; + } + var webglMessage = contextOptions.requestWebgl2 ? ': WebGL 2' : ''; afterAll(function() { context.destroyForSpecs(); @@ -41,7 +40,7 @@ defineSuite([ } }); - it('throws when creating a vertex buffer with no context', function() { + it('throws when creating a vertex buffer with no context' + webglMessage, function() { expect(function() { buffer = Buffer.createVertexBuffer({ sizeInBytes : 4, @@ -50,7 +49,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating a vertex buffer with an invalid typed array', function() { + it('throws when creating a vertex buffer with an invalid typed array' + webglMessage, function() { expect(function() { buffer = Buffer.createVertexBuffer({ context : context, @@ -60,7 +59,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating a vertex buffer with both a typed array and size in bytes', function() { + it('throws when creating a vertex buffer with both a typed array and size in bytes' + webglMessage, function() { expect(function() { buffer = Buffer.createVertexBuffer({ context : context, @@ -71,7 +70,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating a vertex buffer without a typed array or size in bytes', function() { + it('throws when creating a vertex buffer without a typed array or size in bytes' + webglMessage, function() { expect(function() { buffer = Buffer.createVertexBuffer({ context : context, @@ -80,7 +79,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating a vertex buffer with invalid usage', function() { + it('throws when creating a vertex buffer with invalid usage' + webglMessage, function() { expect(function() { buffer = Buffer.createVertexBuffer({ context : context, @@ -90,7 +89,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating a vertex buffer with size of zero', function() { + it('throws when creating a vertex buffer with size of zero' + webglMessage, function() { expect(function() { buffer = Buffer.createVertexBuffer({ context : context, @@ -100,7 +99,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('creates vertex buffer', function() { + it('creates vertex buffer' + webglMessage, function() { buffer = Buffer.createVertexBuffer({ context : context, sizeInBytes : 16, @@ -111,7 +110,7 @@ defineSuite([ expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); }); - it('copies array to a vertex buffer', function() { + it('copies array to a vertex buffer' + webglMessage, function() { var sizeInBytes = 3 * Float32Array.BYTES_PER_ELEMENT; var vertices = new ArrayBuffer(sizeInBytes); var positions = new Float32Array(vertices); @@ -127,7 +126,7 @@ defineSuite([ buffer.copyFromArrayView(vertices); }); - it('can create a vertex buffer from a typed array', function() { + it('can create a vertex buffer from a typed array' + webglMessage, function() { var typedArray = new Float32Array(3); typedArray[0] = 1.0; typedArray[1] = 2.0; @@ -142,7 +141,7 @@ defineSuite([ expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); }); - it('can create a vertex buffer from a size in bytes', function() { + it('can create a vertex buffer from a size in bytes' + webglMessage, function() { buffer = Buffer.createVertexBuffer({ context : context, sizeInBytes : 4, @@ -152,7 +151,7 @@ defineSuite([ expect(buffer.usage).toEqual(BufferUsage.STATIC_DRAW); }); - it('throws when creating an index buffer with no context', function() { + it('throws when creating an index buffer with no context' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ sizeInBytes : 4, @@ -162,7 +161,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating an index buffer with an invalid typed array', function() { + it('throws when creating an index buffer with an invalid typed array' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ context : context, @@ -173,7 +172,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating an index buffer with both a typed array and size in bytes', function() { + it('throws when creating an index buffer with both a typed array and size in bytes' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ context : context, @@ -185,7 +184,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating an index buffer without a typed array or size in bytes', function() { + it('throws when creating an index buffer without a typed array or size in bytes' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ context : context, @@ -195,7 +194,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating an index buffer with invalid usage', function() { + it('throws when creating an index buffer with invalid usage' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ context : context, @@ -206,7 +205,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating an index buffer with invalid index data type', function() { + it('throws when creating an index buffer with invalid index data type' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ context : context, @@ -217,7 +216,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws when creating an index buffer with size of zero', function() { + it('throws when creating an index buffer with size of zero' + webglMessage, function() { expect(function() { buffer = Buffer.createIndexBuffer({ context : context, @@ -228,7 +227,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('creates index buffer', function() { + it('creates index buffer' + webglMessage, function() { buffer = Buffer.createIndexBuffer({ context : context, sizeInBytes : 6, @@ -244,7 +243,7 @@ defineSuite([ expect(buffer.numberOfIndices).toEqual(3); }); - it('copies array to an index buffer', function() { + it('copies array to an index buffer' + webglMessage, function() { var sizeInBytes = 3 * Uint16Array.BYTES_PER_ELEMENT; var elements = new ArrayBuffer(sizeInBytes); var indices = new Uint16Array(elements); @@ -261,7 +260,7 @@ defineSuite([ buffer.copyFromArrayView(elements); }); - it('can create an index buffer from a typed array', function() { + it('can create an index buffer from a typed array' + webglMessage, function() { var typedArray = new Uint16Array(3); typedArray[0] = 1; typedArray[1] = 2; @@ -278,7 +277,7 @@ defineSuite([ expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); }); - it('can create an index buffer from a size in bytes', function() { + it('can create an index buffer from a size in bytes' + webglMessage, function() { buffer = Buffer.createIndexBuffer({ context : context, sizeInBytes : 6, @@ -290,7 +289,7 @@ defineSuite([ expect(buffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT); }); - it('getBufferData throws without WebGL 2', function() { + it('getBufferData throws without WebGL 2' + webglMessage, function() { if (context.webgl2) { return; } @@ -307,7 +306,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('getBufferData throws without arrayView', function() { + it('getBufferData throws without arrayView' + webglMessage, function() { if (!context.webgl2) { return; } @@ -323,7 +322,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('getBufferData throws with invalid sourceOffset', function() { + it('getBufferData throws with invalid sourceOffset' + webglMessage, function() { if (!context.webgl2) { return; } @@ -343,7 +342,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('getBufferData throws with invalid destinationOffset', function() { + it('getBufferData throws with invalid destinationOffset' + webglMessage, function() { if (!context.webgl2) { return; } @@ -363,7 +362,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('getBufferData throws with invalid length', function() { + it('getBufferData throws with invalid length' + webglMessage, function() { if (!context.webgl2) { return; } @@ -383,7 +382,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('getBufferData reads from vertex buffer', function() { + it('getBufferData reads from vertex buffer' + webglMessage, function() { if (!context.webgl2) { return; } @@ -406,7 +405,7 @@ defineSuite([ expect(destArray).toEqual(typedArray); }); - it('getBufferData reads from index buffer', function() { + it('getBufferData reads from index buffer' + webglMessage, function() { if (!context.webgl2) { return; } @@ -428,7 +427,7 @@ defineSuite([ expect(destArray).toEqual(typedArray); }); - it('copyFromBuffer throws without WebGL 2', function() { + it('copyFromBuffer throws without WebGL 2' + webglMessage, function() { if (context.webgl2) { return; } @@ -449,7 +448,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer throws without readBuffer', function() { + it('copyFromBuffer throws without readBuffer' + webglMessage, function() { if (!context.webgl2) { return; } @@ -465,7 +464,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer throws with invalid readOffset', function() { + it('copyFromBuffer throws with invalid readOffset' + webglMessage, function() { if (!context.webgl2) { return; } @@ -492,7 +491,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer throws with invalid writeOffset', function() { + it('copyFromBuffer throws with invalid writeOffset' + webglMessage, function() { if (!context.webgl2) { return; } @@ -519,7 +518,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer throws with invalid sizeInBytes', function() { + it('copyFromBuffer throws with invalid sizeInBytes' + webglMessage, function() { if (!context.webgl2) { return; } @@ -549,7 +548,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer throws with one index buffer and the other is not an index buffer', function() { + it('copyFromBuffer throws with one index buffer and the other is not an index buffer' + webglMessage, function() { if (!context.webgl2) { return; } @@ -573,7 +572,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer throws when readBuffer is the same buffer and copy range overlaps', function() { + it('copyFromBuffer throws when readBuffer is the same buffer and copy range overlaps' + webglMessage, function() { if (!context.webgl2) { return; } @@ -592,7 +591,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('copyFromBuffer with vertex buffers', function() { + it('copyFromBuffer with vertex buffers' + webglMessage, function() { if (!context.webgl2) { return; } @@ -621,7 +620,7 @@ defineSuite([ expect(destArray).toEqual(typedArray); }); - it('copyFromBuffer with index buffers', function() { + it('copyFromBuffer with index buffers' + webglMessage, function() { if (!context.webgl2) { return; } @@ -652,7 +651,7 @@ defineSuite([ expect(destArray).toEqual(typedArray); }); - it('destroys', function() { + it('destroys' + webglMessage, function() { var b = Buffer.createIndexBuffer({ context : context, sizeInBytes : 3, @@ -664,7 +663,7 @@ defineSuite([ expect(b.isDestroyed()).toEqual(true); }); - it('fails to provide an array view', function() { + it('fails to provide an array view' + webglMessage, function() { buffer = Buffer.createVertexBuffer({ context : context, sizeInBytes : 3, @@ -675,7 +674,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('fails to copy a large array view', function() { + it('fails to copy a large array view' + webglMessage, function() { buffer = Buffer.createVertexBuffer({ context : context, sizeInBytes : 3, @@ -688,7 +687,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('fails to destroy', function() { + it('fails to destroy' + webglMessage, function() { var b = Buffer.createIndexBuffer({ context : context, sizeInBytes : 3, From f5b81794609b1b0ff67aa04fc40c5afb99215a7d Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Wed, 26 Apr 2017 16:28:31 -0400 Subject: [PATCH 08/60] Better context lifetime --- Specs/Renderer/BufferSpec.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Specs/Renderer/BufferSpec.js b/Specs/Renderer/BufferSpec.js index 3419c2930a87..3f5170b6ab6c 100644 --- a/Specs/Renderer/BufferSpec.js +++ b/Specs/Renderer/BufferSpec.js @@ -12,21 +12,23 @@ defineSuite([ 'use strict'; createBufferSpecs({}); - createBufferSpecs({ - requestWebgl2 : true - }); + var c = createContext({ requestWebgl2 : true }); + // Don't repeat WebGL 1 tests when WebGL 2 is not supported + if (c.webgl2) { + createBufferSpecs({ requestWebgl2 : true }); + } + c.destroyForSpecs(); function createBufferSpecs(contextOptions) { + var context; var buffer; var buffer2; - var context = createContext(contextOptions); - - if (contextOptions.requestWebgl2 && !context.webgl2) { - // Don't repeat WebGL 1 tests - return; - } var webglMessage = contextOptions.requestWebgl2 ? ': WebGL 2' : ''; + beforeAll(function() { + context = createContext(contextOptions); + }); + afterAll(function() { context.destroyForSpecs(); }); From 6dd5bba045688a1683f1c9548ac181f151154d4a Mon Sep 17 00:00:00 2001 From: hates Date: Mon, 29 May 2017 22:38:27 +0300 Subject: [PATCH 09/60] createMaterialId refactored --- Source/Scene/PolylineCollection.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/Scene/PolylineCollection.js b/Source/Scene/PolylineCollection.js index 815f95d93dc7..104fb962074d 100644 --- a/Source/Scene/PolylineCollection.js +++ b/Source/Scene/PolylineCollection.js @@ -28,6 +28,7 @@ define([ '../Renderer/ShaderProgram', '../Renderer/ShaderSource', '../Renderer/VertexArray', + '../Renderer/Texture', '../Shaders/PolylineCommon', '../Shaders/PolylineFS', '../Shaders/PolylineVS', @@ -65,6 +66,7 @@ define([ ShaderProgram, ShaderSource, VertexArray, + Texture, PolylineCommon, PolylineFS, PolylineVS, @@ -1013,6 +1015,19 @@ define([ } } + var scratchTextureArray = []; + function createTextureId(texture) { + scratchTextureArray[0] = texture.pixelFormat; + scratchTextureArray[1] = texture.pixelDatatype; + scratchTextureArray[2] = texture.dimensions; + scratchTextureArray[3] = texture.preMultiplyAlpha; + scratchTextureArray[4] = texture.flipY; + scratchTextureArray[5] = texture.width; + scratchTextureArray[6] = texture.sizeInBytes; + + return JSON.stringify(scratchTextureArray); + } + var scratchUniformArray = []; function createMaterialId(material) { var uniforms = Material._uniformList[material.type]; @@ -1020,10 +1035,16 @@ define([ scratchUniformArray.length = 2.0 * length; var index = 0; + var value; for (var i = 0; i < length; ++i) { var uniform = uniforms[i]; scratchUniformArray[index] = uniform; - scratchUniformArray[index + 1] = material._uniforms[uniform](); + value = material._uniforms[uniform](); + if(value instanceof Texture){ + scratchUniformArray[index + 1] = createTextureId(value); + } else { + scratchUniformArray[index + 1] = value; + } index += 2; } From 80d7bc362aaf13d18065fa73772f6b0ba8f05936 Mon Sep 17 00:00:00 2001 From: hates Date: Thu, 1 Jun 2017 22:15:33 +0300 Subject: [PATCH 10/60] unique id property added to Texture --- Source/Renderer/Texture.js | 9 +++++++++ Source/Scene/PolylineCollection.js | 29 ++++++++--------------------- Specs/Renderer/TextureSpec.js | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Source/Renderer/Texture.js b/Source/Renderer/Texture.js index a330e3aecfc0..53c338d9354c 100644 --- a/Source/Renderer/Texture.js +++ b/Source/Renderer/Texture.js @@ -33,6 +33,8 @@ define([ TextureMinificationFilter) { 'use strict'; + var currentId = 0; + function Texture(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); @@ -196,6 +198,7 @@ define([ sizeInBytes = PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, height); } + this._id = 'Texture_' + currentId++; this._context = context; this._textureFilterAnisotropic = context._textureFilterAnisotropic; this._textureTarget = textureTarget; @@ -308,6 +311,12 @@ define([ }; defineProperties(Texture.prototype, { + + id : { + get : function() { + return this._id; + } + }, /** * The sampler to use when sampling this texture. * Create a sampler by calling {@link Sampler}. If this diff --git a/Source/Scene/PolylineCollection.js b/Source/Scene/PolylineCollection.js index 104fb962074d..3d43c0847764 100644 --- a/Source/Scene/PolylineCollection.js +++ b/Source/Scene/PolylineCollection.js @@ -28,7 +28,6 @@ define([ '../Renderer/ShaderProgram', '../Renderer/ShaderSource', '../Renderer/VertexArray', - '../Renderer/Texture', '../Shaders/PolylineCommon', '../Shaders/PolylineFS', '../Shaders/PolylineVS', @@ -66,7 +65,6 @@ define([ ShaderProgram, ShaderSource, VertexArray, - Texture, PolylineCommon, PolylineFS, PolylineVS, @@ -1015,17 +1013,12 @@ define([ } } - var scratchTextureArray = []; - function createTextureId(texture) { - scratchTextureArray[0] = texture.pixelFormat; - scratchTextureArray[1] = texture.pixelDatatype; - scratchTextureArray[2] = texture.dimensions; - scratchTextureArray[3] = texture.preMultiplyAlpha; - scratchTextureArray[4] = texture.flipY; - scratchTextureArray[5] = texture.width; - scratchTextureArray[6] = texture.sizeInBytes; - - return JSON.stringify(scratchTextureArray); + function replacer(key, value) { + if(defined(value) && value.hasOwnProperty('id')) { + return value.id; + } + + return value; } var scratchUniformArray = []; @@ -1035,20 +1028,14 @@ define([ scratchUniformArray.length = 2.0 * length; var index = 0; - var value; for (var i = 0; i < length; ++i) { var uniform = uniforms[i]; scratchUniformArray[index] = uniform; - value = material._uniforms[uniform](); - if(value instanceof Texture){ - scratchUniformArray[index + 1] = createTextureId(value); - } else { - scratchUniformArray[index + 1] = value; - } + scratchUniformArray[index + 1] = material._uniforms[uniform](); index += 2; } - return material.type + ':' + JSON.stringify(scratchUniformArray); + return material.type + ':' + JSON.stringify(scratchUniformArray, replacer); } function sortPolylinesIntoBuckets(collection) { diff --git a/Specs/Renderer/TextureSpec.js b/Specs/Renderer/TextureSpec.js index aaae78a5248f..dfc1ae2afbe3 100644 --- a/Specs/Renderer/TextureSpec.js +++ b/Specs/Renderer/TextureSpec.js @@ -94,6 +94,24 @@ defineSuite([ texture = texture && texture.destroy(); }); + it('has unique id', function() { + var t1 = new Texture({ + context : context, + source : blueImage + }); + + var t2 = new Texture({ + context : context, + source : blueImage + }); + + expect(t1.id).toBeDefined(); + expect(t1.id).not.toEqual(t2.id); + + t1.destroy(); + t2.destroy(); + }); + it('has expected default values for pixel format and datatype', function() { texture = new Texture({ context : context, From f6bf4c44726fd3ea6b17f41c0ab0a317471e730b Mon Sep 17 00:00:00 2001 From: hates Date: Mon, 12 Jun 2017 23:31:04 +0300 Subject: [PATCH 11/60] Replaced DeveloperErrors with Check in Renderer folder --- Source/Renderer/Buffer.js | 6 +++--- Source/Renderer/Context.js | 6 +++--- Source/Renderer/CubeMap.js | 6 +++--- Source/Renderer/Framebuffer.js | 6 +++--- Source/Renderer/Renderbuffer.js | 14 +++++--------- Source/Renderer/Sampler.js | 6 +++--- Source/Renderer/Texture.js | 6 +++--- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index edb489e7d313..64407c2d4581 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -7,6 +7,7 @@ define([ '../Core/DeveloperError', '../Core/IndexDatatype', '../Core/WebGLConstants', + '../Core/Check', './BufferUsage' ], function( defaultValue, @@ -16,6 +17,7 @@ define([ DeveloperError, IndexDatatype, WebGLConstants, + Check, BufferUsage) { 'use strict'; @@ -26,9 +28,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); if (!defined(options.typedArray) && !defined(options.sizeInBytes)) { throw new DeveloperError('Either options.sizeInBytes or options.typedArray is required.'); diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index 7966c47e0418..b515ce239859 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -4,6 +4,7 @@ define([ '../Core/Color', '../Core/ComponentDatatype', '../Core/createGuid', + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -34,6 +35,7 @@ define([ Color, ComponentDatatype, createGuid, + Check, defaultValue, defined, defineProperties, @@ -179,9 +181,7 @@ define([ } //>>includeStart('debug', pragmas.debug); - if (!defined(canvas)) { - throw new DeveloperError('canvas is required.'); - } + Check.defined('canvas', canvas); //>>includeEnd('debug'); this._canvas = canvas; diff --git a/Source/Renderer/CubeMap.js b/Source/Renderer/CubeMap.js index 8f29baa1343b..7d78a6fdcdd8 100644 --- a/Source/Renderer/CubeMap.js +++ b/Source/Renderer/CubeMap.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -15,6 +16,7 @@ define([ './TextureMagnificationFilter', './TextureMinificationFilter' ], function( + Check, defaultValue, defined, defineProperties, @@ -36,9 +38,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); //>>includeEnd('debug'); var context = options.context; diff --git a/Source/Renderer/Framebuffer.js b/Source/Renderer/Framebuffer.js index 2e2c1f97406a..6ce1d1427277 100644 --- a/Source/Renderer/Framebuffer.js +++ b/Source/Renderer/Framebuffer.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -8,6 +9,7 @@ define([ '../Core/PixelFormat', './ContextLimits' ], function( + Check, defaultValue, defined, defineProperties, @@ -72,9 +74,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); //>>includeEnd('debug'); var gl = options.context._gl; diff --git a/Source/Renderer/Renderbuffer.js b/Source/Renderer/Renderbuffer.js index ebee4b0be504..9b60ea93a9f2 100644 --- a/Source/Renderer/Renderbuffer.js +++ b/Source/Renderer/Renderbuffer.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -8,6 +9,7 @@ define([ './ContextLimits', './RenderbufferFormat' ], function( + Check, defaultValue, defined, defineProperties, @@ -24,9 +26,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined(options.context); //>>includeEnd('debug'); var context = options.context; @@ -42,17 +42,13 @@ define([ throw new DeveloperError('Invalid format.'); } - if (width <= 0) { - throw new DeveloperError('Width must be greater than zero.'); - } + Check.typeOf.number.greaterThan('width', width, 0); if (width > maximumRenderbufferSize) { throw new DeveloperError('Width must be less than or equal to the maximum renderbuffer size (' + maximumRenderbufferSize + '). Check maximumRenderbufferSize.'); } - if (height <= 0) { - throw new DeveloperError('Height must be greater than zero.'); - } + Check.typeOf.number.greaterThan('height', height, 0); if (height > maximumRenderbufferSize) { throw new DeveloperError('Height must be less than or equal to the maximum renderbuffer size (' + maximumRenderbufferSize + '). Check maximumRenderbufferSize.'); diff --git a/Source/Renderer/Sampler.js b/Source/Renderer/Sampler.js index 85c8c6e32bcb..fe422a639eb4 100644 --- a/Source/Renderer/Sampler.js +++ b/Source/Renderer/Sampler.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -8,6 +9,7 @@ define([ './TextureMinificationFilter', './TextureWrap' ], function( + Check, defaultValue, defined, defineProperties, @@ -46,9 +48,7 @@ define([ throw new DeveloperError('Invalid sampler.magnificationFilter.'); } - if (maximumAnisotropy < 1.0) { - throw new DeveloperError('sampler.maximumAnisotropy must be greater than or equal to one.'); - } + Check.typeOf.number.greaterThanOrEquals('maximumAnisotropy', maximumAnisotropy, 1.0); //>>includeEnd('debug'); this._wrapS = wrapS; diff --git a/Source/Renderer/Texture.js b/Source/Renderer/Texture.js index a330e3aecfc0..fd51f44b01f3 100644 --- a/Source/Renderer/Texture.js +++ b/Source/Renderer/Texture.js @@ -1,6 +1,7 @@ /*global define*/ define([ '../Core/Cartesian2', + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -17,6 +18,7 @@ define([ './TextureMinificationFilter' ], function( Cartesian2, + Check, defaultValue, defined, defineProperties, @@ -37,9 +39,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); //>>includeEnd('debug'); var context = options.context; From 08a2d73792a8ab79268ecd0130046520d5c14edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Tue, 13 Jun 2017 17:37:56 +0300 Subject: [PATCH 12/60] tweak --- Source/Renderer/Renderbuffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Renderer/Renderbuffer.js b/Source/Renderer/Renderbuffer.js index 9b60ea93a9f2..dd45d3f2c35c 100644 --- a/Source/Renderer/Renderbuffer.js +++ b/Source/Renderer/Renderbuffer.js @@ -26,7 +26,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - Check.defined(options.context); + Check.defined('options.context', options.context); //>>includeEnd('debug'); var context = options.context; From 3842e3b332ee9635b69021f0db82e56bb85af726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Tue, 13 Jun 2017 17:54:28 +0300 Subject: [PATCH 13/60] tweak --- Source/Renderer/freezeRenderState.js | 7 +- Specs/Renderer/freezeRenderStateSpec.js | 103 ++++++++++++------------ 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/Source/Renderer/freezeRenderState.js b/Source/Renderer/freezeRenderState.js index 2f7b97b9a812..e93bf71f4443 100644 --- a/Source/Renderer/freezeRenderState.js +++ b/Source/Renderer/freezeRenderState.js @@ -22,17 +22,16 @@ define([ return renderState; } - var i, propName, propNames = Object.keys(renderState); + var propName; + var propNames = Object.keys(renderState); - for (i = 0; i < propNames.length; i++) { + for (var i = 0; i < propNames.length; i++) { propName = propNames[i]; if (renderState.hasOwnProperty(propName) && propName !== '_applyFunctions') { renderState[propName] = freezeRenderState(renderState[propName]); } } - return freezeObject(renderState); } - return freezeRenderState; }); diff --git a/Specs/Renderer/freezeRenderStateSpec.js b/Specs/Renderer/freezeRenderStateSpec.js index 59e64688b1b4..b702657356b0 100644 --- a/Specs/Renderer/freezeRenderStateSpec.js +++ b/Specs/Renderer/freezeRenderStateSpec.js @@ -1,68 +1,67 @@ /*global defineSuite*/ defineSuite([ - 'Renderer/freezeRenderState' -], 'Renderer/freezeRenderState', function( - freezeRenderState -) { - 'use strict'; + 'Renderer/freezeRenderState' + ], function( + freezeRenderState) { + 'use strict'; - it('works for literals', function() { - var fresh = { - a: 1, - b: 'b', - c: 2.2, - u: undefined, - n: null - }; + it('works for literals', function() { + var fresh = { + a: 1, + b: 'b', + c: 2.2, + u: undefined, + n: null + }; - var frozen = freezeRenderState(fresh); + var frozen = freezeRenderState(fresh); - expect(function() { - frozen.a = 2; - }).toThrow(); + expect(function() { + frozen.a = 2; + }).toThrow(); - expect(function() { - frozen.b = 'c'; - }).toThrow(); + expect(function() { + frozen.b = 'c'; + }).toThrow(); - expect(function() { - frozen.c = 2; - }).toThrow(); + expect(function() { + frozen.c = 2; + }).toThrow(); - }); - - it('works for deep objects', function() { - var fresh = { - a: 2, - o: { - b: 2, - c: 'c' - } - }; + }); - var frozen = freezeRenderState(fresh); + it('works for deep objects', function() { + var fresh = { + a: 2, + o: { + b: 2, + c: 'c' + } + }; - expect(function() { - frozen.o.b = 3; - frozen.o.c = 'dddd'; - }).toThrow(); - }); + var frozen = freezeRenderState(fresh); - it('ignores _applyFunctions', function() { - var fresh = { - a: 1, - _applyFunctions: [function() { }] - }; + expect(function() { + frozen.o.b = 3; + frozen.o.c = 'dddd'; + }).toThrow(); + }); - var frozen = freezeRenderState(fresh); + it('ignores _applyFunctions', function() { + var fresh = { + a: 1, + _applyFunctions: [function() { }] + }; - expect(function() { - frozen.a = 0; - }).toThrow(); + var frozen = freezeRenderState(fresh); - expect(function() { - frozen._applyFunctions.push(function() { }); - }).not.toThrow(); - }); + expect(function() { + frozen.a = 0; + }).toThrow(); + expect(function() { + frozen._applyFunctions.push(function() { }); + }).not.toThrow(); }); + +}); From f44054fb778c8e10f5c73376e3e1547e3be59df7 Mon Sep 17 00:00:00 2001 From: hates Date: Fri, 16 Jun 2017 00:50:04 +0300 Subject: [PATCH 14/60] Replaced DeveloperErrors with Check in Renderer --- Source/Renderer/Buffer.js | 21 ++++------ Source/Renderer/ComputeEngine.js | 10 ++--- Source/Renderer/Context.js | 53 ++++++-------------------- Source/Renderer/CubeMapFace.js | 30 +++++---------- Source/Renderer/ShaderProgram.js | 10 ++--- Source/Renderer/Texture.js | 57 +++++++++------------------- Source/Renderer/VertexArray.js | 19 +++------- Source/Renderer/VertexArrayFacade.js | 6 +-- Source/Renderer/loadCubeMap.js | 6 +-- 9 files changed, 66 insertions(+), 146 deletions(-) diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index 64407c2d4581..9b9585470388 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -7,9 +8,9 @@ define([ '../Core/DeveloperError', '../Core/IndexDatatype', '../Core/WebGLConstants', - '../Core/Check', './BufferUsage' ], function( + Check, defaultValue, defined, defineProperties, @@ -17,7 +18,6 @@ define([ DeveloperError, IndexDatatype, WebGLConstants, - Check, BufferUsage) { 'use strict'; @@ -59,9 +59,7 @@ define([ } //>>includeStart('debug', pragmas.debug); - if (sizeInBytes <= 0) { - throw new DeveloperError('Buffer size must be greater than zero.'); - } + Check.typeOf.number.greaterThan('sizeInBytes', sizeInBytes, 0); //>>includeEnd('debug'); var buffer = gl.createBuffer(); @@ -119,9 +117,7 @@ define([ */ Buffer.createVertexBuffer = function(options) { //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); //>>includeEnd('debug'); return new Buffer({ @@ -180,9 +176,7 @@ define([ */ Buffer.createIndexBuffer = function(options) { //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); if (!IndexDatatype.validate(options.indexDatatype)) { throw new DeveloperError('Invalid indexDatatype.'); @@ -250,9 +244,8 @@ define([ offsetInBytes = defaultValue(offsetInBytes, 0); //>>includeStart('debug', pragmas.debug); - if (!arrayView) { - throw new DeveloperError('arrayView is required.'); - } + Check.defined('arrayView', arrayView); + if (offsetInBytes + arrayView.byteLength > this._sizeInBytes) { throw new DeveloperError('This buffer is not large enough.'); } diff --git a/Source/Renderer/ComputeEngine.js b/Source/Renderer/ComputeEngine.js index 13235334a893..3b05fcacf034 100644 --- a/Source/Renderer/ComputeEngine.js +++ b/Source/Renderer/ComputeEngine.js @@ -1,6 +1,7 @@ /*global define*/ define([ '../Core/BoundingRectangle', + '../Core/Check', '../Core/Color', '../Core/defined', '../Core/destroyObject', @@ -14,6 +15,7 @@ define([ './ShaderProgram' ], function( BoundingRectangle, + Check, Color, defined, destroyObject, @@ -76,9 +78,7 @@ define([ ComputeEngine.prototype.execute = function(computeCommand) { //>>includeStart('debug', pragmas.debug); - if (!defined(computeCommand)) { - throw new DeveloperError('computeCommand is required.'); - } + Check.defined('computeCommand', computeCommand); //>>includeEnd('debug'); // This may modify the command's resources, so do error checking afterwards @@ -91,9 +91,7 @@ define([ throw new DeveloperError('computeCommand.fragmentShaderSource or computeCommand.shaderProgram is required.'); } - if (!defined(computeCommand.outputTexture)) { - throw new DeveloperError('computeCommand.outputTexture is required.'); - } + Check.defined('computeCommand.outputTexture', computeCommand.outputTexture); //>>includeEnd('debug'); var outputTexture = computeCommand.outputTexture; diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index b515ce239859..ee31f290a298 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -1,10 +1,10 @@ /*global define*/ define([ + '../Core/Check', '../Core/clone', '../Core/Color', '../Core/ComponentDatatype', '../Core/createGuid', - '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -31,11 +31,11 @@ define([ './UniformState', './VertexArray' ], function( + Check, clone, Color, ComponentDatatype, createGuid, - Check, defaultValue, defined, defineProperties, @@ -892,25 +892,10 @@ define([ throw new DeveloperError('drawCommand.primitiveType is required and must be valid.'); } - if (!defined(va)) { - throw new DeveloperError('drawCommand.vertexArray is required.'); - } - - if (offset < 0) { - throw new DeveloperError('drawCommand.offset must be greater than or equal to zero.'); - } - - if (count < 0) { - throw new DeveloperError('drawCommand.count must be greater than or equal to zero.'); - } - - if (instanceCount < 0) { - throw new DeveloperError('drawCommand.instanceCount must be greater than or equal to zero.'); - } - - if (instanceCount > 0 && !context.instancedArrays) { - throw new DeveloperError('Instanced arrays extension is not supported'); - } + Check.defined('drawCommand.vertexArray', va); + Check.typeOf.numgreaterThanOrEquals('drawCommand.offset', offset, 0); + Check.typeOf.numgreaterThanOrEquals('drawCommand.count', count, 0); + Check.typeOf.numgreaterThanOrEquals('drawCommand.instanceCount', instanceCount, 0); //>>includeEnd('debug'); context._us.model = defaultValue(drawCommand._modelMatrix, Matrix4.IDENTITY); @@ -941,13 +926,8 @@ define([ Context.prototype.draw = function(drawCommand, passState) { //>>includeStart('debug', pragmas.debug); - if (!defined(drawCommand)) { - throw new DeveloperError('drawCommand is required.'); - } - - if (!defined(drawCommand._shaderProgram)) { - throw new DeveloperError('drawCommand.shaderProgram is required.'); - } + Check.defined('drawCommand', drawCommand); + Check.defined('drawCommand.shaderProgram', drawCommand._shaderProgram); //>>includeEnd('debug'); passState = defaultValue(passState, this._defaultPassState); @@ -991,13 +971,8 @@ define([ var framebuffer = readState.framebuffer; //>>includeStart('debug', pragmas.debug); - if (width <= 0) { - throw new DeveloperError('readState.width must be greater than zero.'); - } - - if (height <= 0) { - throw new DeveloperError('readState.height must be greater than zero.'); - } + Check.typeOf.number.greaterThan('readState.width', width, 0); + Check.typeOf.number.greaterThan('readState.height', height, 0); //>>includeEnd('debug'); var pixels = new Uint8Array(4 * width * height); @@ -1098,9 +1073,7 @@ define([ */ Context.prototype.getObjectByPickColor = function(pickColor) { //>>includeStart('debug', pragmas.debug); - if (!defined(pickColor)) { - throw new DeveloperError('pickColor is required.'); - } + Check.defined('pickColor', pickColor); //>>includeEnd('debug'); return this._pickObjects[pickColor.toRgba()]; @@ -1149,9 +1122,7 @@ define([ */ Context.prototype.createPickId = function(object) { //>>includeStart('debug', pragmas.debug); - if (!defined(object)) { - throw new DeveloperError('object is required.'); - } + Check.defined('object', object); //>>includeEnd('debug'); // the increment and assignment have to be separate statements to diff --git a/Source/Renderer/CubeMapFace.js b/Source/Renderer/CubeMapFace.js index ca923da99fe7..2b81ffced48c 100644 --- a/Source/Renderer/CubeMapFace.js +++ b/Source/Renderer/CubeMapFace.js @@ -1,10 +1,12 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defineProperties', '../Core/DeveloperError', './PixelDatatype' ], function( + Check, defaultValue, defineProperties, DeveloperError, @@ -75,15 +77,9 @@ define([ yOffset = defaultValue(yOffset, 0); //>>includeStart('debug', pragmas.debug); - if (!source) { - throw new DeveloperError('source is required.'); - } - if (xOffset < 0) { - throw new DeveloperError('xOffset must be greater than or equal to zero.'); - } - if (yOffset < 0) { - throw new DeveloperError('yOffset must be greater than or equal to zero.'); - } + Check.defined('source', source); + Check.typeOf.number.greaterThanOrEquals('xOffset', xOffset, 0); + Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); if (xOffset + source.width > this._size) { throw new DeveloperError('xOffset + source.width must be less than or equal to width.'); } @@ -143,18 +139,10 @@ define([ height = defaultValue(height, this._size); //>>includeStart('debug', pragmas.debug); - if (xOffset < 0) { - throw new DeveloperError('xOffset must be greater than or equal to zero.'); - } - if (yOffset < 0) { - throw new DeveloperError('yOffset must be greater than or equal to zero.'); - } - if (framebufferXOffset < 0) { - throw new DeveloperError('framebufferXOffset must be greater than or equal to zero.'); - } - if (framebufferYOffset < 0) { - throw new DeveloperError('framebufferYOffset must be greater than or equal to zero.'); - } + Check.typeOf.number.greaterThanOrEquals('xOffset', xOffset, 0); + Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); + Check.typeOf.number.greaterThanOrEquals('framebufferXOffset', framebufferXOffset, 0); + Check.typeOf.number.greaterThanOrEquals('framebufferYOffset', framebufferYOffset, 0); if (xOffset + width > this._size) { throw new DeveloperError('xOffset + source.width must be less than or equal to width.'); } diff --git a/Source/Renderer/ShaderProgram.js b/Source/Renderer/ShaderProgram.js index a76faa6acb8e..f7e1463231d1 100644 --- a/Source/Renderer/ShaderProgram.js +++ b/Source/Renderer/ShaderProgram.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -11,6 +12,7 @@ define([ './createUniform', './createUniformArray' ], function( + Check, defaultValue, defined, defineProperties, @@ -66,9 +68,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('context', context); //>>includeEnd('debug'); return options.context.shaderCache.getShaderProgram(options); @@ -78,9 +78,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('context', context); //>>includeEnd('debug'); return options.context.shaderCache.replaceShaderProgram(options); diff --git a/Source/Renderer/Texture.js b/Source/Renderer/Texture.js index fd51f44b01f3..38b160e1801a 100644 --- a/Source/Renderer/Texture.js +++ b/Source/Renderer/Texture.js @@ -79,17 +79,13 @@ define([ throw new DeveloperError('options requires a source field to create an initialized texture or width and height fields to create a blank texture.'); } - if (width <= 0) { - throw new DeveloperError('Width must be greater than zero.'); - } + Check.typeOf.number.greaterThan('width', width, 0); if (width > ContextLimits.maximumTextureSize) { throw new DeveloperError('Width must be less than or equal to the maximum texture size (' + ContextLimits.maximumTextureSize + '). Check maximumTextureSize.'); } - if (height <= 0) { - throw new DeveloperError('Height must be greater than zero.'); - } + Check.typeOf.number.greaterThan('height', height, 0); if (height > ContextLimits.maximumTextureSize) { throw new DeveloperError('Height must be less than or equal to the maximum texture size (' + ContextLimits.maximumTextureSize + '). Check maximumTextureSize.'); @@ -251,9 +247,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); //>>includeEnd('debug'); var context = options.context; @@ -267,21 +261,16 @@ define([ var framebuffer = options.framebuffer; //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('context is required.'); - } if (!PixelFormat.validate(pixelFormat)) { throw new DeveloperError('Invalid pixelFormat.'); } if (PixelFormat.isDepthFormat(pixelFormat) || PixelFormat.isCompressedFormat(pixelFormat)) { throw new DeveloperError('pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format.'); } - if (framebufferXOffset < 0) { - throw new DeveloperError('framebufferXOffset must be greater than or equal to zero.'); - } - if (framebufferYOffset < 0) { - throw new DeveloperError('framebufferYOffset must be greater than or equal to zero.'); - } + + Check.typeOf.number.greaterThanOrEquals('framebufferXOffset', framebufferXOffset, 0); + Check.typeOf.number.greaterThanOrEquals('framebufferYOffset', framebufferYOffset, 0); + if (framebufferXOffset + width > gl.drawingBufferWidth) { throw new DeveloperError('framebufferXOffset + width must be less than or equal to drawingBufferWidth'); } @@ -433,21 +422,17 @@ define([ yOffset = defaultValue(yOffset, 0); //>>includeStart('debug', pragmas.debug); - if (!defined(source)) { - throw new DeveloperError('source is required.'); - } + Check.defined('source', source); if (PixelFormat.isDepthFormat(this._pixelFormat)) { throw new DeveloperError('Cannot call copyFrom when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.'); } if (PixelFormat.isCompressedFormat(this._pixelFormat)) { throw new DeveloperError('Cannot call copyFrom with a compressed texture pixel format.'); } - if (xOffset < 0) { - throw new DeveloperError('xOffset must be greater than or equal to zero.'); - } - if (yOffset < 0) { - throw new DeveloperError('yOffset must be greater than or equal to zero.'); - } + + Check.typeOf.number.greaterThanOrEquals('xOffset', xOffset, 0); + Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); + if (xOffset + source.width > this._width) { throw new DeveloperError('xOffset + source.width must be less than or equal to width.'); } @@ -511,18 +496,12 @@ define([ if (PixelFormat.isCompressedFormat(this._pixelFormat)) { throw new DeveloperError('Cannot call copyFrom with a compressed texture pixel format.'); } - if (xOffset < 0) { - throw new DeveloperError('xOffset must be greater than or equal to zero.'); - } - if (yOffset < 0) { - throw new DeveloperError('yOffset must be greater than or equal to zero.'); - } - if (framebufferXOffset < 0) { - throw new DeveloperError('framebufferXOffset must be greater than or equal to zero.'); - } - if (framebufferYOffset < 0) { - throw new DeveloperError('framebufferYOffset must be greater than or equal to zero.'); - } + + Check.typeOf.number.greaterThanOrEquals('xOffset', xOffset, 0); + Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); + Check.typeOf.number.greaterThanOrEquals('framebufferXOffset', framebufferXOffset, 0); + Check.typeOf.number.greaterThanOrEquals('framebufferYOffset', framebufferYOffset, 0); + if (xOffset + width > this._width) { throw new DeveloperError('xOffset + width must be less than or equal to width.'); } diff --git a/Source/Renderer/VertexArray.js b/Source/Renderer/VertexArray.js index a02d27dc7996..fe0d78592d32 100644 --- a/Source/Renderer/VertexArray.js +++ b/Source/Renderer/VertexArray.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/ComponentDatatype', '../Core/defaultValue', '../Core/defined', @@ -14,6 +15,7 @@ define([ './BufferUsage', './ContextLimits' ], function( + Check, ComponentDatatype, defaultValue, defined, @@ -267,13 +269,8 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } - - if (!defined(options.attributes)) { - throw new DeveloperError('options.attributes is required.'); - } + Check.defined('options.context', options.context); + Check.defined('options.attributes', options.attributes); //>>includeEnd('debug'); var context = options.context; @@ -529,9 +526,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - if (!defined(options.context)) { - throw new DeveloperError('options.context is required.'); - } + Check.defined('options.context', options.context); //>>includeEnd('debug'); var context = options.context; @@ -670,9 +665,7 @@ define([ */ VertexArray.prototype.getAttribute = function(index) { //>>includeStart('debug', pragmas.debug); - if (!defined(index)) { - throw new DeveloperError('index is required.'); - } + Check.defined('index', index); //>>includeEnd('debug'); return this._attributes[index]; diff --git a/Source/Renderer/VertexArrayFacade.js b/Source/Renderer/VertexArrayFacade.js index d7a793888394..9655d813d03b 100644 --- a/Source/Renderer/VertexArrayFacade.js +++ b/Source/Renderer/VertexArrayFacade.js @@ -1,5 +1,6 @@ /*global define*/ define([ + '../Core/Check', '../Core/ComponentDatatype', '../Core/defaultValue', '../Core/defined', @@ -10,6 +11,7 @@ define([ './BufferUsage', './VertexArray' ], function( + Check, ComponentDatatype, defaultValue, defined, @@ -26,9 +28,7 @@ define([ */ function VertexArrayFacade(context, attributes, sizeInVertices, instanced) { //>>includeStart('debug', pragmas.debug); - if (!context) { - throw new DeveloperError('context is required.'); - } + Check.defined('context', context); if (!attributes || (attributes.length === 0)) { throw new DeveloperError('At least one attribute is required.'); } diff --git a/Source/Renderer/loadCubeMap.js b/Source/Renderer/loadCubeMap.js index 81d6528aff59..a49c7f47f725 100644 --- a/Source/Renderer/loadCubeMap.js +++ b/Source/Renderer/loadCubeMap.js @@ -1,11 +1,13 @@ /*global define*/ define([ + '../Core/Check', '../Core/defined', '../Core/DeveloperError', '../Core/loadImage', '../ThirdParty/when', './CubeMap' ], function( + Check, defined, DeveloperError, loadImage, @@ -51,9 +53,7 @@ define([ */ function loadCubeMap(context, urls, allowCrossOrigin) { //>>includeStart('debug', pragmas.debug); - if (!defined(context)) { - throw new DeveloperError('context is required.'); - } + Check.defined('context', context); if ((!defined(urls)) || (!defined(urls.positiveX)) || (!defined(urls.negativeX)) || From 3f5afd1442d3c45a642ebf1a7ab1157b69ae9d86 Mon Sep 17 00:00:00 2001 From: hates Date: Fri, 16 Jun 2017 00:52:29 +0300 Subject: [PATCH 15/60] tweak --- Source/Renderer/ShaderProgram.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Renderer/ShaderProgram.js b/Source/Renderer/ShaderProgram.js index f7e1463231d1..c3f11cabaae4 100644 --- a/Source/Renderer/ShaderProgram.js +++ b/Source/Renderer/ShaderProgram.js @@ -68,7 +68,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - Check.defined('context', context); + Check.defined('options.context', options.context); //>>includeEnd('debug'); return options.context.shaderCache.getShaderProgram(options); @@ -78,7 +78,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug); - Check.defined('context', context); + Check.defined('options.context', options.context); //>>includeEnd('debug'); return options.context.shaderCache.replaceShaderProgram(options); From e0079f2433dc347c30ccc626bfce15c47cf5d5e6 Mon Sep 17 00:00:00 2001 From: hates Date: Fri, 16 Jun 2017 01:00:13 +0300 Subject: [PATCH 16/60] typo --- Source/Renderer/Context.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index ee31f290a298..6a6d5b81d6bc 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -893,9 +893,9 @@ define([ } Check.defined('drawCommand.vertexArray', va); - Check.typeOf.numgreaterThanOrEquals('drawCommand.offset', offset, 0); - Check.typeOf.numgreaterThanOrEquals('drawCommand.count', count, 0); - Check.typeOf.numgreaterThanOrEquals('drawCommand.instanceCount', instanceCount, 0); + Check.typeOf.number.greaterThanOrEquals('drawCommand.offset', offset, 0); + Check.typeOf.number.greaterThanOrEquals('drawCommand.count', count, 0); + Check.typeOf.number.greaterThanOrEquals('drawCommand.instanceCount', instanceCount, 0); //>>includeEnd('debug'); context._us.model = defaultValue(drawCommand._modelMatrix, Matrix4.IDENTITY); From f9bbb277ff9656de5aa7e86d2b1c8144df261785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Wed, 21 Jun 2017 13:03:22 +0300 Subject: [PATCH 17/60] render state freezed --- Source/Renderer/RenderState.js | 9 +++++++-- Source/Renderer/freezeRenderState.js | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/Renderer/RenderState.js b/Source/Renderer/RenderState.js index 93c074526257..a32befbf0f7d 100644 --- a/Source/Renderer/RenderState.js +++ b/Source/Renderer/RenderState.js @@ -7,7 +7,8 @@ define([ '../Core/DeveloperError', '../Core/WebGLConstants', '../Core/WindingOrder', - './ContextLimits' + './ContextLimits', + './freezeRenderState' ], function( BoundingRectangle, Color, @@ -16,7 +17,8 @@ define([ DeveloperError, WebGLConstants, WindingOrder, - ContextLimits) { + ContextLimits, + freezeRenderState) { 'use strict'; function validateBlendEquation(blendEquation) { @@ -406,6 +408,9 @@ define([ // Cache miss. Fully define render state and try again. var states = new RenderState(renderState); + //>>includeStart('debug', pragmas.debug); + states = freezeRenderState(states); + //>>includeEnd('debug'); var fullKey = JSON.stringify(states); cachedState = renderStateCache[fullKey]; if (!defined(cachedState)) { diff --git a/Source/Renderer/freezeRenderState.js b/Source/Renderer/freezeRenderState.js index e93bf71f4443..e93a3535ade4 100644 --- a/Source/Renderer/freezeRenderState.js +++ b/Source/Renderer/freezeRenderState.js @@ -11,7 +11,7 @@ define([ * Returns frozen renderState as well as all of the object literal properties. This function is deep object freeze * function ignoring properties named "_applyFunctions". * - * @exports freezeRenderState + * @private * * @param {Object} renderState * @returns {Object} Returns frozen renderState. @@ -34,4 +34,4 @@ define([ return freezeObject(renderState); } return freezeRenderState; - }); +}); From d380cac7490d34b674502f87af1d90122bac253d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Wed, 21 Jun 2017 13:19:33 +0300 Subject: [PATCH 18/60] freeze render state test --- Source/Renderer/RenderState.js | 13 ++++++------- Specs/Renderer/RenderStateSpec.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Source/Renderer/RenderState.js b/Source/Renderer/RenderState.js index a32befbf0f7d..8f4536154b69 100644 --- a/Source/Renderer/RenderState.js +++ b/Source/Renderer/RenderState.js @@ -408,17 +408,16 @@ define([ // Cache miss. Fully define render state and try again. var states = new RenderState(renderState); - //>>includeStart('debug', pragmas.debug); - states = freezeRenderState(states); - //>>includeEnd('debug'); var fullKey = JSON.stringify(states); cachedState = renderStateCache[fullKey]; if (!defined(cachedState)) { states.id = nextRenderStateId++; - + //>>includeStart('debug', pragmas.debug); + states = freezeRenderState(states); + //>>includeEnd('debug'); cachedState = { - referenceCount : 0, - state : states + referenceCount: 0, + state: states }; // Cache full render state. Multiple partially defined render states may map to this. @@ -433,7 +432,7 @@ define([ state : cachedState.state }; - return cachedState.state; + return cachedState.state; }; /** diff --git a/Specs/Renderer/RenderStateSpec.js b/Specs/Renderer/RenderStateSpec.js index 479618ad1ff0..7ed5878808ce 100644 --- a/Specs/Renderer/RenderStateSpec.js +++ b/Specs/Renderer/RenderStateSpec.js @@ -408,6 +408,21 @@ defineSuite([ expect(cache[fullKey]).not.toBeDefined(); }); + it('freezes render states', function(){ + var rs = RenderState.fromCache(); + expect(function() { + rs.depthRange = {}; + }).toThrow(); + + expect(function() { + rs.frontFace = WindingOrder.COUNTER_CLOCKWISE; + }).toThrow(); + + expect(function() { + rs._applyFunctions.push(function(){}); + }).not.toThrow(); + }); + it('fails to create (frontFace)', function() { expect(function() { RenderState.fromCache({ From cf9583bba67d215fa0ef71da49a4a27481752f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ATE=C5=9E?= Date: Thu, 22 Jun 2017 11:35:30 +0300 Subject: [PATCH 19/60] tweak --- Source/Renderer/Buffer.js | 4 +++- Source/Renderer/Context.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index 9b9585470388..57ca4f9bf923 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -59,7 +59,9 @@ define([ } //>>includeStart('debug', pragmas.debug); - Check.typeOf.number.greaterThan('sizeInBytes', sizeInBytes, 0); + if (sizeInBytes <= 0) { + throw new DeveloperError('Buffer size must be greater than zero.'); + } //>>includeEnd('debug'); var buffer = gl.createBuffer(); diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index 6a6d5b81d6bc..cacb97ae4444 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -894,7 +894,9 @@ define([ Check.defined('drawCommand.vertexArray', va); Check.typeOf.number.greaterThanOrEquals('drawCommand.offset', offset, 0); - Check.typeOf.number.greaterThanOrEquals('drawCommand.count', count, 0); + if (defined(count)) { + Check.typeOf.number.greaterThanOrEquals('drawCommand.count', count, 0); + } Check.typeOf.number.greaterThanOrEquals('drawCommand.instanceCount', instanceCount, 0); //>>includeEnd('debug'); From 614c8c0675699af595647491843839303eb8d812 Mon Sep 17 00:00:00 2001 From: Esra ERIK Date: Tue, 15 Aug 2017 20:34:13 +0300 Subject: [PATCH 20/60] Czml properties changed as fillcolor --- .../gallery/CZML Reference Properties.html | 140 +++++++++--------- 1 file changed, 69 insertions(+), 71 deletions(-) diff --git a/Apps/Sandcastle/gallery/CZML Reference Properties.html b/Apps/Sandcastle/gallery/CZML Reference Properties.html index fb11549fab24..44fed9f29a40 100644 --- a/Apps/Sandcastle/gallery/CZML Reference Properties.html +++ b/Apps/Sandcastle/gallery/CZML Reference Properties.html @@ -28,82 +28,80 @@ function startup(Cesium) { 'use strict'; //Sandcastle_Begin -var czml = [{ - "id" : "document", - "name" : "CZML Reference Properties", - "version" : "1.0" -}, { - "id" : "position-reference", - "position" : { - "cartographicDegrees" : [-110.0, 50.0, 0] - } -}, { - "id" : "outlineColor-reference", - "name" : "Referencing Position", - "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", - "billboard" : { - "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACvSURBVDhPrZDRDcMgDAU9GqN0lIzijw6SUbJJygUeNQgSqepJTyHG91LVVpwDdfxM3T9TSl1EXZvDwii471fivK73cBFFQNTT/d2KoGpfGOpSIkhUpgUMxq9DFEsWv4IXhlyCnhBFnZcFEEuYqbiUlNwWgMTdrZ3JbQFoEVG53rd8ztG9aPJMnBUQf/VFraBJeWnLS0RfjbKyLJA8FkT5seDYS1Qwyv8t0B/5C2ZmH2/eTGNNBgMmAAAAAElFTkSuQmCC", - "scale" : 1.5 - }, - "label" : { - "fillColor" : { - "rgba" : [255, 255, 255, 255] + var czml = [{ + "id" : "document", + "name" : "CZML Reference Properties", + "version" : "1.0" + }, { + "id" : "position-reference", + "position" : { + "cartographicDegrees" : [-110.0, 50.0, 0] + } + }, { + "id" : "fillColor-reference", + "name" : "Referencing Position", + "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", + "billboard" : { + "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACvSURBVDhPrZDRDcMgDAU9GqN0lIzijw6SUbJJygUeNQgSqepJTyHG91LVVpwDdfxM3T9TSl1EXZvDwii471fivK73cBFFQNTT/d2KoGpfGOpSIkhUpgUMxq9DFEsWv4IXhlyCnhBFnZcFEEuYqbiUlNwWgMTdrZ3JbQFoEVG53rd8ztG9aPJMnBUQf/VFraBJeWnLS0RfjbKyLJA8FkT5seDYS1Qwyv8t0B/5C2ZmH2/eTGNNBgMmAAAAAElFTkSuQmCC", + "scale" : 1.5 }, - "font" : "13pt Lucida Console", - "horizontalOrigin" : "LEFT", - "outlineColor" : { - "rgba":[150, 0, 150, 255] + "label" : { + "fillColor" : { + "rgba" : [255, 255, 255, 255] + }, + "font" : "13pt Lucida Console", + "horizontalOrigin" : "LEFT", + "outlineColor" : { + "rgba":[150, 0, 150, 255] + }, + "outlineWidth" : 3, + "pixelOffset" : { + "cartesian2" : [20, 0] + }, + "style" : "FILL_AND_OUTLINE", + "text" : "referencing position" }, - "outlineWidth" : 3, - "pixelOffset" : { - "cartesian2" : [20, 0] + "position" : { + "reference" : "position-reference#position" + } + }, { + "id" : "polygon", + "name" : "Referencing Fill Color", + "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", + "label" : { + "fillColor" : { + "rgba" : [255, 255, 255, 255] + }, + "font" : "13pt Lucida Console", + "horizontalOrigin" : "LEFT", + "pixelOffset" : { + "cartesian2" : [20, 0] + }, + "style" : "FILL_AND_OUTLINE", + "text" : "referencing fillColor" }, - "style" : "FILL_AND_OUTLINE", - "text" : "referencing position" - }, - "position" : { - "reference" : "position-reference#position" - } -}, { - "id" : "polygon", - "name" : "Referencing Outline Color", - "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", - "label" : { - "fillColor" : { - "rgba" : [255, 255, 255, 255] + "position" : { + "cartographicDegrees" : [-105, 35, 0] }, - "font" : "13pt Lucida Console", - "horizontalOrigin" : "LEFT", - "pixelOffset" : { - "cartesian2" : [20, 0] - }, - "style" : "FILL_AND_OUTLINE", - "text" : "referencing outlineColor" - }, - "position" : { - "cartographicDegrees" : [-105, 35, 0] - }, - "polygon" : { - "positions" : { - "cartographicDegrees" : [ - -115.0, 37.0, 0, - -115.0, 32.0, 0, - -107.0, 33.0, 0, - -102.0, 31.0, 0, - -102.0, 35.0, 0 - ] - }, - "height" : 0, - "outline" : true, - "outlineColor" : { - "reference" : "outlineColor-reference#label.outlineColor" - }, - "outlineWidth" : 5 - } -}]; + "polygon" : { + "positions" : { + "cartographicDegrees" : [ + -115.0, 37.0, 0, + -115.0, 32.0, 0, + -107.0, 33.0, 0, + -102.0, 31.0, 0, + -102.0, 35.0, 0 + ] + }, + "height" : 0, + "fillColor" : { + "reference" : "fillColor-reference#label.fillColor" + } + } + }]; -var viewer = new Cesium.Viewer('cesiumContainer'); -viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); + var viewer = new Cesium.Viewer('cesiumContainer'); + viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); //Sandcastle_End Sandcastle.finishedLoading(); From c16e29709402a473b7c893871fc908f169eb1cd3 Mon Sep 17 00:00:00 2001 From: Esra ERIK Date: Thu, 17 Aug 2017 19:36:49 +0300 Subject: [PATCH 21/60] changes added to changes.md --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5e0e29d56022..d7296fbb24da 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ Change Log ========== +### 1.36 - 2017-08-17 + +* Breaking changes + *`CZML Reference Properties` reference property changed as fillColor-reference from outlineColor-reference. ### 1.36 - 2017-08-01 From 634b078eb744ffd312d676db18e1f0b1c54fbe5e Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 25 Aug 2017 14:30:28 +0800 Subject: [PATCH 22/60] consider the situation of mercator projection --- Source/Core/HeightmapTessellator.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Core/HeightmapTessellator.js b/Source/Core/HeightmapTessellator.js index 93f39bb0f2b0..d189c2fde208 100644 --- a/Source/Core/HeightmapTessellator.js +++ b/Source/Core/HeightmapTessellator.js @@ -218,6 +218,11 @@ define([ var granularityX = rectangleWidth / (width - 1); var granularityY = rectangleHeight / (height - 1); + + if (!isGeographic) { + rectangleWidth *= oneOverGlobeSemimajorAxis; + rectangleHeight *= oneOverGlobeSemimajorAxis; + } var radiiSquared = ellipsoid.radiiSquared; var radiiSquaredX = radiiSquared.x; From 3273b1bac7cfe89566b531349e2e372155605d94 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 25 Aug 2017 14:31:45 +0800 Subject: [PATCH 23/60] consider the situation of mercator projection --- Source/Core/OrientedBoundingBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 8d3e61b3c7b3..414d6efde0d0 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -272,7 +272,7 @@ define([ if (!defined(rectangle)) { throw new DeveloperError('rectangle is required'); } - if (rectangle.width < 0.0 || rectangle.width > CesiumMath.PI) { + if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { throw new DeveloperError('Rectangle width must be between 0 and pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { From fb1a3983d6ffffe575bb3783dfc331eb79ad04bf Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 25 Aug 2017 14:38:45 +0800 Subject: [PATCH 24/60] consider the situation of mercator projection --- Source/Core/OrientedBoundingBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 414d6efde0d0..7a2e995938ea 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -273,7 +273,7 @@ define([ throw new DeveloperError('rectangle is required'); } if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { - throw new DeveloperError('Rectangle width must be between 0 and pi'); + throw new DeveloperError('Rectangle width must be between 0 and 2pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { throw new DeveloperError('Rectangle height must be between 0 and pi'); From 6fc752bac0dd065d130737b47e2efcb73e981309 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 25 Aug 2017 15:04:45 +0800 Subject: [PATCH 25/60] support touch event --- Apps/Sandcastle/gallery/Imagery Layers Split.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Apps/Sandcastle/gallery/Imagery Layers Split.html b/Apps/Sandcastle/gallery/Imagery Layers Split.html index adec29907a4a..92b86f8c4347 100644 --- a/Apps/Sandcastle/gallery/Imagery Layers Split.html +++ b/Apps/Sandcastle/gallery/Imagery Layers Split.html @@ -71,21 +71,27 @@ var dragStartX = 0; document.getElementById('slider').addEventListener('mousedown', mouseDown, false); +document.getElementById('slider').addEventListener('touchstart', mouseDown, false); window.addEventListener('mouseup', mouseUp, false); +window.addEventListener('touchend', mouseUp, false); function mouseUp() { window.removeEventListener('mousemove', sliderMove, true); + window.removeEventListener('touchmove', sliderMove, true); } function mouseDown(e) { var slider = document.getElementById('slider'); - dragStartX = e.clientX - slider.offsetLeft; + var nPos = e.clientX != undefined?e.clientX:e.changedTouches[0].clientX; + dragStartX = nPos - slider.offsetLeft; window.addEventListener('mousemove', sliderMove, true); + window.addEventListener('touchmove', sliderMove, true); } function sliderMove(e) { var slider = document.getElementById('slider'); - var splitPosition = (e.clientX - dragStartX) / slider.parentElement.offsetWidth; + var nPos = e.clientX != undefined?e.clientX:e.changedTouches[0].clientX; + var splitPosition = (nPos - dragStartX) / slider.parentElement.offsetWidth; slider.style.left = 100.0 * splitPosition + "%"; viewer.scene.imagerySplitPosition = splitPosition; } From 42ba752b30204e38e4f2870beb061c4f589838ed Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 25 Aug 2017 22:34:47 +0800 Subject: [PATCH 26/60] Update OrientedBoundingBox.js correct the DeveloperError description: from 2pi to 2*pi --- Source/Core/OrientedBoundingBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 7a2e995938ea..986732df8348 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -273,7 +273,7 @@ define([ throw new DeveloperError('rectangle is required'); } if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { - throw new DeveloperError('Rectangle width must be between 0 and 2pi'); + throw new DeveloperError('Rectangle width must be between 0 and 2*pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { throw new DeveloperError('Rectangle height must be between 0 and pi'); From c4c85f4bed24b530534af09f27da5eb58b278dde Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 25 Aug 2017 23:28:29 +0800 Subject: [PATCH 27/60] Update OrientedBoundingBoxSpec.js broaden the restriction of the rectangle width, because there is a special situation for the level zero tile in Mercator scheme --- Specs/Core/OrientedBoundingBoxSpec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Specs/Core/OrientedBoundingBoxSpec.js b/Specs/Core/OrientedBoundingBoxSpec.js index 4341fd3fe346..1632505f6053 100644 --- a/Specs/Core/OrientedBoundingBoxSpec.js +++ b/Specs/Core/OrientedBoundingBoxSpec.js @@ -172,14 +172,14 @@ defineSuite([ it('fromRectangle throws with invalid rectangles', function() { var ellipsoid = Ellipsoid.UNIT_SPHERE; - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + //expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, 1.0, -1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + //expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, 2.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 2.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -2.0, 4.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 1.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, -2.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -1.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -1.0, 4.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); }); it('fromRectangle throws with non-revolution ellipsoids', function() { From 188bdc03ad52c41e0d58afcace14b0feac1b8520 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 26 Aug 2017 00:05:24 +0800 Subject: [PATCH 28/60] Update HeightmapTessellator.js remove this invisible trailing space... --- Source/Core/HeightmapTessellator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/HeightmapTessellator.js b/Source/Core/HeightmapTessellator.js index d189c2fde208..b7604ce29a86 100644 --- a/Source/Core/HeightmapTessellator.js +++ b/Source/Core/HeightmapTessellator.js @@ -218,7 +218,7 @@ define([ var granularityX = rectangleWidth / (width - 1); var granularityY = rectangleHeight / (height - 1); - + if (!isGeographic) { rectangleWidth *= oneOverGlobeSemimajorAxis; rectangleHeight *= oneOverGlobeSemimajorAxis; From 72c7f3d11d8dead14db1603e8026bdf96cc5ea19 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 26 Aug 2017 00:07:54 +0800 Subject: [PATCH 29/60] Update Imagery Layers Split.html change to !== --- Apps/Sandcastle/gallery/Imagery Layers Split.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Apps/Sandcastle/gallery/Imagery Layers Split.html b/Apps/Sandcastle/gallery/Imagery Layers Split.html index 92b86f8c4347..1ccbaf4f7fb7 100644 --- a/Apps/Sandcastle/gallery/Imagery Layers Split.html +++ b/Apps/Sandcastle/gallery/Imagery Layers Split.html @@ -82,7 +82,7 @@ function mouseDown(e) { var slider = document.getElementById('slider'); - var nPos = e.clientX != undefined?e.clientX:e.changedTouches[0].clientX; + var nPos = e.clientX !== undefined?e.clientX:e.changedTouches[0].clientX; dragStartX = nPos - slider.offsetLeft; window.addEventListener('mousemove', sliderMove, true); window.addEventListener('touchmove', sliderMove, true); @@ -90,7 +90,7 @@ function sliderMove(e) { var slider = document.getElementById('slider'); - var nPos = e.clientX != undefined?e.clientX:e.changedTouches[0].clientX; + var nPos = e.clientX !== undefined?e.clientX:e.changedTouches[0].clientX; var splitPosition = (nPos - dragStartX) / slider.parentElement.offsetWidth; slider.style.left = 100.0 * splitPosition + "%"; viewer.scene.imagerySplitPosition = splitPosition; From 918bbdc40fb668e087557fbedb40c7b6cfc613eb Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 26 Aug 2017 09:58:40 +0800 Subject: [PATCH 30/60] rollback for the CI Test --- Apps/Sandcastle/gallery/Imagery Layers Split.html | 10 ++-------- Source/Core/HeightmapTessellator.js | 5 ----- Source/Core/OrientedBoundingBox.js | 4 ++-- Specs/Core/OrientedBoundingBoxSpec.js | 8 ++++---- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Apps/Sandcastle/gallery/Imagery Layers Split.html b/Apps/Sandcastle/gallery/Imagery Layers Split.html index 1ccbaf4f7fb7..adec29907a4a 100644 --- a/Apps/Sandcastle/gallery/Imagery Layers Split.html +++ b/Apps/Sandcastle/gallery/Imagery Layers Split.html @@ -71,27 +71,21 @@ var dragStartX = 0; document.getElementById('slider').addEventListener('mousedown', mouseDown, false); -document.getElementById('slider').addEventListener('touchstart', mouseDown, false); window.addEventListener('mouseup', mouseUp, false); -window.addEventListener('touchend', mouseUp, false); function mouseUp() { window.removeEventListener('mousemove', sliderMove, true); - window.removeEventListener('touchmove', sliderMove, true); } function mouseDown(e) { var slider = document.getElementById('slider'); - var nPos = e.clientX !== undefined?e.clientX:e.changedTouches[0].clientX; - dragStartX = nPos - slider.offsetLeft; + dragStartX = e.clientX - slider.offsetLeft; window.addEventListener('mousemove', sliderMove, true); - window.addEventListener('touchmove', sliderMove, true); } function sliderMove(e) { var slider = document.getElementById('slider'); - var nPos = e.clientX !== undefined?e.clientX:e.changedTouches[0].clientX; - var splitPosition = (nPos - dragStartX) / slider.parentElement.offsetWidth; + var splitPosition = (e.clientX - dragStartX) / slider.parentElement.offsetWidth; slider.style.left = 100.0 * splitPosition + "%"; viewer.scene.imagerySplitPosition = splitPosition; } diff --git a/Source/Core/HeightmapTessellator.js b/Source/Core/HeightmapTessellator.js index b7604ce29a86..93f39bb0f2b0 100644 --- a/Source/Core/HeightmapTessellator.js +++ b/Source/Core/HeightmapTessellator.js @@ -219,11 +219,6 @@ define([ var granularityX = rectangleWidth / (width - 1); var granularityY = rectangleHeight / (height - 1); - if (!isGeographic) { - rectangleWidth *= oneOverGlobeSemimajorAxis; - rectangleHeight *= oneOverGlobeSemimajorAxis; - } - var radiiSquared = ellipsoid.radiiSquared; var radiiSquaredX = radiiSquared.x; var radiiSquaredY = radiiSquared.y; diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 986732df8348..8d3e61b3c7b3 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -272,8 +272,8 @@ define([ if (!defined(rectangle)) { throw new DeveloperError('rectangle is required'); } - if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { - throw new DeveloperError('Rectangle width must be between 0 and 2*pi'); + if (rectangle.width < 0.0 || rectangle.width > CesiumMath.PI) { + throw new DeveloperError('Rectangle width must be between 0 and pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { throw new DeveloperError('Rectangle height must be between 0 and pi'); diff --git a/Specs/Core/OrientedBoundingBoxSpec.js b/Specs/Core/OrientedBoundingBoxSpec.js index 1632505f6053..4341fd3fe346 100644 --- a/Specs/Core/OrientedBoundingBoxSpec.js +++ b/Specs/Core/OrientedBoundingBoxSpec.js @@ -172,14 +172,14 @@ defineSuite([ it('fromRectangle throws with invalid rectangles', function() { var ellipsoid = Ellipsoid.UNIT_SPHERE; - //expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, 1.0, -1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - //expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, 2.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -2.0, 4.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 2.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 1.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, -2.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -1.0, 4.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -1.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); }); it('fromRectangle throws with non-revolution ellipsoids', function() { From 97003d510e86d90a142e0adbbb04d66d69f7b11c Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 26 Aug 2017 10:21:45 +0800 Subject: [PATCH 31/60] consider the Mercator projection --- Source/Core/HeightmapTessellator.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Core/HeightmapTessellator.js b/Source/Core/HeightmapTessellator.js index 93f39bb0f2b0..b7604ce29a86 100644 --- a/Source/Core/HeightmapTessellator.js +++ b/Source/Core/HeightmapTessellator.js @@ -219,6 +219,11 @@ define([ var granularityX = rectangleWidth / (width - 1); var granularityY = rectangleHeight / (height - 1); + if (!isGeographic) { + rectangleWidth *= oneOverGlobeSemimajorAxis; + rectangleHeight *= oneOverGlobeSemimajorAxis; + } + var radiiSquared = ellipsoid.radiiSquared; var radiiSquaredX = radiiSquared.x; var radiiSquaredY = radiiSquared.y; From 26cbbee9071a3ed14370d7718c04a3173a0d1986 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 26 Aug 2017 10:40:59 +0800 Subject: [PATCH 32/60] broaden the restriction of rectangle.width, because the level zero tile bounding in Mercator Projection and its unit test --- Source/Core/OrientedBoundingBox.js | 4 ++-- Specs/Core/OrientedBoundingBoxSpec.js | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 8d3e61b3c7b3..986732df8348 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -272,8 +272,8 @@ define([ if (!defined(rectangle)) { throw new DeveloperError('rectangle is required'); } - if (rectangle.width < 0.0 || rectangle.width > CesiumMath.PI) { - throw new DeveloperError('Rectangle width must be between 0 and pi'); + if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { + throw new DeveloperError('Rectangle width must be between 0 and 2*pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { throw new DeveloperError('Rectangle height must be between 0 and pi'); diff --git a/Specs/Core/OrientedBoundingBoxSpec.js b/Specs/Core/OrientedBoundingBoxSpec.js index 4341fd3fe346..242890fe98bf 100644 --- a/Specs/Core/OrientedBoundingBoxSpec.js +++ b/Specs/Core/OrientedBoundingBoxSpec.js @@ -172,14 +172,12 @@ defineSuite([ it('fromRectangle throws with invalid rectangles', function() { var ellipsoid = Ellipsoid.UNIT_SPHERE; - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, 1.0, -1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, 2.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 2.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -2.0, 4.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 1.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, -2.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -1.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -1.0, 4.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); }); it('fromRectangle throws with non-revolution ellipsoids', function() { From ae6c6a8d97b7b3c28bc4917d496d616bda45df9d Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 29 Aug 2017 13:17:33 +0800 Subject: [PATCH 33/60] support touch event --- .../gallery/Imagery Layers Split.html | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/Apps/Sandcastle/gallery/Imagery Layers Split.html b/Apps/Sandcastle/gallery/Imagery Layers Split.html index adec29907a4a..4ce92ef04a20 100644 --- a/Apps/Sandcastle/gallery/Imagery Layers Split.html +++ b/Apps/Sandcastle/gallery/Imagery Layers Split.html @@ -26,7 +26,7 @@ left: 50%; top: 0px; background-color: #D3D3D3; - width: 2px; + width: 5px; height: 100%; z-index: 9999; } @@ -68,27 +68,40 @@ var slider = document.getElementById('slider'); viewer.scene.imagerySplitPosition = (slider.offsetLeft) / slider.parentElement.offsetWidth; -var dragStartX = 0; +var handler = new Cesium.ScreenSpaceEventHandler(slider); -document.getElementById('slider').addEventListener('mousedown', mouseDown, false); -window.addEventListener('mouseup', mouseUp, false); +var bMoveActive = false; -function mouseUp() { - window.removeEventListener('mousemove', sliderMove, true); -} +function move(movement){ + if(!bMoveActive) + return; -function mouseDown(e) { - var slider = document.getElementById('slider'); - dragStartX = e.clientX - slider.offsetLeft; - window.addEventListener('mousemove', sliderMove, true); + var nMove = movement.endPosition.x ;//- movement.startPosition.x; + var splitPosition = (slider.offsetLeft + nMove) / slider.parentElement.offsetWidth; + slider.style.left = 100.0 * splitPosition + "%"; + viewer.scene.imagerySplitPosition = splitPosition; } -function sliderMove(e) { - var slider = document.getElementById('slider'); - var splitPosition = (e.clientX - dragStartX) / slider.parentElement.offsetWidth; - slider.style.left = 100.0 * splitPosition + "%"; - viewer.scene.imagerySplitPosition = splitPosition; -} +handler.setInputAction(function(movement) { + bMoveActive = true; +}, Cesium.ScreenSpaceEventType.LEFT_DOWN); +handler.setInputAction(function(movement) { + bMoveActive = true; +}, Cesium.ScreenSpaceEventType.PINCH_START); + +handler.setInputAction(function(movement) { + move(movement); +}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); +handler.setInputAction(function(movement) { + move(movement); +}, Cesium.ScreenSpaceEventType.PINCH_MOVE); + +handler.setInputAction(function(movement) { + bMoveActive = false; +}, Cesium.ScreenSpaceEventType.LEFT_UP); +handler.setInputAction(function(movement) { + bMoveActive = false; +}, Cesium.ScreenSpaceEventType.PINCH_END); //Sandcastle_End From 202b44b343d445a4eb415be64da5936e7c74265c Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 29 Aug 2017 13:44:48 +0800 Subject: [PATCH 34/60] --- .../gallery/Imagery Layers Split.html | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/Apps/Sandcastle/gallery/Imagery Layers Split.html b/Apps/Sandcastle/gallery/Imagery Layers Split.html index 4ce92ef04a20..adec29907a4a 100644 --- a/Apps/Sandcastle/gallery/Imagery Layers Split.html +++ b/Apps/Sandcastle/gallery/Imagery Layers Split.html @@ -26,7 +26,7 @@ left: 50%; top: 0px; background-color: #D3D3D3; - width: 5px; + width: 2px; height: 100%; z-index: 9999; } @@ -68,40 +68,27 @@ var slider = document.getElementById('slider'); viewer.scene.imagerySplitPosition = (slider.offsetLeft) / slider.parentElement.offsetWidth; -var handler = new Cesium.ScreenSpaceEventHandler(slider); +var dragStartX = 0; -var bMoveActive = false; +document.getElementById('slider').addEventListener('mousedown', mouseDown, false); +window.addEventListener('mouseup', mouseUp, false); -function move(movement){ - if(!bMoveActive) - return; +function mouseUp() { + window.removeEventListener('mousemove', sliderMove, true); +} - var nMove = movement.endPosition.x ;//- movement.startPosition.x; - var splitPosition = (slider.offsetLeft + nMove) / slider.parentElement.offsetWidth; - slider.style.left = 100.0 * splitPosition + "%"; - viewer.scene.imagerySplitPosition = splitPosition; +function mouseDown(e) { + var slider = document.getElementById('slider'); + dragStartX = e.clientX - slider.offsetLeft; + window.addEventListener('mousemove', sliderMove, true); } -handler.setInputAction(function(movement) { - bMoveActive = true; -}, Cesium.ScreenSpaceEventType.LEFT_DOWN); -handler.setInputAction(function(movement) { - bMoveActive = true; -}, Cesium.ScreenSpaceEventType.PINCH_START); - -handler.setInputAction(function(movement) { - move(movement); -}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); -handler.setInputAction(function(movement) { - move(movement); -}, Cesium.ScreenSpaceEventType.PINCH_MOVE); - -handler.setInputAction(function(movement) { - bMoveActive = false; -}, Cesium.ScreenSpaceEventType.LEFT_UP); -handler.setInputAction(function(movement) { - bMoveActive = false; -}, Cesium.ScreenSpaceEventType.PINCH_END); +function sliderMove(e) { + var slider = document.getElementById('slider'); + var splitPosition = (e.clientX - dragStartX) / slider.parentElement.offsetWidth; + slider.style.left = 100.0 * splitPosition + "%"; + viewer.scene.imagerySplitPosition = splitPosition; +} //Sandcastle_End From 48bb3068ca9c1e8bb8ccbf278435d75bec9aca39 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 29 Aug 2017 14:09:31 +0800 Subject: [PATCH 35/60] rollback for ci --- Source/Core/OrientedBoundingBox.js | 4 ++-- Specs/Core/OrientedBoundingBoxSpec.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 986732df8348..8d3e61b3c7b3 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -272,8 +272,8 @@ define([ if (!defined(rectangle)) { throw new DeveloperError('rectangle is required'); } - if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { - throw new DeveloperError('Rectangle width must be between 0 and 2*pi'); + if (rectangle.width < 0.0 || rectangle.width > CesiumMath.PI) { + throw new DeveloperError('Rectangle width must be between 0 and pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { throw new DeveloperError('Rectangle height must be between 0 and pi'); diff --git a/Specs/Core/OrientedBoundingBoxSpec.js b/Specs/Core/OrientedBoundingBoxSpec.js index 242890fe98bf..4341fd3fe346 100644 --- a/Specs/Core/OrientedBoundingBoxSpec.js +++ b/Specs/Core/OrientedBoundingBoxSpec.js @@ -172,12 +172,14 @@ defineSuite([ it('fromRectangle throws with invalid rectangles', function() { var ellipsoid = Ellipsoid.UNIT_SPHERE; + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, 1.0, -1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, 2.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -2.0, 4.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 2.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 1.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, -2.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -1.0, 4.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -1.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); }); it('fromRectangle throws with non-revolution ellipsoids', function() { From 398b46bee85f9760e63850cd172b92f77436a010 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 29 Aug 2017 14:43:36 +0800 Subject: [PATCH 36/60] rollback for ci --- Source/Core/HeightmapTessellator.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Source/Core/HeightmapTessellator.js b/Source/Core/HeightmapTessellator.js index b7604ce29a86..93f39bb0f2b0 100644 --- a/Source/Core/HeightmapTessellator.js +++ b/Source/Core/HeightmapTessellator.js @@ -219,11 +219,6 @@ define([ var granularityX = rectangleWidth / (width - 1); var granularityY = rectangleHeight / (height - 1); - if (!isGeographic) { - rectangleWidth *= oneOverGlobeSemimajorAxis; - rectangleHeight *= oneOverGlobeSemimajorAxis; - } - var radiiSquared = ellipsoid.radiiSquared; var radiiSquaredX = radiiSquared.x; var radiiSquaredY = radiiSquared.y; From 47cd7e1ff9fb88a94b2b29bc0709fafff8ca2348 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 29 Aug 2017 17:07:38 +0800 Subject: [PATCH 37/60] consider the situation of mercator projection --- Source/Core/HeightmapTessellator.js | 5 +++++ Source/Core/OrientedBoundingBox.js | 4 ++-- Specs/Core/OrientedBoundingBoxSpec.js | 6 ++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Core/HeightmapTessellator.js b/Source/Core/HeightmapTessellator.js index 93f39bb0f2b0..b7604ce29a86 100644 --- a/Source/Core/HeightmapTessellator.js +++ b/Source/Core/HeightmapTessellator.js @@ -219,6 +219,11 @@ define([ var granularityX = rectangleWidth / (width - 1); var granularityY = rectangleHeight / (height - 1); + if (!isGeographic) { + rectangleWidth *= oneOverGlobeSemimajorAxis; + rectangleHeight *= oneOverGlobeSemimajorAxis; + } + var radiiSquared = ellipsoid.radiiSquared; var radiiSquaredX = radiiSquared.x; var radiiSquaredY = radiiSquared.y; diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 8d3e61b3c7b3..986732df8348 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -272,8 +272,8 @@ define([ if (!defined(rectangle)) { throw new DeveloperError('rectangle is required'); } - if (rectangle.width < 0.0 || rectangle.width > CesiumMath.PI) { - throw new DeveloperError('Rectangle width must be between 0 and pi'); + if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { + throw new DeveloperError('Rectangle width must be between 0 and 2*pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { throw new DeveloperError('Rectangle height must be between 0 and pi'); diff --git a/Specs/Core/OrientedBoundingBoxSpec.js b/Specs/Core/OrientedBoundingBoxSpec.js index 4341fd3fe346..242890fe98bf 100644 --- a/Specs/Core/OrientedBoundingBoxSpec.js +++ b/Specs/Core/OrientedBoundingBoxSpec.js @@ -172,14 +172,12 @@ defineSuite([ it('fromRectangle throws with invalid rectangles', function() { var ellipsoid = Ellipsoid.UNIT_SPHERE; - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(1.0, -1.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, 1.0, -1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, 1.0, -2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, 2.0, -1.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 2.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -2.0, 4.0, 1.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -2.0, 1.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-1.0, -2.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); - expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-2.0, -1.0, 2.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); + expect(function() { return OrientedBoundingBox.fromRectangle(new Rectangle(-4.0, -1.0, 4.0, 2.0), 0.0, 0.0, ellipsoid); }).toThrowDeveloperError(); }); it('fromRectangle throws with non-revolution ellipsoids', function() { From e726b0d1811f271e23d05f25531dfedf54e04da8 Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Mon, 31 Jul 2017 16:51:49 +0200 Subject: [PATCH 38/60] Allow custom parameters in the template url of an UrlTemplateImageryProvider --- CHANGES.md | 1 + Source/Scene/UrlTemplateImageryProvider.js | 19 +++++++++++++ Specs/Scene/UrlTemplateImageryProviderSpec.js | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6a04cd71c154..f0b618d5b06e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,7 @@ Change Log * Fixed specular computation for certain models using the `KHR_materials_common` extension. [#5773](https://github.com/AnalyticalGraphicsInc/cesium/pull/5773) * Fixed a picking bug in the `3D Tiles Interactivity` Sandcastle demo. [#5703](https://github.com/AnalyticalGraphicsInc/cesium/issues/5703) * Updated knockout from 3.4.0 to 3.4.2 [#5703](https://github.com/AnalyticalGraphicsInc/cesium/pull/5829) +* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. ### 1.36 - 2017-08-01 diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index 7187182f0700..245a68583a2b 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -132,6 +132,7 @@ define([ * source does not support picking features or if you don't want this provider's features to be pickable. Note * that this can be dynamically overridden by modifying the {@link UriTemplateImageryProvider#enablePickFeatures} * property. + * @param {Object} [options.customTags] Allow to replace custom keywords in the URL template. The object must have strings as keys and functions as values. * * * @example @@ -157,6 +158,15 @@ define([ * 'width=256&height=256', * rectangle : Cesium.Rectangle.fromDegrees(96.799393, -43.598214999057824, 153.63925700000001, -9.2159219997013) * }); + * // Using custom tags in your template url. + * var custom = new Cesium.UrlTemplateImageryProvider({ + * url : 'https://yoururl/{time}/{z}/{y}/{x}.png', + * customTags : { + * '{time}': function(imageryProvider, x, y , level) { + * return '20171231' + * } + * } + * }); * * @see ArcGisMapServerImageryProvider * @see BingMapsImageryProvider @@ -568,6 +578,15 @@ define([ } that._credit = credit; + if (properties.customTags) { + for (var tag in properties.customTags) { + if (properties.customTags.hasOwnProperty(tag)) { + tags[tag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + pickFeaturesTags[tag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + } + } + } + that._urlParts = urlTemplateToParts(that._url, tags); //eslint-disable-line no-use-before-define that._pickFeaturesUrlParts = urlTemplateToParts(that._pickFeaturesUrl, pickFeaturesTags); //eslint-disable-line no-use-before-define return true; diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index b8befc7068a8..b166e49550b0 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -634,6 +634,34 @@ defineSuite([ }); }); + it('uses custom tags', function() { + var provider = new UrlTemplateImageryProvider({ + url: 'made/up/tms/server/{custom1}/{custom2}/{z}/{y}/{x}.PNG', + tilingScheme: new GeographicTilingScheme(), + maximumLevel: 6, + customTags: { + '{custom1}': function() { return 'foo';}, + '{custom2}': function() { return 'bar';} + } + }); + + return pollToPromise(function() { + return provider.ready; + }).then(function() {console.error('spyon'); + spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) { + expect(url).toEqual('made/up/tms/server/foo/bar/2/1/3.PNG'); + + // Just return any old image. + loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred); + }); + + return provider.requestImage(3, 1, 2).then(function(image) { + expect(loadImage.createImage).toHaveBeenCalled(); + expect(image).toBeInstanceOf(Image); + }); + }); + }); + describe('pickFeatures', function() { it('returns undefined when enablePickFeatures is false', function() { var provider = new UrlTemplateImageryProvider({ From 8566cf2d680f1c37a2a0e5a9c7d0cc2da6c7940f Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Thu, 3 Aug 2017 09:03:38 +0200 Subject: [PATCH 39/60] Remove use of curly braces --- Source/Scene/UrlTemplateImageryProvider.js | 11 ++++++----- Specs/Scene/UrlTemplateImageryProviderSpec.js | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index 245a68583a2b..bfc2630ff205 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -160,9 +160,9 @@ define([ * }); * // Using custom tags in your template url. * var custom = new Cesium.UrlTemplateImageryProvider({ - * url : 'https://yoururl/{time}/{z}/{y}/{x}.png', + * url : 'https://yoururl/{Time}/{z}/{y}/{x}.png', * customTags : { - * '{time}': function(imageryProvider, x, y , level) { + * Time: function(imageryProvider, x, y , level) { * return '20171231' * } * } @@ -578,11 +578,12 @@ define([ } that._credit = credit; - if (properties.customTags) { + if (defined(properties.customTags)) { for (var tag in properties.customTags) { if (properties.customTags.hasOwnProperty(tag)) { - tags[tag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define - pickFeaturesTags[tag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + var targetTag = '{' + tag + '}'; + tags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + pickFeaturesTags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define } } } diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index b166e49550b0..58b36954a391 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -640,14 +640,14 @@ defineSuite([ tilingScheme: new GeographicTilingScheme(), maximumLevel: 6, customTags: { - '{custom1}': function() { return 'foo';}, - '{custom2}': function() { return 'bar';} + custom1: function() { return 'foo';}, + custom2: function() { return 'bar';} } }); return pollToPromise(function() { return provider.ready; - }).then(function() {console.error('spyon'); + }).then(function() { spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) { expect(url).toEqual('made/up/tms/server/foo/bar/2/1/3.PNG'); From 26ec8de52e62523a4a6d91712ede37891934f511 Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Wed, 20 Sep 2017 09:27:06 +0200 Subject: [PATCH 40/60] Don't override tags and pickFeaturesTags objects --- Source/Scene/UrlTemplateImageryProvider.js | 93 +++++++++++++--------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index bfc2630ff205..94529176764a 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -44,6 +44,38 @@ define([ ImageryProvider) { 'use strict'; + var tags = { + '{x}': xTag, + '{y}': yTag, + '{z}': zTag, + '{s}': sTag, + '{reverseX}': reverseXTag, + '{reverseY}': reverseYTag, + '{reverseZ}': reverseZTag, + '{westDegrees}': westDegreesTag, + '{southDegrees}': southDegreesTag, + '{eastDegrees}': eastDegreesTag, + '{northDegrees}': northDegreesTag, + '{westProjected}': westProjectedTag, + '{southProjected}': southProjectedTag, + '{eastProjected}': eastProjectedTag, + '{northProjected}': northProjectedTag, + '{width}': widthTag, + '{height}': heightTag + }; + + var pickFeaturesTags = combine(tags, { + '{i}' : iTag, + '{j}' : jTag, + '{reverseI}' : reverseITag, + '{reverseJ}' : reverseJTag, + '{longitudeDegrees}' : longitudeDegreesTag, + '{latitudeDegrees}' : latitudeDegreesTag, + '{longitudeProjected}' : longitudeProjectedTag, + '{latitudeProjected}' : latitudeProjectedTag, + '{format}' : formatTag + }); + /** * Provides imagery by requesting tiles using a specified URL template. * @@ -578,18 +610,33 @@ define([ } that._credit = credit; - if (defined(properties.customTags)) { - for (var tag in properties.customTags) { - if (properties.customTags.hasOwnProperty(tag)) { + var tag; + var allTags = {}; + var allPickFeaturesTags = {}; + for (tag in tags) { + if (tags.hasOwnProperty(tag)) { + allTags[tag] = tags[tag]; + } + } + for (tag in pickFeaturesTags) { + if (pickFeaturesTags.hasOwnProperty(tag)) { + allPickFeaturesTags[tag] = pickFeaturesTags[tag]; + } + } + + var customTags = properties.customTags; + if (defined(customTags)) { + for (tag in customTags) { + if (customTags.hasOwnProperty(tag)) { var targetTag = '{' + tag + '}'; - tags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define - pickFeaturesTags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + allTags[targetTag] = customTags[tag]; + allPickFeaturesTags[targetTag] = customTags[tag]; } } } - that._urlParts = urlTemplateToParts(that._url, tags); //eslint-disable-line no-use-before-define - that._pickFeaturesUrlParts = urlTemplateToParts(that._pickFeaturesUrl, pickFeaturesTags); //eslint-disable-line no-use-before-define + that._urlParts = urlTemplateToParts(that._url, allTags); + that._pickFeaturesUrlParts = urlTemplateToParts(that._pickFeaturesUrl, allPickFeaturesTags); return true; }); }; @@ -983,37 +1030,5 @@ define([ return format; } - var tags = { - '{x}': xTag, - '{y}': yTag, - '{z}': zTag, - '{s}': sTag, - '{reverseX}': reverseXTag, - '{reverseY}': reverseYTag, - '{reverseZ}': reverseZTag, - '{westDegrees}': westDegreesTag, - '{southDegrees}': southDegreesTag, - '{eastDegrees}': eastDegreesTag, - '{northDegrees}': northDegreesTag, - '{westProjected}': westProjectedTag, - '{southProjected}': southProjectedTag, - '{eastProjected}': eastProjectedTag, - '{northProjected}': northProjectedTag, - '{width}': widthTag, - '{height}': heightTag - }; - - var pickFeaturesTags = combine(tags, { - '{i}' : iTag, - '{j}' : jTag, - '{reverseI}' : reverseITag, - '{reverseJ}' : reverseJTag, - '{longitudeDegrees}' : longitudeDegreesTag, - '{latitudeDegrees}' : latitudeDegreesTag, - '{longitudeProjected}' : longitudeProjectedTag, - '{latitudeProjected}' : latitudeProjectedTag, - '{format}' : formatTag - }); - return UrlTemplateImageryProvider; }); From 24eb802b45d1b1a15a23f4c9af66c7be18a4a00d Mon Sep 17 00:00:00 2001 From: Dmitry Kiselev Date: Mon, 2 Oct 2017 16:29:57 -0300 Subject: [PATCH 41/60] Don't reject the whole KML Data load on Network Link failure --- Source/DataSources/KmlDataSource.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 18873465eb5f..42840ba0b74d 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -2188,6 +2188,8 @@ define([ } else if (viewRefreshMode === 'onRegion') { oneTimeWarning('kml-refrehMode-onRegion', 'KML - Unsupported viewRefreshMode: onRegion'); } + }).otherwise(function(error) { + oneTimeWarning('An error occured during loading ' + linkUrl); }); promises.push(promise); From abc1dc0d86c301a5b71939df07772cb38ab34922 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 9 Oct 2017 10:50:44 +0800 Subject: [PATCH 42/60] use macro CesiumMath.TWO_PI --- Source/Core/OrientedBoundingBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 986732df8348..d130972aab50 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -272,7 +272,7 @@ define([ if (!defined(rectangle)) { throw new DeveloperError('rectangle is required'); } - if (rectangle.width < 0.0 || rectangle.width > 2*CesiumMath.PI) { + if (rectangle.width < 0.0 || rectangle.width > CesiumMath.TWO_PI) { throw new DeveloperError('Rectangle width must be between 0 and 2*pi'); } if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) { From 1b72bd3ac14603deeac84b2aa1e45e083f3bc817 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 9 Oct 2017 12:03:44 -0400 Subject: [PATCH 43/60] Allow local-running Cesium to load its resources --- Source/Core/loadWithXhr.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Core/loadWithXhr.js b/Source/Core/loadWithXhr.js index 1b92cfc10de7..696e7a8dd8aa 100644 --- a/Source/Core/loadWithXhr.js +++ b/Source/Core/loadWithXhr.js @@ -172,8 +172,13 @@ define([ xhr.responseType = responseType; } + var localFile = false; + if (typeof url === 'string') { + localFile = url.indexOf('file://') === 0; + } + xhr.onload = function() { - if (xhr.status < 200 || xhr.status >= 300) { + if ((xhr.status < 200 || xhr.status >= 300) && !(localFile && xhr.status === 0)) { deferred.reject(new RequestErrorEvent(xhr.status, xhr.response, xhr.getAllResponseHeaders())); return; } From 5be3e3e0f4615ab3a8680dd0b1efdcaa7457b6bd Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 9 Oct 2017 12:07:39 -0400 Subject: [PATCH 44/60] Update CHANGES.md --- CHANGES.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 432dff7bc1a0..d4647e8e1cc6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ Change Log ========== + +### 1.39 - 2017-11-01 + +* Breaking Changes + * +* Added the ability to load Cesium's assets from the local file system [#5830](https://github.com/AnalyticalGraphicsInc/cesium/issues/5830) + ### 1.38 - 2017-10-02 * Breaking changes From 9def4ab159e156313bea4618c8bca37dd819e35c Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 18 Oct 2017 17:25:24 -0400 Subject: [PATCH 45/60] Make eye separartion and focal length configurable. --- Source/Scene/Scene.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 2e649fa00944..d8b4a25ecdd1 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -631,6 +631,18 @@ define([ enabled : defaultValue(options.shadows, false) }); + /** + * The focal length for use when with cardboard or WebVR. + * @type {Number} + */ + this.focalLength = undefined; + + /** + * The eye separation distance in meters for use with cardboard or WebVR. + * @type {Number} + */ + this.eyeSeparation = undefined; + this._brdfLutGenerator = new BrdfLutGenerator(); this._terrainExaggeration = defaultValue(options.terrainExaggeration, 1.0); @@ -2157,8 +2169,8 @@ define([ var savedCamera = Camera.clone(camera, scene._cameraVR); var near = camera.frustum.near; - var fo = near * 5.0; - var eyeSeparation = fo / 30.0; + var fo = near * defaultValue(scene.focalLength, 5.0); + var eyeSeparation = defaultValue(scene.eyeSeparation, fo / 30.0); var eyeTranslation = Cartesian3.multiplyByScalar(savedCamera.right, eyeSeparation * 0.5, scratchEyeTranslation); camera.frustum.aspectRatio = viewport.width / viewport.height; From e84a3399d64a3327aa883a08454def7155b53d30 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 19 Oct 2017 15:00:31 -0400 Subject: [PATCH 46/60] Add timeout configuration when running from the command line. --- Specs/karma-main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Specs/karma-main.js b/Specs/karma-main.js index 46b04fc0451b..76f6d7d201d5 100644 --- a/Specs/karma-main.js +++ b/Specs/karma-main.js @@ -20,12 +20,14 @@ if (release) { require.config({ - baseUrl : '/base/Build/Cesium' + baseUrl : '/base/Build/Cesium', + waitSeconds : 0 }); toRequire.push('../Stubs/paths'); } else { require.config({ - baseUrl : '/base/Source' + baseUrl : '/base/Source', + waitSeconds : 0 }); } From b3a0d513a34e8aceee3db56f18af8fcd257d1f99 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 19 Oct 2017 15:53:03 -0400 Subject: [PATCH 47/60] Test eye separation. --- Apps/Sandcastle/gallery/Cardboard.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Apps/Sandcastle/gallery/Cardboard.html b/Apps/Sandcastle/gallery/Cardboard.html index b354db4f8e26..97c1a94fdb84 100644 --- a/Apps/Sandcastle/gallery/Cardboard.html +++ b/Apps/Sandcastle/gallery/Cardboard.html @@ -34,6 +34,9 @@ viewer.scene.globe.enableLighting = true; +// TEST +viewer.scene.eyeSeparation = 1.0; + viewer.terrainProvider = new Cesium.CesiumTerrainProvider({ url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles', requestVertexNormals : true From ccb3c600c8e099363cfe29f7a7fc1b2ec5adcc3c Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 19 Oct 2017 15:57:53 -0400 Subject: [PATCH 48/60] Remove test. --- Apps/Sandcastle/gallery/Cardboard.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/Apps/Sandcastle/gallery/Cardboard.html b/Apps/Sandcastle/gallery/Cardboard.html index 97c1a94fdb84..b354db4f8e26 100644 --- a/Apps/Sandcastle/gallery/Cardboard.html +++ b/Apps/Sandcastle/gallery/Cardboard.html @@ -34,9 +34,6 @@ viewer.scene.globe.enableLighting = true; -// TEST -viewer.scene.eyeSeparation = 1.0; - viewer.terrainProvider = new Cesium.CesiumTerrainProvider({ url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles', requestVertexNormals : true From 4ebbca8a0c990cc525010744c4653160264f1dcc Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 19 Oct 2017 16:12:05 -0400 Subject: [PATCH 49/60] Update CHANGES.md. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 850dd9f51fcd..2a021bcc9253 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,10 @@ Change Log ========== ### 1.39 - 2017-11-01 + * Added support for the layer.json `parentUrl` property in `CesiumTerrainProvider` to allow for compositing of tilesets. * Fixed a bug that caused KML ground overlays to appear distorted when rotation was applied. [#5914](https://github.com/AnalyticalGraphicsInc/cesium/issues/5914) +* Added `eyeSeparation` and `focalLength` properties to `Scene` to configure VR settings. [#5917](https://github.com/AnalyticalGraphicsInc/cesium/pull/5917) ### 1.38 - 2017-10-02 From fcd035c9abfbb593806bb6cab4b7c525a4fdd5f3 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 19 Oct 2017 16:43:09 -0400 Subject: [PATCH 50/60] Fix merge error. --- Source/Scene/Scene.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 7e6f909f3fcd..6329d5364404 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -653,6 +653,7 @@ define([ this._actualInvertClassificationColor = Color.clone(this._invertClassificationColor); this._invertClassification = new InvertClassification(); + /** * The focal length for use when with cardboard or WebVR. * @type {Number} */ From 295b30c03918b15b18c7ed1d4c03da894d7f1a98 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 10:15:44 -0400 Subject: [PATCH 51/60] doc --- Source/DataSources/BillboardGraphics.js | 1 + Source/DataSources/LabelGraphics.js | 1 + Source/DataSources/PointGraphics.js | 1 + 3 files changed, 3 insertions(+) diff --git a/Source/DataSources/BillboardGraphics.js b/Source/DataSources/BillboardGraphics.js index 86c260c86d5f..07dc53346bd3 100644 --- a/Source/DataSources/BillboardGraphics.js +++ b/Source/DataSources/BillboardGraphics.js @@ -46,6 +46,7 @@ define([ * @param {Property} [options.sizeInMeters] A boolean Property specifying whether this billboard's size should be measured in meters. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this billboard will be displayed. + * @param {Property} [options.disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to. * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Billboards.html|Cesium Sandcastle Billboard Demo} */ diff --git a/Source/DataSources/LabelGraphics.js b/Source/DataSources/LabelGraphics.js index 52cf604de454..b06f92f343ae 100644 --- a/Source/DataSources/LabelGraphics.js +++ b/Source/DataSources/LabelGraphics.js @@ -47,6 +47,7 @@ define([ * @param {Property} [options.scaleByDistance] A {@link NearFarScalar} Property used to set scale based on distance from the camera. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this label will be displayed. + * @param {Property} [options.disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to. * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Labels.html|Cesium Sandcastle Labels Demo} */ diff --git a/Source/DataSources/PointGraphics.js b/Source/DataSources/PointGraphics.js index 923622822561..14b10d6f78a2 100644 --- a/Source/DataSources/PointGraphics.js +++ b/Source/DataSources/PointGraphics.js @@ -30,6 +30,7 @@ define([ * @param {Property} [options.translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this point will be displayed. + * @param {Property} [options.disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to. */ function PointGraphics(options) { this._color = undefined; From 01c8d8ffcbffbf5ebba9819ec16ad7f038e15b32 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 14:42:46 -0400 Subject: [PATCH 52/60] cleanup --- Source/Renderer/Texture.js | 14 ++++++++++---- Source/Scene/PolylineCollection.js | 4 +++- Specs/Renderer/TextureSpec.js | 19 +------------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Source/Renderer/Texture.js b/Source/Renderer/Texture.js index 53c338d9354c..106b075d2d14 100644 --- a/Source/Renderer/Texture.js +++ b/Source/Renderer/Texture.js @@ -1,6 +1,7 @@ /*global define*/ define([ '../Core/Cartesian2', + '../Core/createGuid', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -17,6 +18,7 @@ define([ './TextureMinificationFilter' ], function( Cartesian2, + createGuid, defaultValue, defined, defineProperties, @@ -33,8 +35,6 @@ define([ TextureMinificationFilter) { 'use strict'; - var currentId = 0; - function Texture(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); @@ -198,7 +198,7 @@ define([ sizeInBytes = PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, height); } - this._id = 'Texture_' + currentId++; + this._id = createGuid(); this._context = context; this._textureFilterAnisotropic = context._textureFilterAnisotropic; this._textureTarget = textureTarget; @@ -311,7 +311,13 @@ define([ }; defineProperties(Texture.prototype, { - + /** + * A unique id for the texture + * @memberof Texture.prototype + * @type {String} + * @readonly + * @private + */ id : { get : function() { return this._id; diff --git a/Source/Scene/PolylineCollection.js b/Source/Scene/PolylineCollection.js index 3d43c0847764..efbab522013b 100644 --- a/Source/Scene/PolylineCollection.js +++ b/Source/Scene/PolylineCollection.js @@ -27,6 +27,7 @@ define([ '../Renderer/RenderState', '../Renderer/ShaderProgram', '../Renderer/ShaderSource', + '../Renderer/Texture', '../Renderer/VertexArray', '../Shaders/PolylineCommon', '../Shaders/PolylineFS', @@ -64,6 +65,7 @@ define([ RenderState, ShaderProgram, ShaderSource, + Texture, VertexArray, PolylineCommon, PolylineFS, @@ -1014,7 +1016,7 @@ define([ } function replacer(key, value) { - if(defined(value) && value.hasOwnProperty('id')) { + if (value instanceof Texture) { return value.id; } diff --git a/Specs/Renderer/TextureSpec.js b/Specs/Renderer/TextureSpec.js index dfc1ae2afbe3..1b79c47a1305 100644 --- a/Specs/Renderer/TextureSpec.js +++ b/Specs/Renderer/TextureSpec.js @@ -94,30 +94,13 @@ defineSuite([ texture = texture && texture.destroy(); }); - it('has unique id', function() { - var t1 = new Texture({ - context : context, - source : blueImage - }); - - var t2 = new Texture({ - context : context, - source : blueImage - }); - - expect(t1.id).toBeDefined(); - expect(t1.id).not.toEqual(t2.id); - - t1.destroy(); - t2.destroy(); - }); - it('has expected default values for pixel format and datatype', function() { texture = new Texture({ context : context, source : blueImage }); + expect(texture.id).toBeDefined(); expect(texture.pixelFormat).toEqual(PixelFormat.RGBA); expect(texture.pixelDatatype).toEqual(PixelDatatype.UNSIGNED_BYTE); }); From 53ec1527178c45fdedf47f5173a2222a9d239a42 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 15:35:05 -0400 Subject: [PATCH 53/60] cleanup --- Source/Renderer/Buffer.js | 16 +- Source/Renderer/Context.js | 248 +++++++++++++++++------------- Source/Renderer/Texture.js | 22 +-- Specs/Renderer/VertexArraySpec.js | 2 +- 4 files changed, 152 insertions(+), 136 deletions(-) diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index 95122f003e21..48d5ae49f1ba 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -37,8 +37,9 @@ define([ throw new DeveloperError('Cannot pass in both options.sizeInBytes and options.typedArray.'); } - if (defined(options.typedArray) && !(typeof options.typedArray === 'object' && typeof options.typedArray.byteLength === 'number')) { - throw new DeveloperError('options.typedArray must be a typed array'); + if (defined(options.typedArray)) { + Check.typeOf.object('options.typedArray', options.typedArray); + Check.typeOf.number('options.typedArray.byteLength', options.typedArray.byteLength); } if (!BufferUsage.validate(options.usage)) { @@ -58,9 +59,7 @@ define([ } //>>includeStart('debug', pragmas.debug); - if (sizeInBytes <= 0) { - throw new DeveloperError('Buffer size must be greater than zero.'); - } + Check.typeOf.number.greaterThan('sizeInBytes', sizeInBytes, 0); //>>includeEnd('debug'); var buffer = gl.createBuffer(); @@ -183,7 +182,7 @@ define([ throw new DeveloperError('Invalid indexDatatype.'); } - if ((options.indexDatatype === IndexDatatype.UNSIGNED_INT) && !options.context.elementIndexUint) { + if (options.indexDatatype === IndexDatatype.UNSIGNED_INT && !options.context.elementIndexUint) { throw new DeveloperError('IndexDatatype.UNSIGNED_INT requires OES_element_index_uint, which is not supported on this system. Check context.elementIndexUint.'); } //>>includeEnd('debug'); @@ -246,10 +245,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.defined('arrayView', arrayView); - - if (offsetInBytes + arrayView.byteLength > this._sizeInBytes) { - throw new DeveloperError('This buffer is not large enough.'); - } + Check.typeOf.number.lessThanOrEquals('offsetInBytes + arrayView.byteLength', offsetInBytes + arrayView.byteLength, this._sizeInBytes); //>>includeEnd('debug'); var gl = this._gl; diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index 508a91f465d5..e74b5866408b 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -1,89 +1,90 @@ define([ - '../Core/Check', - '../Core/clone', - '../Core/Color', - '../Core/ComponentDatatype', - '../Core/createGuid', - '../Core/defaultValue', - '../Core/defined', - '../Core/defineProperties', - '../Core/destroyObject', - '../Core/DeveloperError', - '../Core/Geometry', - '../Core/GeometryAttribute', - '../Core/Matrix4', - '../Core/PrimitiveType', - '../Core/RuntimeError', - '../Core/WebGLConstants', - '../Shaders/ViewportQuadVS', - './BufferUsage', - './ClearCommand', - './ContextLimits', - './CubeMap', - './DrawCommand', - './PassState', - './PickFramebuffer', - './RenderState', - './ShaderCache', - './ShaderProgram', - './Texture', - './UniformState', - './VertexArray' - ], function( - Check, - clone, - Color, - ComponentDatatype, - createGuid, - defaultValue, - defined, - defineProperties, - destroyObject, - DeveloperError, - Geometry, - GeometryAttribute, - Matrix4, - PrimitiveType, - RuntimeError, - WebGLConstants, - ViewportQuadVS, - BufferUsage, - ClearCommand, - ContextLimits, - CubeMap, - DrawCommand, - PassState, - PickFramebuffer, - RenderState, - ShaderCache, - ShaderProgram, - Texture, - UniformState, - VertexArray) { + '../Core/Check', + '../Core/clone', + '../Core/Color', + '../Core/ComponentDatatype', + '../Core/createGuid', + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/destroyObject', + '../Core/DeveloperError', + '../Core/Geometry', + '../Core/GeometryAttribute', + '../Core/Matrix4', + '../Core/PrimitiveType', + '../Core/RuntimeError', + '../Core/WebGLConstants', + '../Shaders/ViewportQuadVS', + './BufferUsage', + './ClearCommand', + './ContextLimits', + './CubeMap', + './DrawCommand', + './PassState', + './PickFramebuffer', + './RenderState', + './ShaderCache', + './ShaderProgram', + './Texture', + './UniformState', + './VertexArray' +], function( + Check, + clone, + Color, + ComponentDatatype, + createGuid, + defaultValue, + defined, + defineProperties, + destroyObject, + DeveloperError, + Geometry, + GeometryAttribute, + Matrix4, + PrimitiveType, + RuntimeError, + WebGLConstants, + ViewportQuadVS, + BufferUsage, + ClearCommand, + ContextLimits, + CubeMap, + DrawCommand, + PassState, + PickFramebuffer, + RenderState, + ShaderCache, + ShaderProgram, + Texture, + UniformState, + VertexArray) { 'use strict'; /*global WebGLRenderingContext*/ + /*global WebGL2RenderingContext*/ function errorToString(gl, error) { var message = 'WebGL Error: '; switch (error) { - case gl.INVALID_ENUM: - message += 'INVALID_ENUM'; - break; - case gl.INVALID_VALUE: - message += 'INVALID_VALUE'; - break; - case gl.INVALID_OPERATION: - message += 'INVALID_OPERATION'; - break; - case gl.OUT_OF_MEMORY: - message += 'OUT_OF_MEMORY'; - break; - case gl.CONTEXT_LOST_WEBGL: - message += 'CONTEXT_LOST_WEBGL lost'; - break; - default: - message += 'Unknown (' + error + ')'; + case gl.INVALID_ENUM: + message += 'INVALID_ENUM'; + break; + case gl.INVALID_VALUE: + message += 'INVALID_VALUE'; + break; + case gl.INVALID_OPERATION: + message += 'INVALID_OPERATION'; + break; + case gl.OUT_OF_MEMORY: + message += 'OUT_OF_MEMORY'; + break; + case gl.CONTEXT_LOST_WEBGL: + message += 'CONTEXT_LOST_WEBGL lost'; + break; + default: + message += 'Unknown (' + error + ')'; } return message; @@ -92,7 +93,7 @@ define([ function createErrorMessage(gl, glFunc, glFuncArguments, error) { var message = errorToString(gl, error) + ': ' + glFunc.name + '('; - for ( var i = 0; i < glFuncArguments.length; ++i) { + for (var i = 0; i < glFuncArguments.length; ++i) { if (i !== 0) { message += ', '; } @@ -303,33 +304,61 @@ define([ if (webgl2) { var that = this; - glCreateVertexArray = function () { return that._gl.createVertexArray(); }; - glBindVertexArray = function(vao) { that._gl.bindVertexArray(vao); }; - glDeleteVertexArray = function(vao) { that._gl.deleteVertexArray(vao); }; + glCreateVertexArray = function() { + return that._gl.createVertexArray(); + }; + glBindVertexArray = function(vao) { + that._gl.bindVertexArray(vao); + }; + glDeleteVertexArray = function(vao) { + that._gl.deleteVertexArray(vao); + }; - glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) { gl.drawElementsInstanced(mode, count, type, offset, instanceCount); }; - glDrawArraysInstanced = function(mode, first, count, instanceCount) { gl.drawArraysInstanced(mode, first, count, instanceCount); }; - glVertexAttribDivisor = function(index, divisor) { gl.vertexAttribDivisor(index, divisor); }; + glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) { + gl.drawElementsInstanced(mode, count, type, offset, instanceCount); + }; + glDrawArraysInstanced = function(mode, first, count, instanceCount) { + gl.drawArraysInstanced(mode, first, count, instanceCount); + }; + glVertexAttribDivisor = function(index, divisor) { + gl.vertexAttribDivisor(index, divisor); + }; - glDrawBuffers = function(buffers) { gl.drawBuffers(buffers); }; + glDrawBuffers = function(buffers) { + gl.drawBuffers(buffers); + }; } else { vertexArrayObject = getExtension(gl, ['OES_vertex_array_object']); if (defined(vertexArrayObject)) { - glCreateVertexArray = function() { return vertexArrayObject.createVertexArrayOES(); }; - glBindVertexArray = function(vertexArray) { vertexArrayObject.bindVertexArrayOES(vertexArray); }; - glDeleteVertexArray = function(vertexArray) { vertexArrayObject.deleteVertexArrayOES(vertexArray); }; + glCreateVertexArray = function() { + return vertexArrayObject.createVertexArrayOES(); + }; + glBindVertexArray = function(vertexArray) { + vertexArrayObject.bindVertexArrayOES(vertexArray); + }; + glDeleteVertexArray = function(vertexArray) { + vertexArrayObject.deleteVertexArrayOES(vertexArray); + }; } instancedArrays = getExtension(gl, ['ANGLE_instanced_arrays']); if (defined(instancedArrays)) { - glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) { instancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount); }; - glDrawArraysInstanced = function(mode, first, count, instanceCount) { instancedArrays.drawArraysInstancedANGLE(mode, first, count, instanceCount); }; - glVertexAttribDivisor = function(index, divisor) { instancedArrays.vertexAttribDivisorANGLE(index, divisor); }; + glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) { + instancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount); + }; + glDrawArraysInstanced = function(mode, first, count, instanceCount) { + instancedArrays.drawArraysInstancedANGLE(mode, first, count, instanceCount); + }; + glVertexAttribDivisor = function(index, divisor) { + instancedArrays.vertexAttribDivisorANGLE(index, divisor); + }; } drawBuffers = getExtension(gl, ['WEBGL_draw_buffers']); if (defined(drawBuffers)) { - glDrawBuffers = function(buffers) { drawBuffers.drawBuffersWEBGL(buffers); }; + glDrawBuffers = function(buffers) { + drawBuffers.drawBuffersWEBGL(buffers); + }; } } @@ -787,18 +816,18 @@ define([ var message; switch (status) { - case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - message = 'Framebuffer is not complete. Incomplete attachment: at least one attachment point with a renderbuffer or texture attached has its attached object no longer in existence or has an attached image with a width or height of zero, or the color attachment point has a non-color-renderable image attached, or the depth attachment point has a non-depth-renderable image attached, or the stencil attachment point has a non-stencil-renderable image attached. Color-renderable formats include GL_RGBA4, GL_RGB5_A1, and GL_RGB565. GL_DEPTH_COMPONENT16 is the only depth-renderable format. GL_STENCIL_INDEX8 is the only stencil-renderable format.'; - break; - case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - message = 'Framebuffer is not complete. Incomplete dimensions: not all attached images have the same width and height.'; - break; - case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - message = 'Framebuffer is not complete. Missing attachment: no images are attached to the framebuffer.'; - break; - case gl.FRAMEBUFFER_UNSUPPORTED: - message = 'Framebuffer is not complete. Unsupported: the combination of internal formats of the attached images violates an implementation-dependent set of restrictions.'; - break; + case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + message = 'Framebuffer is not complete. Incomplete attachment: at least one attachment point with a renderbuffer or texture attached has its attached object no longer in existence or has an attached image with a width or height of zero, or the color attachment point has a non-color-renderable image attached, or the depth attachment point has a non-depth-renderable image attached, or the stencil attachment point has a non-stencil-renderable image attached. Color-renderable formats include GL_RGBA4, GL_RGB5_A1, and GL_RGB565. GL_DEPTH_COMPONENT16 is the only depth-renderable format. GL_STENCIL_INDEX8 is the only stencil-renderable format.'; + break; + case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: + message = 'Framebuffer is not complete. Incomplete dimensions: not all attached images have the same width and height.'; + break; + case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + message = 'Framebuffer is not complete. Missing attachment: no images are attached to the framebuffer.'; + break; + case gl.FRAMEBUFFER_UNSUPPORTED: + message = 'Framebuffer is not complete. Unsupported: the combination of internal formats of the attached images violates an implementation-dependent set of restrictions.'; + break; } throw new DeveloperError(message); @@ -928,6 +957,9 @@ define([ Check.typeOf.number.greaterThanOrEquals('drawCommand.count', count, 0); } Check.typeOf.number.greaterThanOrEquals('drawCommand.instanceCount', instanceCount, 0); + if (instanceCount > 0 && !context.instancedArrays) { + throw new DeveloperError('Instanced arrays extension is not supported'); + } //>>includeEnd('debug'); context._us.model = defaultValue(drawCommand._modelMatrix, Matrix4.IDENTITY); @@ -1032,10 +1064,10 @@ define([ componentDatatype : ComponentDatatype.FLOAT, componentsPerAttribute : 2, values : [ - -1.0, -1.0, + -1.0, -1.0, 1.0, -1.0, - 1.0, 1.0, - -1.0, 1.0 + 1.0, 1.0, + -1.0, 1.0 ] }), diff --git a/Source/Renderer/Texture.js b/Source/Renderer/Texture.js index 36eafde43c54..19d5decc9bb7 100644 --- a/Source/Renderer/Texture.js +++ b/Source/Renderer/Texture.js @@ -283,10 +283,9 @@ define([ if (PixelFormat.isDepthFormat(pixelFormat) || PixelFormat.isCompressedFormat(pixelFormat)) { throw new DeveloperError('pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format.'); } - + Check.defined('options.context', options.context); Check.typeOf.number.greaterThanOrEquals('framebufferXOffset', framebufferXOffset, 0); Check.typeOf.number.greaterThanOrEquals('framebufferYOffset', framebufferYOffset, 0); - if (framebufferXOffset + width > gl.drawingBufferWidth) { throw new DeveloperError('framebufferXOffset + width must be less than or equal to drawingBufferWidth'); } @@ -445,16 +444,10 @@ define([ if (PixelFormat.isCompressedFormat(this._pixelFormat)) { throw new DeveloperError('Cannot call copyFrom with a compressed texture pixel format.'); } - Check.typeOf.number.greaterThanOrEquals('xOffset', xOffset, 0); Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); - - if (xOffset + source.width > this._width) { - throw new DeveloperError('xOffset + source.width must be less than or equal to width.'); - } - if (yOffset + source.height > this._height) { - throw new DeveloperError('yOffset + source.height must be less than or equal to height.'); - } + Check.typeOf.number.lessThanOrEquals('xOffset + source.width', xOffset + source.width, this._width); + Check.typeOf.number.lessThanOrEquals('yOffset + source.height', yOffset + source.height, this._height); //>>includeEnd('debug'); var gl = this._context._gl; @@ -517,13 +510,8 @@ define([ Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); Check.typeOf.number.greaterThanOrEquals('framebufferXOffset', framebufferXOffset, 0); Check.typeOf.number.greaterThanOrEquals('framebufferYOffset', framebufferYOffset, 0); - - if (xOffset + width > this._width) { - throw new DeveloperError('xOffset + width must be less than or equal to width.'); - } - if (yOffset + height > this._height) { - throw new DeveloperError('yOffset + height must be less than or equal to height.'); - } + Check.typeOf.number.lessThanOrEquals('xOffset + width', xOffset + width, this._width); + Check.typeOf.number.lessThanOrEquals('yOffset + height', yOffset + height, this._height); //>>includeEnd('debug'); var gl = this._context._gl; diff --git a/Specs/Renderer/VertexArraySpec.js b/Specs/Renderer/VertexArraySpec.js index f59af9fb5fa6..1974532d9ddf 100644 --- a/Specs/Renderer/VertexArraySpec.js +++ b/Specs/Renderer/VertexArraySpec.js @@ -510,7 +510,7 @@ defineSuite([ attributes : [{ vertexBuffer : Buffer.createVertexBuffer({ context : context, - sizeInBytes : new Float32Array([0, 0, 0, 1]), + sizeInBytes : new Float32Array([0, 0, 0, 1]).byteLength, usage : BufferUsage.STATIC_DRAW }), componentsPerAttribute : 4 From d6abaf12f17ba88afa475546c0a723141fe76351 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 16:02:20 -0400 Subject: [PATCH 54/60] fix changes --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b481a09606ed..be32a8d8b62b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Change Log * Added support for the layer.json `parentUrl` property in `CesiumTerrainProvider` to allow for compositing of tilesets. * Fixed a bug that caused KML ground overlays to appear distorted when rotation was applied. [#5914](https://github.com/AnalyticalGraphicsInc/cesium/issues/5914) * Adds `invertClassification` and `invertClassificationColor` to `Scene`. When `invertClassification` is `true`, any 3D Tiles geometry that is not classified by a `ClassificationPrimitive` or `GroundPrimitive` will have its color multiplied by `invertClassificationColor`. [#5836](https://github.com/AnalyticalGraphicsInc/cesium/pull/5836) +* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696) ### 1.38 - 2017-10-02 @@ -52,7 +53,6 @@ Change Log * Fixed specular computation for certain models using the `KHR_materials_common` extension. [#5773](https://github.com/AnalyticalGraphicsInc/cesium/pull/5773) * Fixed a picking bug in the `3D Tiles Interactivity` Sandcastle demo. [#5703](https://github.com/AnalyticalGraphicsInc/cesium/issues/5703) * Updated knockout from 3.4.0 to 3.4.2 [#5703](https://github.com/AnalyticalGraphicsInc/cesium/pull/5829) -* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. ### 1.36 - 2017-08-01 From 751854358573dd8215ab29d150d5788ee355a226 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 16:24:46 -0400 Subject: [PATCH 55/60] fix example --- .../gallery/CZML Reference Properties.html | 149 +++++++++--------- 1 file changed, 77 insertions(+), 72 deletions(-) diff --git a/Apps/Sandcastle/gallery/CZML Reference Properties.html b/Apps/Sandcastle/gallery/CZML Reference Properties.html index 44fed9f29a40..862c96ca8a6e 100644 --- a/Apps/Sandcastle/gallery/CZML Reference Properties.html +++ b/Apps/Sandcastle/gallery/CZML Reference Properties.html @@ -10,10 +10,12 @@ @@ -28,81 +30,84 @@ function startup(Cesium) { 'use strict'; //Sandcastle_Begin - var czml = [{ - "id" : "document", - "name" : "CZML Reference Properties", - "version" : "1.0" - }, { - "id" : "position-reference", - "position" : { - "cartographicDegrees" : [-110.0, 50.0, 0] - } - }, { - "id" : "fillColor-reference", - "name" : "Referencing Position", - "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", - "billboard" : { - "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACvSURBVDhPrZDRDcMgDAU9GqN0lIzijw6SUbJJygUeNQgSqepJTyHG91LVVpwDdfxM3T9TSl1EXZvDwii471fivK73cBFFQNTT/d2KoGpfGOpSIkhUpgUMxq9DFEsWv4IXhlyCnhBFnZcFEEuYqbiUlNwWgMTdrZ3JbQFoEVG53rd8ztG9aPJMnBUQf/VFraBJeWnLS0RfjbKyLJA8FkT5seDYS1Qwyv8t0B/5C2ZmH2/eTGNNBgMmAAAAAElFTkSuQmCC", - "scale" : 1.5 +var czml = [{ + "id" : "document", + "name" : "CZML Reference Properties", + "version" : "1.0" +}, { + "id" : "position-reference", + "position" : { + "cartographicDegrees" : [-110.0, 50.0, 0] + } +}, { + "id" : "fillColor-reference", + "name" : "Referencing Position", + "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", + "billboard" : { + "image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACvSURBVDhPrZDRDcMgDAU9GqN0lIzijw6SUbJJygUeNQgSqepJTyHG91LVVpwDdfxM3T9TSl1EXZvDwii471fivK73cBFFQNTT/d2KoGpfGOpSIkhUpgUMxq9DFEsWv4IXhlyCnhBFnZcFEEuYqbiUlNwWgMTdrZ3JbQFoEVG53rd8ztG9aPJMnBUQf/VFraBJeWnLS0RfjbKyLJA8FkT5seDYS1Qwyv8t0B/5C2ZmH2/eTGNNBgMmAAAAAElFTkSuQmCC", + "scale" : 1.5 + }, + "label" : { + "fillColor" : { + "rgba" : [255, 255, 255, 255] }, - "label" : { - "fillColor" : { - "rgba" : [255, 255, 255, 255] - }, - "font" : "13pt Lucida Console", - "horizontalOrigin" : "LEFT", - "outlineColor" : { - "rgba":[150, 0, 150, 255] - }, - "outlineWidth" : 3, - "pixelOffset" : { - "cartesian2" : [20, 0] - }, - "style" : "FILL_AND_OUTLINE", - "text" : "referencing position" + "font" : "13pt Lucida Console", + "horizontalOrigin" : "LEFT", + "outlineColor" : { + "rgba":[150, 0, 150, 255] }, - "position" : { - "reference" : "position-reference#position" - } - }, { - "id" : "polygon", - "name" : "Referencing Fill Color", - "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", - "label" : { - "fillColor" : { - "rgba" : [255, 255, 255, 255] - }, - "font" : "13pt Lucida Console", - "horizontalOrigin" : "LEFT", - "pixelOffset" : { - "cartesian2" : [20, 0] - }, - "style" : "FILL_AND_OUTLINE", - "text" : "referencing fillColor" + "outlineWidth" : 3, + "pixelOffset" : { + "cartesian2" : [20, 0] }, - "position" : { - "cartographicDegrees" : [-105, 35, 0] + "style" : "FILL_AND_OUTLINE", + "text" : "referencing position" + }, + "position" : { + "reference" : "position-reference#position" + } +}, { + "id" : "polygon", + "name" : "Referencing Fill Color", + "description" : "

For more examples of reference properties, see CZML Polygon - Interpolating References.

", + "label" : { + "fillColor" : { + "rgba" : [255, 255, 255, 255] }, - "polygon" : { - "positions" : { - "cartographicDegrees" : [ - -115.0, 37.0, 0, - -115.0, 32.0, 0, - -107.0, 33.0, 0, - -102.0, 31.0, 0, - -102.0, 35.0, 0 - ] - }, - "height" : 0, - "fillColor" : { - "reference" : "fillColor-reference#label.fillColor" + "font" : "13pt Lucida Console", + "horizontalOrigin" : "LEFT", + "pixelOffset" : { + "cartesian2" : [20, 0] + }, + "style" : "FILL_AND_OUTLINE", + "text" : "referencing fillColor" + }, + "position" : { + "cartographicDegrees" : [-105, 35, 0] + }, + "polygon" : { + "positions" : { + "cartographicDegrees" : [ + -115.0, 37.0, 0, + -115.0, 32.0, 0, + -107.0, 33.0, 0, + -102.0, 31.0, 0, + -102.0, 35.0, 0 + ] + }, + "height" : 0, + "material" : { + "solidColor" : { + "color" : { + "reference" : "fillColor-reference#label.outlineColor" + } } } - }]; - - var viewer = new Cesium.Viewer('cesiumContainer'); - viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); + } +}]; +var viewer = new Cesium.Viewer('cesiumContainer'); +viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); //Sandcastle_End Sandcastle.finishedLoading(); } From 30a637dce5dab27af4c94d09bfb837596ff1045d Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 16:55:28 -0400 Subject: [PATCH 56/60] fix clone --- Source/Scene/ShadowMap.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Scene/ShadowMap.js b/Source/Scene/ShadowMap.js index 152676ce2643..cae5d0f5210a 100644 --- a/Source/Scene/ShadowMap.js +++ b/Source/Scene/ShadowMap.js @@ -1512,6 +1512,7 @@ define([ var cullEnabled = command.renderState.cull.enabled; if (!cullEnabled) { castRenderState = clone(castRenderState, false); + castRenderState.cull = clone(castRenderState.cull, false); castRenderState.cull.enabled = false; castRenderState = RenderState.fromCache(castRenderState); } From e7532bfd270ba37f66a32b5de28512a502785d27 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 20 Oct 2017 16:59:14 -0400 Subject: [PATCH 57/60] Add comment. --- Source/Core/loadWithXhr.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/loadWithXhr.js b/Source/Core/loadWithXhr.js index 696e7a8dd8aa..49b35e94e7f8 100644 --- a/Source/Core/loadWithXhr.js +++ b/Source/Core/loadWithXhr.js @@ -172,6 +172,7 @@ define([ xhr.responseType = responseType; } + // While non-standard, file protocol always returns a status of 0 on success var localFile = false; if (typeof url === 'string') { localFile = url.indexOf('file://') === 0; From c2f3bbaec53c89568c05c09339b48881b527bd44 Mon Sep 17 00:00:00 2001 From: Hannah Date: Fri, 20 Oct 2017 17:08:43 -0400 Subject: [PATCH 58/60] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 755de86e411b..7883952f1238 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Change Log * Added function that inserts missing namespace declarations into KML files. [#5860](https://github.com/AnalyticalGraphicsInc/cesium/pull/5860) * Added support for the layer.json `parentUrl` property in `CesiumTerrainProvider` to allow for compositing of tilesets. * Fixed a bug that caused KML ground overlays to appear distorted when rotation was applied. [#5914](https://github.com/AnalyticalGraphicsInc/cesium/issues/5914) +* KML files load when a Network Link fails [#5871](https://github.com/AnalyticalGraphicsInc/cesium/pull/5871) * Adds `invertClassification` and `invertClassificationColor` to `Scene`. When `invertClassification` is `true`, any 3D Tiles geometry that is not classified by a `ClassificationPrimitive` or `GroundPrimitive` will have its color multiplied by `invertClassificationColor`. [#5836](https://github.com/AnalyticalGraphicsInc/cesium/pull/5836) * Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696) * Improved CZML Reference Properties example [#5754](https://github.com/AnalyticalGraphicsInc/cesium/pull/5754) From e734fb041ff30a492b9bf487b506f2e5578116d3 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Fri, 20 Oct 2017 17:18:21 -0400 Subject: [PATCH 59/60] Fix occluded level zero tile when there is only one. --- Source/Scene/GlobeSurfaceTileProvider.js | 2 +- Source/Scene/QuadtreePrimitive.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Scene/GlobeSurfaceTileProvider.js b/Source/Scene/GlobeSurfaceTileProvider.js index 00c047e2b83d..801376f39439 100644 --- a/Source/Scene/GlobeSurfaceTileProvider.js +++ b/Source/Scene/GlobeSurfaceTileProvider.js @@ -504,7 +504,7 @@ define([ } var ortho3D = frameState.mode === SceneMode.SCENE3D && frameState.camera.frustum instanceof OrthographicFrustum; - if (frameState.mode === SceneMode.SCENE3D && !ortho3D) { + if (frameState.mode === SceneMode.SCENE3D && !ortho3D && defined(occluders)) { var occludeePointInScaledSpace = surfaceTile.occludeePointInScaledSpace; if (!defined(occludeePointInScaledSpace)) { return intersection; diff --git a/Source/Scene/QuadtreePrimitive.js b/Source/Scene/QuadtreePrimitive.js index 7b990cb5697e..fe5444d669aa 100644 --- a/Source/Scene/QuadtreePrimitive.js +++ b/Source/Scene/QuadtreePrimitive.js @@ -427,12 +427,12 @@ define([ primitive._occluders.ellipsoid.cameraPosition = frameState.camera.positionWC; - var tileProvider = primitive._tileProvider; - var occluders = primitive._occluders; - var tile; var levelZeroTiles = primitive._levelZeroTiles; + var tileProvider = primitive._tileProvider; + var occluders = levelZeroTiles.length > 1 ? primitive._occluders : undefined; + // Sort the level zero tiles by the distance from the center to the camera. // The level zero tiles aren't necessarily a nice neat quad, so we can use the // quadtree ordering we use elsewhere in the tree From 4dea9a615ffbd4bebcc1727cb0c5fb061d4d0fe1 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 17:39:21 -0400 Subject: [PATCH 60/60] fix whitespace --- Source/Renderer/RenderState.js | 47 ++++++++++++++-------------- Source/Renderer/freezeRenderState.js | 10 +++--- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Source/Renderer/RenderState.js b/Source/Renderer/RenderState.js index 5655c35c2801..774f7a04871f 100644 --- a/Source/Renderer/RenderState.js +++ b/Source/Renderer/RenderState.js @@ -63,7 +63,7 @@ define([ (depthFunction === WebGLConstants.ALWAYS)); } - function validateStencilFunction (stencilFunction) { + function validateStencilFunction(stencilFunction) { return ((stencilFunction === WebGLConstants.NEVER) || (stencilFunction === WebGLConstants.LESS) || (stencilFunction === WebGLConstants.EQUAL) || @@ -177,8 +177,8 @@ define([ //>>includeStart('debug', pragmas.debug); if ((this.lineWidth < ContextLimits.minimumAliasedLineWidth) || - (this.lineWidth > ContextLimits.maximumAliasedLineWidth)) { - throw new DeveloperError('renderState.lineWidth is out of range. Check minimumAliasedLineWidth and maximumAliasedLineWidth.'); + (this.lineWidth > ContextLimits.maximumAliasedLineWidth)) { + throw new DeveloperError('renderState.lineWidth is out of range. Check minimumAliasedLineWidth and maximumAliasedLineWidth.'); } if (!WindingOrder.validate(this.frontFace)) { throw new DeveloperError('Invalid renderState.frontFace.'); @@ -417,8 +417,8 @@ define([ states = freezeRenderState(states); //>>includeEnd('debug'); cachedState = { - referenceCount: 0, - state: states + referenceCount : 0, + state : states }; // Cache full render state. Multiple partially defined render states may map to this. @@ -433,7 +433,7 @@ define([ state : cachedState.state }; - return cachedState.state; + return cachedState.state; }; /** @@ -626,6 +626,7 @@ define([ } var scratchViewport = new BoundingRectangle(); + function applyViewport(gl, renderState, passState) { var viewport = defaultValue(renderState.viewport, passState.viewport); if (!defined(viewport)) { @@ -671,8 +672,8 @@ define([ } if ((previousState.polygonOffset.enabled !== nextState.polygonOffset.enabled) || - (previousState.polygonOffset.factor !== nextState.polygonOffset.factor) || - (previousState.polygonOffset.units !== nextState.polygonOffset.units)) { + (previousState.polygonOffset.factor !== nextState.polygonOffset.factor) || + (previousState.polygonOffset.units !== nextState.polygonOffset.units)) { funcs.push(applyPolygonOffset); } @@ -685,9 +686,9 @@ define([ } if ((previousState.colorMask.red !== nextState.colorMask.red) || - (previousState.colorMask.green !== nextState.colorMask.green) || - (previousState.colorMask.blue !== nextState.colorMask.blue) || - (previousState.colorMask.alpha !== nextState.colorMask.alpha)) { + (previousState.colorMask.green !== nextState.colorMask.green) || + (previousState.colorMask.blue !== nextState.colorMask.blue) || + (previousState.colorMask.alpha !== nextState.colorMask.alpha)) { funcs.push(applyColorMask); } @@ -700,21 +701,21 @@ define([ } if ((previousState.stencilTest.enabled !== nextState.stencilTest.enabled) || - (previousState.stencilTest.frontFunction !== nextState.stencilTest.frontFunction) || - (previousState.stencilTest.backFunction !== nextState.stencilTest.backFunction) || - (previousState.stencilTest.reference !== nextState.stencilTest.reference) || - (previousState.stencilTest.mask !== nextState.stencilTest.mask) || - (previousState.stencilTest.frontOperation.fail !== nextState.stencilTest.frontOperation.fail) || - (previousState.stencilTest.frontOperation.zFail !== nextState.stencilTest.frontOperation.zFail) || - (previousState.stencilTest.backOperation.fail !== nextState.stencilTest.backOperation.fail) || - (previousState.stencilTest.backOperation.zFail !== nextState.stencilTest.backOperation.zFail) || - (previousState.stencilTest.backOperation.zPass !== nextState.stencilTest.backOperation.zPass)) { + (previousState.stencilTest.frontFunction !== nextState.stencilTest.frontFunction) || + (previousState.stencilTest.backFunction !== nextState.stencilTest.backFunction) || + (previousState.stencilTest.reference !== nextState.stencilTest.reference) || + (previousState.stencilTest.mask !== nextState.stencilTest.mask) || + (previousState.stencilTest.frontOperation.fail !== nextState.stencilTest.frontOperation.fail) || + (previousState.stencilTest.frontOperation.zFail !== nextState.stencilTest.frontOperation.zFail) || + (previousState.stencilTest.backOperation.fail !== nextState.stencilTest.backOperation.fail) || + (previousState.stencilTest.backOperation.zFail !== nextState.stencilTest.backOperation.zFail) || + (previousState.stencilTest.backOperation.zPass !== nextState.stencilTest.backOperation.zPass)) { funcs.push(applyStencilTest); } if ((previousState.sampleCoverage.enabled !== nextState.sampleCoverage.enabled) || - (previousState.sampleCoverage.value !== nextState.sampleCoverage.value) || - (previousState.sampleCoverage.invert !== nextState.sampleCoverage.invert)) { + (previousState.sampleCoverage.value !== nextState.sampleCoverage.value) || + (previousState.sampleCoverage.invert !== nextState.sampleCoverage.invert)) { funcs.push(applySampleCoverage); } @@ -753,7 +754,7 @@ define([ var previousBlendingEnabled = (defined(previousPassState.blendingEnabled)) ? previousPassState.blendingEnabled : previousRenderState.blending.enabled; var blendingEnabled = (defined(passState.blendingEnabled)) ? passState.blendingEnabled : renderState.blending.enabled; if ((previousBlendingEnabled !== blendingEnabled) || - (blendingEnabled && (previousRenderState.blending !== renderState.blending))) { + (blendingEnabled && (previousRenderState.blending !== renderState.blending))) { applyBlending(gl, renderState, passState); } diff --git a/Source/Renderer/freezeRenderState.js b/Source/Renderer/freezeRenderState.js index e93a3535ade4..bc568ee4ef7f 100644 --- a/Source/Renderer/freezeRenderState.js +++ b/Source/Renderer/freezeRenderState.js @@ -1,10 +1,10 @@ /*global define*/ define([ - '../Core/defined', - '../Core/freezeObject' -], function( - defined, - freezeObject) { + '../Core/defined', + '../Core/freezeObject' + ], function( + defined, + freezeObject) { 'use strict'; /**