@@ -64,11 +64,19 @@ You then tell the shader which texture unit you bound the texture to by calling
6464gl .uniform1i (someTextureUniformLocation, indexOfTextureUnit);
6565```
6666
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:
6969
7070``` js
7171// 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+
7280gl .activeTexture = function (unit ) {
7381 gl .activeTextureUnit = unit - gl .TEXTURE0 ; // convert to 0 based index
7482};
@@ -88,7 +96,8 @@ be implemented something like
8896gl .texImage2D = function (target , level , internalFormat , width , height , border , format , type , data ) {
8997 const textureUnit = gl .textureUnits [gl .activeTextureUnit ];
9098 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);
92101}
93102
94103gl .texParameteri = function (target , pname , value ) {
0 commit comments