Skip to content

Commit 51ea354

Browse files
committed
Rename slices to layers to better match WebGPU naming but also gl.framebufferTextureLayer
1 parent 8787cfe commit 51ea354

File tree

8 files changed

+66
-66
lines changed

8 files changed

+66
-66
lines changed

examples/src/examples/graphics/texture-array.example.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ assetListLoader.load(() => {
108108
dimension: pc.TEXTUREDIMENSION_2D_ARRAY,
109109
width: 1024,
110110
height: 1024,
111-
slices: 4, // array texture with 4 textures
111+
layers: 4, // array texture with 4 textures
112112
magFilter: pc.FILTER_NEAREST,
113113
minFilter: pc.FILTER_NEAREST_MIPMAP_NEAREST,
114114
mipmaps: true,
@@ -131,7 +131,7 @@ assetListLoader.load(() => {
131131
const mipmaps = generateMipmaps(textureArrayOptions.width, textureArrayOptions.height);
132132
const levels = mipmaps.map((data) => {
133133
const textures = [];
134-
for (let i = 0; i < textureArrayOptions.slices; i++) {
134+
for (let i = 0; i < textureArrayOptions.layers; i++) {
135135
textures.push(data);
136136
}
137137
return textures;

src/framework/handlers/texture.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ const _completePartialMipmapChain = function (texture) {
101101
const height = Math.max(1, texture._height >> (level - 1));
102102
if (texture.cubemap || texture.array) {
103103
const mips = [];
104-
for (let slice = 0; slice < texture.slices; ++slice) {
105-
mips.push(downsample(width, height, texture._levels[level - 1][slice]));
104+
for (let layer = 0; layer < texture.layers; ++layer) {
105+
mips.push(downsample(width, height, texture._levels[level - 1][layer]));
106106
}
107107
texture._levels.push(mips);
108108
} else {
109109
texture._levels.push(downsample(width, height, texture._levels[level - 1]));
110110
}
111111
}
112112

113-
texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.slices).fill(true)] : [true];
113+
texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.layers).fill(true)] : [true];
114114
};
115115

116116
/**

src/framework/xr/xr-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class XrView extends EventHandler {
173173
this._textureDepth = new Texture(device, {
174174
format: this._manager.views.depthPixelFormat,
175175
array: viewsCount > 1,
176-
slices: viewsCount,
176+
layers: viewsCount,
177177
mipmaps: false,
178178
addressU: ADDRESS_CLAMP_TO_EDGE,
179179
addressV: ADDRESS_CLAMP_TO_EDGE,

src/platform/graphics/texture-utils.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TextureUtils {
2626
*
2727
* @param {number} width - Texture's width.
2828
* @param {number} height - Texture's height.
29-
* @param {number} [depth] - Texture's depth slices. Defaults to 1.
29+
* @param {number} [depth] - Texture's depth layers. Defaults to 1.
3030
* @returns {number} The number of mip levels required for the texture.
3131
*/
3232
static calcMipLevelsCount(width, height, depth = 1) {
@@ -38,7 +38,7 @@ class TextureUtils {
3838
*
3939
* @param {number} width - Texture's width.
4040
* @param {number} height - Texture's height.
41-
* @param {number} depth - Texture's depth slices.
41+
* @param {number} depth - Texture's depth layers.
4242
* @param {number} format - Texture's pixel format PIXELFORMAT_***.
4343
* @returns {number} The number of bytes of GPU memory required for the texture.
4444
*/
@@ -70,15 +70,15 @@ class TextureUtils {
7070
*
7171
* @param {number} width - Texture's width.
7272
* @param {number} height - Texture's height.
73-
* @param {number} slices - Texture's slices.
73+
* @param {number} layers - Texture's layers.
7474
* @param {number} format - Texture's pixel format PIXELFORMAT_***.
7575
* @param {boolean} isVolume - True if the texture is a volume texture, false otherwise.
7676
* @param {boolean} mipmaps - True if the texture includes mipmaps, false otherwise.
7777
* @returns {number} The number of bytes of GPU memory required for the texture.
7878
*/
79-
static calcGpuSize(width, height, slices, format, isVolume, mipmaps) {
79+
static calcGpuSize(width, height, layers, format, isVolume, mipmaps) {
8080
let result = 0;
81-
let depth = isVolume ? slices : 1;
81+
let depth = isVolume ? layers : 1;
8282

8383
while (1) {
8484
result += TextureUtils.calcLevelGpuSize(width, height, depth, format);
@@ -92,7 +92,7 @@ class TextureUtils {
9292
depth = Math.max(depth >> 1, 1);
9393
}
9494

95-
return result * (isVolume ? 1 : slices);
95+
return result * (isVolume ? 1 : layers);
9696
}
9797
}
9898

src/platform/graphics/texture.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Texture {
9494
* @param {string} [options.name] - The name of the texture. Defaults to null.
9595
* @param {number} [options.width] - The width of the texture in pixels. Defaults to 4.
9696
* @param {number} [options.height] - The height of the texture in pixels. Defaults to 4.
97-
* @param {number} [options.slices] - The number of depth slices in a 3D texture, the number of textures
97+
* @param {number} [options.layers] - The number of depth layers in a 3D texture, the number of textures
9898
* in a texture array or the number of faces for a cubemap.
9999
* @param {string} [options.dimension] - The texture dimension type. Can be:
100100
* - {@link TEXTUREDIMENSION_2D}
@@ -221,7 +221,7 @@ class Texture {
221221
Debug.assert(this.device, "Texture constructor requires a graphicsDevice to be valid");
222222
Debug.assert(!options.width || Number.isInteger(options.width), "Texture width must be an integer number, got", options);
223223
Debug.assert(!options.height || Number.isInteger(options.height), "Texture height must be an integer number, got", options);
224-
Debug.assert(!options.slices || Number.isInteger(options.slices), "Texture slices must be an integer number, got", options);
224+
Debug.assert(!options.layers || Number.isInteger(options.layers), "Texture layers must be an integer number, got", options);
225225

226226
this.name = options.name ?? '';
227227

@@ -233,9 +233,9 @@ class Texture {
233233
this._width = Math.floor(options.width ?? 4);
234234
this._height = Math.floor(options.height ?? 4);
235235

236-
this._slices = Math.floor(options.slices ?? (this._dimension === TEXTUREDIMENSION_CUBE ? 6 : 1));
236+
this._layers = Math.floor(options.layers ?? (this._dimension === TEXTUREDIMENSION_CUBE ? 6 : 1));
237237

238-
Debug.assert((this._dimension === TEXTUREDIMENSION_CUBE ? this._slices === 6 : true), "Texture cube map must have 6 slices");
238+
Debug.assert((this._dimension === TEXTUREDIMENSION_CUBE ? this._layers === 6 : true), "Texture cube map must have 6 layers");
239239

240240
this._format = options.format ?? PIXELFORMAT_RGBA8;
241241
this._compressed = isCompressedPixelFormat(this._format);
@@ -284,7 +284,7 @@ class Texture {
284284
if (this._levels) {
285285
this.upload(options.immediate ?? false);
286286
} else {
287-
this._levels = (this.cubemap || this.array) ? [Array(this._slices).fill(null)] : [null];
287+
this._levels = (this.cubemap || this.array) ? [Array(this._layers).fill(null)] : [null];
288288
}
289289

290290
// track the texture
@@ -332,10 +332,10 @@ class Texture {
332332
*
333333
* @param {number} width - The new width of the texture.
334334
* @param {number} height - The new height of the texture.
335-
* @param {number} [slices] - The new number of slices for the texture. Defaults to 1.
335+
* @param {number} [layers] - The new number of layers for the texture. Defaults to 1.
336336
* @ignore
337337
*/
338-
resize(width, height, slices = 1) {
338+
resize(width, height, layers = 1) {
339339

340340
// destroy texture impl
341341
const device = this.device;
@@ -344,7 +344,7 @@ class Texture {
344344

345345
this._width = Math.floor(width);
346346
this._height = Math.floor(height);
347-
this._slices = Math.floor(slices);
347+
this._layers = Math.floor(layers);
348348

349349
// re-create the implementation
350350
this.impl = device.createTextureImpl(this);
@@ -681,21 +681,21 @@ class Texture {
681681
}
682682

683683
/**
684-
* The number of depth slices in a 3D texture.
684+
* The number of depth layers in a 3D texture.
685685
*
686686
* @type {number}
687687
*/
688688
get depth() {
689-
return this._dimension === TEXTUREDIMENSION_3D ? this._slices : 1;
689+
return this._dimension === TEXTUREDIMENSION_3D ? this._layers : 1;
690690
}
691691

692692
/**
693693
* The number of textures in a texture array or the number of faces for a cubemap.
694694
*
695695
* @type {number}
696696
*/
697-
get slices() {
698-
return this._slices;
697+
get layers() {
698+
return this._layers;
699699
}
700700

701701
/**
@@ -742,7 +742,7 @@ class Texture {
742742

743743
get gpuSize() {
744744
const mips = this.pot && this._mipmaps && !(this._compressed && this._levels.length === 1);
745-
return TextureUtils.calcGpuSize(this._width, this._height, this._slices, this._format, this.volume, mips);
745+
return TextureUtils.calcGpuSize(this._width, this._height, this._layers, this._format, this.volume, mips);
746746
}
747747

748748
/**
@@ -823,7 +823,7 @@ class Texture {
823823

824824
// Force a full resubmission of the texture to the GPU (used on a context restore event)
825825
dirtyAll() {
826-
this._levelsUpdated = (this.cubemap || this.array) ? [Array(this._slices).fill(true)] : [true];
826+
this._levelsUpdated = (this.cubemap || this.array) ? [Array(this._layers).fill(true)] : [true];
827827

828828
this._needsUpload = true;
829829
this._needsMipmapsUpload = this._mipmaps;
@@ -840,8 +840,8 @@ class Texture {
840840
* to 0.
841841
* @param {number} [options.face] - If the texture is a cubemap, this is the index of the face
842842
* to lock.
843-
* @param {number} [options.slice] - If the texture is a texture array, this is the index of the
844-
* slice to lock.
843+
* @param {number} [options.layer] - If the texture is a texture array, this is the index of the
844+
* layer to lock.
845845
* @param {number} [options.mode] - The lock mode. Can be:
846846
* - {@link TEXTURELOCK_READ}
847847
* - {@link TEXTURELOCK_WRITE}
@@ -853,7 +853,7 @@ class Texture {
853853
// Initialize options to some sensible defaults
854854
options.level ??= 0;
855855
options.face ??= 0;
856-
options.slice ??= 0;
856+
options.layer ??= 0;
857857
options.mode ??= TEXTURELOCK_WRITE;
858858

859859
Debug.assert(
@@ -882,7 +882,7 @@ class Texture {
882882

883883
this._lockedMode = options.mode;
884884

885-
const levels = this.cubemap ? this._levels[options.face] : this.array ? this._levels[options.slice] : this._levels;
885+
const levels = this.cubemap ? this._levels[options.face] : this.array ? this._levels[options.layer] : this._levels;
886886
if (levels[options.level] === null) {
887887
// allocate storage for this mip level
888888
const width = Math.max(1, this._width >> options.level);
@@ -894,7 +894,7 @@ class Texture {
894894

895895
if (this._lockedMode === TEXTURELOCK_WRITE) {
896896
if (this.cubemap || this.array) {
897-
this._levelsUpdated[0][options.face ?? options.slice] = true;
897+
this._levelsUpdated[0][options.face ?? options.layer] = true;
898898
} else {
899899
this._levelsUpdated[0] = true;
900900
}
@@ -923,7 +923,7 @@ class Texture {
923923
width = source[0].width || 0;
924924
height = source[0].height || 0;
925925

926-
for (let i = 0; i < this._slices; i++) {
926+
for (let i = 0; i < this._layers; i++) {
927927
const face = source[i];
928928
// cubemap becomes invalid if any condition is not satisfied
929929
if (!face || // face is missing
@@ -941,7 +941,7 @@ class Texture {
941941

942942
if (!invalid) {
943943
// mark levels as updated
944-
for (let i = 0; i < this._slices; i++) {
944+
for (let i = 0; i < this._layers; i++) {
945945
if (this._levels[0][i] !== source[i])
946946
this._levelsUpdated[0][i] = true;
947947
}
@@ -971,7 +971,7 @@ class Texture {
971971

972972
// remove levels
973973
if (this.cubemap || this.array) {
974-
for (let i = 0; i < this._slices; i++) {
974+
for (let i = 0; i < this._layers; i++) {
975975
this._levels[0][i] = null;
976976
this._levelsUpdated[0][i] = true;
977977
}

src/platform/graphics/webgl/webgl-texture.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ class WebglTexture {
482482
if (texture.array && !this._glCreated) {
483483
// for texture arrays we reserve the space in advance
484484
gl.texStorage3D(gl.TEXTURE_2D_ARRAY,
485-
requiredMipLevels,
486-
this._glInternalFormat,
487-
texture._width,
488-
texture._height,
489-
texture._slices);
485+
requiredMipLevels,
486+
this._glInternalFormat,
487+
texture._width,
488+
texture._height,
489+
texture._layers);
490490
}
491491

492492
// Upload all existing mip levels. Initialize 0 mip anyway.
@@ -516,9 +516,9 @@ class WebglTexture {
516516

517517
if (device._isBrowserInterface(mipObject[0])) {
518518
// Upload the image, canvas or video
519-
for (face = 0; face < texture.slices; face++) {
519+
for (face = 0; face < texture.layers; face++) {
520520
let src = mipObject[face];
521-
if (!texture._levelsUpdated[0][face] || !src)
521+
if (!texture._levelsUpdated[0][face] || !src) {
522522
continue;
523523
}
524524

@@ -559,9 +559,9 @@ class WebglTexture {
559559
} else {
560560
// Upload the byte array
561561
resMult = 1 / Math.pow(2, mipLevel);
562-
for (face = 0; face < texture.slices; face++) {
562+
for (face = 0; face < texture.layers; face++) {
563563
const texData = mipObject[face];
564-
if (!texture._levelsUpdated[0][face])
564+
if (!texture._levelsUpdated[0][face]) {
565565
continue;
566566
}
567567

@@ -622,30 +622,30 @@ class WebglTexture {
622622
// Upload the byte array
623623
if (texture._compressed) {
624624
gl.compressedTexImage3D(gl.TEXTURE_3D,
625-
mipLevel,
626-
this._glInternalFormat,
627-
Math.max(texture._width * resMult, 1),
628-
Math.max(texture._height * resMult, 1),
629-
Math.max(texture._slices * resMult, 1),
630-
0,
631-
mipObject);
625+
mipLevel,
626+
this._glInternalFormat,
627+
Math.max(texture._width * resMult, 1),
628+
Math.max(texture._height * resMult, 1),
629+
Math.max(texture._layers * resMult, 1),
630+
0,
631+
mipObject);
632632
} else {
633633
device.setUnpackFlipY(false);
634634
device.setUnpackPremultiplyAlpha(texture._premultiplyAlpha);
635635
gl.texImage3D(gl.TEXTURE_3D,
636-
mipLevel,
637-
this._glInternalFormat,
638-
Math.max(texture._width * resMult, 1),
639-
Math.max(texture._height * resMult, 1),
640-
Math.max(texture._slices * resMult, 1),
641-
0,
642-
this._glFormat,
643-
this._glPixelType,
644-
mipObject);
636+
mipLevel,
637+
this._glInternalFormat,
638+
Math.max(texture._width * resMult, 1),
639+
Math.max(texture._height * resMult, 1),
640+
Math.max(texture._layers * resMult, 1),
641+
0,
642+
this._glFormat,
643+
this._glPixelType,
644+
mipObject);
645645
}
646646
} else if (texture.array && typeof mipObject === "object") {
647647
if (texture._compressed) {
648-
for (let index = 0; index < texture._slices; index++) {
648+
for (let index = 0; index < texture._layers; index++) {
649649
if (!texture._levelsUpdated[0][index] || !mipObject[index])
650650
continue;
651651
gl.compressedTexSubImage3D(
@@ -662,7 +662,7 @@ class WebglTexture {
662662
);
663663
}
664664
} else {
665-
for (let index = 0; index < texture.slices; index++) {
665+
for (let index = 0; index < texture.layers; index++) {
666666
if (!texture._levelsUpdated[0][index] || !mipObject[index])
667667
continue;
668668
gl.texSubImage3D(
@@ -793,7 +793,7 @@ class WebglTexture {
793793

794794
if (texture._needsUpload) {
795795
if (texture.cubemap || texture.array) {
796-
for (let i = 0; i < texture.slices; i++)
796+
for (let i = 0; i < texture.layers; i++) {
797797
texture._levelsUpdated[0][i] = false;
798798
}
799799
} else {

src/platform/graphics/webgpu/webgpu-mipmap-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class WebgpuMipmapRenderer {
110110
DebugHelper.setLabel(pipeline, 'RenderPipeline-MipmapRenderer');
111111

112112
const texture = webgpuTexture.texture;
113-
const numFaces = texture.slices;
113+
const numFaces = texture.layers;
114114

115115
const srcViews = [];
116116
for (let face = 0; face < numFaces; face++) {

src/platform/graphics/webgpu/webgpu-texture.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class WebgpuTexture {
100100
size: {
101101
width: texture.width,
102102
height: texture.height,
103-
depthOrArrayLayers: texture.slices
103+
depthOrArrayLayers: texture.layers
104104
},
105105
format: this.format,
106106
mipLevelCount: mipLevelCount,
@@ -337,9 +337,9 @@ class WebgpuTexture {
337337

338338
} else if (texture.array) { // texture array
339339

340-
if (texture.slices === mipObject.length) {
340+
if (texture.layers === mipObject.length) {
341341

342-
for (let index = 0; index < texture.slices; index++) {
342+
for (let index = 0; index < texture.layers; index++) {
343343
const arraySource = mipObject[index];
344344

345345
if (this.isExternalImage(arraySource)) {

0 commit comments

Comments
 (0)