Creates a new program from the supplied vertex and fragment shaders.

@return A handle to the program, or 0 on failure.
558548
public static int createProgram(String vertexSource, String fragmentSource) {
        int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
        if (vertexShader == 0) {
            return 0;
        }
        int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
        if (pixelShader == 0) {
            return 0;
        }

        int program = GLES20.glCreateProgram();
        checkGlError("glCreateProgram");
        if (program == 0) {
            Log.e(TAG, "Could not create program");
        }
        GLES20.glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        GLES20.glAttachShader(program, pixelShader);
        checkGlError("glAttachShader");
        GLES20.glLinkProgram(program);
        int[] linkStatus = new int[1];
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
        if (linkStatus[0] != GLES20.GL_TRUE) {
            Log.e(TAG, "Could not link program: ");
            Log.e(TAG, GLES20.glGetProgramInfoLog(program));
            GLES20.glDeleteProgram(program);
            program = 0;
        }
        return program;
    }
810831
private void createVertexNumber()
    {
    	c = graph.vertexSet().size();
        vertexToVertexNumber = new HashMap<>(c);

        for (V vertex : graph.vertexSet()) {
            vertexToVertexNumber.put(vertex, new VertexNumber<V>(vertex, 0));            
        }
        
        stack = new ArrayDeque<>(c);
        B = new ArrayDeque<>(c);
    }
697563
public static int compileShader(Class<?> context, GL2 gl, int type, String name) throws ShaderCompilationException {
    int prog = -1;
    try (InputStream in = context.getResourceAsStream(name)) {
      int[] error = new int[1];
      String shaderdata = FileUtil.slurp(in);
      prog = gl.glCreateShader(type);
      gl.glShaderSource(prog, 1, new String[] { shaderdata }, null, 0);
      gl.glCompileShader(prog);
      // This worked best for me to capture error messages:
      gl.glGetObjectParameterivARB(prog, GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB, error, 0);
      if(error[0] > 1) {
        byte[] info = new byte[error[0]];
        gl.glGetInfoLogARB(prog, info.length, error, 0, info, 0);
        String out = new String(info);
        gl.glDeleteShader(prog);
        throw new ShaderCompilationException("Shader compilation error in '" + name + "': " + out);
      }
      // Different way of catching errors.
      gl.glGetShaderiv(prog, GL2.GL_COMPILE_STATUS, error, 0);
      if(error[0] > 1) {
        throw new ShaderCompilationException("Shader compilation of '" + name + "' failed.");
      }
    }
    catch(IOException e) {
      throw new ShaderCompilationException("IO error loading shader: " + name, e);
    }
    return prog;
  }
536867
public byte[] getProgram() {
        try {
            // Don't round-trip as Bitcoin Core doesn't and it would introduce a mismatch.
            if (program != null)
                return Arrays.copyOf(program, program.length);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            for (ScriptChunk chunk : chunks) {
                chunk.write(bos);
            }
            program = bos.toByteArray();
            return program;
        } catch (IOException e) {
            throw new RuntimeException(e);  // Cannot happen.
        }
    }
612909
public CompletionHandler createAsyncHandler() {
        return Utility.createAsyncHandler((v, a) -> {
            finish(v);
        }, (t, a) -> {
            context.getLogger().log(Level.WARNING, "Servlet occur, force to close channel. request = " + request + ", result is CompletionHandler", (Throwable) t);
            finish(500, null);
        });
    }
