Skip to content

Commit 65a4418

Browse files
author
hanbollar
committed
Merge branch 'master' into particle-system-updates-and-deprecations
2 parents f2e7261 + 9259693 commit 65a4418

17 files changed

+393
-85
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Change Log
88
* 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)
99
* Fixed glTF support to handle skinned meshes when no skin is supplied. [#6061](https://github.com/AnalyticalGraphicsInc/cesium/issues/6061)
1010
* Allow loadWithXhr to work with string URLs in a web worker.
11+
* Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912)
1112

1213
### 1.44 - 2018-04-02
1314

Source/Core/PixelFormat.js

+41-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ define([
147147
*/
148148
componentsLength : function(pixelFormat) {
149149
switch (pixelFormat) {
150-
// Many GPUs store RGB as RGBA internally
151-
// https://devtalk.nvidia.com/default/topic/699479/general-graphics-programming/rgb-auto-converted-to-rgba/post/4142379/#4142379
152150
case PixelFormat.RGB:
151+
return 3;
153152
case PixelFormat.RGBA:
154153
return 4;
155154
case PixelFormat.LUMINANCE_ALPHA:
@@ -281,6 +280,46 @@ define([
281280
componentsLength = 1;
282281
}
283282
return componentsLength * PixelDatatype.sizeInBytes(pixelDatatype) * width * height;
283+
},
284+
285+
/**
286+
* @private
287+
*/
288+
createTypedArray : function(pixelFormat, pixelDatatype, width, height) {
289+
var constructor;
290+
var sizeInBytes = PixelDatatype.sizeInBytes(pixelDatatype);
291+
if (sizeInBytes === Uint8Array.BYTES_PER_ELEMENT) {
292+
constructor = Uint8Array;
293+
} else if (sizeInBytes === Uint16Array.BYTES_PER_ELEMENT) {
294+
constructor = Uint16Array;
295+
} else if (sizeInBytes === Float32Array.BYTES_PER_ELEMENT && pixelDatatype === PixelDatatype.FLOAT) {
296+
constructor = Float32Array;
297+
} else {
298+
constructor = Uint32Array;
299+
}
300+
301+
var size = PixelFormat.componentsLength(pixelFormat) * width * height;
302+
return new constructor(size);
303+
},
304+
305+
/**
306+
* @private
307+
*/
308+
flipY : function(bufferView, pixelFormat, pixelDatatype, width, height) {
309+
if (height === 1) {
310+
return bufferView;
311+
}
312+
var flipped = PixelFormat.createTypedArray(pixelFormat, pixelDatatype, width, height);
313+
var numberOfComponents = PixelFormat.componentsLength(pixelFormat);
314+
var textureWidth = width * numberOfComponents;
315+
for (var i = 0; i < height; ++i) {
316+
var row = i * height * numberOfComponents;
317+
var flippedRow = (height - i - 1) * height * numberOfComponents;
318+
for (var j = 0; j < textureWidth; ++j) {
319+
flipped[flippedRow + j] = bufferView[row + j];
320+
}
321+
}
322+
return flipped;
284323
}
285324
};
286325

Source/Renderer/Context.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ define([
720720
width : 1,
721721
height : 1,
722722
arrayBufferView : new Uint8Array([255, 255, 255, 255])
723-
}
723+
},
724+
flipY : false
724725
});
725726
}
726727

@@ -753,7 +754,8 @@ define([
753754
negativeY : face,
754755
positiveZ : face,
755756
negativeZ : face
756-
}
757+
},
758+
flipY : false
757759
});
758760
}
759761

Source/Renderer/CubeMap.js

