修复polygon数组错误 修复emit空注册报错

This commit is contained in:
yhh
2020-06-15 20:08:21 +08:00
parent c3120d791f
commit 5186bc0187
16 changed files with 398 additions and 32 deletions

View File

@@ -23,7 +23,9 @@ class Emitter<T> {
public emit(eventType: T, data: any){
let list: Function[] = this._messageTable.get(eventType);
for (let i = list.length - 1; i >= 0; i --)
list[i](data);
if (list){
for (let i = list.length - 1; i >= 0; i --)
list[i](data);
}
}
}

View File

@@ -1,12 +1,13 @@
class WebGLUtils {
public static getWebGL(): WebGLRenderingContext{
public static getWebGL(): WebGLRenderingContext {
if (egret.WebGLUtils.checkCanUseWebGL())
return document.querySelector("canvas").getContext("webgl");
throw new Error("cannot get webgl");
}
public static drawUserIndexPrimitives<T>(primitiveType: number, vertexData: T[], vertexOffset: number, numVertices: number, indexData: number[], indexOffset: number, primitiveCount: number){
public static drawUserIndexPrimitives<T>(primitiveType: number, vertexData: T[], vertexOffset: number,
numVertices: number, indexData: number[], indexOffset: number, primitiveCount: number) {
let GL = this.getWebGL();
GL.bindBuffer(GL.ARRAY_BUFFER, 0);
@@ -14,16 +15,16 @@ class WebGLUtils {
GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
this.checkGLError();
GL.drawElements(primitiveType,
this.getElementCountArray(primitiveType, primitiveCount),
GL.UNSIGNED_SHORT,
GL.drawElements(primitiveType,
this.getElementCountArray(primitiveType, primitiveCount),
GL.UNSIGNED_SHORT,
indexOffset * 2);
this.checkGLError();
}
private static getElementCountArray(primitiveType: number, primitiveCount: number){
private static getElementCountArray(primitiveType: number, primitiveCount: number) {
let GL = this.getWebGL();
switch (primitiveType){
switch (primitiveType) {
case GL.LINES:
return primitiveCount * 2;
case GL.LINE_STRIP:
@@ -37,10 +38,10 @@ class WebGLUtils {
throw new Error("not support");
}
public static checkGLError(){
public static checkGLError() {
let GL = this.getWebGL();
let error = GL.getError();
if (error != GL.NO_ERROR){
if (error != GL.NO_ERROR) {
throw new Error("GL.GetError() returned" + error);
}
}