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

Fix IconManager upsizing auto-packed icon atlas #8673

Merged
merged 2 commits into from
Mar 18, 2024
Merged
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
19 changes: 9 additions & 10 deletions modules/layers/src/icon-layer/icon-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global document */
import {Device, Texture, SamplerProps} from '@luma.gl/core';
// import {ImageLoader} from '@loaders.gl/images';
import {load} from '@loaders.gl/core';
import {createIterable} from '@deck.gl/core';

Expand Down Expand Up @@ -119,19 +118,19 @@ function resizeTexture(
height: number,
sampler: SamplerProps
): Texture {
const oldWidth = texture.width;
const oldHeight = texture.height;

const newTexture = texture.device.createTexture({format: 'rgba8unorm', width, height, sampler});
// @ts-expect-error TODO v9 import
// device.copyToTextureWebGL(texture, newTexture, {
copyToTexture(texture, newTexture, {
targetY: 0,
const {width: oldWidth, height: oldHeight, device} = texture;

const newTexture = device.createTexture({format: 'rgba8unorm', width, height, sampler});
const commandEncoder = device.createCommandEncoder();
commandEncoder.copyTextureToTexture({
source: texture,
destination: newTexture,
width: oldWidth,
height: oldHeight
});
commandEncoder.finish();

texture.delete();
texture.destroy();
return newTexture;
}

Expand Down
83 changes: 41 additions & 42 deletions test/render/test-cases/icon-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,48 +130,47 @@ export default [
},
// This is based on last test case
// use the same layer id 'icon-lnglat-auto' as last test case to trigger the layer update and test texture resize logic
// TODO - v9 texture
// {
// name: 'icon-lnglat-auto-2',
// viewState: {
// latitude: 37.751537058389985,
// longitude: -122.42694203247012,
// zoom: 12,
// pitch: 0,
// bearing: 0
// },
// layers: [
// new IconLayer({
// id: 'icon-lnglat-auto',
// data: points,
// updateTriggers: {
// getIcon: 2
// },
// sizeScale: 16,
// opacity: 0.8,
// getSize: d => (d.RACKS > 2 ? 2 : 1),
// getPosition: d => d.COORDINATES,
// getColor: d => [64, 64, 72],
// getIcon: d => {
// if (d.PLACEMENT === 'SW') {
// return Object.assign({}, iconMapping.marker, {
// url: './test/data/icon-marker.png',
// id: 'marker-large',
// width: 256,
// height: 256
// });
// }
// return Object.assign({}, iconMapping['marker-warning'], {
// id: 'warning-large',
// url: './test/data/icon-warning.png',
// width: 1024,
// height: 1024
// });
// }
// })
// ],
// goldenImage: './test/render/golden-images/icon-lnglat-resize-texture.png'
// },
{
name: 'icon-lnglat-auto-2',
viewState: {
latitude: 37.751537058389985,
longitude: -122.42694203247012,
zoom: 12,
pitch: 0,
bearing: 0
},
layers: [
new IconLayer({
id: 'icon-lnglat-auto',
data: points,
updateTriggers: {
getIcon: 2
},
sizeScale: 16,
opacity: 0.8,
getSize: d => (d.RACKS > 2 ? 2 : 1),
getPosition: d => d.COORDINATES,
getColor: d => [64, 64, 72],
getIcon: d => {
if (d.PLACEMENT === 'SW') {
return Object.assign({}, iconMapping.marker, {
url: './test/data/icon-marker.png',
id: 'marker-large',
width: 256,
height: 256
});
}
return Object.assign({}, iconMapping['marker-warning'], {
id: 'warning-large',
url: './test/data/icon-warning.png',
width: 1024,
height: 1024
});
}
})
],
goldenImage: './test/render/golden-images/icon-lnglat-resize-texture.png'
},
{
name: 'icon-meters',
viewState: {
Expand Down
Loading