Skip to content

Commit 47a8b74

Browse files
author
hpinkos
committed
revert #5939
1 parent e40d522 commit 47a8b74

File tree

4 files changed

+112
-227
lines changed

4 files changed

+112
-227
lines changed

Source/Core/PixelFormat.js

-20
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,6 @@ define([
281281
componentsLength = 1;
282282
}
283283
return componentsLength * PixelDatatype.sizeInBytes(pixelDatatype) * width * height;
284-
},
285-
286-
/**
287-
* @private
288-
*/
289-
createTypedArray : function(pixelFormat, pixelDatatype, width, height) {
290-
var constructor;
291-
var sizeInBytes = PixelDatatype.sizeInBytes(pixelDatatype);
292-
if (sizeInBytes === Uint8Array.BYTES_PER_ELEMENT) {
293-
constructor = Uint8Array;
294-
} else if (sizeInBytes === Uint16Array.BYTES_PER_ELEMENT) {
295-
constructor = Uint16Array;
296-
} else if (sizeInBytes === Float32Array.BYTES_PER_ELEMENT && pixelDatatype === PixelDatatype.FLOAT) {
297-
constructor = Float32Array;
298-
} else {
299-
constructor = Uint32Array;
300-
}
301-
302-
var size = PixelFormat.componentsLength(pixelFormat) * width * height;
303-
return new constructor(size);
304284
}
305285
};
306286

Source/Renderer/CubeMap.js

