summaryrefslogtreecommitdiffstats
path: root/blockgame/shaders.js
diff options
context:
space:
mode:
Diffstat (limited to 'blockgame/shaders.js')
-rw-r--r--blockgame/shaders.js40
1 files changed, 29 insertions, 11 deletions
diff --git a/blockgame/shaders.js b/blockgame/shaders.js
index f89270a..6a6e9af 100644
--- a/blockgame/shaders.js
+++ b/blockgame/shaders.js
@@ -1,25 +1,43 @@
+
const vs_src = `
- attribute vec4 position;
+ attribute vec4 aVertexPosition;
- uniform mat4 mv_matrix;
- uniform mat4 projection_matrix;
+ uniform mat4 uModelViewMatrix;
+ uniform mat4 uProjectionMatrix;
- void main() {
- gl_Position = projection_matrix * mv_matrix * position;
- }
+ void main() {
+ gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;
+ }
`;
+// Fragment shader program
+
const fs_src = `
- void main() {
- gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
- }
+ void main() {
+ gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
+ }
`;
+export class ShaderInfo {
+ constructor(gl, program) {
+ this.program = program;
+
+ this.attribs = {
+ position: gl.getAttribLocation(program, 'aVertexPosition')
+ };
+
+ this.uniforms = {
+ projectionMatrix: gl.getUniformLocation(program, 'uProjectionMatrix'),
+ modelViewMatrix: gl.getUniformLocation(program, 'uModelViewMatrix')
+ };
+ }
+}
+
export function init(gl) {
const vshader = loadShader(gl, gl.VERTEX_SHADER, vs_src);
const fshader = loadShader(gl, gl.FRAGMENT_SHADER, fs_src);
- const program = gl.createProgram();
+ let program = gl.createProgram();
gl.attachShader(program, vshader);
gl.attachShader(program, fshader);
@@ -30,7 +48,7 @@ export function init(gl) {
return null;
}
- return program;
+ return new ShaderInfo(gl, program);
}
export function loadShader(gl, type, src){