<commit_before>'use strict';

var p5 = require('../core/main');
var constants = require('../core/constants');
var libtess = require('libtess');
require('./p5.Shader');
require('./p5.Camera');
require('../core/p5.Renderer');
require('./p5.Matrix');
var fs = require('fs');

var defaultShaders = {
  immediateVert: fs.readFileSync(
    __dirname + '/shaders/immediate.vert',
    'utf-8'
  ),
  vertexColorVert: fs.readFileSync(
    __dirname + '/shaders/vertexColor.vert',
    'utf-8'
  ),
  vertexColorFrag: fs.readFileSync(
    __dirname + '/shaders/vertexColor.frag',
    'utf-8'
  ),
  normalVert: fs.readFileSync(__dirname + '/shaders/normal.vert', 'utf-8'),
  normalFrag: fs.readFileSync(__dirname + '/shaders/normal.frag', 'utf-8'),
  basicFrag: fs.readFileSync(__dirname + '/shaders/basic.frag', 'utf-8'),
  lightVert: fs.readFileSync(__dirname + '/shaders/light.vert', 'utf-8'),
  lightTextureFrag: fs.readFileSync(
    __dirname + '/shaders/light_texture.frag',
    'utf-8'
  ),
  phongVert: fs.readFileSync(__dirname + '/shaders/phong.vert', 'utf-8'),
  phongFrag: fs.readFileSync(__dirname + '/shaders/phong.frag', 'utf-8'),
  fontVert: fs.readFileSync(__dirname + '/shaders/font.vert', 'utf-8'),
  fontFrag: fs.readFileSync(__dirname + '/shaders/font.frag', 'utf-8'),
  lineVert: fs.readFileSync(__dirname + '/shaders/line.vert', 'utf-8'),
  lineFrag: fs.readFileSync(__dirname + '/shaders/line.frag', 'utf-8'),
  pointVert: fs.readFileSync(__dirname + '/shaders/point.vert', 'utf-8'),
  pointFrag: fs.readFileSync(__dirname + '/shaders/point.frag', 'utf-8')
};

/**
 * 3D graphics class
 * @private
 * @class p5.RendererGL
 * @constructor
 * @extends p5.Renderer
 * @todo extend class to include public method for offscreen
 * rendering (FBO).
 *
 */
p5.RendererGL = function(elt, pInst, isMainCanvas, attr) {
  p5.Renderer.call(this, elt, pInst, isMainCanvas);
  this.attributes = {};
  attr = attr || {};
  this.attributes.alpha = attr.alpha === undefined ? true : attr.alpha;
  this.attributes.depth = attr.depth === undefined ? true : attr.depth;
  this.attributes.stencil = attr.stencil === undefined ? true : attr.stencil;
  this.attributes.antialias =
    attr.antialias === undefined ? false : attr.antialias;
  this.attributes.premultipliedAlpha =
    attr.premultipliedAlpha === undefined ? false : attr.premultipliedAlpha;
  this.attributes.preserveDrawingBuffer =
    attr.preserveDrawingBuffer === undefined
      ? true
      : attr.preserveDrawingBuffer;
  this.attributes.perPixelLighting =
    attr.perPixelLighting === undefined ? false : attr.perPixelLighting;
  this._initContext();
  this.isP3D = true; //lets us know we're in 3d mode
  this.GL = this.drawingContext;

  // lights

  this.ambientLightColors = [];
  this.directionalLightDirections = [];
  this.directionalLightColors = [];

  this.pointLightPositions = [];
  this.pointLightColors = [];

  /**
   * model view, projection, & normal
   * matrices
   */
  this.uMVMatrix = new p5.Matrix();
  this.uPMatrix = new p5.Matrix();
  this.uNMatrix = new p5.Matrix('mat3');

  // Camera
  this._curCamera = new p5.Camera(this);
  this._curCamera._computeCameraDefaultSettings();
  this._curCamera._setDefaultCamera();

  //Geometry & Material hashes
  this.gHash = {};

  this._defaultLightShader = undefined;
  this._defaultImmediateModeShader = undefined;
  this._defaultNormalShader = undefined;
  this._defaultColorShader = undefined;
  this._defaultPointShader = undefined;

  this.curFillShader = undefined;
  this.curStrokeShader = undefined;
  this.curPointShader = undefined;

  this._useColorShader();
  this.setStrokeShader(this._getLineShader());
  this._usePointShader();

  this._pointVertexBuffer = this.GL.createBuffer();

  //Imediate Mode
  //default drawing is done in Retained Mode
  this.isImmediateDrawing = false;
  this.immediateMode = {};

  // note: must call fill() and stroke () AFTER
  // default shader has been set.
  this.fill(255, 255, 255, 255);
  //this.stroke(0, 0, 0, 255);
  this.pointSize = 5.0; //default point size
  this.strokeWeight(1);
  this.stroke(0, 0, 0);
  // array of textures created in this gl context via this.getTexture(src)
  this.textures = [];
  this.textureImage = undefined;
  this.textureMode = constants.IMAGE;
  this._curveTightness = 6;

  // lookUpTable for coefficients needed to be calculated for bezierVertex, same are used for curveVertex
  this._lookUpTableBezier = [];
  // lookUpTable for coefficients needed to be calculated for quadraticVertex
  this._lookUpTableQuadratic = [];

  // current curveDetail in the Bezier lookUpTable
  this._lutBezierDetail = 0;
  // current curveDetail in the Quadratic lookUpTable
  this._lutQuadraticDetail = 0;

  this._tessy = this._initTessy();

  this.fontInfos = {};
  return this;
};

