Code coverage report for src/pixi/renderers/webgl/shaders/PrimitiveShader.js

Statements: 11.11% (2 / 18)      Branches: 100% (0 / 0)      Functions: 0% (0 / 2)      Lines: 11.11% (2 / 18)     

All files » src/pixi/renderers/webgl/shaders\ » PrimitiveShader.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66          1                                                                         1                                              
/**
 * @author Mat Groves http://matgroves.com/ @Doormat23
 */
 
 
PIXI.PrimitiveShader = function(gl)
{
    this.gl = gl;
 
    // the webGL program..
    this.program = null;
 
    this.fragmentSrc = [
        'precision mediump float;',
        'varying vec4 vColor;',
 
        'void main(void) {',
        '   gl_FragColor = vColor;',
        '}'
    ];
 
    this.vertexSrc  = [
        'attribute vec2 aVertexPosition;',
        'attribute vec4 aColor;',
        'uniform mat3 translationMatrix;',
        'uniform vec2 projectionVector;',
        'uniform vec2 offsetVector;',
        'uniform float alpha;',
        'uniform vec3 tint;',
        'varying vec4 vColor;',
 
        'void main(void) {',
        '   vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);',
        '   v -= offsetVector.xyx;',
        '   gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);',
        '   vColor = aColor * vec4(tint * alpha, alpha);',
        '}'
    ];
 
    this.init();
};
 
PIXI.PrimitiveShader.prototype.init = function()
{
 
    var gl = this.gl;
 
    var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc);
    gl.useProgram(program);
 
    // get and store the uniforms for the shader
    this.projectionVector = gl.getUniformLocation(program, 'projectionVector');
    this.offsetVector = gl.getUniformLocation(program, 'offsetVector');
    this.tintColor = gl.getUniformLocation(program, 'tint');
 
 
    // get and store the attributes
    this.aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition');
    this.colorAttribute = gl.getAttribLocation(program, 'aColor');
 
    this.translationMatrix = gl.getUniformLocation(program, 'translationMatrix');
    this.alpha = gl.getUniformLocation(program, 'alpha');
 
    this.program = program;
};