<commit_before>"use strict"

var color = require("color")
var makeGameShell = require("game-shell")

function parseColor(str) {
  if(!str || str === "") {
    return null
  }
  var c = color(str)
  return [ c.values.rgb[0], c.values.rgb[1], c.values.rgb[2], c.alpha ]
}

function createGLShell(options) {
  options = options || {}

  //First create shell
  var shell = makeGameShell(options)

  shell.on("init", function() {
  
    //Create canvas
    var canvas = document.createElement("canvas")
    canvas.style.position = "absolute"
    canvas.style.left = "0px"
    canvas.style.top = "0px"
    shell.element.appendChild(canvas)

    //Load width/height
    var width = shell.element.clientWidth
    var height = shell.element.clientHeight    
    canvas.width = width
    canvas.height = height
    
    //Try initializing WebGL
    var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl")
    if(!gl) {
      throw new Error("Unable to initialize WebGL")
    }
    
    //Add variables to game-shell
    shell.canvas = canvas
    shell.gl = gl
    Object.defineProperty(shell, "width", {
      get: function() { return width }
    })
    Object.defineProperty(shell, "height", {
      get: function() { return height }
    })
    
    //Load default parameters
    shell.clearFlags = options.clearFlags === undefined ? (gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) : options.clearFlags
    shell.clearColor = options.clearColor || parseColor(shell.element.style["background-color"]) || [0.2, 0.4, 0.8, 1.0]
    shell.clearDepth = options.clearDepth || 1.0
    shell.clearStencil = options.clearStencil || 0
    
    //Called when the window is resized or DOM element updates
    function handleResize() {
      var w = shell.element.clientWidth|0
      var h = shell.element.clientHeight|0
      if((w !== width) || (h !== height)) {
        width = w
        height = h
        canvas.width = width
        canvas.height = height
        shell.emit("resize", width, height)
      }
    }
    shell.element.addEventListener("DOMSubtreeModified", handleResize)
    window.addEventListener("resize", handleResize)

    shell.on("render", function glRender(t) {
    
      //Bind default framebuffer
      gl.bindFramebuffer(gl.FRAMEBUFFER, null)
      
      //Set viewport
      gl.viewport(0, 0, width, height)
      
      //Clear buffers
      if(shell.clearFlags & gl.STENCIL_BUFFER_BIT) {
        gl.clearStencil(shell.clearStencil)
      }
      if(shell.clearFlags & gl.COLOR_BUFFER_BIT) {
        gl.clearColor(shell.clearColor[0], shell.clearColor[1], shell.clearColor[2], shell.clearColor[3])
      }
      if(shell.clearFlags & gl.DEPTH_BUFFER_BIT) {
        gl.clearDepth(shell.clearDepth)
      }
      if(shell.clearFlags) {
        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
      }
    
      //Render frame
      shell.emit("gl-render", t)
    })
    
    //WebGL initialized
    shell.emit("gl-init")
  })
  
  return shell
}

module.exports = createGLShell<commit_msg>added function name for init<commit_after>"use strict"

var color = require("color")
var makeGameShell = require("game-shell")

function parseColor(str) {
  if(!str || str === "") {
    return null
  }
  var c = color(str)
  return [ c.values.rgb[0], c.values.rgb[1], c.values.rgb[2], c.alpha ]
}

function createGLShell(options) {
  options = options || {}

  //First create shell
  var shell = makeGameShell(options)

  shell.on("init", function initGLNow() {
  
    //Create canvas
    var canvas = document.createElement("canvas")
    canvas.style.position = "absolute"
    canvas.style.left = "0px"
    canvas.style.top = "0px"
    shell.element.appendChild(canvas)

    //Load width/height
    var width = shell.element.clientWidth
    var height = shell.element.clientHeight    
    canvas.width = width
    canvas.height = height
    
    //Try initializing WebGL
    var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl")
    if(!gl) {
      throw new Error("Unable to initialize WebGL")
    }
    
    //Add variables to game-shell
    shell.canvas = canvas
    shell.gl = gl
    Object.defineProperty(shell, "width", {
      get: function() { return width }
    })
    Object.defineProperty(shell, "height", {
      get: function() { return height }
    })
    
    //Load default parameters
    shell.clearFlags = options.clearFlags === undefined ? (gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) : options.clearFlags
    shell.clearColor = options.clearColor || parseColor(shell.element.style["background-color"]) || [0.2, 0.4, 0.8, 1.0]
    shell.clearDepth = options.clearDepth || 1.0
    shell.clearStencil = options.clearStencil || 0
    
    //Called when the window is resized or DOM element updates
    function handleResize() {
      var w = shell.element.clientWidth|0
      var h = shell.element.clientHeight|0
      if((w !== width) || (h !== height)) {
        width = w
        height = h
        canvas.width = width
        canvas.height = height
        shell.emit("resize", width, height)
      }
    }
    shell.element.addEventListener("DOMSubtreeModified", handleResize)
    window.addEventListener("resize", handleResize)

    shell.on("render", function renderGLNow(t) {
    
      //Bind default framebuffer
      gl.bindFramebuffer(gl.FRAMEBUFFER, null)
      
      //Set viewport
      gl.viewport(0, 0, width, height)
      
      //Clear buffers
      if(shell.clearFlags & gl.STENCIL_BUFFER_BIT) {
        gl.clearStencil(shell.clearStencil)
      }
      if(shell.clearFlags & gl.COLOR_BUFFER_BIT) {
        gl.clearColor(shell.clearColor[0], shell.clearColor[1], shell.clearColor[2], shell.clearColor[3])
      }
      if(shell.clearFlags & gl.DEPTH_BUFFER_BIT) {
        gl.clearDepth(shell.clearDepth)
      }
      if(shell.clearFlags) {
        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
      }
    
      //Render frame
      shell.emit("gl-render", t)
    })
    
    //WebGL initialized
    shell.emit("gl-init")
  })
  
  return shell
}

module.exports = createGLShell
{'fraction_non_alphanumeric': 0.12777777777777777, 'fraction_numerical': 0.00784313725490196, 'mean_word_length': 2.6740696278511407, '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': '2379619', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1894, 'n_words': 392}