diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index 3e6d4bdbede3..48d5ae49f1ba 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -8,6 +9,7 @@ define([ '../Core/WebGLConstants', './BufferUsage' ], function( + Check, defaultValue, defined, defineProperties, @@ -25,9 +27,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.'); @@ -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(); @@ -118,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({ @@ -179,15 +176,13 @@ 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.'); } - 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'); @@ -249,12 +244,8 @@ define([ offsetInBytes = defaultValue(offsetInBytes, 0); //>>includeStart('debug', pragmas.debug); - if (!arrayView) { - throw new DeveloperError('arrayView is required.'); - } - if (offsetInBytes + arrayView.byteLength > this._sizeInBytes) { - throw new DeveloperError('This buffer is not large enough.'); - } + Check.defined('arrayView', arrayView); + Check.typeOf.number.lessThanOrEquals('offsetInBytes + arrayView.byteLength', offsetInBytes + arrayView.byteLength, this._sizeInBytes); //>>includeEnd('debug'); var gl = this._gl; diff --git a/Source/Renderer/ComputeEngine.js b/Source/Renderer/ComputeEngine.js index 1ab87d6cebd8..2329b840b216 100644 --- a/Source/Renderer/ComputeEngine.js +++ b/Source/Renderer/ComputeEngine.js @@ -1,5 +1,6 @@ define([ '../Core/BoundingRectangle', + '../Core/Check', '../Core/Color', '../Core/defined', '../Core/destroyObject', @@ -13,6 +14,7 @@ define([ './ShaderProgram' ], function( BoundingRectangle, + Check, Color, defined, destroyObject, @@ -75,9 +77,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 @@ -90,9 +90,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 5ab984919331..e74b5866408b 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -1,87 +1,90 @@ define([ - '../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( - 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; @@ -90,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 += ', '; } @@ -178,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; @@ -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); @@ -922,22 +951,12 @@ 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.'); + Check.defined('drawCommand.vertexArray', va); + Check.typeOf.number.greaterThanOrEquals('drawCommand.offset', offset, 0); + if (defined(count)) { + Check.typeOf.number.greaterThanOrEquals('drawCommand.count', count, 0); } - - if (instanceCount < 0) { - throw new DeveloperError('drawCommand.instanceCount must be greater than or equal to zero.'); - } - + Check.typeOf.number.greaterThanOrEquals('drawCommand.instanceCount', instanceCount, 0); if (instanceCount > 0 && !context.instancedArrays) { throw new DeveloperError('Instanced arrays extension is not supported'); } @@ -971,13 +990,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); @@ -1021,13 +1035,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); @@ -1055,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 ] }), @@ -1129,9 +1138,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()]; @@ -1180,9 +1187,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/CubeMap.js b/Source/Renderer/CubeMap.js index b95bf56c009f..e08eccd1c718 100644 --- a/Source/Renderer/CubeMap.js +++ b/Source/Renderer/CubeMap.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -14,6 +15,7 @@ define([ './TextureMagnificationFilter', './TextureMinificationFilter' ], function( + Check, defaultValue, defined, defineProperties, @@ -35,9 +37,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/CubeMapFace.js b/Source/Renderer/CubeMapFace.js index 1695c9a09776..83e9a165cd73 100644 --- a/Source/Renderer/CubeMapFace.js +++ b/Source/Renderer/CubeMapFace.js @@ -1,9 +1,11 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defineProperties', '../Core/DeveloperError', './PixelDatatype' ], function( + Check, defaultValue, defineProperties, DeveloperError, @@ -74,15 +76,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.'); } @@ -142,18 +138,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/Framebuffer.js b/Source/Renderer/Framebuffer.js index a98a6aa376ec..20f54665c1ce 100644 --- a/Source/Renderer/Framebuffer.js +++ b/Source/Renderer/Framebuffer.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -7,6 +8,7 @@ define([ '../Core/PixelFormat', './ContextLimits' ], function( + Check, defaultValue, defined, defineProperties, @@ -71,9 +73,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 c36c80e0bc84..8da442cbd5bf 100644 --- a/Source/Renderer/Renderbuffer.js +++ b/Source/Renderer/Renderbuffer.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -7,6 +8,7 @@ define([ './ContextLimits', './RenderbufferFormat' ], function( + Check, defaultValue, defined, defineProperties, @@ -23,9 +25,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; @@ -41,17 +41,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 c11922f91a52..d074b9a0d38d 100644 --- a/Source/Renderer/Sampler.js +++ b/Source/Renderer/Sampler.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -7,6 +8,7 @@ define([ './TextureMinificationFilter', './TextureWrap' ], function( + Check, defaultValue, defined, defineProperties, @@ -45,9 +47,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/ShaderProgram.js b/Source/Renderer/ShaderProgram.js index e839d4cd4e0f..7a79505965e8 100644 --- a/Source/Renderer/ShaderProgram.js +++ b/Source/Renderer/ShaderProgram.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -10,6 +11,7 @@ define([ './createUniform', './createUniformArray' ], function( + Check, defaultValue, defined, defineProperties, @@ -65,9 +67,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'); return options.context.shaderCache.getShaderProgram(options); @@ -77,9 +77,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'); return options.context.shaderCache.replaceShaderProgram(options); diff --git a/Source/Renderer/Texture.js b/Source/Renderer/Texture.js index 1557d205d139..2ba7284e05c7 100644 --- a/Source/Renderer/Texture.js +++ b/Source/Renderer/Texture.js @@ -1,5 +1,6 @@ define([ '../Core/Cartesian2', + '../Core/Check', '../Core/createGuid', '../Core/defaultValue', '../Core/defined', @@ -17,6 +18,7 @@ define([ './TextureMinificationFilter' ], function( Cartesian2, + Check, createGuid, defaultValue, defined, @@ -38,9 +40,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; @@ -97,17 +97,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.'); @@ -270,9 +266,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; @@ -286,21 +280,15 @@ 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.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'); } @@ -464,27 +452,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.'); - } - 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.greaterThanOrEquals('xOffset', xOffset, 0); + Check.typeOf.number.greaterThanOrEquals('yOffset', yOffset, 0); + 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; @@ -542,24 +520,13 @@ 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.'); - } - 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.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); + 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/Source/Renderer/VertexArray.js b/Source/Renderer/VertexArray.js index 535f57e76307..5807c94cb71c 100644 --- a/Source/Renderer/VertexArray.js +++ b/Source/Renderer/VertexArray.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/ComponentDatatype', '../Core/defaultValue', '../Core/defined', @@ -13,6 +14,7 @@ define([ './BufferUsage', './ContextLimits' ], function( + Check, ComponentDatatype, defaultValue, defined, @@ -266,13 +268,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; @@ -528,9 +525,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; @@ -669,9 +664,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 82c3d0a5ba0b..4a0c7efaa0f8 100644 --- a/Source/Renderer/VertexArrayFacade.js +++ b/Source/Renderer/VertexArrayFacade.js @@ -1,4 +1,5 @@ define([ + '../Core/Check', '../Core/ComponentDatatype', '../Core/defaultValue', '../Core/defined', @@ -9,6 +10,7 @@ define([ './BufferUsage', './VertexArray' ], function( + Check, ComponentDatatype, defaultValue, defined, @@ -25,9 +27,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 e3b28341b8db..723009863b6e 100644 --- a/Source/Renderer/loadCubeMap.js +++ b/Source/Renderer/loadCubeMap.js @@ -1,10 +1,12 @@ define([ + '../Core/Check', '../Core/defined', '../Core/DeveloperError', '../Core/loadImage', '../ThirdParty/when', './CubeMap' ], function( + Check, defined, DeveloperError, loadImage, @@ -50,9 +52,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)) || 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