Add glMatrix
This commit is contained in:
parent
582979d3ed
commit
e88b4589d2
2 changed files with 212 additions and 359 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { Vec2 } from '../../math/vec2';
|
||||
import { FragmentShaderOnlyProgram } from './fragment-shader-only-program';
|
||||
import { vec2 } from 'gl-matrix';
|
||||
|
||||
export abstract class FrameBuffer {
|
||||
public renderScale = 1;
|
||||
public enableHighDpiRendering = false;
|
||||
|
||||
protected size: Vec2;
|
||||
protected size: vec2;
|
||||
protected frameBuffer: WebGLFramebuffer;
|
||||
|
||||
constructor(
|
||||
|
|
@ -39,10 +39,10 @@ export abstract class FrameBuffer {
|
|||
const displayWidth = Math.floor(canvasWidth * realToCssPixels);
|
||||
const displayHeight = Math.floor(canvasHeight * realToCssPixels);
|
||||
|
||||
this.size = new Vec2(displayWidth, displayHeight);
|
||||
this.size = vec2.fromValues(displayWidth, displayHeight);
|
||||
}
|
||||
|
||||
public getSize(): Vec2 {
|
||||
public getSize(): vec2 {
|
||||
return this.size;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Vec2 } from '../../math/vec2';
|
||||
import { Mat3 } from '../../math/mat3';
|
||||
import { mat3, vec2 } from 'gl-matrix';
|
||||
|
||||
const loaderMat3 = mat3.create();
|
||||
|
||||
export const loadUniform = (
|
||||
gl: WebGL2RenderingContext,
|
||||
|
|
@ -22,23 +23,23 @@ export const loadUniform = (
|
|||
|
||||
converters.set(
|
||||
WebGL2RenderingContext.FLOAT_VEC2,
|
||||
(gl, v: Vec2 | Array<Vec2>, l) => {
|
||||
if (v instanceof Array) {
|
||||
(gl, v: vec2 | Array<vec2>, l) => {
|
||||
if (v[0] instanceof Array) {
|
||||
const result = new Float32Array(v.length * 2);
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
result[2 * i] = v[i].x;
|
||||
result[2 * i + 1] = v[i].y;
|
||||
result[2 * i] = (v[i] as Array<number>).x;
|
||||
result[2 * i + 1] = (v[i] as Array<number>).y;
|
||||
}
|
||||
gl.uniform2fv(l, new Float32Array(result));
|
||||
} else {
|
||||
gl.uniform2fv(l, new Float32Array(v.list));
|
||||
gl.uniform2fv(l, v as vec2);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
converters.set(WebGL2RenderingContext.FLOAT_MAT3, (gl, v: Mat3, l) =>
|
||||
gl.uniformMatrix3fv(l, false, new Float32Array(v.transposedFlat))
|
||||
);
|
||||
converters.set(WebGL2RenderingContext.FLOAT_MAT3, (gl, v, l) => {
|
||||
gl.uniformMatrix3fv(l, true, mat3.fromMat2d(loaderMat3, v));
|
||||
});
|
||||
|
||||
converters.set(WebGL2RenderingContext.BOOL, (gl, v, l) =>
|
||||
gl.uniform1i(l, v)
|
||||
|
|
|
|||
Loading…
Reference in a new issue