diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2019-12-24 13:53:16 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2019-12-24 13:53:16 +0100 |
commit | 3c51a1994f41b625823c4f15e92396b5498ce23c (patch) | |
tree | 7a96310ec32df82ac87039ea555300bcab510a5e /src/renderer/view/renderer/shaders.ts | |
parent | 33926af829848050c54c698ed22da9fe2b912aea (diff) | |
download | rpgedit-3c51a1994f41b625823c4f15e92396b5498ce23c.tar rpgedit-3c51a1994f41b625823c4f15e92396b5498ce23c.zip |
Move renderer into "runtime" subdirectory
Diffstat (limited to 'src/renderer/view/renderer/shaders.ts')
-rw-r--r-- | src/renderer/view/renderer/shaders.ts | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/src/renderer/view/renderer/shaders.ts b/src/renderer/view/renderer/shaders.ts deleted file mode 100644 index 8fd1fda..0000000 --- a/src/renderer/view/renderer/shaders.ts +++ /dev/null @@ -1,79 +0,0 @@ -import fragmentShaderSrc from './shaders/default.fs'; -import vertexShaderSrc from './shaders/default.vs'; - -export class Shaders { - public readonly viewportLoc: WebGLUniformLocation; - public readonly translateLoc: WebGLUniformLocation; - - public readonly vertexPosLoc: number; - public readonly textureCoordLoc: number; - public readonly samplerLoc: WebGLUniformLocation; - - constructor(private readonly gl: WebGLRenderingContext) { - const shaderProgram = this.gl.createProgram(); - if (!shaderProgram) - throw new Error('Unable to create shader program'); - - const vertexShader = this.compileShader(this.gl.VERTEX_SHADER, vertexShaderSrc); - const fragmentShader = this.compileShader(this.gl.FRAGMENT_SHADER, fragmentShaderSrc); - - this.gl.attachShader(shaderProgram, vertexShader); - this.gl.attachShader(shaderProgram, fragmentShader); - - this.gl.linkProgram(shaderProgram); - if (!this.gl.getProgramParameter(shaderProgram, this.gl.LINK_STATUS)) { - const err = this.gl.getProgramInfoLog(shaderProgram); - - this.gl.deleteShader(vertexShader); - this.gl.deleteShader(fragmentShader); - this.gl.deleteProgram(shaderProgram); - - throw new Error('Unable to link shader: ' + err); - } - - this.gl.useProgram(shaderProgram); - - this.vertexPosLoc = this.getAttribLocation(shaderProgram, 'aVertexPos'); - this.gl.enableVertexAttribArray(this.vertexPosLoc); - - this.textureCoordLoc = this.getAttribLocation(shaderProgram, 'aTextureCoord'); - this.gl.enableVertexAttribArray(this.textureCoordLoc); - - this.viewportLoc = this.getUniformLocation(shaderProgram, 'uViewport'); - this.translateLoc = this.getUniformLocation(shaderProgram, 'uTranslate'); - this.samplerLoc = this.getUniformLocation(shaderProgram, 'uSampler'); - } - - private compileShader(type: number, src: string): WebGLShader { - const shader = this.gl.createShader(type); - if (!shader) - throw new Error('Unable to create shader'); - - this.gl.shaderSource(shader, src); - this.gl.compileShader(shader); - - if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { - const err = this.gl.getShaderInfoLog(shader); - this.gl.deleteShader(shader); - throw new Error('Unable to compile shader: ' + err); - } - - return shader; - } - - private getAttribLocation(program: WebGLProgram, name: string): number { - const ret = this.gl.getAttribLocation(program, name); - if (ret < 0) - throw new Error("unable to get location of attribute '" + name + "'"); - - return ret; - } - - private getUniformLocation(program: WebGLProgram, name: string): WebGLUniformLocation { - const ret = this.gl.getUniformLocation(program, name); - if (!ret) - throw new Error("unable to get location of uniform '" + name + "'"); - - return ret; - } -} |