609958
function makePointsProgram(gl, data) {
  let vertexProgram = vertexProgramCache.get(gl)
  if (!vertexProgram) {
    let vertexShader = gl_utils.compile(gl, gl.VERTEX_SHADER, vertexShaderSrc);
    let fragmentShader = gl_utils.compile(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
    vertexProgram = gl_utils.link(gl, vertexShader, fragmentShader);
    vertexProgramCache.set(gl, vertexProgram);
  }

  let locations = gl_utils.getLocations(gl, vertexProgram);

  var buffer = gl.createBuffer();
  if (!buffer) throw new Error('failed to create a nodesBuffer');
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  gl.bufferData(gl.ARRAY_BUFFER, data.byteLength, gl.DYNAMIC_DRAW);

  var pointTexture = createCircleTexture(gl);

  var api = {
    draw,
    updateData,
    dispose
  };
  return api;

  function updateData(newData) {
    data = newData;
  }

  function dispose() {
    // For some reason disposing the buffer results in unbindable
    // buffer for the lines program (that is created after this scene is disposed).
    // gl.deleteBuffer(buffer);
    gl.deleteProgram(vertexProgram);
    gl.deleteTexture(pointTexture);
    vertexProgramCache.delete(gl);
  }

  function draw(transform, screen, count) {
    gl.useProgram(vertexProgram);

    var bpe = data.BYTES_PER_ELEMENT;

    if (transform) {
      gl.uniformMatrix4fv(locations.uniforms.uTransform, false, transform.getArray());
    }
    gl.uniform2f(locations.uniforms.uScreenSize, screen.width, screen.height);
    gl.bindTexture(gl.TEXTURE_2D, pointTexture);

    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
    gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);

    gl.vertexAttribPointer(locations.attributes.aPosition, 2, gl.FLOAT, false, bpe * 6, 0)
    gl.enableVertexAttribArray(locations.attributes.aPosition)

    gl.vertexAttribPointer(locations.attributes.aPointSize, 1, gl.FLOAT, false, bpe * 6, 2 * bpe)
    gl.enableVertexAttribArray(locations.attributes.aPointSize)

    gl.vertexAttribPointer(locations.attributes.aColor, 3, gl.FLOAT, false, bpe * 6, 3 * bpe)
    gl.enableVertexAttribArray(locations.attributes.aColor);
    gl.drawArrays(gl.POINTS, 0, count);
  }
}
842535
function compileProgram(gl, vertex, fragment) {
       var vertShader = compileShader(gl, gl.VERTEX_SHADER, vertex);
       var fragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
       var program = gl.createProgram();
       gl.attachShader(program, vertShader);
       gl.attachShader(program, fragShader);
       gl.linkProgram(program);

       if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
         throw new Error("Error initializing Shader " + this + "\n" + "gl.VALIDATE_STATUS: " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n" + "gl.getError()" + gl.getError() + "\n" + "gl.getProgramInfoLog()" + gl.getProgramInfoLog(program));
       }

       gl.useProgram(program); // clean-up

       gl.deleteShader(vertShader);
       gl.deleteShader(fragShader);
       return program;
     }
507348
function initShaders() {
  var fragmentShader = getShader(gl, fragmentShaderSource, false);
  var vertexShader = getShader(gl, vertexShaderSource, true);

  // Create the shader program

  shaderProgram = gl.createProgram();
  gl.attachShader(shaderProgram, vertexShader);
  gl.attachShader(shaderProgram, fragmentShader);
  gl.linkProgram(shaderProgram);

  // If creating the shader program failed, alert

  if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
    alert("Unable to initialize the shader program: " + gl.getProgramInfoLog(shader));
  }

  gl.useProgram(shaderProgram);

  vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
  gl.enableVertexAttribArray(vertexPositionAttribute);
}
969661
protected QuadBatch createDefaultBatch (GL20 gl) {
    try {
      if (UniformQuadBatch.isLikelyToPerform(gl)) return new UniformQuadBatch(gl);
    } catch (Exception e) {
      // oops, fall through and use a TriangleBatch
    }
    return new TriangleBatch(gl);
  }
1339073
public static RenderTarget create (Graphics gfx, final Texture tex) {
    GL20 gl = gfx.gl;
    final int fb = gl.glGenFramebuffer();
    if (fb == 0) throw new RuntimeException("Failed to gen framebuffer: " + gl.glGetError());
    gl.glBindFramebuffer(GL_FRAMEBUFFER, fb);
    gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.id, 0);
    gl.checkError("RenderTarget.create");
    return new RenderTarget (gfx) {
      public int id () { return fb; }
      public int width () { return tex.pixelWidth; }
      public int height () { return tex.pixelHeight; }
      public float xscale () { return tex.pixelWidth / tex.displayWidth; }
      public float yscale () { return tex.pixelHeight / tex.displayHeight; }
      public boolean flip () { return false; }
    };
  }
1279952
@Override
    public ExecutionGraphVertex createVertex(String address) {
        // create new vertex object
        ExecutionGraphVertex v = ExecutionGraph.createVertex(removeSymbol(address, '$'));

        // add vertex to actual graph
        this.graph.addVertex(v);

        // put new vertex to set of vertices with the same address, since they
        // all must have the same set of properties and values
        Set<ExecutionGraphVertex> vs = this.addressToVertices.getOrDefault(address, new HashSet<>());
        vs.add(v);
        if (vs.size() - 1 == 0) { this.addressToVertices.put(address, vs); }

        return v;
    }
