more rendering code, not much changes, beginning refactor of the rendering API

This commit is contained in:
2026-04-02 06:31:30 +02:00
parent 92418e7e4e
commit 60313f5373
7 changed files with 317 additions and 263 deletions
+19 -2
View File
@@ -4,6 +4,7 @@ class Renderer {
private gl: WebGL2RenderingContext;
private posBuffer!: WebGLBuffer;
private program!: WebGLProgram;
private drawMode: DrawMode = DrawMode.TEX;
constructor(canvas: HTMLCanvasElement) {
let context = canvas.getContext('webgl2');
@@ -45,7 +46,6 @@ class Renderer {
this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
let resUniLoc = this.gl.getUniformLocation(program, 'u_resolution');
this.gl.uniform2f(resUniLoc, this.gl.canvas.width, this.gl.canvas.height);
this.gl.clearColor(0, 0, 0, 0);
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
@@ -56,6 +56,7 @@ class Renderer {
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, pos);
this.gl.vertexAttribPointer(0, 2, this.gl.FLOAT, false, 0, 0);
this.gl.uniform2f(resUniLoc, this.gl.canvas.width, this.gl.canvas.height);
} catch (error) {
console.log(error);
this.gl.VERTEX_SHADER;
@@ -91,7 +92,17 @@ class Renderer {
this.gl.viewport(0, 0, width, height);
}
/**
* Set the draw mode to one of the enum values
* @param {DrawMode} mode
* @returns {void}
*/
public set SetDrawMode(mode: DrawMode) {}
public Draw(pos: Vector2, size: number): void {
//this.gl.clearColor(0, 0, 0, 0);
// this.gl.clear(this.gl.COLOR_BUFFER_BIT);
let x1 = pos.x - size;
let x2 = pos.x + size;
let y1 = pos.y + size;
@@ -101,7 +112,7 @@ class Renderer {
this.gl.bufferData(
this.gl.ARRAY_BUFFER,
new Float32Array([x1, y1, x2, y1, x2, y2, x1, y1, x1, y2, x2, y2]),
this.gl.STATIC_DRAW
this.gl.DYNAMIC_DRAW
);
var primitiveType = this.gl.TRIANGLES;
@@ -111,4 +122,10 @@ class Renderer {
}
}
enum DrawMode {
TEX = 0,
WIRE = 1,
VERT = 2
}
export default Renderer;