Skip to content

Commit 9217b49

Browse files
committed
update texture units
1 parent 133b9f2 commit 9217b49

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

webgl/lessons/webgl-texture-units.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,19 @@ You then tell the shader which texture unit you bound the texture to by calling
6464
gl.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+
7280
gl.activeTexture = function(unit) {
7381
gl.activeTextureUnit = unit - gl.TEXTURE0; // convert to 0 based index
7482
};
@@ -88,7 +96,8 @@ be implemented something like
8896
gl.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

94103
gl.texParameteri = function(target, pname, value) {

0 commit comments

Comments
 (0)