Skip to content

Commit

Permalink
fix: device 渲染模式下 setData 时不生效 (#2447)
Browse files Browse the repository at this point in the history
* fix: device 渲染模式下 setData 时不生效

* fix: 避免 gl.deleteVertexArray 删除后,后续不能重复使用

* chore: 关闭 vao 缓存
  • Loading branch information
lvisei authored May 9, 2024
1 parent 50e7063 commit ee64cef
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 79 deletions.
2 changes: 1 addition & 1 deletion examples/demos/bugfix/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { MapRender as color } from './color';
export { MapRender as event_legend } from './event_legend';
export { MapRender as polygon } from './polygon';
export { MapRender as remove_muti_layer } from './remove-muti-layer';
export { MapRender as setData } from './set-data';
export { MapRender as size } from './size';
export { MapRender as text } from './text_offsets';
export { MapRender as tile_update } from './tile_update';
Expand Down
76 changes: 0 additions & 76 deletions examples/demos/bugfix/polygon.ts

This file was deleted.

94 changes: 94 additions & 0 deletions examples/demos/bugfix/set-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { PolygonLayer, Scene } from '@antv/l7';
import * as allMap from '@antv/l7-maps';
import type { RenderDemoOptions } from '../../types';

const data1 = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
base_height: 100,
},
geometry: {
type: 'Polygon',
coordinates: [
[
[119.948198, 30.339818],
[120.344273, 30.513865],
[120.414729, 30.288859],
[120.346177, 30.160522],
[120.100535, 30.041909],
[119.906306, 30.094644],
[119.845646, 30.175339],
[119.81137, 30.244454],
[119.807562, 30.352965],
[119.948198, 30.339818],
],
],
},
},
],
};

const data2 = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
base_height: 200,
},
geometry: {
type: 'Polygon',
coordinates: [
[
[119.948198, 30.339818],
[120.344273, 30.513865],
[120.414729, 30.288859],
[121.346177, 30.160522],
[120.100535, 30.041909],
[119.906306, 30.094644],
[119.845646, 30.175339],
[119.81137, 30.244454],
[119.807562, 30.352965],
[119.948198, 30.339818],
],
],
},
},
],
};

export function MapRender(options: RenderDemoOptions) {
const scene = new Scene({
id: 'map',
renderer: options.renderer,
map: new allMap[options.map]({
style: 'light',
center: [120.100535, 30.041909],
zoom: 14.83,
}),
});

scene.on('loaded', () => {
const layer = new PolygonLayer({
autoFit: false,
})
.source(data1)
.shape('fill')
.active(true)
.color('red');

layer.once('inited', () => {
layer.fitBounds({ animate: false });
});

scene.addLayer(layer);

setTimeout(() => {
console.log('setData: ');
layer.setData(data2);
}, 2000);
});
}
5 changes: 3 additions & 2 deletions packages/renderer/src/device/DeviceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class DeviceModel implements IModel {
this.indexBuffer = (elements as DeviceElements).get();
}

const inputLayout = service.renderCache.createInputLayout({
const inputLayout = device.createInputLayout({
vertexBufferDescriptors,
indexBufferFormat: elements ? Format.U32_R : null,
program: this.program,
Expand Down Expand Up @@ -346,7 +346,8 @@ export default class DeviceModel implements IModel {
}

destroy() {
this.program.destroy();
// 不销毁,方便后续重复使用
// this.program.destroy();
this.vertexBuffers?.forEach((buffer) => buffer.destroy());
this.indexBuffer?.destroy();
this.bindings?.destroy();
Expand Down

0 comments on commit ee64cef

Please sign in to comment.