@@ -64,11 +64,19 @@ You then tell the shader which texture unit you bound the texture to by calling
64
64
gl .uniform1i (someTextureUniformLocation, indexOfTextureUnit);
65
65
```
66
66
67
- If ` activeTexture ` and ` bindTexture ` WebGL functions were implemented in JavaScript they'd look
68
- something like:
67
+ If ` createTexture ` , ` activeTexture ` and ` bindTexture ` WebGL functions were
68
+ implemented in JavaScript they'd look something like:
69
69
70
70
``` js
71
71
// PSEUDO CODE!!!
72
+ gl .createTexture = function () {
73
+ return new Texture ();
74
+ };
75
+
76
+ class Texture () {
77
+ mips = [new Array (6 )]; // faces of mip levels
78
+ }
79
+
72
80
gl .activeTexture = function (unit ) {
73
81
gl .activeTextureUnit = unit - gl .TEXTURE0 ; // convert to 0 based index
74
82
};
@@ -88,7 +96,8 @@ be implemented something like
88
96
gl .texImage2D = function (target , level , internalFormat , width , height , border , format , type , data ) {
89
97
const textureUnit = gl .textureUnits [gl .activeTextureUnit ];
90
98
const texture = textureUnit[target];
91
- texture .mips [level] = convertDataToInternalFormat (internalFormat, width, height, format, type, data);
99
+ const face = targetToFace (target) // 0-5, 0 for 2D texture, 0-5 for cube maps
100
+ texture .mips [face][level] = convertDataToInternalFormat (internalFormat, width, height, format, type, data);
92
101
}
93
102
94
103
gl .texParameteri = function (target , pname , value ) {
0 commit comments