mirror of https://gitee.com/antv-l7/antv-l7
chore: remove useless
This commit is contained in:
parent
de77a82ba4
commit
9d7f4cc212
|
@ -46,7 +46,6 @@
|
||||||
"@typescript-eslint/parser": "^5.6.0",
|
"@typescript-eslint/parser": "^5.6.0",
|
||||||
"@umijs/fabric": "^2.8.1",
|
"@umijs/fabric": "^2.8.1",
|
||||||
"@umijs/test": "^3.0.5",
|
"@umijs/test": "^3.0.5",
|
||||||
"antd": "^4.12.3",
|
|
||||||
"awesome-typescript-loader": "^5.2.1",
|
"awesome-typescript-loader": "^5.2.1",
|
||||||
"babel-jest": "^24.9.0",
|
"babel-jest": "^24.9.0",
|
||||||
"babel-loader": "^8.0.6",
|
"babel-loader": "^8.0.6",
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
|
import { IRendererService, TYPES } from '@antv/l7-core';
|
||||||
import BaseLayer from '../core/BaseLayer';
|
import BaseLayer from '../core/BaseLayer';
|
||||||
import { IPointLayerStyleOptions } from '../core/interface';
|
import { IPointLayerStyleOptions } from '../core/interface';
|
||||||
import {
|
|
||||||
TYPES,
|
|
||||||
IRendererService,
|
|
||||||
} from '@antv/l7-core';
|
|
||||||
|
|
||||||
|
|
||||||
export default class PointLayer extends BaseLayer<IPointLayerStyleOptions> {
|
export default class PointLayer extends BaseLayer<IPointLayerStyleOptions> {
|
||||||
public type: string = 'PointLayer';
|
public type: string = 'PointLayer';
|
||||||
|
|
||||||
public async buildModels() {
|
public async buildModels() {
|
||||||
this.rendererService = this.getContainer().get<IRendererService>(TYPES.IRendererService);
|
this.rendererService = this.getContainer().get<IRendererService>(
|
||||||
|
TYPES.IRendererService,
|
||||||
|
);
|
||||||
const { createModel } = this.rendererService;
|
const { createModel } = this.rendererService;
|
||||||
const model = createModel();
|
const model = createModel();
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
"reflect-metadata": "^0.1.13"
|
"reflect-metadata": "^0.1.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antv/l7-test-utils": "2.11.4",
|
|
||||||
"gl": "^5.0.3"
|
"gl": "^5.0.3"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
import { gl } from '@antv/l7-core';
|
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import quad from '../../../../core/src/shaders/post-processing/quad.glsl';
|
|
||||||
import ReglAttribute from '../ReglAttribute';
|
|
||||||
import ReglBuffer from '../ReglBuffer';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import checkPixels from './utils/check-pixels';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
|
|
||||||
describe('ReglAttribute', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize without `size`', () => {
|
|
||||||
const attribute = new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: attribute,
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
attribute.updateBuffer({
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
offset: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
attribute.destroy();
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should update buffer correctly', () => {
|
|
||||||
|
|
||||||
const attribute = new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
});
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: attribute,
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
attribute.updateBuffer({
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
offset: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
attribute.destroy();
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,89 +0,0 @@
|
||||||
import { gl } from '@antv/l7-core';
|
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import quad from '../../../../core/src/shaders/post-processing/quad.glsl';
|
|
||||||
import ReglAttribute from '../ReglAttribute';
|
|
||||||
import ReglBuffer from '../ReglBuffer';
|
|
||||||
import ReglElements from '../ReglElements';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import checkPixels from './utils/check-pixels';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
|
|
||||||
describe('ReglElements', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements: new ReglElements(reGL, {
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should update correctly', () => {
|
|
||||||
const elements = new ReglElements(reGL, {
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
elements.subData({
|
|
||||||
data: [0, 1, 2],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
elements.destroy();
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,190 +0,0 @@
|
||||||
import { gl } from '@antv/l7-core';
|
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import quad from '../../../../core/src/shaders/post-processing/quad.glsl';
|
|
||||||
import ReglAttribute from '../ReglAttribute';
|
|
||||||
import ReglBuffer from '../ReglBuffer';
|
|
||||||
import ReglElements from '../ReglElements';
|
|
||||||
import ReglFramebuffer from '../ReglFramebuffer';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import ReglRenderbuffer from '../ReglRenderbuffer';
|
|
||||||
import ReglTexture2D from '../ReglTexture2D';
|
|
||||||
import checkPixels from './utils/check-pixels';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
|
|
||||||
describe('ReglFramebuffer', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements: new ReglElements(reGL, {
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const framebuffer = new ReglFramebuffer(reGL, {
|
|
||||||
color: new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL({ framebuffer: framebuffer.get() })(() => {
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize with colors correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements: new ReglElements(reGL, {
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const framebuffer = new ReglFramebuffer(reGL, {
|
|
||||||
colors: [
|
|
||||||
new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL({ framebuffer: framebuffer.get() })(() => {
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should resize correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements: new ReglElements(reGL, {
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const framebuffer = new ReglFramebuffer(reGL, {
|
|
||||||
color: new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
framebuffer.resize({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL({ framebuffer: framebuffer.get() })(() => {
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
framebuffer.destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize with renderbuffer correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements: new ReglElements(reGL, {
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const renderbuffer = new ReglRenderbuffer(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
format: gl.RGBA4,
|
|
||||||
});
|
|
||||||
const framebuffer = new ReglFramebuffer(reGL, {
|
|
||||||
color: renderbuffer,
|
|
||||||
});
|
|
||||||
|
|
||||||
renderbuffer.resize({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL({ framebuffer: framebuffer.get() })(() => {
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
});
|
|
||||||
|
|
||||||
framebuffer.destroy();
|
|
||||||
renderbuffer.destroy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,157 +0,0 @@
|
||||||
import { gl } from '@antv/l7-core';
|
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import quad from '../../../../core/src/shaders/post-processing/quad.glsl';
|
|
||||||
import ReglAttribute from '../ReglAttribute';
|
|
||||||
import ReglBuffer from '../ReglBuffer';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import checkPixels from './utils/check-pixels';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
import globalDefaultprecision from './utils/default-precision';
|
|
||||||
|
|
||||||
describe('Initialization for ReglModel', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should draw a red quad', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
stencil: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
blend: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
primitive: gl.TRIANGLES,
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should cull front face', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
cull: {
|
|
||||||
enable: true,
|
|
||||||
face: gl.FRONT,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [0])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should draw with instances', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
instances: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should draw with uniforms', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: `
|
|
||||||
${globalDefaultprecision}
|
|
||||||
uniform vec4 u_Color;
|
|
||||||
void main() {
|
|
||||||
gl_FragColor = u_Color;
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [-4, -4, 4, -4, 0, 4],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
size: 2,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
uniforms: {
|
|
||||||
u_Color: [0, 0, 0, 0],
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({
|
|
||||||
uniforms: {
|
|
||||||
u_Color: [1, 0, 0, 1],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,75 +0,0 @@
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
|
|
||||||
describe('ReglModel', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate model with empty uniforms correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate model with uniforms correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
uniforms: {
|
|
||||||
u_1: 1,
|
|
||||||
u_2: [1, 2],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_1).toEqual(1);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_2).toEqual([1, 2]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate model with struct uniforms correctly', () => {
|
|
||||||
// 支持 struct 结构,例如 'colors[0].r'
|
|
||||||
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#uniforms
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
// @ts-ignore
|
|
||||||
uniforms: {
|
|
||||||
// @ts-ignore
|
|
||||||
u_Struct: [
|
|
||||||
{
|
|
||||||
a: 1,
|
|
||||||
b: [1, 2],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: 2,
|
|
||||||
b: [3, 4],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[0].a']).toEqual(1);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[0].b']).toEqual([1, 2]);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[1].a']).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[1].b']).toEqual([3, 4]);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,210 +0,0 @@
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import ReglFramebuffer from '../ReglFramebuffer';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import ReglTexture2D from '../ReglTexture2D';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
|
|
||||||
describe('uniforms in ReglModel', () => {
|
|
||||||
let gl;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
gl = createContext(1, 1);
|
|
||||||
reGL = regl(gl);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate model with empty uniforms correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate model with uniforms correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
uniforms: {
|
|
||||||
u_1: 1,
|
|
||||||
u_2: [1, 2],
|
|
||||||
u_3: false,
|
|
||||||
u_4: new Float32Array([1, 2, 3]),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_1).toEqual(1);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_2).toEqual([1, 2]);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_3).toEqual(false);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_4).toEqual(new Float32Array([1, 2, 3]));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate model with struct uniforms correctly', () => {
|
|
||||||
// 支持 struct 结构,例如 'colors[0].r'
|
|
||||||
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#uniforms
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
// @ts-ignore
|
|
||||||
uniforms: {
|
|
||||||
// @ts-ignore
|
|
||||||
u_Struct: [
|
|
||||||
{
|
|
||||||
a: 1,
|
|
||||||
b: [1, 2],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
a: 2,
|
|
||||||
b: [3, 4],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[0].a']).toEqual(1);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[0].b']).toEqual([1, 2]);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[1].a']).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_Struct[1].b']).toEqual([3, 4]);
|
|
||||||
|
|
||||||
// 测试结构体嵌套的场景
|
|
||||||
const model2 = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
// @ts-ignore
|
|
||||||
uniforms: {
|
|
||||||
// @ts-ignore
|
|
||||||
u_Struct: {
|
|
||||||
a: 1,
|
|
||||||
b: [1, 2],
|
|
||||||
c: {
|
|
||||||
d: 2,
|
|
||||||
e: [3, 4],
|
|
||||||
},
|
|
||||||
f: false,
|
|
||||||
g: [
|
|
||||||
{
|
|
||||||
h: 3,
|
|
||||||
i: [
|
|
||||||
{
|
|
||||||
j: 4,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
k: new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
}),
|
|
||||||
l: new ReglFramebuffer(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
}),
|
|
||||||
m: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.a']).toEqual(1);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.b']).toEqual([1, 2]);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.c.d']).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.c.e']).toEqual([3, 4]);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.f']).toEqual(false);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.g[0].h']).toEqual(3);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.g[0].i[0].j']).toEqual(4);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.k'] instanceof ReglTexture2D).toBeTruthy();
|
|
||||||
// @ts-ignore
|
|
||||||
expect(
|
|
||||||
// @ts-ignore
|
|
||||||
model2.uniforms['u_Struct.l'] instanceof ReglFramebuffer,
|
|
||||||
).toBeTruthy();
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model2.uniforms['u_Struct.m']).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should update uniforms correctly', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: 'void main() {gl_Position = vec4(0.);}',
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(0.);}',
|
|
||||||
attributes: {},
|
|
||||||
// @ts-ignore
|
|
||||||
uniforms: {
|
|
||||||
u_1: 1,
|
|
||||||
u_2: [1, 2],
|
|
||||||
u_3: false,
|
|
||||||
u_4: {
|
|
||||||
a: 1,
|
|
||||||
b: 2,
|
|
||||||
},
|
|
||||||
// @ts-ignore
|
|
||||||
u_5: [
|
|
||||||
{
|
|
||||||
c: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
c: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
c: 3,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
model.addUniforms({
|
|
||||||
u_1: 2,
|
|
||||||
u_2: [3, 4],
|
|
||||||
u_3: true,
|
|
||||||
u_4: {
|
|
||||||
a: 2,
|
|
||||||
},
|
|
||||||
// @ts-ignore
|
|
||||||
u_5: [
|
|
||||||
// @ts-ignore
|
|
||||||
{
|
|
||||||
c: 100, // 只修改第一个
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'u_5[2].c': 200, // 直接修改结构体属性
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_1).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_2).toEqual([3, 4]);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms.u_3).toBeTruthy();
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_4.a']).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_4.b']).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_5[0].c']).toEqual(100);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_5[1].c']).toEqual(2);
|
|
||||||
// @ts-ignore
|
|
||||||
expect(model.uniforms['u_5[2].c']).toEqual(200);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,290 +0,0 @@
|
||||||
import { gl } from '@antv/l7-core';
|
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import copy from '../../../../core/src/shaders/post-processing/copy.glsl';
|
|
||||||
import quad from '../../../../core/src/shaders/post-processing/quad.glsl';
|
|
||||||
import { ReglRendererService } from '../../index';
|
|
||||||
import ReglAttribute from '../ReglAttribute';
|
|
||||||
import ReglBuffer from '../ReglBuffer';
|
|
||||||
import checkPixels from './utils/check-pixels';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
import globalDefaultprecision from './utils/default-precision';
|
|
||||||
|
|
||||||
describe('ReglRendererService', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
const rendererService = new ReglRendererService();
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
// @ts-ignore
|
|
||||||
rendererService.gl = reGL;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should getViewportSize correctly after setViewport', () => {
|
|
||||||
const { viewport, getViewportSize } = rendererService;
|
|
||||||
const { width, height } = getViewportSize();
|
|
||||||
expect(width).toEqual(1);
|
|
||||||
expect(height).toEqual(1);
|
|
||||||
|
|
||||||
viewport({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(width).toEqual(1);
|
|
||||||
expect(height).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create model with createModel API', () => {
|
|
||||||
const {
|
|
||||||
clear,
|
|
||||||
createModel,
|
|
||||||
createAttribute,
|
|
||||||
createBuffer,
|
|
||||||
} = rendererService;
|
|
||||||
const model = createModel({
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: createAttribute({
|
|
||||||
buffer: createBuffer({
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should draw with createElements', () => {
|
|
||||||
const {
|
|
||||||
clear,
|
|
||||||
createModel,
|
|
||||||
createAttribute,
|
|
||||||
createBuffer,
|
|
||||||
createElements,
|
|
||||||
} = rendererService;
|
|
||||||
const model = createModel({
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: createAttribute({
|
|
||||||
buffer: createBuffer({
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
elements: createElements({
|
|
||||||
data: [0, 1, 2],
|
|
||||||
count: 3,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render to framebuffer with `useFramebuffer` correctly', () => {
|
|
||||||
const {
|
|
||||||
clear,
|
|
||||||
createModel,
|
|
||||||
createAttribute,
|
|
||||||
createBuffer,
|
|
||||||
createFramebuffer,
|
|
||||||
useFramebuffer,
|
|
||||||
} = rendererService;
|
|
||||||
const model = createModel({
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: createAttribute({
|
|
||||||
buffer: createBuffer({
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
const framebuffer = createFramebuffer({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
useFramebuffer(framebuffer, () => {
|
|
||||||
clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
framebuffer,
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
// render to screen
|
|
||||||
useFramebuffer(null, () => {
|
|
||||||
clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should readPixels correctly', () => {
|
|
||||||
const {
|
|
||||||
clear,
|
|
||||||
createModel,
|
|
||||||
createAttribute,
|
|
||||||
createBuffer,
|
|
||||||
createFramebuffer,
|
|
||||||
useFramebuffer,
|
|
||||||
readPixels,
|
|
||||||
destroy,
|
|
||||||
} = rendererService;
|
|
||||||
const model = createModel({
|
|
||||||
vs: quad,
|
|
||||||
fs: 'void main() {gl_FragColor = vec4(1., 0., 0., 1.);}',
|
|
||||||
attributes: {
|
|
||||||
a_Position: createAttribute({
|
|
||||||
buffer: createBuffer({
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
const framebuffer = createFramebuffer({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
useFramebuffer(framebuffer, () => {
|
|
||||||
clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
framebuffer,
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
const pixels = readPixels({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
framebuffer,
|
|
||||||
});
|
|
||||||
expect(pixels[0]).toBe(255);
|
|
||||||
});
|
|
||||||
|
|
||||||
// render to screen
|
|
||||||
useFramebuffer(null, () => {
|
|
||||||
clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
model.draw({});
|
|
||||||
const pixels = readPixels({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
framebuffer: undefined,
|
|
||||||
});
|
|
||||||
expect(pixels[0]).toBe(255);
|
|
||||||
});
|
|
||||||
|
|
||||||
destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render a fullscreen texture', () => {
|
|
||||||
const { createModel, createTexture2D } = rendererService;
|
|
||||||
const model = createModel({
|
|
||||||
vs: quad,
|
|
||||||
fs: globalDefaultprecision + copy,
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
uniforms: {
|
|
||||||
// 创建一个红色的纹理
|
|
||||||
u_Texture: createTexture2D({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
data: [255, 0, 0, 255],
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
// 全屏应该都是红色
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should getContainer correctly', () => {
|
|
||||||
const { getContainer } = rendererService;
|
|
||||||
expect(getContainer()).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,208 +0,0 @@
|
||||||
import { gl } from '@antv/l7-core';
|
|
||||||
import regl from 'l7regl';
|
|
||||||
import 'reflect-metadata';
|
|
||||||
import copy from '../../../../core/src/shaders/post-processing/copy.glsl';
|
|
||||||
import quad from '../../../../core/src/shaders/post-processing/quad.glsl';
|
|
||||||
import ReglAttribute from '../ReglAttribute';
|
|
||||||
import ReglBuffer from '../ReglBuffer';
|
|
||||||
import ReglModel from '../ReglModel';
|
|
||||||
import ReglTexture2D from '../ReglTexture2D';
|
|
||||||
import checkPixels from './utils/check-pixels';
|
|
||||||
import { createContext } from '@antv/l7-test-utils';
|
|
||||||
import globalDefaultprecision from './utils/default-precision';
|
|
||||||
|
|
||||||
describe('ReglTexture', () => {
|
|
||||||
let context;
|
|
||||||
let reGL: regl.Regl;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
context = createContext(1, 1);
|
|
||||||
reGL = regl(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize with `data`', () => {
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: globalDefaultprecision + copy,
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
uniforms: {
|
|
||||||
// 创建一个红色的纹理
|
|
||||||
u_Texture: new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
data: [255, 0, 0, 255],
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
// 全屏应该都是红色
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should resize texture', () => {
|
|
||||||
const texture = new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
data: [255, 0, 0, 255],
|
|
||||||
});
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: globalDefaultprecision + copy,
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
uniforms: {
|
|
||||||
// 创建一个红色的纹理
|
|
||||||
u_Texture: texture,
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
texture.resize({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
texture.destroy();
|
|
||||||
|
|
||||||
// 全屏应该都是红色
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should mipmap with default options', () => {
|
|
||||||
const texture = new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
data: [255, 0, 0, 255],
|
|
||||||
mipmap: true,
|
|
||||||
});
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: globalDefaultprecision + copy,
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
uniforms: {
|
|
||||||
// 创建一个红色的纹理
|
|
||||||
u_Texture: texture,
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
texture.resize({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
texture.destroy();
|
|
||||||
|
|
||||||
// 全屏应该都是红色
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should mipmap with hints', () => {
|
|
||||||
const texture = new ReglTexture2D(reGL, {
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
data: [255, 0, 0, 255],
|
|
||||||
mipmap: gl.DONT_CARE,
|
|
||||||
});
|
|
||||||
const model = new ReglModel(reGL, {
|
|
||||||
vs: quad,
|
|
||||||
fs: globalDefaultprecision + copy,
|
|
||||||
attributes: {
|
|
||||||
a_Position: new ReglAttribute(reGL, {
|
|
||||||
buffer: new ReglBuffer(reGL, {
|
|
||||||
data: [
|
|
||||||
[-4, -4],
|
|
||||||
[4, -4],
|
|
||||||
[0, 4],
|
|
||||||
],
|
|
||||||
type: gl.FLOAT,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
uniforms: {
|
|
||||||
// 创建一个红色的纹理
|
|
||||||
u_Texture: texture,
|
|
||||||
},
|
|
||||||
depth: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
count: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
reGL.clear({
|
|
||||||
color: [0, 0, 0, 0],
|
|
||||||
});
|
|
||||||
|
|
||||||
texture.resize({
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
model.draw({});
|
|
||||||
|
|
||||||
texture.destroy();
|
|
||||||
|
|
||||||
// 全屏应该都是红色
|
|
||||||
expect(checkPixels(reGL, [255])).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,15 +0,0 @@
|
||||||
import regl from 'l7regl';
|
|
||||||
|
|
||||||
// borrow from https://github.com/regl-project/regl/blob/gh-pages/test/attributes.js#L303-L311
|
|
||||||
export default function checkPixels(
|
|
||||||
reGL: regl.Regl,
|
|
||||||
expected: number[],
|
|
||||||
): boolean {
|
|
||||||
const actual = reGL.read();
|
|
||||||
for (let i = 0; i < 1 * 1; ++i) {
|
|
||||||
if (actual[4 * i] !== expected[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
import gl from 'gl';
|
|
||||||
|
|
||||||
// borrow from regl
|
|
||||||
// @see https://github.com/regl-project/regl/blob/gh-pages/test/util/create-context.js#L28
|
|
||||||
const CONTEXT = gl(1, 1, { preserveDrawingBuffer: true });
|
|
||||||
const RESIZE = CONTEXT.getExtension('STACKGL_resize_drawingbuffer');
|
|
||||||
|
|
||||||
export default function(width: number, height: number) {
|
|
||||||
resize(width, height);
|
|
||||||
return CONTEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resize(width: number, height: number) {
|
|
||||||
if (RESIZE) {
|
|
||||||
RESIZE.resize(width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function destroy() {
|
|
||||||
//
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
const globalDefaultprecision =
|
|
||||||
'#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n#endif\n';
|
|
||||||
export default globalDefaultprecision;
|
|
|
@ -109,7 +109,7 @@ layout(std140) uniform ub_MaterialParams {
|
||||||
out vec4 outputColor;
|
out vec4 outputColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
outputColor = vec4(1.0, 0.0, 0.0, 1.0);
|
outputColor = vec4(1.0, 0.0, 0.0, 0.5);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -237,6 +237,61 @@ class ReglModel {
|
||||||
// draw 6 vertices
|
// draw 6 vertices
|
||||||
bufferGeometry.vertexCount = 6;
|
bufferGeometry.vertexCount = 6;
|
||||||
|
|
||||||
|
const offset = 0.5;
|
||||||
|
const bufferGeometry2 = new BufferGeometry(device);
|
||||||
|
bufferGeometry2.setVertexBuffer({
|
||||||
|
bufferIndex: VertexAttributeBufferIndex.POSITION,
|
||||||
|
byteStride: 4 * 3,
|
||||||
|
frequency: VertexBufferFrequency.PerVertex,
|
||||||
|
attributes: [
|
||||||
|
{
|
||||||
|
format: Format.F32_RGB,
|
||||||
|
bufferByteOffset: 4 * 0,
|
||||||
|
location: VertexAttributeLocation.POSITION,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// use 6 vertices
|
||||||
|
data: Float32Array.from([
|
||||||
|
120 + offset,
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
120 + offset,
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
120 + offset,
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
120 + offset,
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
120 + offset,
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
120 + offset,
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
bufferGeometry2.setVertexBuffer({
|
||||||
|
bufferIndex: VertexAttributeBufferIndex.MAX,
|
||||||
|
byteStride: 4 * 3,
|
||||||
|
frequency: VertexBufferFrequency.PerVertex,
|
||||||
|
attributes: [
|
||||||
|
{
|
||||||
|
format: Format.F32_RGB,
|
||||||
|
bufferByteOffset: 4 * 0,
|
||||||
|
location: VertexAttributeLocation.MAX,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// use 6 vertices
|
||||||
|
data: Float32Array.from([
|
||||||
|
1, 1, 0, -1, 1, 0, -1, -1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0,
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
// draw 6 vertices
|
||||||
|
bufferGeometry.vertexCount = 6;
|
||||||
|
bufferGeometry2.vertexCount = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see https://g.antv.antgroup.com/api/3d/mesh
|
* @see https://g.antv.antgroup.com/api/3d/mesh
|
||||||
*/
|
*/
|
||||||
|
@ -248,7 +303,16 @@ class ReglModel {
|
||||||
material: shaderMaterial,
|
material: shaderMaterial,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const mesh2 = new Mesh({
|
||||||
|
style: {
|
||||||
|
fill: '#1890FF',
|
||||||
|
opacity: 1,
|
||||||
|
geometry: bufferGeometry2,
|
||||||
|
material: shaderMaterial,
|
||||||
|
},
|
||||||
|
});
|
||||||
canvas.appendChild(mesh);
|
canvas.appendChild(mesh);
|
||||||
|
canvas.appendChild(mesh2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addUniforms(uniforms: any) {
|
public addUniforms(uniforms: any) {
|
||||||
|
@ -271,6 +335,7 @@ class ReglModel {
|
||||||
u_ViewportCenter,
|
u_ViewportCenter,
|
||||||
u_ViewportCenterProjection,
|
u_ViewportCenterProjection,
|
||||||
} = this.uniforms;
|
} = this.uniforms;
|
||||||
|
console.log('u_ZoomScale', u_ZoomScale);
|
||||||
|
|
||||||
this.shaderMaterial.setUniforms({
|
this.shaderMaterial.setUniforms({
|
||||||
u_CoordinateSystem,
|
u_CoordinateSystem,
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
// @ts-ignore
|
|
||||||
import { TestScene } from '@antv/l7-test-utils'
|
|
||||||
|
|
||||||
|
|
||||||
describe('template', () => {
|
|
||||||
|
|
||||||
const el = document.createElement('div');
|
|
||||||
el.id = 'test-div-id';
|
|
||||||
const body = document.querySelector('body') as HTMLBodyElement;
|
|
||||||
body.appendChild(el);
|
|
||||||
const scene = TestScene({});
|
|
||||||
|
|
||||||
|
|
||||||
it('scene map status', async () => {
|
|
||||||
expect( scene.getZoom()).toEqual(3)
|
|
||||||
expect(scene.getMinZoom()).toEqual(-2)
|
|
||||||
expect(scene.getMaxZoom()).toEqual(22)
|
|
||||||
expect(scene.getType()).toEqual('default');
|
|
||||||
expect(scene.getBounds()).toEqual([[92.61570169583138, 18.27006017947646], [127.7719516958324, 40.94589761553888]])
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,9 +0,0 @@
|
||||||
// @ts-ignore
|
|
||||||
import { PolygonLayer } from '@antv/l7-layers';
|
|
||||||
import { Map } from '@antv/l7-maps';
|
|
||||||
import { Scene } from '../src/';
|
|
||||||
describe('template', () => {
|
|
||||||
it('scene l7 map method', () => {
|
|
||||||
expect(2).toEqual(2);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -34,9 +34,6 @@
|
||||||
"mapbox-gl": "^1.2.1",
|
"mapbox-gl": "^1.2.1",
|
||||||
"reflect-metadata": "^0.1.13"
|
"reflect-metadata": "^0.1.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"@antv/l7-test-utils": "2.11.4"
|
|
||||||
},
|
|
||||||
"gitHead": "684ba4eb806a798713496d3fc0b4d1e17517dc31",
|
"gitHead": "684ba4eb806a798713496d3fc0b4d1e17517dc31",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
|
|
@ -4,8 +4,6 @@ declare module '@antv/l7-layers';
|
||||||
declare module '@antv/l7-maps';
|
declare module '@antv/l7-maps';
|
||||||
declare module '@antv/l7-utils';
|
declare module '@antv/l7-utils';
|
||||||
declare module '@antv/l7-scene';
|
declare module '@antv/l7-scene';
|
||||||
declare module '@antv/l7-test-utils';
|
|
||||||
declare module '@antv/l7-test-utils';
|
|
||||||
declare module '@antv/l7-component';
|
declare module '@antv/l7-component';
|
||||||
declare module 'l7regl';
|
declare module 'l7regl';
|
||||||
declare module 'l7hammerjs';
|
declare module 'l7hammerjs';
|
||||||
|
|
Loading…
Reference in New Issue