Skip to content

Commit fa85fe1

Browse files
committed
Rename slices to layers to better match WebGPU naming but also gl.framebufferTextureLayer
1 parent a15f721 commit fa85fe1

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
@@ -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
@@ -104,7 +104,7 @@ class Texture {
104104
* @param {string} [options.name] - The name of the texture. Defaults to null.
105105
* @param {number} [options.width] - The width of the texture in pixels. Defaults to 4.
106106
* @param {number} [options.height] - The height of the texture in pixels. Defaults to 4.
107-
* @param {number} [options.slices] - The number of depth slices in a 3D texture, the number of textures
107+
* @param {number} [options.layers] - The number of depth layers in a 3D texture, the number of textures
108108
* in a texture array or the number of faces for a cubemap.
109109
* @param {string} [options.dimension] - The texture dimension type. Can be:
110110
* - {@link TEXTUREDIMENSION_2D}
@@ -231,7 +231,7 @@ class Texture {
231231
Debug.assert(this.device, "Texture constructor requires a graphicsDevice to be valid");
232232
Debug.assert(!options.width || Number.isInteger(options.width), "Texture width must be an integer number, got", options);
233233
Debug.assert(!options.height || Number.isInteger(options.height), "Texture height must be an integer number, got", options);
234-
Debug.assert(!options.slices || Number.isInteger(options.slices), "Texture slices must be an integer number, got", options);
234+
Debug.assert(!options.layers || Number.isInteger(options.layers), "Texture layers must be an integer number, got", options);
235235

236236
this.name = options.name ?? '';
237237

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

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

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

250250
this._format = options.format ?? PIXELFORMAT_RGBA8;
251251
this._compressed = isCompressedPixelFormat(this._format);
@@ -294,7 +294,7 @@ class Texture {
294294
if (this._levels) {
295295
this.upload(options.immediate ?? false);
296296
} else {
297-
this._levels = (this.cubemap || this.array) ? [Array(this._slices).fill(null)] : [null];
297+
this._levels = (this.cubemap || this.array) ? [Array(this._layers).fill(null)] : [null];
298298
}
299299

300300
// track the texture
@@ -342,10 +342,10 @@ class Texture {
342342
*
343343
* @param {number} width - The new width of the texture.
344344
* @param {number} height - The new height of the texture.
345-
* @param {number} [slices] - The new number of slices for the texture. Defaults to 1.
345+
* @param {number} [layers] - The new number of layers for the texture. Defaults to 1.
346346
* @ignore
347347
*/
348-
resize(width, height, slices = 1) {
348+
resize(width, height, layers = 1) {
349349

350350
// destroy texture impl
351351
const device = this.device;
@@ -354,7 +354,7 @@ class Texture {
354354

355355
this._width = Math.floor(width);
356356
this._height = Math.floor(height);
357-
this._slices = Math.floor(slices);
357+
this._layers = Math.floor(layers);
358358

359359
// re-create the implementation
360360
this.impl = device.createTextureImpl(this);
@@ -691,21 +691,21 @@ class Texture {
691691
}
692692

693693
/**
694-
* The number of depth slices in a 3D texture.
694+
* The number of depth layers in a 3D texture.
695695
*
696696
* @type {number}
697697
*/
698698
get depth() {
699-
return this._dimension === TEXTUREDIMENSION_3D ? this._slices : 1;
699+
return this._dimension === TEXTUREDIMENSION_3D ? this._layers : 1;
700700
}
701701

702702
/**
703703
* The number of textures in a texture array or the number of faces for a cubemap.
704704
*
705705
* @type {number}
706706
*/
707-
get slices() {
708-
return this._slices;
707+
get layers() {
708+
return this._layers;
709709
}
710710

711711
/**
@@ -752,7 +752,7 @@ class Texture {
752752

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

758758
/**
@@ -833,7 +833,7 @@ class Texture {
833833

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

838838
this._needsUpload = true;
839839
this._needsMipmapsUpload = this._mipmaps;
@@ -850,8 +850,8 @@ class Texture {
850850
* to 0.
851851
* @param {number} [options.face] - If the texture is a cubemap, this is the index of the face
852852
* to lock.
853-
* @param {number} [options.slice] - If the texture is a texture array, this is the index of the
854-
* slice to lock.
853+
* @param {number} [options.layer] - If the texture is a texture array, this is the index of the
854+
* layer to lock.
855855
* @param {number} [options.mode] - The lock mode. Can be:
856856
* - {@link TEXTURELOCK_READ}
857857
* - {@link TEXTURELOCK_WRITE}
@@ -863,7 +863,7 @@ class Texture {
863863
// Initialize options to some sensible defaults
864864
options.level ??= 0;
865865
options.face ??= 0;
866-
options.slice ??= 0;
866+
options.layer ??= 0;
867867
options.mode ??= TEXTURELOCK_WRITE;
868868

869869
Debug.assert(
@@ -892,7 +892,7 @@ class Texture {
892892

893893
this._lockedMode = options.mode;
894894

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

905905
if (this._lockedMode === TEXTURELOCK_WRITE) {
906906
if (this.cubemap || this.array) {
907-
this._levelsUpdated[0][options.face ?? options.slice] = true;
907+
this._levelsUpdated[0][options.face ?? options.layer] = true;
908908
} else {
909909
this._levelsUpdated[0] = true;
910910
}
@@ -933,7 +933,7 @@ class Texture {
933933
width = source[0].width || 0;
934934
height = source[0].height || 0;
935935

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

952952
if (!invalid) {
953953
// mark levels as updated
954-
for (let i = 0; i < this._slices; i++) {
954+
for (let i = 0; i < this._layers; i++) {
955955
if (this._levels[0][i] !== source[i])
956956
this._levelsUpdated[0][i] = true;
957957
}
@@ -980,7 +980,7 @@ class Texture {
980980

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

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class WebglTexture {
468468
this._glInternalFormat,
469469
texture._width,
470470
texture._height,
471-
texture._slices);
471+
texture._layers);
472472
}
473473

474474
// Upload all existing mip levels. Initialize 0 mip anyway.
@@ -498,7 +498,7 @@ class WebglTexture {
498498

499499
if (device._isBrowserInterface(mipObject[0])) {
500500
// Upload the image, canvas or video
501-
for (face = 0; face < texture.slices; face++) {
501+
for (face = 0; face < texture.layers; face++) {
502502
let src = mipObject[face];
503503
if (!texture._levelsUpdated[0][face] || !src)
504504
continue;
@@ -540,7 +540,7 @@ class WebglTexture {
540540
} else {
541541
// Upload the byte array
542542
resMult = 1 / Math.pow(2, mipLevel);
543-
for (face = 0; face < texture.slices; face++) {
543+
for (face = 0; face < texture.layers; face++) {
544544
const texData = mipObject[face];
545545
if (!texture._levelsUpdated[0][face])
546546
continue;
@@ -606,7 +606,7 @@ class WebglTexture {
606606
this._glInternalFormat,
607607
Math.max(texture._width * resMult, 1),
608608
Math.max(texture._height * resMult, 1),
609-
Math.max(texture._slices * resMult, 1),
609+
Math.max(texture._layers * resMult, 1),
610610
0,
611611
mipObject);
612612
} else {
@@ -617,15 +617,15 @@ class WebglTexture {
617617
this._glInternalFormat,
618618
Math.max(texture._width * resMult, 1),
619619
Math.max(texture._height * resMult, 1),
620-
Math.max(texture._slices * resMult, 1),
620+
Math.max(texture._layers * resMult, 1),
621621
0,
622622
this._glFormat,
623623
this._glPixelType,
624624
mipObject);
625625
}
626626
} else if (texture.array && typeof mipObject === "object") {
627627
if (texture._compressed) {
628-
for (let index = 0; index < texture._slices; index++) {
628+
for (let index = 0; index < texture._layers; index++) {
629629
if (!texture._levelsUpdated[0][index] || !mipObject[index])
630630
continue;
631631
gl.compressedTexSubImage3D(
@@ -642,7 +642,7 @@ class WebglTexture {
642642
);
643643
}
644644
} else {
645-
for (let index = 0; index < texture.slices; index++) {
645+
for (let index = 0; index < texture.layers; index++) {
646646
if (!texture._levelsUpdated[0][index] || !mipObject[index])
647647
continue;
648648
gl.texSubImage3D(
@@ -773,7 +773,7 @@ class WebglTexture {
773773

774774
if (texture._needsUpload) {
775775
if (texture.cubemap || texture.array) {
776-
for (let i = 0; i < texture.slices; i++)
776+
for (let i = 0; i < texture.layers; i++)
777777
texture._levelsUpdated[0][i] = false;
778778
} else {
779779
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
@@ -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)