change drawable interface

This commit is contained in:
monoid 2021-10-10 00:20:31 +09:00
parent af1a1319a5
commit 1517b1ef2c
4 changed files with 9 additions and 7 deletions

View File

@ -35,8 +35,8 @@ export class CanvasApp{
this.gl.clearColor(0,0,0,0);
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
this.renderer.draw(this.gl);
this.trenderer.draw(this.gl);
this.renderer.draw(this.gl,{});
this.trenderer.draw(this.gl,{});
requestAnimationFrame(this.drawScene.bind(this));
}
};

View File

@ -1,4 +1,6 @@
export interface RenderState{
}
export interface Drawable{
draw(gl:WebGL2RenderingContext):void;
draw(gl:WebGL2RenderingContext, state : RenderState):void;
};

View File

@ -17,7 +17,7 @@ uniform vec4 u_color;
void main() {
outColor = u_color;
}`;
import { Drawable } from "./drawable";
import { Drawable, RenderState } from "./drawable";
import * as G from "./glWrapper";
import { getUniformDefaultValue, UniformSet } from "./uniform";
@ -82,7 +82,7 @@ export class Drawer2D implements Drawable{
setUniform(u:UniformSet){
this.uniforms = u;
}
draw(gl:WebGL2RenderingContext){
draw(gl:WebGL2RenderingContext, state : RenderState){
this.useProgram();
this.program.setUniform4fv(gl,"u_color",[this.uniforms.redcolor,0.3,0.8,1.0]);

View File

@ -1,4 +1,4 @@
import { Drawable } from "./drawable";
import { Drawable, RenderState } from "./drawable";
import {createProgramFromSource, ProgramError, ShaderError} from "./gl_util";
import { createIndexBuffer, createVertexArray, createVertexBuffer, GLProgram, IndexBuffer, VertexArray, VertexBuffer } from "./glWrapper";
@ -55,7 +55,7 @@ export class TriangleDrawer implements Drawable{
this.indexBuffer.bind(gl);
this.vao.unbind(gl);
}
draw(gl: WebGL2RenderingContext): void {
draw(gl: WebGL2RenderingContext, state :RenderState): void {
this.program.use(gl);
this.vao.bind(gl);