761387
function() {
    if (!this.normals) this.addVertexBuffer('normals', 'gl_Normal');
    for (var i = 0; i < this.vertices.length; i++) {
      this.normals[i] = new Vector();
    }
    for (var i = 0; i < this.triangles.length; i++) {
      var t = this.triangles[i];
      var a = Vector.fromArray(this.vertices[t[0]]);
      var b = Vector.fromArray(this.vertices[t[1]]);
      var c = Vector.fromArray(this.vertices[t[2]]);
      var normal = b.subtract(a).cross(c.subtract(a)).unit();
      this.normals[t[0]] = this.normals[t[0]].add(normal);
      this.normals[t[1]] = this.normals[t[1]].add(normal);
      this.normals[t[2]] = this.normals[t[2]].add(normal);
    }
    for (var i = 0; i < this.vertices.length; i++) {
      this.normals[i] = this.normals[i].unit().toArray();
    }
    this.compile();
    return this;
  }
527474
def insert_into_shaders(self, vertex, fragment):
        """"""
        to_insert = defaultdict(str)
        to_insert.update({key: '\n'.join(self._to_insert[key]) + '\n'
                          for key in self._to_insert})
        return _insert_glsl(vertex, fragment, to_insert)
1321800
function compile(gl, vertSource, fragSource, attribs, verbose) {
    var log = "";

    var vert = loadShader(gl, gl.VERTEX_SHADER, vertSource, verbose);
    var frag = loadShader(gl, gl.FRAGMENT_SHADER, fragSource, verbose);

    var vertShader = vert.shader;
    var fragShader = frag.shader;

    log += vert.log + "\n" + frag.log;

    var program = gl.createProgram();

    gl.attachShader(program, vertShader);
    gl.attachShader(program, fragShader);

    //TODO: Chrome seems a bit buggy with attribute bindings...
    if (attribs) {
        for (var key in attribs) {
            if (attribs.hasOwnProperty(key)) {
                gl.bindAttribLocation(program, Math.floor(attribs[key]), key);
            }
        }
    }

    gl.linkProgram(program); 

    log += gl.getProgramInfoLog(program) || "";

    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
        if (verbose) {
            console.error("Shader error:\n"+log);
            console.error("Problematic shaders:\nVERTEX_SHADER:\n"+addLineNumbers(vertSource)
                    +"\n\nFRAGMENT_SHADER:\n"+addLineNumbers(fragSource));
        }
        //delete before throwing error    
        gl.detachShader(program, vertShader);
        gl.detachShader(program, fragShader);
        gl.deleteShader(vertShader);
        gl.deleteShader(fragShader);
        
        throw new Error("Error linking the shader program:\n" + log);

    }
    return {
        program: program,
        vertex: vertShader,
        fragment: fragShader,
        log: log.trim()
    };
}
861379
function() {
		this.gl = this.context.gl;
		var gl = this.gl;
		this.vertexBuffer = gl.createBuffer();

		//ignore index buffer if we haven't specified any
		this.indexBuffer = this.numIndices > 0
					? gl.createBuffer()
					: null;

		this.dirty = true;
	}
416127
def _insert_glsl(vertex, fragment, to_insert):
    
    # Find the place where to insert the GLSL snippet.
    # This is "gl_Position = transform(data_var_name);" where
    # data_var_name is typically an attribute.
    vs_regex = re.compile(r'gl_Position = transform\(([\S]+)\);')
    r = vs_regex.search(vertex)
    if not r:
        logger.debug("The vertex shader doesn't contain the transform "
                     "placeholder: skipping the transform chain "
                     "GLSL insertion.")
        return vertex, fragment
    assert r
    logger.log(5, "Found transform placeholder in vertex code: `%s`",
               r.group(0))

    # Find the GLSL variable with the data (should be a `vec2`).
    var = r.group(1)
    assert var and var in vertex

    # Headers.
    vertex = to_insert['vert', 'header'] + '\n\n' + vertex
    fragment = to_insert['frag', 'header'] + '\n\n' + fragment

    # Get the pre and post transforms.
    vs_insert = to_insert['vert', 'before_transforms']
    vs_insert += to_insert['vert', 'transforms']
    vs_insert += to_insert['vert', 'after_transforms']

    # Insert the GLSL snippet in the vertex shader.
    vertex = vs_regex.sub(indent(vs_insert), vertex)

    # Now, we make the replacements in the fragment shader.
    fs_regex = re.compile(r'(void main\(\)\s*\{)')
    # NOTE: we add the `void main(){` that was removed by the regex.
    fs_insert = '\\1\n' + to_insert['frag', 'before_transforms']
    fragment = fs_regex.sub(indent(fs_insert), fragment)

    # Replace the transformed variable placeholder by its name.
    vertex = vertex.replace('{{ var }}', var)

    return vertex, fragment
1362580
@Override public GLRMModel createImpl() {
    GLRMModel.GLRMParameters parms = parameters.createImpl();
    return new GLRMModel( model_id.key(), parms, null );
  }