+49-53
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
define([
2-
'../Core/Check',
3-
'../Core/defaultValue',
4-
'../Core/defined',
5-
'../Core/defineProperties',
6-
'../Core/destroyObject',
7-
'../Core/DeveloperError',
8-
'../Core/Math',
9-
'../Core/PixelFormat',
10-
'./ContextLimits',
11-
'./CubeMapFace',
12-
'./MipmapHint',
13-
'./PixelDatatype',
14-
'./Sampler',
15-
'./TextureMagnificationFilter',
16-
'./TextureMinificationFilter'
17-
], function(
18-
Check,
19-
defaultValue,
20-
defined,
21-
defineProperties,
22-
destroyObject,
23-
DeveloperError,
24-
CesiumMath,
25-
PixelFormat,
26-
ContextLimits,
27-
CubeMapFace,
28-
MipmapHint,
29-
PixelDatatype,
30-
Sampler,
31-
TextureMagnificationFilter,
32-
TextureMinificationFilter) {
2+
'../Core/Check',
3+
'../Core/defaultValue',
4+
'../Core/defined',
5+
'../Core/defineProperties',
6+
'../Core/destroyObject',
7+
'../Core/DeveloperError',
8+
'../Core/Math',
9+
'../Core/PixelFormat',
10+
'./ContextLimits',
11+
'./CubeMapFace',
12+
'./MipmapHint',
13+
'./PixelDatatype',
14+
'./Sampler',
15+
'./TextureMagnificationFilter',
16+
'./TextureMinificationFilter'
17+
], function(
18+
Check,
19+
defaultValue,
20+
defined,
21+
defineProperties,
22+
destroyObject,
23+
DeveloperError,
24+
CesiumMath,
25+
PixelFormat,
26+
ContextLimits,
27+
CubeMapFace,
28+
MipmapHint,
29+
PixelDatatype,
30+
Sampler,
31+
TextureMagnificationFilter,
32+
TextureMinificationFilter) {
3333
'use strict';
3434

3535
function CubeMap(options) {
36+
3637
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
3738

3839
//>>includeStart('debug', pragmas.debug);
@@ -120,29 +121,25 @@ define([
120121
gl.activeTexture(gl.TEXTURE0);
121122
gl.bindTexture(textureTarget, texture);
122123

123-
function createFace(target, sourceFace, preMultiplyAlpha, flipY) {
124-
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
124+
function createFace(target, sourceFace) {
125125
if (sourceFace.arrayBufferView) {
126-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
127-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
128126
gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, sourceFace.arrayBufferView);
129127
} else {
130-
// Only valid for DOM-Element uploads
131-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
132-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
133-
134-
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
135128
gl.texImage2D(target, 0, pixelFormat, pixelFormat, pixelDatatype, sourceFace);
136129
}
137130
}
138131

139132
if (defined(source)) {
140-
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X, source.positiveX, preMultiplyAlpha, flipY);
141-
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, source.negativeX, preMultiplyAlpha, flipY);
142-
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY, preMultiplyAlpha, flipY);
143-
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY, preMultiplyAlpha, flipY);
144-
createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ, preMultiplyAlpha, flipY);
145-
createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ, preMultiplyAlpha, flipY);
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);
146143
} else {
147144
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
148145
gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
@@ -166,13 +163,12 @@ define([
166163
this._flipY = flipY;
167164
this._sampler = undefined;
168165

169-
var initialized = defined(source);
170-
this._positiveX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
171-
this._negativeX = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_X, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
172-
this._positiveY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
173-
this._negativeY = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
174-
this._positiveZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_POSITIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
175-
this._negativeZ = new CubeMapFace(gl, texture, textureTarget, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized);
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);
176172

177173
this.sampler = defined(options.sampler) ? options.sampler : new Sampler();
178174
}

Source/Renderer/CubeMapFace.js

+18-61
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
define([
2-
'../Core/Check',
3-
'../Core/defaultValue',
4-
'../Core/defined',
5-
'../Core/defineProperties',
6-
'../Core/DeveloperError',
7-
'../Core/PixelFormat',
8-
'./PixelDatatype'
9-
], function(
10-
Check,
11-
defaultValue,
12-
defined,
13-
defineProperties,
14-
DeveloperError,
15-
PixelFormat,
16-
PixelDatatype) {
2+
'../Core/Check',
3+
'../Core/defaultValue',
4+
'../Core/defineProperties',
5+
'../Core/DeveloperError',
6+
'./PixelDatatype'
7+
], function(
8+
Check,
9+
defaultValue,
10+
defineProperties,
11+
DeveloperError,
12+
PixelDatatype) {
1713
'use strict';
1814

1915
/**
2016
* @private
2117
*/
22-
function CubeMapFace(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY, initialized) {
18+
function CubeMapFace(gl, texture, textureTarget, targetFace, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY) {
2319
this._gl = gl;
2420
this._texture = texture;
2521
this._textureTarget = textureTarget;
@@ -29,7 +25,6 @@ define([
2925
this._size = size;
3026
this._preMultiplyAlpha = preMultiplyAlpha;
3127
this._flipY = flipY;
32-
this._initialized = initialized;
3328
}
3429

3530
defineProperties(CubeMapFace.prototype, {
@@ -96,52 +91,15 @@ define([
9691
var target = this._textureTarget;
9792

9893
// TODO: gl.pixelStorei(gl._UNPACK_ALIGNMENT, 4);
99-
94+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
95+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
10096
gl.activeTexture(gl.TEXTURE0);
10197
gl.bindTexture(target, this._texture);
10298

103-
var uploaded = false;
104-
if (!this._initialized) {
105-
if (xOffset === 0 && yOffset === 0 && source.width === this._size && source.height === this._size) {
106-
// initialize the entire texture
107-
if (defined(source.arrayBufferView)) {
108-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
109-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
110-
111-
gl.texImage2D(this._targetFace, 0, this._pixelFormat, this._size, this._size, 0, this._pixelFormat, this._pixelDatatype, source.arrayBufferView);
112-
} else {
113-
// Only valid for DOM-Element uploads
114-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
115-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
116-
117-
gl.texImage2D(this._targetFace, 0, this._pixelFormat, this._pixelFormat, this._pixelDatatype, source);
118-
}
119-
uploaded = true;
120-
} else {
121-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
122-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
123-
124-
// initialize the entire texture to zero
125-
var bufferView = PixelFormat.createTypedArray(this._pixelFormat, this._pixelDatatype, this._size, this._size);
126-
gl.texImage2D(this._targetFace, 0, this._pixelFormat, this._size, this._size, 0, this._pixelFormat, this._pixelDatatype, bufferView);
127-
}
128-
this._initialized = true;
129-
}
130-
131-
if (!uploaded) {
132-
if (source.arrayBufferView) {
133-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
134-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
135-
136-
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, source.width, source.height, this._pixelFormat, this._pixelDatatype, source.arrayBufferView);
137-
} else {
138-
// Only valid for DOM-Element uploads
139-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._preMultiplyAlpha);
140-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this._flipY);
141-
142-
// Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
143-
gl.texSubImage2D(this._targetFace, 0, xOffset, yOffset, this._pixelFormat, this._pixelDatatype, source);
144-
}
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);
145103
}
146104

147105
gl.bindTexture(target, null);
@@ -202,7 +160,6 @@ define([
202160
gl.bindTexture(target, this._texture);
203161
gl.copyTexSubImage2D(this._targetFace, 0, xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height);
204162
gl.bindTexture(target, null);
205-
this._initialized = true;
206163
};
207164

208165
return CubeMapFace;

0 commit comments

Comments
 (0)