Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture array and cubemaps single slice updates #6693

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/src/examples/graphics/texture-array.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ assetListLoader.load(() => {
const textureArrayOptions = {
name: 'textureArrayImages',
format: pc.PIXELFORMAT_SRGBA8,
dimension: pc.TEXTUREDIMENSION_2D_ARRAY,
width: 1024,
height: 1024,
arrayLength: 4, // array texture with 4 textures
layers: 4, // array texture with 4 textures
magFilter: pc.FILTER_NEAREST,
minFilter: pc.FILTER_NEAREST_MIPMAP_NEAREST,
mipmaps: true,
Expand All @@ -120,17 +121,17 @@ assetListLoader.load(() => {
assets.aerialRocks.resource.getSource(),
assets.coastSand.resource.getSource()
]
]
],
immediate: true
};

const textureArray = new pc.Texture(app.graphicsDevice, textureArrayOptions);
textureArray.upload();

// generate mipmaps for visualization
const mipmaps = generateMipmaps(textureArrayOptions.width, textureArrayOptions.height);
const levels = mipmaps.map((data) => {
const textures = [];
for (let i = 0; i < textureArrayOptions.arrayLength; i++) {
for (let i = 0; i < textureArrayOptions.layers; i++) {
textures.push(data);
}
return textures;
Expand Down
12 changes: 6 additions & 6 deletions src/framework/handlers/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ const _completePartialMipmapChain = function (texture) {

if (!(texture._format === PIXELFORMAT_RGBA8 ||
texture._format === PIXELFORMAT_RGBA32F) ||
texture._volume ||
texture.volume ||
texture._compressed ||
texture._levels.length === 1 ||
texture._levels.length === requiredMipLevels ||
isHtmlElement(texture._cubemap ? texture._levels[0][0] : texture._levels[0])) {
isHtmlElement(texture.cubemap ? texture._levels[0][0] : texture._levels[0])) {
return;
}

Expand Down Expand Up @@ -99,18 +99,18 @@ const _completePartialMipmapChain = function (texture) {
for (let level = texture._levels.length; level < requiredMipLevels; ++level) {
const width = Math.max(1, texture._width >> (level - 1));
const height = Math.max(1, texture._height >> (level - 1));
if (texture._cubemap) {
if (texture.cubemap || texture.array) {
const mips = [];
for (let face = 0; face < 6; ++face) {
mips.push(downsample(width, height, texture._levels[level - 1][face]));
for (let layer = 0; layer < texture.layers; ++layer) {
mips.push(downsample(width, height, texture._levels[level - 1][layer]));
}
texture._levels.push(mips);
} else {
texture._levels.push(downsample(width, height, texture._levels[level - 1]));
}
}

texture._levelsUpdated = texture._cubemap ? [[true, true, true, true, true, true]] : [true];
texture._levelsUpdated = (texture.cubemap || texture.array) ? [Array(texture.layers).fill(true)] : [true];
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/framework/lightmapper/lightmapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,8 @@ class Lightmapper {

} else { // use the old path for WebGL till the render pass way above is fixed

device._uploadDirtyTextures();

// ping-ponging output
this.renderer.setCamera(this.camera, tempRT, true);

Expand Down
3 changes: 2 additions & 1 deletion src/framework/xr/xr-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class XrView extends EventHandler {

this._textureDepth = new Texture(device, {
format: this._manager.views.depthPixelFormat,
arrayLength: (viewsCount === 1) ? 0 : viewsCount,
array: viewsCount > 1,
layers: viewsCount,
mipmaps: false,
addressU: ADDRESS_CLAMP_TO_EDGE,
addressV: ADDRESS_CLAMP_TO_EDGE,
Expand Down
3 changes: 3 additions & 0 deletions src/platform/graphics/null/null-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class NullTexture {

loseContext() {
}

uploadImmediate(device, texture, immediate) {
}
}

export { NullTexture };
13 changes: 7 additions & 6 deletions src/platform/graphics/texture-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TextureUtils {
*
* @param {number} width - Texture's width.
* @param {number} height - Texture's height.
* @param {number} [depth] - Texture's depth. Defaults to 1.
* @param {number} [depth] - Texture's depth layers. Defaults to 1.
* @returns {number} The number of mip levels required for the texture.
*/
static calcMipLevelsCount(width, height, depth = 1) {
Expand All @@ -38,7 +38,7 @@ class TextureUtils {
*
* @param {number} width - Texture's width.
* @param {number} height - Texture's height.
* @param {number} depth - Texture's depth.
* @param {number} depth - Texture's depth layers.
* @param {number} format - Texture's pixel format PIXELFORMAT_***.
* @returns {number} The number of bytes of GPU memory required for the texture.
*/
Expand Down Expand Up @@ -70,14 +70,15 @@ class TextureUtils {
*
* @param {number} width - Texture's width.
* @param {number} height - Texture's height.
* @param {number} depth - Texture's depth.
* @param {number} layers - Texture's layers.
* @param {number} format - Texture's pixel format PIXELFORMAT_***.
* @param {boolean} isVolume - True if the texture is a volume texture, false otherwise.
* @param {boolean} mipmaps - True if the texture includes mipmaps, false otherwise.
* @param {boolean} cubemap - True is the texture is a cubemap, false otherwise.
* @returns {number} The number of bytes of GPU memory required for the texture.
*/
static calcGpuSize(width, height, depth, format, mipmaps, cubemap) {
static calcGpuSize(width, height, layers, format, isVolume, mipmaps) {
let result = 0;
let depth = isVolume ? layers : 1;

while (1) {
result += TextureUtils.calcLevelGpuSize(width, height, depth, format);
Expand All @@ -91,7 +92,7 @@ class TextureUtils {
depth = Math.max(depth >> 1, 1);
}

return result * (cubemap ? 6 : 1);
return result * (isVolume ? 1 : layers);
}
}

Expand Down
Loading