+29-20
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ define([
3333
'use strict';
3434

3535
function CubeMap(options) {
36-
3736
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
3837

3938
//>>includeStart('debug', pragmas.debug);
@@ -121,25 +120,34 @@ define([
121120
gl.activeTexture(gl.TEXTURE0);
122121
gl.bindTexture(textureTarget, texture);
123122

124-
function createFace(target, sourceFace) {
125-
if (sourceFace.arrayBufferView) {
126-
gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, sourceFace.arrayBufferView);
123+
function createFace(target, sourceFace, preMultiplyAlpha, flipY) {
124+
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
125+
var arrayBufferView = sourceFace.arrayBufferView;
126+
if (arrayBufferView) {
127+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
128+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
129+
130+
if (flipY) {
131+
arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, size, size);
132+
}
133+
gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, arrayBufferView);
127134
} else {
135+
// Only valid for DOM-Element uploads
136+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
137+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
138+
139+
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
128140
gl.texImage2D(target, 0, pixelFormat, pixelFormat, pixelDatatype, sourceFace);
129141
}
130142
}
131143

132144
if (defined(source)) {
133-
// TODO: _gl.pixelStorei(_gl._UNPACK_ALIGNMENT, 4);
134-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
135-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
136-
137-
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X, source.positiveX);
138-
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, source.negativeX);
139-
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY);
140-
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY);
141-
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ);
142-
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ);
145+
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X, source.positiveX, preMultiplyAlpha, flipY);
146+
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, source.negativeX, preMultiplyAlpha, flipY);
147+
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY, preMultiplyAlpha, flipY);
148+
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY, preMultiplyAlpha, flipY);
149+
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ, preMultiplyAlpha, flipY);
150+
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ, preMultiplyAlpha, flipY);
143151
} else {
144152
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
145153
gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
@@ -163,12 +171,13 @@ define([
163171
this._flipY = flipY;
164172
this._sampler = undefined;
165173

166-
this._positiveX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
167-
this._negativeX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
168-
this._positiveY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
169-
this._negativeY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
170-
this._positiveZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
171-
this._negativeZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
174+
var initialized = defined(source);
175+
this._positiveX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
176+
this._negativeX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
177+
this._positiveY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
178+
this._negativeY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
179+
this._positiveZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
180+
this._negativeZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
172181

173182
this.sampler = defined(options.sampler) ? options.sampler : new Sampler();
174183
}

Source/Renderer/CubeMapFace.js

+68-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
define([
22
'../Core/Check',
33
'../Core/defaultValue',
4+
'../Core/defined',
45
'../Core/defineProperties',
56
'../Core/DeveloperError',
7+
'../Core/PixelFormat',
68
'./PixelDatatype'
79
], function(
810
Check,
911
defaultValue,
12+
defined,
1013
defineProperties,
1114
DeveloperError,
15+
PixelFormat,
1216
PixelDatatype) {
1317
'use strict';
1418

1519
/**
1620
* @private
1721
*/
18-
function CubeMapFace(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY) {
22+
function CubeMapFace(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized) {
1923
this._gl = gl;
2024
this._texture = texture;
2125
this._textureTarget = textureTarget;
@@ -25,6 +29,7 @@ define([
2529
this._size = size;
2630
this._preMultiplyAlpha = preMultiplyAlpha;
2731
this._flipY = flipY;
32+
this._initialized = initialized;
2833
}
2934

3035
defineProperties(CubeMapFace.prototype, {
@@ -89,17 +94,72 @@ define([
8994

9095
var gl = this._gl;
9196
var target = this._textureTarget;
97+
var targetFace = this._targetFace;
9298

9399
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
94-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
95-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
100+
96101
gl.activeTexture(gl.TEXTURE0);
97102
gl.bindTexture(target, this._texture);
98103

99-
if (source.arrayBufferView) {
100-
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView);
101-
} else {
102-
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source);
104+
var width = source.width;
105+
var height = source.height;
106+
var arrayBufferView = source.arrayBufferView;
107+
108+
var size = this._size;
109+
var pixelFormat = this._pixelFormat;
110+
var pixelDatatype = this._pixelDatatype;
111+
112+
var preMultiplyAlpha = this._preMultiplyAlpha;
113+
var flipY = this._flipY;
114+
115+
var uploaded = false;
116+
if (!this._initialized) {
117+
if (xOffset === 0 && yOffset === 0 && width === size && height === size) {
118+
// initialize the entire texture
119+
if (defined(arrayBufferView)) {
120+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
121+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
122+
123+
if (flipY) {
124+
arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, size, size);
125+
}
126+
gl.texImage2D(targetFace, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, arrayBufferView);
127+
} else {
128+
// Only valid for DOM-Element uploads
129+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
130+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
131+
132+
gl.texImage2D(targetFace, 0, pixelFormat, pixelFormat, pixelDatatype, source);
133+
}
134+
uploaded = true;
135+
} else {
136+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
137+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
138+
139+
// initialize the entire texture to zero
140+
var bufferView = PixelFormat.createTypedArray(pixelFormat, pixelDatatype, size, size);
141+
gl.texImage2D(targetFace, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, bufferView);
142+
}
143+
this._initialized = true;
144+
}
145+
146+
if (!uploaded) {
147+
if (arrayBufferView) {
148+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
149+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
150+
151+
if (flipY) {
152+
arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, width, height);
153+
}
154+
gl.texSubImage2D(targetFace, 0, xOffset, yOffset, width, height, pixelFormat, pixelDatatype, arrayBufferView);
155+
} else {
156+
// Only valid for DOM-Element uploads
157+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
158+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
159+
160+
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
161+
gl.texSubImage2D(targetFace, 0, xOffset, yOffset, pixelFormat, pixelDatatype, source);
162+
}
103163
}
104164

105165
gl.bindTexture(target, null);
@@ -160,6 +220,7 @@ define([
160220
gl.bindTexture(target, this._texture);
161221
gl.copyTexSubImage2D(this._targetFace, 0, xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height);
162222
gl.bindTexture(target, null);
223+
this._initialized = true;
163224
};
164225

165226
return CubeMapFace;

0 commit comments

Comments
 (0)