<commit_before>//  Copyright 2002-2014, University of Colorado Boulder

/**
 * ColorTriangleRenderer manages the program & attributes & drawing for rendering indepdent triangles.  Geometry +data provided
 * by colorTriangleBufferData.
 *
 * @author <NAME> (PhET Interactive Simulations)
 */
define( function( require ) {
  'use strict';

  // modules
  var inherit = require( 'PHET_CORE/inherit' );
  var ColorTriangleBufferData = require( 'SCENERY/display/webgl/colorTriangleBufferData' );
  var WebGLUtil = require( 'SCENERY/display/webgl/WebGLUtil' );

  // shaders
  var colorVertexShader = require( 'text!SCENERY/display/webgl/color2d.vert' );
  var colorFragmentShader = require( 'text!SCENERY/display/webgl/color2d.frag' );

  /**
   *
   * @constructor
   */
  function ColorTriangleRenderer( gl, backingScale, canvas ) {
    this.gl = gl;
    this.canvas = canvas;
    this.backingScale = backingScale;

    // Manages the indices within a single array, so that disjoint geometries can be represented easily here.
    // TODO: Compare this same idea to triangle strips
    this.colorTriangleBufferData = new ColorTriangleBufferData();

    this.colorShaderProgram = gl.createProgram();
    gl.attachShader( this.colorShaderProgram, WebGLUtil.toShader( gl, colorVertexShader, gl.VERTEX_SHADER, 'VERTEX' ) );
    gl.attachShader( this.colorShaderProgram, WebGLUtil.toShader( gl, colorFragmentShader, gl.FRAGMENT_SHADER, 'FRAGMENT' ) );
    gl.linkProgram( this.colorShaderProgram );

    this.positionAttribLocation = gl.getAttribLocation( this.colorShaderProgram, 'aPosition' );
    this.colorAttributeLocation = gl.getAttribLocation( this.colorShaderProgram, 'aVertexColor' );
    this.transform1AttributeLocation = gl.getAttribLocation( this.colorShaderProgram, 'aTransform1' );
    this.transform2AttributeLocation = gl.getAttribLocation( this.colorShaderProgram, 'aTransform2' );

    gl.enableVertexAttribArray( this.positionAttribLocation );
    gl.enableVertexAttribArray( this.colorAttributeLocation );
    gl.enableVertexAttribArray( this.transform1AttributeLocation );
    gl.enableVertexAttribArray( this.transform2AttributeLocation );
    gl.useProgram( this.colorShaderProgram );

    // set the resolution
    this.resolutionLocation = gl.getUniformLocation( this.colorShaderProgram, 'uResolution' );

    this.vertexBuffer = gl.createBuffer();
    this.bindVertexBuffer();

    gl.clearColor( 0.0, 0.0, 0.0, 0.0 );
    gl.enable( gl.DEPTH_TEST );
  }

  return inherit( Object, ColorTriangleRenderer, {

    draw: function() {
      var gl = this.gl;

      //TODO: Only call this when the canvas changes size
      //TODO: This backing scale multiply seems very buggy and contradicts everything we know!
      // Still, it gives the right behavior on iPad3 and OSX (non-retina).  Should be discussed and investigated.
      gl.uniform2f( this.resolutionLocation, this.canvas.width / this.backingScale, this.canvas.height / this.backingScale );

      var step = Float32Array.BYTES_PER_ELEMENT;
      var total = 3 + 4 + 3 + 3;
      var stride = step * total;

      gl.enableVertexAttribArray( this.positionAttribLocation );
      gl.enableVertexAttribArray( this.colorAttributeLocation );
      gl.enableVertexAttribArray( this.transform1AttributeLocation );
      gl.enableVertexAttribArray( this.transform2AttributeLocation );
      gl.useProgram( this.colorShaderProgram );

      gl.bindBuffer( gl.ARRAY_BUFFER, this.vertexBuffer );
      gl.vertexAttribPointer( this.positionAttribLocation, 3, gl.FLOAT, false, stride, 0 );
      gl.vertexAttribPointer( this.colorAttributeLocation, 4, gl.FLOAT, false, stride, step * (3) );
      gl.vertexAttribPointer( this.transform1AttributeLocation, 3, gl.FLOAT, false, stride, step * (3 + 4) );
      gl.vertexAttribPointer( this.transform2AttributeLocation, 3, gl.FLOAT, false, stride, step * (3 + 4 + 3) );

      gl.drawArrays( gl.TRIANGLES, 0, this.colorTriangleBufferData.vertexArray.length / 13 );

      gl.disableVertexAttribArray( this.positionAttribLocation );
      gl.disableVertexAttribArray( this.colorAttributeLocation );
      gl.disableVertexAttribArray( this.transform1AttributeLocation );
      gl.disableVertexAttribArray( this.transform2AttributeLocation );<commit_msg>Use the right program before specifying resolution<commit_after>//  Copyright 2002-2014, University of Colorado Boulder

/**
 * ColorTriangleRenderer manages the program & attributes & drawing for rendering indepdent triangles.  Geometry +data provided
 * by colorTriangleBufferData.
 *
 * @author <NAME> (PhET Interactive Simulations)
 */
define( function( require ) {
  'use strict';

  // modules
  var inherit = require( 'PHET_CORE/inherit' );
  var ColorTriangleBufferData = require( 'SCENERY/display/webgl/colorTriangleBufferData' );
  var WebGLUtil = require( 'SCENERY/display/webgl/WebGLUtil' );

  // shaders
  var colorVertexShader = require( 'text!SCENERY/display/webgl/color2d.vert' );
  var colorFragmentShader = require( 'text!SCENERY/display/webgl/color2d.frag' );

  /**
   *
   * @constructor
   */
  function ColorTriangleRenderer( gl, backingScale, canvas ) {
    this.gl = gl;
    this.canvas = canvas;
    this.backingScale = backingScale;

    // Manages the indices within a single array, so that disjoint geometries can be represented easily here.
    // TODO: Compare this same idea to triangle strips
    this.colorTriangleBufferData = new ColorTriangleBufferData();

    this.colorShaderProgram = gl.createProgram();
    gl.attachShader( this.colorShaderProgram, WebGLUtil.toShader( gl, colorVertexShader, gl.VERTEX_SHADER, 'VERTEX' ) );
    gl.attachShader( this.colorShaderProgram, WebGLUtil.toShader( gl, colorFragmentShader, gl.FRAGMENT_SHADER, 'FRAGMENT' ) );
    gl.linkProgram( this.colorShaderProgram );

    this.positionAttribLocation = gl.getAttribLocation( this.colorShaderProgram, 'aPosition' );
    this.colorAttributeLocation = gl.getAttribLocation( this.colorShaderProgram, 'aVertexColor' );
    this.transform1AttributeLocation = gl.getAttribLocation( this.colorShaderProgram, 'aTransform1' );
    this.transform2AttributeLocation = gl.getAttribLocation( this.colorShaderProgram, 'aTransform2' );

    gl.enableVertexAttribArray( this.positionAttribLocation );
    gl.enableVertexAttribArray( this.colorAttributeLocation );
    gl.enableVertexAttribArray( this.transform1AttributeLocation );
    gl.enableVertexAttribArray( this.transform2AttributeLocation );
    gl.useProgram( this.colorShaderProgram );

    // set the resolution
    this.resolutionLocation = gl.getUniformLocation( this.colorShaderProgram, 'uResolution' );

    this.vertexBuffer = gl.createBuffer();
    this.bindVertexBuffer();

    gl.clearColor( 0.0, 0.0, 0.0, 0.0 );
    gl.enable( gl.DEPTH_TEST );
  }

  return inherit( Object, ColorTriangleRenderer, {

    draw: function() {
      var gl = this.gl;

      var step = Float32Array.BYTES_PER_ELEMENT;
      var total = 3 + 4 + 3 + 3;
      var stride = step * total;

      gl.useProgram( this.colorShaderProgram );
      gl.enableVertexAttribArray( this.positionAttribLocation );
      gl.enableVertexAttribArray( this.colorAttributeLocation );
      gl.enableVertexAttribArray( this.transform1AttributeLocation );
      gl.enableVertexAttribArray( this.transform2AttributeLocation );

      //TODO: Only call this when the canvas changes size
      //TODO: This backing scale multiply seems very buggy and contradicts everything we know!
      // Still, it gives the right behavior on iPad3 and OSX (non-retina).  Should be discussed and investigated.
      gl.uniform2f( this.resolutionLocation, this.canvas.width / this.backingScale, this.canvas.height / this.backingScale );

      gl.bindBuffer( gl.ARRAY_BUFFER, this.vertexBuffer );
      gl.vertexAttribPointer( this.positionAttribLocation, 3, gl.FLOAT, false, stride, 0 );
      gl.vertexAttribPointer( this.colorAttributeLocation, 4, gl.FLOAT, false, stride, step * (3) );
      gl.vertexAttribPointer( this.transform1AttributeLocation, 3, gl.FLOAT, false, stride, step * (3 + 4) );
      gl.vertexAttribPointer( this.transform2AttributeLocation, 3, gl.FLOAT, false, stride, step * (3 + 4 + 3) );

      gl.drawArrays( gl.TRIANGLES, 0, this.colorTriangleBufferData.vertexArray.length / 13 );

      gl.disableVertexAttribArray( this.positionAttribLocation );
      gl.disableVertexAttribArray( this.colorAttributeLocation );
      gl.disableVertexAttribArray( this.transform1AttributeLocation );
      gl.disableVertexAttribArray( this.transform2AttributeLocation );
{'fraction_non_alphanumeric': 0.1014137165556724, 'fraction_numerical': 0.012150952214043697, 'mean_word_length': 4.178463399879008, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1071380', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2436, 'n_words': 566}