<commit_before>import GLVertexArray from './GLVertexArray.js';
import GLTexture from './GLTexture.js';

export default class GLObject {
  constructor({
    gl,
    mesh = undefined,
    program = undefined,
    vertexArray = new GLVertexArray({
      gl,
      mesh,
      program,
    }),
  }) {
    this.gl = gl;
    this.mesh = mesh;
    this.program = program;
    this.vertexArray = vertexArray;

    this._boundTextures = new Set();
  }

  bind() {
    this.program.use();
    this.vertexArray.bind();
    for (const [name, type] of this.program.uniformTypes) {
      if (type.startsWith('sampler')) {
        const value = this.program.uniforms.get(name);
        if (value instanceof GLTexture) {
          value.bind({
            unit: this.program.textureUnits.get(name),
          });
          this._boundTextures.add(value);
        }
      }
    }
  }

  draw(options = {}) {
    options = Object.assign({ bind: true, uniforms: {} }, options);
    // Todo: Fix double call to Program.use when bind is true
    // (needed to update texture uniforms before binding them)
    this.program.use();
    for (const key of Object.keys(options.uniforms)) {
      this.program.uniforms.set(key, options.uniforms[key]);
    }
    if (options.bind) {
      this.bind();
    }
    this.mesh.draw(options);
    if (options.bind) {
      this.unbind();
    }
  }<commit_msg>GLObject: set autobind to false<commit_after>import GLVertexArray from './GLVertexArray.js';
import GLTexture from './GLTexture.js';

export default class GLObject {
  constructor({
    gl,
    mesh = undefined,
    program = undefined,
    vertexArray = new GLVertexArray({
      gl,
      mesh,
      program,
    }),
  }) {
    this.gl = gl;
    this.mesh = mesh;
    this.program = program;
    this.vertexArray = vertexArray;

    this._boundTextures = new Set();
  }

  bind() {
    this.program.use();
    this.vertexArray.bind();
    for (const [name, type] of this.program.uniformTypes) {
      if (type.startsWith('sampler')) {
        const value = this.program.uniforms.get(name);
        if (value instanceof GLTexture) {
          value.bind({
            unit: this.program.textureUnits.get(name),
          });
          this._boundTextures.add(value);
        }
      }
    }
  }

  draw(options = {}) {
    options = Object.assign({ bind: false, uniforms: {} }, options);
    // Todo: Fix double call to Program.use when bind is true
    // (needed to update texture uniforms before binding them)
    this.program.use();
    for (const [key, value] of Object.entries(options.uniforms)) {
      this.program.uniforms.set(key, value);
    }
    if (options.bind) {
      this.bind();
    }
    this.mesh.draw(options);
    if (options.bind) {
      this.unbind();
    }
  }
{'fraction_non_alphanumeric': 0.13644589214621788, 'fraction_numerical': 0.0, 'mean_word_length': 2.326113116726835, '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': '5910503', 'n_tokens_mistral': 856, 'n_tokens_neox': 848, 'n_words': 199}