(texture: GPUTexture)
| 64 | } |
| 65 | |
| 66 | releaseTexture(texture: GPUTexture) { |
| 67 | if (this.freeTextures.size === 0) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | const width = texture.width; |
| 72 | const height = texture.height; |
| 73 | const format = texture.format; |
| 74 | const usage = texture.usage; |
| 75 | |
| 76 | const key = getTextureKey(width, height, format, usage); |
| 77 | if (!this.freeTextures.has(key)) { |
| 78 | this.freeTextures.set(key, []); |
| 79 | } |
| 80 | |
| 81 | this.freeTextures.get(key).push(texture); |
| 82 | this.numFreeTextures++; |
| 83 | this.numUsedTextures--; |
| 84 | |
| 85 | const textureList = this.usedTextures.get(key); |
| 86 | const textureIndex = textureList.indexOf(texture); |
| 87 | if (textureIndex < 0) { |
| 88 | throw new Error( |
| 89 | 'Cannot release a texture that was never provided by this ' + |
| 90 | 'texture manager'); |
| 91 | } |
| 92 | textureList.splice(textureIndex, 1); |
| 93 | const bytesPerElement = getBytesPerElement(format); |
| 94 | const byteSize = width * height * bytesPerElement; |
| 95 | this.numBytesUsed -= byteSize; |
| 96 | } |
| 97 | |
| 98 | getNumUsedTextures(): number { |
| 99 | return this.numUsedTextures; |
no test coverage detected