# src/pixi/renderers/WebGLShaders.js - Pixi.JS

#

API Docs for: 1.0.0
Show: Inherited Protected Private Deprecated

# File: src/pixi/renderers/WebGLShaders.js

    /**
     * @author Mat Groves http://matgroves.com/ @Doormat23
     */

    PIXI.shaderFragmentSrc = [
      "precision mediump float;",
      "varying vec2 vTextureCoord;",
      "varying float vColor;",
      "uniform sampler2D uSampler;",
      "void main(void) {",
        "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
        "gl_FragColor = gl_FragColor * vColor;",
      "}"
    ];

    PIXI.shaderVertexSrc = [
      "attribute vec2 aVertexPosition;",
      "attribute vec2 aTextureCoord;",
      "attribute float aColor;",
      "uniform mat4 uMVMatrix;",
      "varying vec2 vTextureCoord;",
      "varying float vColor;",
      "void main(void) {",
        "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);",
        "vTextureCoord = aTextureCoord;",
        "vColor = aColor;",
      "}"
    ];

    PIXI.CompileVertexShader = function(gl, shaderSrc)
    {
      return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER);
    }

    PIXI.CompileFragmentShader = function(gl, shaderSrc)
    {
      return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER);
    }

    PIXI._CompileShader = function(gl, shaderSrc, shaderType)
    {
      var src = shaderSrc.join("\n");
      var shader = gl.createShader(shaderType);
      gl.shaderSource(shader, src);
      gl.compileShader(shader);

      if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
        alert(gl.getShaderInfoLog(shader));
        return null;
      }

      return shader;
    }