@@ -33,7 +33,6 @@ define([
33
33
'use strict' ;
34
34
35
35
function CubeMap ( options ) {
36
-
37
36
options = defaultValue ( options , defaultValue . EMPTY_OBJECT ) ;
38
37
39
38
//>>includeStart('debug', pragmas.debug);
@@ -121,25 +120,34 @@ define([
121
120
gl . activeTexture ( gl . TEXTURE0 ) ;
122
121
gl . bindTexture ( textureTarget , texture ) ;
123
122
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 ) ;
127
134
} 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
128
140
gl . texImage2D ( target , 0 , pixelFormat , pixelFormat , pixelDatatype , sourceFace ) ;
129
141
}
130
142
}
131
143
132
144
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 ) ;
143
151
} else {
144
152
gl . texImage2D ( gl . TEXTURE_CUBE_MAP_POSITIVE_X , 0 , pixelFormat , size , size , 0 , pixelFormat , pixelDatatype , null ) ;
145
153
gl . texImage2D ( gl . TEXTURE_CUBE_MAP_NEGATIVE_X , 0 , pixelFormat , size , size , 0 , pixelFormat , pixelDatatype , null ) ;
@@ -163,12 +171,13 @@ define([
163
171
this . _flipY = flipY ;
164
172
this . _sampler = undefined ;
165
173
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 ) ;
172
181
173
182
this . sampler = defined ( options . sampler ) ? options . sampler : new Sampler ( ) ;
174
183
}
0 commit comments