ecs适配egret
This commit is contained in:
@@ -63,4 +63,8 @@ class Vector2Ext {
|
||||
public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) {
|
||||
this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
|
||||
}
|
||||
|
||||
public static round(vec: Vector2){
|
||||
return new Vector2(Math.round(vec.x), Math.round(vec.y));
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
class WebGLUtils {
|
||||
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) {
|
||||
let GL = this.getWebGL();
|
||||
|
||||
GL.bindBuffer(GL.ARRAY_BUFFER, 0);
|
||||
this.checkGLError();
|
||||
GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0);
|
||||
this.checkGLError();
|
||||
|
||||
GL.drawElements(primitiveType,
|
||||
this.getElementCountArray(primitiveType, primitiveCount),
|
||||
GL.UNSIGNED_SHORT,
|
||||
indexOffset * 2);
|
||||
this.checkGLError();
|
||||
}
|
||||
|
||||
private static getElementCountArray(primitiveType: number, primitiveCount: number) {
|
||||
let GL = this.getWebGL();
|
||||
switch (primitiveType) {
|
||||
case GL.LINES:
|
||||
return primitiveCount * 2;
|
||||
case GL.LINE_STRIP:
|
||||
return primitiveCount + 1;
|
||||
case GL.TRIANGLES:
|
||||
return primitiveCount * 3;
|
||||
case GL.TRIANGLE_STRIP:
|
||||
return primitiveCount + 2;
|
||||
}
|
||||
|
||||
throw new Error("not support");
|
||||
}
|
||||
|
||||
public static checkGLError() {
|
||||
let GL = this.getWebGL();
|
||||
let error = GL.getError();
|
||||
if (error != GL.NO_ERROR) {
|
||||
throw new Error("GL.GetError() returned" + error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user