-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Firefox console warnings. #5939
Changes from 10 commits
f7fac41
95e3f9a
40ab429
4ab51ce
67f9ac4
c1f3a04
19af263
21cc4ec
d9f44d0
09720d0
1bcac56
544d08e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,6 @@ define([ | |
'use strict'; | ||
|
||
function CubeMap(options) { | ||
|
||
options = defaultValue(options, defaultValue.EMPTY_OBJECT); | ||
|
||
//>>includeStart('debug', pragmas.debug); | ||
|
@@ -121,25 +120,29 @@ define([ | |
gl.activeTexture(gl.TEXTURE0); | ||
gl.bindTexture(textureTarget, texture); | ||
|
||
function createFace(target, sourceFace) { | ||
function createFace(target, sourceFace, preMultiplyAlpha, flipY) { | ||
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4); | ||
if (sourceFace.arrayBufferView) { | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); | ||
gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, sourceFace.arrayBufferView); | ||
} else { | ||
// Only valid for DOM-Element uploads | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | ||
|
||
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement | ||
gl.texImage2D(target, 0, pixelFormat, pixelFormat, pixelDatatype, sourceFace); | ||
} | ||
} | ||
|
||
if (defined(source)) { | ||
// TODO: _gl.pixelStorei(_gl._UNPACK_ALIGNMENT, 4); | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | ||
|
||
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X, source.positiveX); | ||
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, source.negativeX); | ||
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY); | ||
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY); | ||
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ); | ||
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ); | ||
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X, source.positiveX, preMultiplyAlpha, flipY); | ||
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, source.negativeX, preMultiplyAlpha, flipY); | ||
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY, preMultiplyAlpha, flipY); | ||
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY, preMultiplyAlpha, flipY); | ||
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ, preMultiplyAlpha, flipY); | ||
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ, preMultiplyAlpha, flipY); | ||
} else { | ||
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it valid to pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did it this way for the case where you create a texture and upload the entire texture later. This avoids creating an array buffer of all zeroes. The only time the array buffer of zeroes would be created would be when a texture is created and then a bunch of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, a texture that is going to be rendered to cannot be set. |
||
gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null); | ||
|
@@ -163,12 +166,13 @@ define([ | |
this._flipY = flipY; | ||
this._sampler = undefined; | ||
|
||
this._positiveX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY); | ||
this._negativeX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY); | ||
this._positiveY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY); | ||
this._negativeY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY); | ||
this._positiveZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY); | ||
this._negativeZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY); | ||
var initialized = defined(source); | ||
this._positiveX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized); | ||
this._negativeX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized); | ||
this._positiveY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized); | ||
this._negativeY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized); | ||
this._positiveZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized); | ||
this._negativeZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized); | ||
|
||
this.sampler = defined(options.sampler) ? options.sampler : new Sampler(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
define([ | ||
'../Core/Check', | ||
'../Core/defaultValue', | ||
'../Core/defined', | ||
'../Core/defineProperties', | ||
'../Core/DeveloperError', | ||
'../Core/PixelFormat', | ||
'./PixelDatatype' | ||
], function( | ||
Check, | ||
defaultValue, | ||
defined, | ||
defineProperties, | ||
DeveloperError, | ||
PixelFormat, | ||
PixelDatatype) { | ||
'use strict'; | ||
|
||
/** | ||
* @private | ||
*/ | ||
function CubeMapFace(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY) { | ||
function CubeMapFace(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized) { | ||
this._gl = gl; | ||
this._texture = texture; | ||
this._textureTarget = textureTarget; | ||
|
@@ -25,6 +29,7 @@ define([ | |
this._size = size; | ||
this._preMultiplyAlpha = preMultiplyAlpha; | ||
this._flipY = flipY; | ||
this._initialized = initialized; | ||
} | ||
|
||
defineProperties(CubeMapFace.prototype, { | ||
|
@@ -91,15 +96,52 @@ define([ | |
var target = this._textureTarget; | ||
|
||
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4); | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY); | ||
|
||
gl.activeTexture(gl.TEXTURE0); | ||
gl.bindTexture(target, this._texture); | ||
|
||
if (source.arrayBufferView) { | ||
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView); | ||
} else { | ||
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source); | ||
var uploaded = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below seems more complicated than it needs to be; I will not have the time to dive deep for awhile. @lilleyse can you take a look? |
||
if (!this._initialized) { | ||
if (xOffset === 0 && yOffset === 0 && source.width === this._size && source.height === this._size) { | ||
// initialize the entire texture | ||
if (defined(source.arrayBufferView)) { | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); | ||
|
||
gl.texImage2D(this._targetFace, 0, this._pixelFormat, this._size, this._size, 0, this._pixelFormat, this._pixelDatatype, source.arrayBufferView); | ||
} else { | ||
// Only valid for DOM-Element uploads | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY); | ||
|
||
gl.texImage2D(this._targetFace, 0, this._pixelFormat, this._pixelFormat, this._pixelDatatype, source); | ||
} | ||
uploaded = true; | ||
} else { | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); | ||
|
||
// initialize the entire texture to zero | ||
var bufferView = PixelFormat.createTypedArray(this._pixelFormat, this._pixelDatatype, this._size, this._size); | ||
gl.texImage2D(this._targetFace, 0, this._pixelFormat, this._size, this._size, 0, this._pixelFormat, this._pixelDatatype, bufferView); | ||
} | ||
this._initialized = true; | ||
} | ||
|
||
if (!uploaded) { | ||
if (source.arrayBufferView) { | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); | ||
|
||
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView); | ||
} else { | ||
// Only valid for DOM-Element uploads | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY); | ||
|
||
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement | ||
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source); | ||
} | ||
} | ||
|
||
gl.bindTexture(target, null); | ||
|
@@ -160,6 +202,7 @@ define([ | |
gl.bindTexture(target, this._texture); | ||
gl.copyTexSubImage2D(this._targetFace, 0, xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height); | ||
gl.bindTexture(target, null); | ||
this._initialized = true; | ||
}; | ||
|
||
return CubeMapFace; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,18 +164,20 @@ define([ | |
var preMultiplyAlpha = options.preMultiplyAlpha || pixelFormat === PixelFormat.RGB || pixelFormat === PixelFormat.LUMINANCE; | ||
var flipY = defaultValue(options.flipY, true); | ||
|
||
var initialized = true; | ||
|
||
var gl = context._gl; | ||
var textureTarget = gl.TEXTURE_2D; | ||
var texture = gl.createTexture(); | ||
|
||
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4); | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); | ||
|
||
gl.activeTexture(gl.TEXTURE0); | ||
gl.bindTexture(textureTarget, texture); | ||
|
||
if (defined(source)) { | ||
// TODO: _gl.pixelStorei(_gl._UNPACK_ALIGNMENT, 4); | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | ||
|
||
if (defined(source.arrayBufferView)) { | ||
// Source: typed array | ||
if (isCompressed) { | ||
|
@@ -195,11 +197,16 @@ define([ | |
source.framebuffer._unBind(); | ||
} | ||
} else { | ||
// Only valid for DOM-Element uploads | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | ||
|
||
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement | ||
gl.texImage2D(textureTarget, 0, internalFormat, pixelFormat, pixelDatatype, source); | ||
} | ||
} else { | ||
gl.texImage2D(textureTarget, 0, internalFormat, width, height, 0, pixelFormat, pixelDatatype, null); | ||
initialized = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically the same note as above, can we initialize the texture with an empty typed array now to avoid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here. |
||
} | ||
gl.bindTexture(textureTarget, null); | ||
|
||
|
@@ -224,6 +231,7 @@ define([ | |
this._sizeInBytes = sizeInBytes; | ||
this._preMultiplyAlpha = preMultiplyAlpha; | ||
this._flipY = flipY; | ||
this._initialized = initialized; | ||
this._sampler = undefined; | ||
|
||
this.sampler = defined(options.sampler) ? options.sampler : new Sampler(); | ||
|
@@ -469,15 +477,44 @@ define([ | |
var target = this._textureTarget; | ||
|
||
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4); | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY); | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the same changes as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
gl.activeTexture(gl.TEXTURE0); | ||
gl.bindTexture(target, this._texture); | ||
|
||
if (source.arrayBufferView) { | ||
gl.texSubImage2D(target, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView); | ||
} else { | ||
gl.texSubImage2D(target, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source); | ||
var uploaded = false; | ||
if (!this._initialized) { | ||
if (xOffset === 0 && yOffset === 0 && source.width === this._width && source.height === this._height) { | ||
// initialize the entire texture | ||
if (defined(source.arrayBufferView)) { | ||
gl.texImage2D(target, 0, this._pixelFormat, this._width, this._height, 0, this._pixelFormat, this._pixelDatatype, source.arrayBufferView); | ||
} else { | ||
// Only valid for DOM-Element uploads | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY); | ||
|
||
gl.texImage2D(target, 0, this._pixelFormat, this._pixelFormat, this._pixelDatatype, source); | ||
} | ||
uploaded = true; | ||
} else { | ||
// initialize the entire texture to zero | ||
var bufferView = PixelFormat.createTypedArray(this._pixelFormat, this._pixelDatatype, this._width, this._height); | ||
gl.texImage2D(target, 0, this._pixelFormat, this._width, this._height, 0, this._pixelFormat, this._pixelDatatype, bufferView); | ||
} | ||
this._initialized = true; | ||
} | ||
|
||
if (!uploaded) { | ||
if (source.arrayBufferView) { | ||
gl.texSubImage2D(target, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView); | ||
} else { | ||
// Only valid for DOM-Element uploads | ||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY); | ||
|
||
gl.texSubImage2D(target, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source); | ||
} | ||
} | ||
|
||
gl.bindTexture(target, null); | ||
|
@@ -536,6 +573,7 @@ define([ | |
gl.bindTexture(target, this._texture); | ||
gl.copyTexSubImage2D(target, 0, xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height); | ||
gl.bindTexture(target, null); | ||
this._initialized = true; | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to leave this TODO in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was in the original code. I just moved it.