Skip to content

Commit 50cbd9b

Browse files
committed
Rename slices to layers to better match WebGPU naming but also gl.framebufferTextureLayer
1 parent 67f5dc9 commit 50cbd9b

File tree

8 files changed

+46
-46
lines changed

8 files changed

+46
-46
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ assetListLoader.load(() => {
135135
dimension: pc.TEXTUREDIMENSION_2D_ARRAY,
136136
width: 1024,
137137
height: 1024,
138-
slices: 4, // array texture with 4 textures
138+
layers: 4, // array texture with 4 textures
139139
magFilter: pc.FILTER_NEAREST,
140140
minFilter: pc.FILTER_NEAREST_MIPMAP_NEAREST,
141141
mipmaps: true,
@@ -158,7 +158,7 @@ assetListLoader.load(() => {
158158
const mipmaps = generateMipmaps(textureArrayOptions.width, textureArrayOptions.height);
159159
const levels = mipmaps.map((data) => {
160160
const textures = [];
161-
for (let i = 0; i < textureArrayOptions.slices; i++) {
161+
for (let i = 0; i < textureArrayOptions.layers; i++) {
162162
textures.push(data);
163163
}
164164
return textures;

src/framework/handlers/texture.js

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

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

115115
/**

src/framework/xr/xr-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class XrView extends EventHandler {
171171
this._textureDepth = new Texture(device, {
172172
format: this._manager.views.depthPixelFormat,
173173
array: viewsCount > 1,
174-
slices: viewsCount,
174+
layers: viewsCount,
175175
mipmaps: false,
176176
addressU: ADDRESS_CLAMP_TO_EDGE,
177177
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
@@ -102,7 +102,7 @@ class Texture {
102102
* @param {string} [options.name] - The name of the texture. Defaults to null.
103103
* @param {number} [options.width] - The width of the texture in pixels. Defaults to 4.
104104
* @param {number} [options.height] - The height of the texture in pixels. Defaults to 4.
105-
* @param {number} [options.slices] - The number of depth slices in a 3D texture, the number of textures
105+
* @param {number} [options.layers] - The number of depth layers in a 3D texture, the number of textures
106106
* in a texture array or the number of faces for a cubemap.
107107
* @param {string} [options.dimension] - The texture dimension type. Can be:
108108
* - {@link TEXTUREDIMENSION_2D}
@@ -229,7 +229,7 @@ class Texture {
229229
Debug.assert(this.device, "Texture constructor requires a graphicsDevice to be valid");
230230
Debug.assert(!options.width || Number.isInteger(options.width), "Texture width must be an integer number, got", options);
231231
Debug.assert(!options.height || Number.isInteger(options.height), "Texture height must be an integer number, got", options);
232-
Debug.assert(!options.slices || Number.isInteger(options.slices), "Texture slices must be an integer number, got", options);
232+
Debug.assert(!options.layers || Number.isInteger(options.layers), "Texture layers must be an integer number, got", options);
233233

234234
this.name = options.name ?? '';
235235

@@ -241,9 +241,9 @@ class Texture {
241241
this._width = Math.floor(options.width ?? 4);
242242
this._height = Math.floor(options.height ?? 4);
243243

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

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

248248
this._format = options.format ?? PIXELFORMAT_RGBA8;
249249
this._compressed = isCompressedPixelFormat(this._format);
@@ -292,7 +292,7 @@ class Texture {
292292
if (this._levels) {
293293
this.upload(options.immediate ?? false);
294294
} else {
295-
this._levels = (this.cubemap || this.array) ? [Array(this._slices).fill(null)] : [null];
295+
this._levels = (this.cubemap || this.array) ? [Array(this._layers).fill(null)] : [null];
296296
}
297297

298298
// track the texture
@@ -340,10 +340,10 @@ class Texture {
340340
*
341341
* @param {number} width - The new width of the texture.
342342
* @param {number} height - The new height of the texture.
343-
* @param {number} [slices] - The new number of slices for the texture. Defaults to 1.
343+
* @param {number} [layers] - The new number of layers for the texture. Defaults to 1.
344344
* @ignore
345345
*/
346-
resize(width, height, slices = 1) {
346+
resize(width, height, layers = 1) {
347347

348348
// destroy texture impl
349349
const device = this.device;
@@ -352,7 +352,7 @@ class Texture {
352352

353353
this._width = Math.floor(width);
354354
this._height = Math.floor(height);
355-
this._slices = Math.floor(slices);
355+
this._layers = Math.floor(layers);
356356

357357
// re-create the implementation
358358
this.impl = device.createTextureImpl(this);
@@ -689,21 +689,21 @@ class Texture {
689689
}
690690

691691
/**
692-
* The number of depth slices in a 3D texture.
692+
* The number of depth layers in a 3D texture.
693693
*
694694
* @type {number}
695695
*/
696696
get depth() {
697-
return this._dimension === TEXTUREDIMENSION_3D ? this._slices : 1;
697+
return this._dimension === TEXTUREDIMENSION_3D ? this._layers : 1;
698698
}
699699

700700
/**
701701
* The number of textures in a texture array or the number of faces for a cubemap.
702702
*
703703
* @type {number}
704704
*/
705-
get slices() {
706-
return this._slices;
705+
get layers() {
706+
return this._layers;
707707
}
708708

709709
/**
@@ -750,7 +750,7 @@ class Texture {
750750

751751
get gpuSize() {
752752
const mips = this.pot && this._mipmaps && !(this._compressed && this._levels.length === 1);
753-
return TextureUtils.calcGpuSize(this._width, this._height, this._slices, this._format, this.volume, mips);
753+
return TextureUtils.calcGpuSize(this._width, this._height, this._layers, this._format, this.volume, mips);
754754
}
755755

756756
/**
@@ -831,7 +831,7 @@ class Texture {
831831

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

836836
this._needsUpload = true;
837837
this._needsMipmapsUpload = this._mipmaps;
@@ -848,8 +848,8 @@ class Texture {
848848
* to 0.
849849
* @param {number} [options.face] - If the texture is a cubemap, this is the index of the face
850850
* to lock.
851-
* @param {number} [options.slice] - If the texture is a texture array, this is the index of the
852-
* slice to lock.
851+
* @param {number} [options.layer] - If the texture is a texture array, this is the index of the
852+
* layer to lock.
853853
* @param {number} [options.mode] - The lock mode. Can be:
854854
* - {@link TEXTURELOCK_READ}
855855
* - {@link TEXTURELOCK_WRITE}
@@ -861,7 +861,7 @@ class Texture {
861861
// Initialize options to some sensible defaults
862862
options.level ??= 0;
863863
options.face ??= 0;
864-
options.slice ??= 0;
864+
options.layer ??= 0;
865865
options.mode ??= TEXTURELOCK_WRITE;
866866

867867
Debug.assert(
@@ -890,7 +890,7 @@ class Texture {
890890

891891
this._lockedMode = options.mode;
892892

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

903903
if (this._lockedMode === TEXTURELOCK_WRITE) {
904904
if (this.cubemap || this.array) {
905-
this._levelsUpdated[0][options.face ?? options.slice] = true;
905+
this._levelsUpdated[0][options.face ?? options.layer] = true;
906906
} else {
907907
this._levelsUpdated[0] = true;
908908
}
@@ -931,7 +931,7 @@ class Texture {
931931
width = source[0].width || 0;
932932
height = source[0].height || 0;
933933

934-
for (let i = 0; i < this._slices; i++) {
934+
for (let i = 0; i < this._layers; i++) {
935935
const face = source[i];
936936
// cubemap becomes invalid if any condition is not satisfied
937937
if (!face || // face is missing
@@ -949,7 +949,7 @@ class Texture {
949949

950950
if (!invalid) {
951951
// mark levels as updated
952-
for (let i = 0; i < this._slices; i++) {
952+
for (let i = 0; i < this._layers; i++) {
953953
if (this._levels[0][i] !== source[i])
954954
this._levelsUpdated[0][i] = true;
955955
}
@@ -978,7 +978,7 @@ class Texture {
978978

979979
// remove levels
980980
if (this.cubemap || this.array) {
981-
for (let i = 0; i < this._slices; i++) {
981+
for (let i = 0; i < this._layers; i++) {
982982
this._levels[0][i] = null;
983983
this._levelsUpdated[0][i] = true;
984984
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class WebglTexture {
463463
this._glInternalFormat,
464464
texture._width,
465465
texture._height,
466-
texture._slices);
466+
texture._layers);
467467
}
468468

469469
// Upload all existing mip levels. Initialize 0 mip anyway.
@@ -493,7 +493,7 @@ class WebglTexture {
493493

494494
if (device._isBrowserInterface(mipObject[0])) {
495495
// Upload the image, canvas or video
496-
for (face = 0; face < texture.slices; face++) {
496+
for (face = 0; face < texture.layers; face++) {
497497
let src = mipObject[face];
498498
if (!texture._levelsUpdated[0][face] || !src)
499499
continue;
@@ -535,7 +535,7 @@ class WebglTexture {
535535
} else {
536536
// Upload the byte array
537537
resMult = 1 / Math.pow(2, mipLevel);
538-
for (face = 0; face < texture.slices; face++) {
538+
for (face = 0; face < texture.layers; face++) {
539539
const texData = mipObject[face];
540540
if (!texture._levelsUpdated[0][face])
541541
continue;
@@ -601,7 +601,7 @@ class WebglTexture {
601601
this._glInternalFormat,
602602
Math.max(texture._width * resMult, 1),
603603
Math.max(texture._height * resMult, 1),
604-
Math.max(texture._slices * resMult, 1),
604+
Math.max(texture._layers * resMult, 1),
605605
0,
606606
mipObject);
607607
} else {
@@ -612,15 +612,15 @@ class WebglTexture {
612612
this._glInternalFormat,
613613
Math.max(texture._width * resMult, 1),
614614
Math.max(texture._height * resMult, 1),
615-
Math.max(texture._slices * resMult, 1),
615+
Math.max(texture._layers * resMult, 1),
616616
0,
617617
this._glFormat,
618618
this._glPixelType,
619619
mipObject);
620620
}
621621
} else if (texture.array && typeof mipObject === "object") {
622622
if (texture._compressed) {
623-
for (let index = 0; index < texture._slices; index++) {
623+
for (let index = 0; index < texture._layers; index++) {
624624
if (!texture._levelsUpdated[0][index] || !mipObject[index])
625625
continue;
626626
gl.compressedTexSubImage3D(
@@ -637,7 +637,7 @@ class WebglTexture {
637637
);
638638
}
639639
} else {
640-
for (let index = 0; index < texture.slices; index++) {
640+
for (let index = 0; index < texture.layers; index++) {
641641
if (!texture._levelsUpdated[0][index] || !mipObject[index])
642642
continue;
643643
gl.texSubImage3D(
@@ -768,7 +768,7 @@ class WebglTexture {
768768

769769
if (texture._needsUpload) {
770770
if (texture.cubemap || texture.array) {
771-
for (let i = 0; i < texture.slices; i++)
771+
for (let i = 0; i < texture.layers; i++)
772772
texture._levelsUpdated[0][i] = false;
773773
} else {
774774
texture._levelsUpdated[0] = false;

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

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

106106
const texture = webgpuTexture.texture;
107-
const numFaces = texture.slices;
107+
const numFaces = texture.layers;
108108

109109
const srcViews = [];
110110
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
@@ -96,7 +96,7 @@ class WebgpuTexture {
9696
size: {
9797
width: texture.width,
9898
height: texture.height,
99-
depthOrArrayLayers: texture.slices
99+
depthOrArrayLayers: texture.layers
100100
},
101101
format: this.format,
102102
mipLevelCount: mipLevelCount,
@@ -334,9 +334,9 @@ class WebgpuTexture {
334334

335335
} else if (texture.array) { // texture array
336336

337-
if (texture.slices === mipObject.length) {
337+
if (texture.layers === mipObject.length) {
338338

339-
for (let index = 0; index < texture.slices; index++) {
339+
for (let index = 0; index < texture.layers; index++) {
340340
const arraySource = mipObject[index];
341341

342342
if (this.isExternalImage(arraySource)) {

0 commit comments

Comments
 (0)