Skip to content
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 warnings #6297

Merged
merged 19 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change Log
* Fixed glTF support to handle meshes with and without tangent vectors, and with/without morph targets, sharing one material. [#6421](https://github.com/AnalyticalGraphicsInc/cesium/pull/6421)
* Fixed glTF support to handle skinned meshes when no skin is supplied. [#6061](https://github.com/AnalyticalGraphicsInc/cesium/issues/6061)
* Allow loadWithXhr to work with string URLs in a web worker.
* Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912)

### 1.44 - 2018-04-02

Expand Down
43 changes: 41 additions & 2 deletions Source/Core/PixelFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ define([
*/
componentsLength : function(pixelFormat) {
switch (pixelFormat) {
// Many GPUs store RGB as RGBA internally
// https://devtalk.nvidia.com/default/topic/699479/general-graphics-programming/rgb-auto-converted-to-rgba/post/4142379/#4142379
case PixelFormat.RGB:
return 3;
case PixelFormat.RGBA:
return 4;
case PixelFormat.LUMINANCE_ALPHA:
Expand Down Expand Up @@ -281,6 +280,46 @@ define([
componentsLength = 1;
}
return componentsLength * PixelDatatype.sizeInBytes(pixelDatatype) * width * height;
},

/**
* @private
*/
createTypedArray : function(pixelFormat, pixelDatatype, width, height) {
var constructor;
var sizeInBytes = PixelDatatype.sizeInBytes(pixelDatatype);
if (sizeInBytes === Uint8Array.BYTES_PER_ELEMENT) {
constructor = Uint8Array;
} else if (sizeInBytes === Uint16Array.BYTES_PER_ELEMENT) {
constructor = Uint16Array;
} else if (sizeInBytes === Float32Array.BYTES_PER_ELEMENT && pixelDatatype === PixelDatatype.FLOAT) {
constructor = Float32Array;
} else {
constructor = Uint32Array;
}

var size = PixelFormat.componentsLength(pixelFormat) * width * height;
return new constructor(size);
},

/**
* @private
*/
flipY : function(bufferView, pixelFormat, pixelDatatype, width, height) {
if (height === 1) {
return bufferView;
}
var flipped = PixelFormat.createTypedArray(pixelFormat, pixelDatatype, width, height);
var numberOfComponents = PixelFormat.componentsLength(pixelFormat);
var textureWidth = width * numberOfComponents;
for (var i = 0; i < height; ++i) {
var row = i * height * numberOfComponents;
var flippedRow = (height - i - 1) * height * numberOfComponents;
for (var j = 0; j < textureWidth; ++j) {
flipped[flippedRow + j] = bufferView[row + j];
}
}
return flipped;
}
};

Expand Down
6 changes: 4 additions & 2 deletions Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ define([
width : 1,
height : 1,
arrayBufferView : new Uint8Array([255, 255, 255, 255])
}
},
flipY : false
});
}

Expand Down Expand Up @@ -753,7 +754,8 @@ define([
negativeY : face,
positiveZ : face,
negativeZ : face
}
},
flipY : false
});
}

Expand Down
49 changes: 29 additions & 20 deletions Source/Renderer/CubeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ define([
'use strict';

function CubeMap(options) {

options = defaultValue(options, defaultValue.EMPTY_OBJECT);

//>>includeStart('debug', pragmas.debug);
Expand Down Expand Up @@ -121,25 +120,34 @@ define([
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(textureTarget, texture);

function createFace(target, sourceFace) {
if (sourceFace.arrayBufferView) {
gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, sourceFace.arrayBufferView);
function createFace(target, sourceFace, preMultiplyAlpha, flipY) {
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
var arrayBufferView = sourceFace.arrayBufferView;
if (arrayBufferView) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);

if (flipY) {
arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, size, size);
}
gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, 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);
gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
Expand All @@ -163,12 +171,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();
}
Expand Down
75 changes: 68 additions & 7 deletions Source/Renderer/CubeMapFace.js
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;
Expand All @@ -25,6 +29,7 @@ define([
this._size = size;
this._preMultiplyAlpha = preMultiplyAlpha;
this._flipY = flipY;
this._initialized = initialized;
}

defineProperties(CubeMapFace.prototype, {
Expand Down Expand Up @@ -89,17 +94,72 @@ define([

var gl = this._gl;
var target = this._textureTarget;
var targetFace = this._targetFace;

// 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 width = source.width;
var height = source.height;
var arrayBufferView = source.arrayBufferView;

var size = this._size;
var pixelFormat = this._pixelFormat;
var pixelDatatype = this._pixelDatatype;

var preMultiplyAlpha = this._preMultiplyAlpha;
var flipY = this._flipY;

var uploaded = false;
if (!this._initialized) {
if (xOffset === 0 && yOffset === 0 && width === size && height === size) {
// initialize the entire texture
if (defined(arrayBufferView)) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);

if (flipY) {
arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, size, size);
}
gl.texImage2D(targetFace, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, arrayBufferView);
} else {
// Only valid for DOM-Element uploads
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);

gl.texImage2D(targetFace, 0, pixelFormat, pixelFormat, 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(pixelFormat, pixelDatatype, size, size);
gl.texImage2D(targetFace, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, bufferView);
}
this._initialized = true;
}

if (!uploaded) {
if (arrayBufferView) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);

if (flipY) {
arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, width, height);
}
gl.texSubImage2D(targetFace, 0, xOffset, yOffset, width, height, pixelFormat, pixelDatatype, 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.texSubImage2D(targetFace, 0, xOffset, yOffset, pixelFormat, pixelDatatype, source);
}
}

gl.bindTexture(target, null);
Expand Down Expand Up @@ -160,6 +220,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;
Expand Down
Loading