Skip to content

Commit 39bfdd2

Browse files
committed
Rename slices to layers to better match WebGPU naming but also gl.framebufferTextureLayer
1 parent 499d812 commit 39bfdd2

File tree

8 files changed

+66
-66
lines changed

8 files changed

+66
-66
lines changed

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

+2-2
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

+3-3
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

+1-1
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

+6-6
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

+22-22
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Texture {
9393
* @param {string} [options.name] - The name of the texture. Defaults to null.
9494
* @param {number} [options.width] - The width of the texture in pixels. Defaults to 4.
9595
* @param {number} [options.height] - The height of the texture in pixels. Defaults to 4.
96-
* @param {number} [options.slices] - The number of depth slices in a 3D texture, the number of textures
96+
* @param {number} [options.layers] - The number of depth layers in a 3D texture, the number of textures
9797
* in a texture array or the number of faces for a cubemap.
9898
* @param {string} [options.dimension] - The texture dimension type. Can be:
9999
* - {@link TEXTUREDIMENSION_2D}
@@ -220,7 +220,7 @@ class Texture {
220220
Debug.assert(this.device, "Texture constructor requires a graphicsDevice to be valid");
221221
Debug.assert(!options.width || Number.isInteger(options.width), "Texture width must be an integer number, got", options);
222222
Debug.assert(!options.height || Number.isInteger(options.height), "Texture height must be an integer number, got", options);
223-
Debug.assert(!options.slices || Number.isInteger(options.slices), "Texture slices must be an integer number, got", options);
223+
Debug.assert(!options.layers || Number.isInteger(options.layers), "Texture layers must be an integer number, got", options);
224224

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

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

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

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

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

289289
// track the texture
@@ -331,10 +331,10 @@ class Texture {
331331
*
332332
* @param {number} width - The new width of the texture.
333333
* @param {number} height - The new height of the texture.
334-
* @param {number} [slices] - The new number of slices for the texture. Defaults to 1.
334+
* @param {number} [layers] - The new number of layers for the texture. Defaults to 1.
335335
* @ignore
336336
*/
337-
resize(width, height, slices = 1) {
337+
resize(width, height, layers = 1) {
338338

339339
// destroy texture impl
340340
const device = this.device;
@@ -343,7 +343,7 @@ class Texture {
343343

344344
this._width = Math.floor(width);
345345
this._height = Math.floor(height);
346-
this._slices = Math.floor(slices);
346+
this._layers = Math.floor(layers);
347347

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

682682
/**
683-
* The number of depth slices in a 3D texture.
683+
* The number of depth layers in a 3D texture.
684684
*
685685
* @type {number}
686686
*/
687687
get depth() {
688-
return this._dimension === TEXTUREDIMENSION_3D ? this._slices : 1;
688+
return this._dimension === TEXTUREDIMENSION_3D ? this._layers : 1;
689689
}
690690

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

700700
/**
@@ -741,7 +741,7 @@ class Texture {
741741

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

747747
/**
@@ -822,7 +822,7 @@ class Texture {
822822

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

827827
this._needsUpload = true;
828828
this._needsMipmapsUpload = this._mipmaps;
@@ -839,8 +839,8 @@ class Texture {
839839
* to 0.
840840
* @param {number} [options.face] - If the texture is a cubemap, this is the index of the face
841841
* to lock.
842-
* @param {number} [options.slice] - If the texture is a texture array, this is the index of the
843-
* slice to lock.
842+
* @param {number} [options.layer] - If the texture is a texture array, this is the index of the
843+
* layer to lock.
844844
* @param {number} [options.mode] - The lock mode. Can be:
845845
* - {@link TEXTURELOCK_READ}
846846
* - {@link TEXTURELOCK_WRITE}
@@ -852,7 +852,7 @@ class Texture {
852852
// Initialize options to some sensible defaults
853853
options.level ??= 0;
854854
options.face ??= 0;
855-
options.slice ??= 0;
855+
options.layer ??= 0;
856856
options.mode ??= TEXTURELOCK_WRITE;
857857

858858
Debug.assert(
@@ -881,7 +881,7 @@ class Texture {
881881

882882
this._lockedMode = options.mode;
883883

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

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

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

941941
if (!invalid) {
942942
// mark levels as updated
943-
for (let i = 0; i < this._slices; i++) {
943+
for (let i = 0; i < this._layers; i++) {
944944
if (this._levels[0][i] !== source[i])
945945
this._levelsUpdated[0][i] = true;
946946
}
@@ -970,7 +970,7 @@ class Texture {
970970

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

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

+28-28
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,11 @@ class WebglTexture {
465465
if (texture.array && !this._glCreated) {
466466
// for texture arrays we reserve the space in advance
467467
gl.texStorage3D(gl.TEXTURE_2D_ARRAY,
468-
requiredMipLevels,
469-
this._glInternalFormat,
470-
texture._width,
471-
texture._height,
472-
texture._slices);
468+
requiredMipLevels,
469+
this._glInternalFormat,
470+
texture._width,
471+
texture._height,
472+
texture._layers);
473473
}
474474

475475
// Upload all existing mip levels. Initialize 0 mip anyway.
@@ -499,9 +499,9 @@ class WebglTexture {
499499

500500
if (device._isBrowserInterface(mipObject[0])) {
501501
// Upload the image, canvas or video
502-
for (face = 0; face < texture.slices; face++) {
502+
for (face = 0; face < texture.layers; face++) {
503503
let src = mipObject[face];
504-
if (!texture._levelsUpdated[0][face] || !src)
504+
if (!texture._levelsUpdated[0][face] || !src) {
505505
continue;
506506
}
507507

@@ -542,9 +542,9 @@ class WebglTexture {
542542
} else {
543543
// Upload the byte array
544544
resMult = 1 / Math.pow(2, mipLevel);
545-
for (face = 0; face < texture.slices; face++) {
545+
for (face = 0; face < texture.layers; face++) {
546546
const texData = mipObject[face];
547-
if (!texture._levelsUpdated[0][face])
547+
if (!texture._levelsUpdated[0][face]) {
548548
continue;
549549
}
550550

@@ -605,30 +605,30 @@ class WebglTexture {
605605
// Upload the byte array
606606
if (texture._compressed) {
607607
gl.compressedTexImage3D(gl.TEXTURE_3D,
608-
mipLevel,
609-
this._glInternalFormat,
610-
Math.max(texture._width * resMult, 1),
611-
Math.max(texture._height * resMult, 1),
612-
Math.max(texture._slices * resMult, 1),
613-
0,
614-
mipObject);
608+
mipLevel,
609+
this._glInternalFormat,
610+
Math.max(texture._width * resMult, 1),
611+
Math.max(texture._height * resMult, 1),
612+
Math.max(texture._layers * resMult, 1),
613+
0,
614+
mipObject);
615615
} else {
616616
device.setUnpackFlipY(false);
617617
device.setUnpackPremultiplyAlpha(texture._premultiplyAlpha);
618618
gl.texImage3D(gl.TEXTURE_3D,
619-
mipLevel,
620-
this._glInternalFormat,
621-
Math.max(texture._width * resMult, 1),
622-
Math.max(texture._height * resMult, 1),
623-
Math.max(texture._slices * resMult, 1),
624-
0,
625-
this._glFormat,
626-
this._glPixelType,
627-
mipObject);
619+
mipLevel,
620+
this._glInternalFormat,
621+
Math.max(texture._width * resMult, 1),
622+
Math.max(texture._height * resMult, 1),
623+
Math.max(texture._layers * resMult, 1),
624+
0,
625+
this._glFormat,
626+
this._glPixelType,
627+
mipObject);
628628
}
629629
} else if (texture.array && typeof mipObject === "object") {
630630
if (texture._compressed) {
631-
for (let index = 0; index < texture._slices; index++) {
631+
for (let index = 0; index < texture._layers; index++) {
632632
if (!texture._levelsUpdated[0][index] || !mipObject[index])
633633
continue;
634634
gl.compressedTexSubImage3D(
@@ -645,7 +645,7 @@ class WebglTexture {
645645
);
646646
}
647647
} else {
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.texSubImage3D(
@@ -776,7 +776,7 @@ class WebglTexture {
776776

777777
if (texture._needsUpload) {
778778
if (texture.cubemap || texture.array) {
779-
for (let i = 0; i < texture.slices; i++)
779+
for (let i = 0; i < texture.layers; i++) {
780780
texture._levelsUpdated[0][i] = false;
781781
}
782782
} else {

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

+1-1
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

+3-3
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)