<commit_before>import Shader from '../3d/Shader.js'

export default class GLProgram {
  constructor({
    gl,
    shader = new Shader(),
    transformFeedbackVaryings = undefined,
  }) {
    this.gl = gl

    this._webGL1 = this.gl.getParameter(this.gl.VERSION).startsWith('WebGL 1.0')
    this._shader = shader instanceof Shader ? shader : new Shader(shader)
    this._program = gl.createProgram()
    this._attachedShaders = new Map()
    this._textureUnits = new Map()

    this._vertexAttribDivisor = () => { }
    const instancedArraysExtension = this.gl.getExtension('ANGLE_instanced_arrays')
    if (instancedArraysExtension) {
      this._vertexAttribDivisor = instancedArraysExtension.vertexAttribDivisorANGLE.bind(instancedArraysExtension)
    } else if (this.gl.vertexAttribDivisor) {
      this._vertexAttribDivisor = this.gl.vertexAttribDivisor.bind(this.gl)
    }

    const self = this

    class Attributes extends Map {
      set(name, { buffer = undefined, location = self._attributesLocations.get(name), size = 1, componentType = gl.FLOAT, normalized = false, byteStride = 0, byteOffset = 0, divisor = 0 } = {}) {
        if (name instanceof Map) {
          for (const [key, value] of name) {
            this.set(key, value)
          }
          return
        }
        buffer.bind()
        if (location === undefined) {
          location = gl.getAttribLocation(self._program, name)
          self._attributesLocations.set(name, location)
        }
        if (location !== -1) {
          gl.enableVertexAttribArray(location)
          if (self._webGL1 || componentType === gl.FLOAT || componentType === gl.HALF_FLOAT) {
            if (componentType === gl.UNSIGNED_INT) componentType = gl.FLOAT
            gl.vertexAttribPointer(location, size, componentType, normalized, byteStride, byteOffset)
          } else {
            gl.vertexAttribIPointer(location, size, componentType, byteStride, byteOffset)
          }
          self._vertexAttribDivisor(location, divisor)
        }

        buffer.unbind()
        super.set(name, { buffer, size, componentType, normalized, byteStride, byteOffset })
      }
    }

    const uploadUniform = (name, value) => {
      if (value === undefined) {
        return
      }

      const type = self.uniformTypes.get(name)

      if (value instanceof Object && !type) {
        for (const key of [...Object.keys(value), ...Object.keys(Object.getPrototypeOf(value))]) {
          uploadUniform(value[0] !== undefined ? `${name}[${key}]` : `${name}.${key}`, value[key])
        }
        return
      }

      self._shader.uniforms[name] = value

      let location = self._uniformLocations.get(name)
      if (location === undefined) {
        location = gl.getUniformLocation(self._program, name)
        self._uniformLocations.set(name, location)
      }

      if (location === null) {
        return
      }

      if (type === 'float' || type === 'bool') {
        gl.uniform1f(location, value)
      } else if (type === 'vec2') {
        gl.uniform2fv(location, value)
      } else if (type === 'vec3') {
        gl.uniform3fv(location, value)
      } else if (type === 'vec4') {
        gl.uniform4fv(location, value)
      } else if (type === 'int') {
        gl.uniform1i(location, value)
      } else if (type === 'ivec2') {
        gl.uniform2iv(location, value)
      } else if (type === 'ivec3') {
        gl.uniform3iv(location, value)
      } else if (type === 'ivec4') {
        gl.uniform4iv(location, value)
      } else if (type === 'mat3') {<commit_msg>GLProgram: add uint uniform upload<commit_after>import Shader from '../3d/Shader.js'

export default class GLProgram {
  constructor({
    gl,
    shader = new Shader(),
    transformFeedbackVaryings = undefined,
  }) {
    this.gl = gl

    this._webGL1 = this.gl.getParameter(this.gl.VERSION).startsWith('WebGL 1.0')
    this._shader = shader instanceof Shader ? shader : new Shader(shader)
    this._program = gl.createProgram()
    this._attachedShaders = new Map()
    this._textureUnits = new Map()

    this._vertexAttribDivisor = () => { }
    const instancedArraysExtension = this.gl.getExtension('ANGLE_instanced_arrays')
    if (instancedArraysExtension) {
      this._vertexAttribDivisor = instancedArraysExtension.vertexAttribDivisorANGLE.bind(instancedArraysExtension)
    } else if (this.gl.vertexAttribDivisor) {
      this._vertexAttribDivisor = this.gl.vertexAttribDivisor.bind(this.gl)
    }

    const self = this

    class Attributes extends Map {
      set(name, { buffer = undefined, location = self._attributesLocations.get(name), size = 1, componentType = gl.FLOAT, normalized = false, byteStride = 0, byteOffset = 0, divisor = 0 } = {}) {
        if (name instanceof Map) {
          for (const [key, value] of name) {
            this.set(key, value)
          }
          return
        }
        buffer.bind()
        if (location === undefined) {
          location = gl.getAttribLocation(self._program, name)
          self._attributesLocations.set(name, location)
        }
        if (location !== -1) {
          gl.enableVertexAttribArray(location)
          if (self._webGL1 || componentType === gl.FLOAT || componentType === gl.HALF_FLOAT) {
            if (componentType === gl.UNSIGNED_INT) componentType = gl.FLOAT
            gl.vertexAttribPointer(location, size, componentType, normalized, byteStride, byteOffset)
          } else {
            gl.vertexAttribIPointer(location, size, componentType, byteStride, byteOffset)
          }
          self._vertexAttribDivisor(location, divisor)
        }

        buffer.unbind()
        super.set(name, { buffer, size, componentType, normalized, byteStride, byteOffset })
      }
    }

    const uploadUniform = (name, value) => {
      if (value === undefined) {
        return
      }

      const type = self.uniformTypes.get(name)

      if (value instanceof Object && !type) {
        for (const key of [...Object.keys(value), ...Object.keys(Object.getPrototypeOf(value))]) {
          uploadUniform(value[0] !== undefined ? `${name}[${key}]` : `${name}.${key}`, value[key])
        }
        return
      }

      self._shader.uniforms[name] = value

      let location = self._uniformLocations.get(name)
      if (location === undefined) {
        location = gl.getUniformLocation(self._program, name)
        self._uniformLocations.set(name, location)
      }

      if (location === null) {
        return
      }

      if (type === 'float' || type === 'bool') {
        gl.uniform1f(location, value)
      } else if (type === 'vec2') {
        gl.uniform2fv(location, value)
      } else if (type === 'vec3') {
        gl.uniform3fv(location, value)
      } else if (type === 'vec4') {
        gl.uniform4fv(location, value)
      } else if (type === 'int') {
        gl.uniform1i(location, value)
      } else if (type === 'uint') {
        gl.uniform1ui(location, value)
      } else if (type === 'ivec2') {
        gl.uniform2iv(location, value)
      } else if (type === 'ivec3') {
        gl.uniform3iv(location, value)
      } else if (type === 'ivec4') {
        gl.uniform4iv(location, value)
      } else if (type === 'mat3') {
{'fraction_non_alphanumeric': 0.13283208020050125, 'fraction_numerical': 0.007379560011138958, 'mean_word_length': 2.5124694376528116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3283660', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2144, 'n_words': 468}