新增webgl帮助类 用于自定义绘图
This commit is contained in:
6
demo/libs/framework/framework.d.ts
vendored
6
demo/libs/framework/framework.d.ts
vendored
@@ -545,3 +545,9 @@ declare class Vector2Ext {
|
||||
static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
|
||||
static cross(u: Vector2, v: Vector2): number;
|
||||
}
|
||||
declare class WebGLUtils {
|
||||
static getWebGL(): WebGLRenderingContext;
|
||||
static drawUserIndexPrimitives<T>(primitiveType: number, vertexData: T[], vertexOffset: number, numVertices: number, indexData: number[], indexOffset: number, primitiveCount: number): void;
|
||||
private static getElementCountArray;
|
||||
static checkGLError(): void;
|
||||
}
|
||||
|
||||
@@ -2677,3 +2677,41 @@ var Vector2Ext = (function () {
|
||||
};
|
||||
return Vector2Ext;
|
||||
}());
|
||||
var WebGLUtils = (function () {
|
||||
function WebGLUtils() {
|
||||
}
|
||||
WebGLUtils.getWebGL = function () {
|
||||
return document.querySelector("canvas").getContext("webgl");
|
||||
};
|
||||
WebGLUtils.drawUserIndexPrimitives = function (primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount) {
|
||||
var 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();
|
||||
};
|
||||
WebGLUtils.getElementCountArray = function (primitiveType, primitiveCount) {
|
||||
var 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");
|
||||
};
|
||||
WebGLUtils.checkGLError = function () {
|
||||
var GL = this.getWebGL();
|
||||
var error = GL.getError();
|
||||
if (error != GL.NO_ERROR) {
|
||||
throw new Error("GL.GetError() returned" + error);
|
||||
}
|
||||
};
|
||||
return WebGLUtils;
|
||||
}());
|
||||
|
||||
2
demo/libs/framework/framework.min.js
vendored
2
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user