p5.RendererGL.prototype = Object.create(p5.Renderer.prototype);

//////////////////////////////////////////////
// Setting
//////////////////////////////////////////////

p5.RendererGL.prototype._initContext = function() {<commit_msg>add renderer state property for texture wrap params<commit_after>'use strict';

var p5 = require('../core/main');
var constants = require('../core/constants');
var libtess = require('libtess');
require('./p5.Shader');
require('./p5.Camera');
require('../core/p5.Renderer');
require('./p5.Matrix');
var fs = require('fs');

var defaultShaders = {
  immediateVert: fs.readFileSync(
    __dirname + '/shaders/immediate.vert',
    'utf-8'
  ),
  vertexColorVert: fs.readFileSync(
    __dirname + '/shaders/vertexColor.vert',
    'utf-8'
  ),
  vertexColorFrag: fs.readFileSync(
    __dirname + '/shaders/vertexColor.frag',
    'utf-8'
  ),
  normalVert: fs.readFileSync(__dirname + '/shaders/normal.vert', 'utf-8'),
  normalFrag: fs.readFileSync(__dirname + '/shaders/normal.frag', 'utf-8'),
  basicFrag: fs.readFileSync(__dirname + '/shaders/basic.frag', 'utf-8'),
  lightVert: fs.readFileSync(__dirname + '/shaders/light.vert', 'utf-8'),
  lightTextureFrag: fs.readFileSync(
    __dirname + '/shaders/light_texture.frag',
    'utf-8'
  ),
  phongVert: fs.readFileSync(__dirname + '/shaders/phong.vert', 'utf-8'),
  phongFrag: fs.readFileSync(__dirname + '/shaders/phong.frag', 'utf-8'),
  fontVert: fs.readFileSync(__dirname + '/shaders/font.vert', 'utf-8'),
  fontFrag: fs.readFileSync(__dirname + '/shaders/font.frag', 'utf-8'),
  lineVert: fs.readFileSync(__dirname + '/shaders/line.vert', 'utf-8'),
  lineFrag: fs.readFileSync(__dirname + '/shaders/line.frag', 'utf-8'),
  pointVert: fs.readFileSync(__dirname + '/shaders/point.vert', 'utf-8'),
  pointFrag: fs.readFileSync(__dirname + '/shaders/point.frag', 'utf-8')
};

/**
 * 3D graphics class
 * @private
 * @class p5.RendererGL
 * @constructor
 * @extends p5.Renderer
 * @todo extend class to include public method for offscreen
 * rendering (FBO).
 *
 */
p5.RendererGL = function(elt, pInst, isMainCanvas, attr) {
  p5.Renderer.call(this, elt, pInst, isMainCanvas);
  this.attributes = {};
  attr = attr || {};
  this.attributes.alpha = attr.alpha === undefined ? true : attr.alpha;
  this.attributes.depth = attr.depth === undefined ? true : attr.depth;
  this.attributes.stencil = attr.stencil === undefined ? true : attr.stencil;
  this.attributes.antialias =
    attr.antialias === undefined ? false : attr.antialias;
  this.attributes.premultipliedAlpha =
    attr.premultipliedAlpha === undefined ? false : attr.premultipliedAlpha;
  this.attributes.preserveDrawingBuffer =
    attr.preserveDrawingBuffer === undefined
      ? true
      : attr.preserveDrawingBuffer;
  this.attributes.perPixelLighting =
    attr.perPixelLighting === undefined ? false : attr.perPixelLighting;
  this._initContext();
  this.isP3D = true; //lets us know we're in 3d mode
  this.GL = this.drawingContext;

  // lights

  this.ambientLightColors = [];
  this.directionalLightDirections = [];
  this.directionalLightColors = [];

  this.pointLightPositions = [];
  this.pointLightColors = [];

  /**
   * model view, projection, & normal
   * matrices
   */
  this.uMVMatrix = new p5.Matrix();
  this.uPMatrix = new p5.Matrix();
  this.uNMatrix = new p5.Matrix('mat3');

  // Camera
  this._curCamera = new p5.Camera(this);
  this._curCamera._computeCameraDefaultSettings();
  this._curCamera._setDefaultCamera();

  //Geometry & Material hashes
  this.gHash = {};

  this._defaultLightShader = undefined;
  this._defaultImmediateModeShader = undefined;
  this._defaultNormalShader = undefined;
  this._defaultColorShader = undefined;
  this._defaultPointShader = undefined;

  this.curFillShader = undefined;
  this.curStrokeShader = undefined;
  this.curPointShader = undefined;

  this._useColorShader();
  this.setStrokeShader(this._getLineShader());
  this._usePointShader();

  this._pointVertexBuffer = this.GL.createBuffer();

  //Imediate Mode
  //default drawing is done in Retained Mode
  this.isImmediateDrawing = false;
  this.immediateMode = {};

  // note: must call fill() and stroke () AFTER
  // default shader has been set.
  this.fill(255, 255, 255, 255);
  //this.stroke(0, 0, 0, 255);
  this.pointSize = 5.0; //default point size
  this.strokeWeight(1);
  this.stroke(0, 0, 0);
  // array of textures created in this gl context via this.getTexture(src)
  this.textures = [];
  this.textureImage = undefined;
  this.textureMode = constants.IMAGE;
  // default wrap settings
  this.textureWrapX = constants.CLAMP;
  this.textureWrapY = constants.CLAMP;
  this._curveTightness = 6;

  // lookUpTable for coefficients needed to be calculated for bezierVertex, same are used for curveVertex
  this._lookUpTableBezier = [];
  // lookUpTable for coefficients needed to be calculated for quadraticVertex
  this._lookUpTableQuadratic = [];

  // current curveDetail in the Bezier lookUpTable
  this._lutBezierDetail = 0;
  // current curveDetail in the Quadratic lookUpTable
  this._lutQuadraticDetail = 0;

  this._tessy = this._initTessy();

  this.fontInfos = {};

  return this;
};

p5.RendererGL.prototype = Object.create(p5.Renderer.prototype);

//////////////////////////////////////////////
// Setting
//////////////////////////////////////////////

p5.RendererGL.prototype._initContext = function() {
{'fraction_non_alphanumeric': 0.15959952885747938, 'fraction_numerical': 0.012367491166077738, 'mean_word_length': 3.6759981642955486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6509516', 'n_tokens_mistral': 3332, 'n_tokens_neox': 3224, 'n_words': 668}