diff --git a/package.json b/package.json index 5363cd5..a3be3c9 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@emotion/styled": "^11.3.0", "@mui/material": "^5.0.1", "@types/react": "^17.0.24", + "gl-matrix": "^3.3.0", "parcel-bundler": "^1.12.5", "react": "^17.0.2", "react-dom": "^17.0.2" diff --git a/src/glWrapper.ts b/src/glWrapper.ts index e70c410..a6723cc 100644 --- a/src/glWrapper.ts +++ b/src/glWrapper.ts @@ -1,3 +1,4 @@ +import { mat4, vec2, vec3, vec4 } from "gl-matrix"; import * as util from "./gl_util"; export class VertexBuffer{ @@ -88,10 +89,32 @@ export class GLProgram{ use(gl:WebGL2RenderingContext):void{ gl.useProgram(this.program); } - setUniform4fv(gl:WebGL2RenderingContext,name:string,v:number[]){ + + setUniform1i(gl:WebGL2RenderingContext,name:string,v:number){ + const loc = this.getUniformLocation(gl,name); + gl.uniform1i(loc,v); + } + setUniform1f(gl:WebGL2RenderingContext,name:string,v:number){ + const loc = this.getUniformLocation(gl,name); + gl.uniform1f(loc,v); + } + setUniform2fv(gl:WebGL2RenderingContext,name:string,v:vec2){ + const loc = this.getUniformLocation(gl,name); + gl.uniform2fv(loc,v); + } + setUniform3fv(gl:WebGL2RenderingContext,name:string,v:vec3){ + const loc = this.getUniformLocation(gl,name); + gl.uniform3fv(loc,v); + } + setUniform4fv(gl:WebGL2RenderingContext,name:string,v:vec4){ const loc = this.getUniformLocation(gl,name); gl.uniform4fv(loc,v); } + setUniformMat4f(gl:WebGL2RenderingContext,name:string,v:mat4){ + const loc = this.getUniformLocation(gl,name); + gl.uniformMatrix4fv(loc,false,v); + } + unuse(gl:WebGL2RenderingContext):void{ gl.useProgram(null); }