diff --git a/example/bunny-instance/bunny-instance.js b/example/bunny-instance/bunny-instance.js index 8df62cf0..e9827764 100755 --- a/example/bunny-instance/bunny-instance.js +++ b/example/bunny-instance/bunny-instance.js @@ -1,22 +1,22 @@ /* globals __line */ -var path = require('path') -var createContext = require('../../index') -var utils = require('../common/utils.js') -var utilsLog = require('../common/utils_log.js') -var log = new utilsLog.Log(path.basename(__filename), 'DEBUG') -var bunny = require('bunny') +const path = require('path') +const createContext = require('../../index') +const utils = require('../common/utils.js') +const utilsLog = require('../common/utils_log.js') +const log = new utilsLog.Log(path.basename(__filename), 'DEBUG') +const bunny = require('bunny') const normals = require('angle-normals') // flatten a multi-dimensional array. // so [[1,2,3], [2,3,4],...] becomes // [1,2,3, 2,3,4] function flatten (data) { - var result = [] - var dimension = data[0].length - var ptr = 0 - for (var i = 0; i < data.length; ++i) { - var v = data[i] - for (var j = 0; j < dimension; ++j) { + const result = [] + const dimension = data[0].length + let ptr = 0 + for (let i = 0; i < data.length; ++i) { + const v = data[i] + for (let j = 0; j < dimension; ++j) { result[ptr++] = v[j] } } @@ -25,18 +25,18 @@ function flatten (data) { function main () { // Create context - var width = 512 - var height = 512 - var gl = createContext(width, height) + const width = 512 + const height = 512 + const gl = createContext(width, height) - var ext = gl.getExtension('ANGLE_instanced_arrays') + const ext = gl.getExtension('ANGLE_instanced_arrays') gl.clearColor(0.0, 0.0, 0.0, 1.0) gl.enable(gl.DEPTH_TEST) gl.enable(gl.CULL_FACE) gl.viewport(0, 0, width, height) - var vertexSrc = ` + const vertexSrc = ` precision mediump float; attribute vec3 position; @@ -55,7 +55,7 @@ function main () { } ` - var fragmentSrc = ` + const fragmentSrc = ` precision mediump float; varying vec3 vNormal; @@ -70,53 +70,53 @@ function main () { ` // setup a GLSL program - var program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) + const program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) gl.useProgram(program) // look up where the vertex data needs to go. - var positionLocation = gl.getAttribLocation(program, 'position') - var normalLocation = gl.getAttribLocation(program, 'normal') - var offsetLocation = gl.getAttribLocation(program, 'offset') + const positionLocation = gl.getAttribLocation(program, 'position') + const normalLocation = gl.getAttribLocation(program, 'normal') + const offsetLocation = gl.getAttribLocation(program, 'offset') // get uniform locations. - var projectionUniformLocation = gl.getUniformLocation(program, 'projection') - var viewUniformLocation = gl.getUniformLocation(program, 'view') + const projectionUniformLocation = gl.getUniformLocation(program, 'projection') + const viewUniformLocation = gl.getUniformLocation(program, 'view') // setup perspective. - var perspectiveMatrix = perspective(Math.PI / 4, width / height, 0.01, 1000.0) + const perspectiveMatrix = perspective(Math.PI / 4, width / height, 0.01, 1000.0) gl.uniformMatrix4fv(projectionUniformLocation, false, new Float32Array(perspectiveMatrix)) // setup view. - var m = lookAt([0.0, 150.5, 100.0], [0, 2.5, 0], [0, 1, 0]) + const m = lookAt([0.0, 150.5, 100.0], [0, 2.5, 0], [0, 1, 0]) gl.uniformMatrix4fv(viewUniformLocation, false, new Float32Array(m)) - var positionBuffer = gl.createBuffer() + const positionBuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(flatten(bunny.positions)), gl.STATIC_DRAW) gl.enableVertexAttribArray(positionLocation) gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0) - var normalBuffer = gl.createBuffer() + const normalBuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, normalBuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(flatten(normals(bunny.cells, bunny.positions))), gl.STATIC_DRAW) gl.enableVertexAttribArray(normalLocation) gl.vertexAttribPointer(normalLocation, 3, gl.FLOAT, false, 0, 0) - var offsets = [] - for (var x = -10; x <= +10; x++) { - for (var z = -10; z <= +10; z++) { + const offsets = [] + for (let x = -10; x <= +10; x++) { + for (let z = -10; z <= +10; z++) { offsets.push([20.0 * x, 0.0, 20.0 * z]) } } - var offsetBuffer = gl.createBuffer() + const offsetBuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, offsetBuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(flatten(offsets)), gl.STATIC_DRAW) gl.enableVertexAttribArray(offsetLocation) gl.vertexAttribPointer(offsetLocation, 3, gl.FLOAT, false, 0, 0) ext.vertexAttribDivisorANGLE(offsetLocation, 1) // This makes it instanced! - var elementsBuffer = gl.createBuffer() + const elementsBuffer = gl.createBuffer() gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementsBuffer) gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(flatten(bunny.cells)), gl.STATIC_DRAW) @@ -133,16 +133,16 @@ function main () { // Taken from gl-mat4 // https://github.com/stackgl/gl-mat4/blob/master/lookAt.js function lookAt (eye, center, up) { - var x0, x1, x2, y0, y1, y2, z0, z1, z2, len - var eyex = eye[0] - var eyey = eye[1] - var eyez = eye[2] - var upx = up[0] - var upy = up[1] - var upz = up[2] - var centerx = center[0] - var centery = center[1] - var centerz = center[2] + let x0, x1, x2, y0, y1, y2, z0, z1, z2, len + const eyex = eye[0] + const eyey = eye[1] + const eyez = eye[2] + const upx = up[0] + const upy = up[1] + const upz = up[2] + const centerx = center[0] + const centery = center[1] + const centerz = center[2] z0 = eyex - centerx z1 = eyey - centery @@ -195,8 +195,8 @@ function lookAt (eye, center, up) { // Taken from gl-mat4 // https://github.com/stackgl/gl-mat4/blob/master/perspective.js function perspective (fovy, aspect, near, far) { - var f = 1.0 / Math.tan(fovy / 2) - var nf = 1 / (near - far) + const f = 1.0 / Math.tan(fovy / 2) + const nf = 1 / (near - far) return [ f / aspect, 0.0, 0.0, 0.0, diff --git a/example/bunny/bunny.js b/example/bunny/bunny.js index 753a236c..9cee85a0 100755 --- a/example/bunny/bunny.js +++ b/example/bunny/bunny.js @@ -1,22 +1,22 @@ /* globals __line */ -var path = require('path') -var createContext = require('../../index') -var utils = require('../common/utils.js') -var utilsLog = require('../common/utils_log.js') -var log = new utilsLog.Log(path.basename(__filename), 'DEBUG') -var bunny = require('bunny') +const path = require('path') +const createContext = require('../../index') +const utils = require('../common/utils.js') +const utilsLog = require('../common/utils_log.js') +const log = new utilsLog.Log(path.basename(__filename), 'DEBUG') +const bunny = require('bunny') const normals = require('angle-normals') // flatten a multi-dimensional array. // so [[1,2,3], [2,3,4],...] becomes // [1,2,3, 2,3,4] function flatten (data) { - var result = [] - var dimension = data[0].length - var ptr = 0 - for (var i = 0; i < data.length; ++i) { - var v = data[i] - for (var j = 0; j < dimension; ++j) { + const result = [] + const dimension = data[0].length + let ptr = 0 + for (let i = 0; i < data.length; ++i) { + const v = data[i] + for (let j = 0; j < dimension; ++j) { result[ptr++] = v[j] } } @@ -25,16 +25,16 @@ function flatten (data) { function main () { // Create context - var width = 512 - var height = 512 - var gl = createContext(width, height) + const width = 512 + const height = 512 + const gl = createContext(width, height) gl.clearColor(0.0, 0.0, 0.0, 1.0) gl.enable(gl.DEPTH_TEST) gl.enable(gl.CULL_FACE) gl.viewport(0, 0, width, height) - var vertexSrc = ` + const vertexSrc = ` precision mediump float; attribute vec3 position; @@ -49,7 +49,7 @@ function main () { } ` - var fragmentSrc = ` + const fragmentSrc = ` precision mediump float; varying vec3 vNormal; @@ -64,38 +64,38 @@ function main () { ` // setup a GLSL program - var program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) + const program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) gl.useProgram(program) // look up where the vertex data needs to go. - var positionLocation = gl.getAttribLocation(program, 'position') - var normalLocation = gl.getAttribLocation(program, 'normal') + const positionLocation = gl.getAttribLocation(program, 'position') + const normalLocation = gl.getAttribLocation(program, 'normal') // get uniform locations. - var projectionUniformLocation = gl.getUniformLocation(program, 'projection') - var viewUniformLocation = gl.getUniformLocation(program, 'view') + const projectionUniformLocation = gl.getUniformLocation(program, 'projection') + const viewUniformLocation = gl.getUniformLocation(program, 'view') // setup perspective. - var perspectiveMatrix = perspective(Math.PI / 4, width / height, 0.01, 1000.0) + const perspectiveMatrix = perspective(Math.PI / 4, width / height, 0.01, 1000.0) gl.uniformMatrix4fv(projectionUniformLocation, false, new Float32Array(perspectiveMatrix)) // setup view. - var m = lookAt([0.0, 12.5, 30.0], [0, 2.5, 0], [0, 1, 0]) + const m = lookAt([0.0, 12.5, 30.0], [0, 2.5, 0], [0, 1, 0]) gl.uniformMatrix4fv(viewUniformLocation, false, new Float32Array(m)) - var positionBuffer = gl.createBuffer() + const positionBuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(flatten(bunny.positions)), gl.STATIC_DRAW) gl.enableVertexAttribArray(positionLocation) gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0) - var normalBuffer = gl.createBuffer() + const normalBuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, normalBuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(flatten(normals(bunny.cells, bunny.positions))), gl.STATIC_DRAW) gl.enableVertexAttribArray(normalLocation) gl.vertexAttribPointer(normalLocation, 3, gl.FLOAT, false, 0, 0) - var elementsBuffer = gl.createBuffer() + const elementsBuffer = gl.createBuffer() gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementsBuffer) gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(flatten(bunny.cells)), gl.STATIC_DRAW) @@ -112,16 +112,16 @@ function main () { // Taken from gl-mat4 // https://github.com/stackgl/gl-mat4/blob/master/lookAt.js function lookAt (eye, center, up) { - var x0, x1, x2, y0, y1, y2, z0, z1, z2, len - var eyex = eye[0] - var eyey = eye[1] - var eyez = eye[2] - var upx = up[0] - var upy = up[1] - var upz = up[2] - var centerx = center[0] - var centery = center[1] - var centerz = center[2] + let x0, x1, x2, y0, y1, y2, z0, z1, z2, len + const eyex = eye[0] + const eyey = eye[1] + const eyez = eye[2] + const upx = up[0] + const upy = up[1] + const upz = up[2] + const centerx = center[0] + const centery = center[1] + const centerz = center[2] z0 = eyex - centerx z1 = eyey - centery @@ -174,8 +174,8 @@ function lookAt (eye, center, up) { // Taken from gl-mat4 // https://github.com/stackgl/gl-mat4/blob/master/perspective.js function perspective (fovy, aspect, near, far) { - var f = 1.0 / Math.tan(fovy / 2) - var nf = 1 / (near - far) + const f = 1.0 / Math.tan(fovy / 2) + const nf = 1 / (near - far) return [ f / aspect, 0.0, 0.0, 0.0, diff --git a/example/common/utils.js b/example/common/utils.js index 4bda0f9f..0489b7cc 100755 --- a/example/common/utils.js +++ b/example/common/utils.js @@ -1,29 +1,29 @@ -var fs = require('fs') +const fs = require('fs') function bufferToStdout (gl, width, height) { // Write output - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) process.stdout.write(['P3\n# gl.ppm\n', width, ' ', height, '\n255\n'].join('')) - for (var i = 0; i < pixels.length; i += 4) { + for (let i = 0; i < pixels.length; i += 4) { process.stdout.write(pixels[i] + ' ' + pixels[i + 1] + ' ' + pixels[i + 2] + ' ') } } function bufferToFile (gl, width, height, filename) { - var file = fs.createWriteStream(filename) + const file = fs.createWriteStream(filename) // Write output - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) file.write(['P3\n# gl.ppm\n', width, ' ', height, '\n255\n'].join('')) - for (var i = 0; i < pixels.length; i += 4) { + for (let i = 0; i < pixels.length; i += 4) { file.write(pixels[i] + ' ' + pixels[i + 1] + ' ' + pixels[i + 2] + ' ') } } function drawTriangle (gl) { - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-2, -2, -2, 4, 4, -2]), gl.STREAM_DRAW) gl.enableVertexAttribArray(0) @@ -35,15 +35,15 @@ function drawTriangle (gl) { } function loadShader (gl, shaderSource, shaderType) { - var shader = gl.createShader(shaderType) + const shader = gl.createShader(shaderType) gl.shaderSource(shader, shaderSource) gl.compileShader(shader) // Check the compile status - var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS) + const compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS) if (!compiled) { // Something went wrong during compilation; get the error - var lastError = gl.getShaderInfoLog(shader) + const lastError = gl.getShaderInfoLog(shader) console.log("*** Error compiling shader '" + shader + "':" + lastError) gl.deleteShader(shader) return null @@ -53,7 +53,7 @@ function loadShader (gl, shaderSource, shaderType) { } function createProgram (gl, shaders, optAttribs, optLocations) { - var program = gl.createProgram() + const program = gl.createProgram() shaders.forEach(function (shader) { gl.attachShader(program, shader) }) @@ -68,10 +68,10 @@ function createProgram (gl, shaders, optAttribs, optLocations) { gl.linkProgram(program) // Check the link status - var linked = gl.getProgramParameter(program, gl.LINK_STATUS) + const linked = gl.getProgramParameter(program, gl.LINK_STATUS) if (!linked) { // something went wrong with the link - var lastError = gl.getProgramInfoLog(program) + const lastError = gl.getProgramInfoLog(program) console.log('Error in program linking:' + lastError) gl.deleteProgram(program) @@ -81,13 +81,13 @@ function createProgram (gl, shaders, optAttribs, optLocations) { } function createProgramFromSources (gl, shaderSources, optAttribs, optLocations) { - var defaultShaderType = [ + const defaultShaderType = [ 'VERTEX_SHADER', 'FRAGMENT_SHADER' ] - var shaders = [] - for (var ii = 0; ii < shaderSources.length; ++ii) { + const shaders = [] + for (let ii = 0; ii < shaderSources.length; ++ii) { shaders.push(loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]])) } return createProgram(gl, shaders, optAttribs, optLocations) diff --git a/example/common/utils_log.js b/example/common/utils_log.js index 5eff58ff..52ad53fa 100755 --- a/example/common/utils_log.js +++ b/example/common/utils_log.js @@ -1,6 +1,6 @@ /* globals __stack */ -var log4js = require('log4js') +const log4js = require('log4js') // var path = require('path') function getLogger (category, level) { @@ -47,13 +47,13 @@ Log.prototype = { Object.defineProperty(global, '__stack', { get: function () { - var orig = Error.prepareStackTrace + const orig = Error.prepareStackTrace Error.prepareStackTrace = function (_, stack) { return stack } - var err = new Error() + const err = new Error() Error.captureStackTrace(err, arguments.callee) // eslint-disable-line - var stack = err.stack + const stack = err.stack Error.prepareStackTrace = orig return stack } diff --git a/example/fbo.js b/example/fbo.js index 56c40f08..66e86d2e 100644 --- a/example/fbo.js +++ b/example/fbo.js @@ -1,11 +1,11 @@ -var createContext = require('../index') -var utils = require('./utils.js') +const createContext = require('../index') +const utils = require('./utils.js') function main () { // Create context - var width = 64 - var height = 64 - var gl = createContext(width, height) + const width = 64 + const height = 64 + const gl = createContext(width, height) // Clear screen to red gl.clearColor(1.0, 0.0, 0.0, 1.0) diff --git a/example/fractals/mandelbrot.js b/example/fractals/mandelbrot.js index b014313d..490abf76 100755 --- a/example/fractals/mandelbrot.js +++ b/example/fractals/mandelbrot.js @@ -1,24 +1,24 @@ /* global __line */ -var path = require('path') -var createContext = require('../../index') -var utils = require('../common/utils.js') -var utilsLog = require('../common/utils_log.js') -var log = new utilsLog.Log(path.basename(__filename), 'DEBUG') +const path = require('path') +const createContext = require('../../index') +const utils = require('../common/utils.js') +const utilsLog = require('../common/utils_log.js') +const log = new utilsLog.Log(path.basename(__filename), 'DEBUG') function main () { // Create context - var width = 512 - var height = 512 - var gl = createContext(width, height) + const width = 512 + const height = 512 + const gl = createContext(width, height) - var vertexSrc = ` + const vertexSrc = ` attribute vec2 a_position; void main() { gl_Position = vec4(a_position,0,1); } ` - var fragmentSrc = ` + const fragmentSrc = ` precision mediump float; const int max_iterations = 255; @@ -59,7 +59,7 @@ function main () { ` // setup a GLSL program - var program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) + const program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) if (!program) { return @@ -67,11 +67,11 @@ function main () { gl.useProgram(program) // look up where the vertex data needs to go. - var positionLocation = gl.getAttribLocation(program, 'a_position') + const positionLocation = gl.getAttribLocation(program, 'a_position') // Create a buffer and put a single clipspace rectangle in // it (2 triangles) - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData( gl.ARRAY_BUFFER, diff --git a/example/misc/fbo.js b/example/misc/fbo.js index b4154c8c..0f2236be 100755 --- a/example/misc/fbo.js +++ b/example/misc/fbo.js @@ -1,16 +1,16 @@ /* globals __line */ -var path = require('path') -var createContext = require('../../index') -var utils = require('../common/utils.js') -var utilsLog = require('../common/utils_log.js') -var log = new utilsLog.Log(path.basename(__filename), 'DEBUG') +const path = require('path') +const createContext = require('../../index') +const utils = require('../common/utils.js') +const utilsLog = require('../common/utils_log.js') +const log = new utilsLog.Log(path.basename(__filename), 'DEBUG') function main () { // Create context - var width = 512 - var height = 512 - var gl = createContext(width, height) + const width = 512 + const height = 512 + const gl = createContext(width, height) // Clear screen to red gl.clearColor(1.0, 0.0, 0.0, 1.0) diff --git a/example/test1.js b/example/test1.js index b1ffb839..086135a3 100755 --- a/example/test1.js +++ b/example/test1.js @@ -1,27 +1,27 @@ -var createContext = require('../index') -var utils = require('./utils') +const createContext = require('../index') +const utils = require('./utils') function main () { // Create context - var width = 64 - var height = 64 - var gl = createContext(width, height) + const width = 64 + const height = 64 + const gl = createContext(width, height) - var vertexSrc = [ + const vertexSrc = [ 'attribute vec2 a_position;', 'void main() {', 'gl_Position = vec4(a_position, 0, 1);', '}' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'void main() {', 'gl_FragColor = vec4(0, 1, 0, 1); // green', '}' ].join('\n') // setup a GLSL program - var program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) + const program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) if (!program) { return @@ -29,11 +29,11 @@ function main () { gl.useProgram(program) // look up where the vertex data needs to go. - var positionLocation = gl.getAttribLocation(program, 'a_position') + const positionLocation = gl.getAttribLocation(program, 'a_position') // Create a buffer and put a single clipspace rectangle in // it (2 triangles) - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData( gl.ARRAY_BUFFER, diff --git a/example/webgl_fundamentals/test0.js b/example/webgl_fundamentals/test0.js index e3efd543..59d62ea7 100755 --- a/example/webgl_fundamentals/test0.js +++ b/example/webgl_fundamentals/test0.js @@ -1,17 +1,17 @@ /* globals __line */ -var path = require('path') -var createContext = require('../../index') -var utils = require('../common/utils.js') -var utilsLog = require('../common/utils_log.js') -var log = new utilsLog.Log(path.basename(__filename), 'DEBUG') +const path = require('path') +const createContext = require('../../index') +const utils = require('../common/utils.js') +const utilsLog = require('../common/utils_log.js') +const log = new utilsLog.Log(path.basename(__filename), 'DEBUG') function main () { // Create context - var width = 512 - var height = 512 - var gl = createContext(width, height) + const width = 512 + const height = 512 + const gl = createContext(width, height) - var vertexSrc = ` + const vertexSrc = ` attribute vec2 a_position; void main() { @@ -19,22 +19,22 @@ function main () { } ` - var fragmentSrc = ` + const fragmentSrc = ` void main() { gl_FragColor = vec4(0, 1, 0, 1); // green } ` // setup a GLSL program - var program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) + const program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) gl.useProgram(program) // look up where the vertex data needs to go. - var positionLocation = gl.getAttribLocation(program, 'a_position') + const positionLocation = gl.getAttribLocation(program, 'a_position') // Create a buffer and put a single clipspace rectangle in // it (2 triangles) - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData( gl.ARRAY_BUFFER, diff --git a/example/webgl_fundamentals/test1.js b/example/webgl_fundamentals/test1.js index 8a273000..4c282d50 100755 --- a/example/webgl_fundamentals/test1.js +++ b/example/webgl_fundamentals/test1.js @@ -1,17 +1,17 @@ /* globals __line */ -var path = require('path') -var createContext = require('../../index') -var utils = require('../common/utils.js') -var utilsLog = require('../common/utils_log.js') -var log = new utilsLog.Log(path.basename(__filename), 'DEBUG') +const path = require('path') +const createContext = require('../../index') +const utils = require('../common/utils.js') +const utilsLog = require('../common/utils_log.js') +const log = new utilsLog.Log(path.basename(__filename), 'DEBUG') function main () { // Create context - var width = 512 - var height = 512 - var gl = createContext(width, height) + const width = 512 + const height = 512 + const gl = createContext(width, height) - var vertexSrc = ` + const vertexSrc = ` attribute vec2 a_position; uniform vec2 u_resolution; @@ -30,26 +30,26 @@ function main () { } ` - var fragmentSrc = ` + const fragmentSrc = ` void main() { gl_FragColor = vec4(0, 1, 0, 1); // green } ` // setup a GLSL program - var program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) + const program = utils.createProgramFromSources(gl, [vertexSrc, fragmentSrc]) gl.useProgram(program) // look up where the vertex data needs to go. - var positionLocation = gl.getAttribLocation(program, 'a_position') + const positionLocation = gl.getAttribLocation(program, 'a_position') // set the resolution - var resolutionLocation = gl.getUniformLocation(program, 'u_resolution') + const resolutionLocation = gl.getUniformLocation(program, 'u_resolution') gl.uniform2f(resolutionLocation, width, height) // Create a buffer and put a single clipspace rectangle in // it (2 triangles) - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 10, 20, diff --git a/test/alpha-texture.js b/test/alpha-texture.js index 71ea061c..66cef9c8 100644 --- a/test/alpha-texture.js +++ b/test/alpha-texture.js @@ -1,16 +1,16 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') -var drawTriangle = require('./util/draw-triangle') -var makeShader = require('./util/make-program') +const tape = require('tape') +const createContext = require('../index') +const drawTriangle = require('./util/draw-triangle') +const makeShader = require('./util/make-program') tape('alpha texture', function (t) { - var width = 64 - var height = 64 - var gl = createContext(width, height) + const width = 64 + const height = 64 + const gl = createContext(width, height) - var vertexSrc = [ + const vertexSrc = [ 'precision mediump float;', 'attribute vec2 position;', 'varying vec2 texCoord;', @@ -20,7 +20,7 @@ tape('alpha texture', function (t) { '}' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'precision mediump float;', 'uniform sampler2D tex;', 'varying vec2 texCoord;', @@ -32,14 +32,14 @@ tape('alpha texture', function (t) { gl.clearColor(0, 0, 0, 0) gl.clear(gl.COLOR_BUFFER_BIT) - var data = new Uint8Array(width * height) - for (var i = 0; i < height; ++i) { - for (var j = 0; j < width; ++j) { + const data = new Uint8Array(width * height) + for (let i = 0; i < height; ++i) { + for (let j = 0; j < width; ++j) { data[width * i + j] = (i + j) % 255 } } - var texture = gl.createTexture() + const texture = gl.createTexture() gl.bindTexture(gl.TEXTURE_2D, texture) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) @@ -55,7 +55,7 @@ tape('alpha texture', function (t) { gl.UNSIGNED_BYTE, data) - var program = makeShader(gl, vertexSrc, fragmentSrc) + const program = makeShader(gl, vertexSrc, fragmentSrc) gl.useProgram(program) gl.uniform1i(gl.getUniformLocation(program, 'tex'), 0) @@ -63,12 +63,12 @@ tape('alpha texture', function (t) { t.equals(gl.getError(), gl.NO_ERROR) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) function checkColor () { - var ptr = 0 - for (i = 0; i < width * height * 4; i += 4) { + let ptr = 0 + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i] || pixels[i + 1] || pixels[i + 2] || diff --git a/test/attribute-weirdness.js b/test/attribute-weirdness.js index eb6ff4b0..e2f52d10 100644 --- a/test/attribute-weirdness.js +++ b/test/attribute-weirdness.js @@ -1,17 +1,17 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') -var makeShader = require('./util/make-program') +const tape = require('tape') +const createContext = require('../index') +const makeShader = require('./util/make-program') tape('attribute-weirdness', function (t) { - var width = 2 - var height = 2 + const width = 2 + const height = 2 function render (flipAttributes, flipLocations) { - var gl = createContext(width, height) + const gl = createContext(width, height) - var attributes = [ + const attributes = [ 'attribute vec2 a_pos;', 'attribute vec2 a_texture_pos;' ] @@ -20,7 +20,7 @@ tape('attribute-weirdness', function (t) { attributes.reverse() } - var vertexSrc = [ + const vertexSrc = [ 'precision mediump float;', attributes[0], attributes[1], @@ -31,7 +31,7 @@ tape('attribute-weirdness', function (t) { '}' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'precision mediump float;', 'varying vec2 v_pos0;', 'void main() {', @@ -42,10 +42,10 @@ tape('attribute-weirdness', function (t) { gl.clearColor(0, 0, 0, 0) gl.clear(gl.COLOR_BUFFER_BIT) - var program = makeShader(gl, vertexSrc, fragmentSrc) + const program = makeShader(gl, vertexSrc, fragmentSrc) gl.useProgram(program) - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData( gl.ARRAY_BUFFER, @@ -57,14 +57,14 @@ tape('attribute-weirdness', function (t) { ]), gl.STATIC_DRAW) - var aPos = gl.getAttribLocation(program, 'a_pos') - var aTexturePos = gl.getAttribLocation(program, 'a_texture_pos') + let aPos = gl.getAttribLocation(program, 'a_pos') + let aTexturePos = gl.getAttribLocation(program, 'a_texture_pos') gl.enableVertexAttribArray(aPos) gl.enableVertexAttribArray(aTexturePos) if (flipLocations) { - var tmp = aPos + const tmp = aPos aPos = aTexturePos aTexturePos = tmp } @@ -79,7 +79,7 @@ tape('attribute-weirdness', function (t) { // console.log('error:', gl.getError()) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) return pixels } @@ -88,10 +88,10 @@ tape('attribute-weirdness', function (t) { // The fragment shader sets a constant alpha value of 255 so we check for that. t.test('all alpha values should be 255', function (t) { - var pixels = render(false, false) + const pixels = render(false, false) // print(pixels) - var ok = true - for (var i = 0; i < width * height * 4; i += 4) { + let ok = true + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i + 3] !== 255) ok = false } t.ok(ok) @@ -100,10 +100,10 @@ tape('attribute-weirdness', function (t) { // But if we flip the order the attributes are defined in the shader it works. t.test('when attributes are flipped all alpha values should be 255', function (t) { - var pixels = render(true, false) + const pixels = render(true, false) // print(pixels) - var ok = true - for (var i = 0; i < width * height * 4; i += 4) { + let ok = true + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i + 3] !== 255) ok = false } t.ok(ok) @@ -112,10 +112,10 @@ tape('attribute-weirdness', function (t) { // even weirder, if we swap the attribute locations used when setting each pointer it works t.test('when attribute locations are swapped all alpha values should NOT be 255', function (t) { - var pixels = render(false, true) + const pixels = render(false, true) // print(pixels) - var ok = false - for (var i = 0; i < width * height * 4; i += 4) { + let ok = false + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i + 3] !== 255) ok = true } t.ok(ok) diff --git a/test/blending.js b/test/blending.js index 7fd15ff5..01e8d1fa 100644 --- a/test/blending.js +++ b/test/blending.js @@ -1,19 +1,19 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') -var drawTriangle = require('./util/draw-triangle') -var makeShader = require('./util/make-program') +const tape = require('tape') +const createContext = require('../index') +const drawTriangle = require('./util/draw-triangle') +const makeShader = require('./util/make-program') -var width = 2 -var height = 2 -var gl = createContext(width, height) +const width = 2 +const height = 2 +const gl = createContext(width, height) -var getVec4 = function (array) { +const getVec4 = function (array) { return 'vec4(' + array[0] + ',' + array[1] + ',' + array[2] + ',' + array[3] + ');' } -var tests = [ +const tests = [ { name: 'Blend: ADD ONE ONE', equn: gl.FUNC_ADD, @@ -65,10 +65,10 @@ var tests = [ } ] -for (var j = 0; j < tests.length; j++) { - var test = tests[j] +for (let j = 0; j < tests.length; j++) { + const test = tests[j] tape(test.name, function (t) { - var vertexSrc = [ + const vertexSrc = [ 'precision mediump float;', 'attribute vec2 position;', 'void main() {', @@ -76,7 +76,7 @@ for (var j = 0; j < tests.length; j++) { '}' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'precision mediump float;', 'void main() {', 'gl_FragColor = ' + test.srcColor, @@ -86,7 +86,7 @@ for (var j = 0; j < tests.length; j++) { gl.clearColor(test.dstColor[0], test.dstColor[1], test.dstColor[2], test.dstColor[3]) gl.clear(gl.COLOR_BUFFER_BIT) - var program = makeShader(gl, vertexSrc, fragmentSrc) + const program = makeShader(gl, vertexSrc, fragmentSrc) gl.useProgram(program) @@ -100,10 +100,10 @@ for (var j = 0; j < tests.length; j++) { gl.disable(gl.BLEND) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) - for (var i = 0; i < width * height * 4; i += 4) { + for (let i = 0; i < width * height * 4; i += 4) { t.ok(Math.abs(pixels[i] - test.expectedColor[0] * 255) < 3, 'red') t.ok(Math.abs(pixels[i] - test.expectedColor[0] * 255) < 3, 'green') t.ok(Math.abs(pixels[i] - test.expectedColor[0] * 255) < 3, 'blue') diff --git a/test/clear-color.js b/test/clear-color.js index 19a5b04d..fd387923 100644 --- a/test/clear-color.js +++ b/test/clear-color.js @@ -1,21 +1,21 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') +const tape = require('tape') +const createContext = require('../index') tape('clear color', function (t) { - var width = 10 - var height = 10 - var gl = createContext(width, height) + const width = 10 + const height = 10 + const gl = createContext(width, height) function testColor (r, g, b, a) { gl.clearColor(r / 255, g / 255, b / 255, a / 255) gl.clear(gl.COLOR_BUFFER_BIT) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) - for (var i = 0; i < width * height * 4; i += 4) { + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i] !== r || pixels[i + 1] !== g || pixels[i + 2] !== b || diff --git a/test/context.js b/test/context.js index 4421f447..c29f78f9 100644 --- a/test/context.js +++ b/test/context.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ 'context_context-type-test', 'context_methods' ] diff --git a/test/create-context.js b/test/create-context.js index 7cc13078..282d28df 100644 --- a/test/create-context.js +++ b/test/create-context.js @@ -1,11 +1,11 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') +const tape = require('tape') +const createContext = require('../index') tape('create context', function (t) { - var width = 10 - var height = 10 + const width = 10 + const height = 10 createContext(width, height) t.end() }) diff --git a/test/cubeMap.js b/test/cubeMap.js index f32bd199..24372171 100644 --- a/test/cubeMap.js +++ b/test/cubeMap.js @@ -1,17 +1,17 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index.js') +const tape = require('tape') +const createContext = require('../index.js') tape('cube map', function (t) { - var width = 64 - var height = 64 + const width = 64 + const height = 64 - var gl = createContext(width, height) + const gl = createContext(width, height) - var tex = gl.createTexture() - var fb = gl.createFramebuffer() - var img = new Uint8Array([255, 255, 255, 255]) + const tex = gl.createTexture() + const fb = gl.createFramebuffer() + const img = new Uint8Array([255, 255, 255, 255]) gl.activeTexture(gl.TEXTURE1) gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex) @@ -22,7 +22,7 @@ tape('cube map', function (t) { gl.bindFramebuffer(gl.FRAMEBUFFER, fb) - for (var i = 0; i < 6; i++) { + for (let i = 0; i < 6; i++) { gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, img) gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, tex, 0) } diff --git a/test/depth-buffer.js b/test/depth-buffer.js index 97a24b35..152b3bef 100644 --- a/test/depth-buffer.js +++ b/test/depth-buffer.js @@ -1,22 +1,22 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') -var drawTriangle = require('./util/draw-triangle') -var makeShader = require('./util/make-program') +const tape = require('tape') +const createContext = require('../index') +const drawTriangle = require('./util/draw-triangle') +const makeShader = require('./util/make-program') tape('depth-buffer', function (t) { - var width = 50 - var height = 50 - var gl = createContext(width, height) + const width = 50 + const height = 50 + const gl = createContext(width, height) - var vertexSrc = [ + const vertexSrc = [ 'attribute vec2 position;', 'uniform float depth;', 'void main() { gl_Position = vec4(position,depth,1); }' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'precision mediump float;', 'uniform vec4 color;', 'void main() { gl_FragColor = color; }' @@ -29,7 +29,7 @@ tape('depth-buffer', function (t) { gl.enable(gl.DEPTH_TEST) gl.depthFunc(gl.NOTEQUAL) - var program = makeShader(gl, vertexSrc, fragmentSrc) + const program = makeShader(gl, vertexSrc, fragmentSrc) gl.useProgram(program) gl.uniform1f(gl.getUniformLocation(program, 'depth'), 0) gl.uniform4f(gl.getUniformLocation(program, 'color'), 1, 0, 0, 1) @@ -38,10 +38,10 @@ tape('depth-buffer', function (t) { gl.uniform4f(gl.getUniformLocation(program, 'color'), 0, 1, 0, 1) drawTriangle(gl) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) function checkPixels () { - for (var i = 0; i < width * height * 4; i += 4) { + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i] !== 0 || pixels[i + 1] !== 255 || pixels[i + 2] !== 0 || diff --git a/test/draw-indexed.js b/test/draw-indexed.js index 488bdd5c..29122f74 100644 --- a/test/draw-indexed.js +++ b/test/draw-indexed.js @@ -1,30 +1,30 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') -var makeShader = require('./util/make-program') +const tape = require('tape') +const createContext = require('../index') +const makeShader = require('./util/make-program') tape('draw-indexed', function (t) { - var width = 50 - var height = 50 - var gl = createContext(width, height) + const width = 50 + const height = 50 + const gl = createContext(width, height) - var vertexSrc = [ + const vertexSrc = [ 'attribute vec2 position;', 'void main() { gl_Position = vec4(position,0,1); }' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'void main() { gl_FragColor = vec4(0,1,0,1); }' ].join('\n') gl.clearColor(1, 0, 0, 1) gl.clear(gl.COLOR_BUFFER_BIT) - var program = makeShader(gl, vertexSrc, fragmentSrc) + const program = makeShader(gl, vertexSrc, fragmentSrc) gl.useProgram(program) - var vbuffer = gl.createBuffer() + const vbuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vbuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ -1, -1, @@ -34,7 +34,7 @@ tape('draw-indexed', function (t) { gl.enableVertexAttribArray(0) gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0) - var ebuffer = gl.createBuffer() + const ebuffer = gl.createBuffer() gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebuffer) gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 0, 1, 2, @@ -43,11 +43,11 @@ tape('draw-indexed', function (t) { gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) function checkPixels () { - for (var i = 0; i < width * height * 4; i += 4) { + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i] !== 0 || pixels[i + 1] !== 255 || pixels[i + 2] !== 0 || diff --git a/test/extensions.js b/test/extensions.js index f8947387..fa2b7ceb 100644 --- a/test/extensions.js +++ b/test/extensions.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ // FIXME: These extensions aren't working yet 'extensions_ext-frag-depth', 'extensions_ext-shader-texture-lod', diff --git a/test/glsl_samplers.js b/test/glsl_samplers.js index 6afd9bf9..9845c001 100644 --- a/test/glsl_samplers.js +++ b/test/glsl_samplers.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ 'glsl_samplers_glsl-function-texture2dprojlod' ] diff --git a/test/mapbox-ansis.js b/test/mapbox-ansis.js index 51b2a13a..add4f15a 100644 --- a/test/mapbox-ansis.js +++ b/test/mapbox-ansis.js @@ -1,32 +1,32 @@ -var tape = require('tape') -var createContext = require('../index') +const tape = require('tape') +const createContext = require('../index') tape('mapbox-ansis', function (t) { - var width = 1 - var height = 1 + const width = 1 + const height = 1 - var gl = createContext(width, height) + const gl = createContext(width, height) - var vertexSource = 'precision mediump float;\n' + + const vertexSource = 'precision mediump float;\n' + 'uniform float u_z;\n' + 'attribute vec2 a_position;\n' + 'void main() {\n' + ' gl_Position = vec4(a_position, u_z, 1);\n' + '}' - var fragmentSource = 'precision mediump float;\n' + + const fragmentSource = 'precision mediump float;\n' + 'uniform vec4 u_color;\n' + 'void main() {\n' + ' gl_FragColor = u_color; // green\n' + '}' - var vertex = gl.createShader(gl.VERTEX_SHADER) + const vertex = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vertex, vertexSource) gl.compileShader(vertex) - var fragment = gl.createShader(gl.FRAGMENT_SHADER) + const fragment = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fragment, fragmentSource) gl.compileShader(fragment) - var program = gl.createProgram() + const program = gl.createProgram() gl.attachShader(program, vertex) gl.attachShader(program, fragment) gl.linkProgram(program) @@ -44,9 +44,9 @@ tape('mapbox-ansis', function (t) { } // Attribute and uniform locations - var aPosition = gl.getAttribLocation(program, 'a_position') - var uColor = gl.getUniformLocation(program, 'u_color') - var uZ = gl.getUniformLocation(program, 'u_z') + const aPosition = gl.getAttribLocation(program, 'a_position') + const uColor = gl.getUniformLocation(program, 'u_color') + const uZ = gl.getUniformLocation(program, 'u_z') // Set up framebuffer gl.renderbuffer = gl.createRenderbuffer() @@ -57,7 +57,7 @@ tape('mapbox-ansis', function (t) { gl.bindRenderbuffer(gl.RENDERBUFFER, gl.depthStencilBuffer) gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, gl.drawingBufferWidth, gl.drawingBufferHeight) - var fbo = gl.createFramebuffer() + const fbo = gl.createFramebuffer() gl.bindFramebuffer(gl.FRAMEBUFFER, fbo) gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, gl.renderbuffer) gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, gl.depthStencilBuffer) @@ -74,7 +74,7 @@ tape('mapbox-ansis', function (t) { // Create a buffer and put a single clipspace rectangle in // it (2 triangles) - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData( gl.ARRAY_BUFFER, @@ -114,7 +114,7 @@ tape('mapbox-ansis', function (t) { // The blue rectangle gets drawn because 0.5 <= 0.5 // Write output - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) t.equals(pixels[0], 0) diff --git a/test/misc.js b/test/misc.js index 20413d81..222a2f7f 100644 --- a/test/misc.js +++ b/test/misc.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ // FIXME: Uninitialized data is broken 'misc_uninitialized-test', 'misc_object-deletion-behaviour' diff --git a/test/more_conformance.js b/test/more_conformance.js index 4bb38599..af066a2f 100644 --- a/test/more_conformance.js +++ b/test/more_conformance.js @@ -1,4 +1,4 @@ -var BLACKLIST = [] +const BLACKLIST = [] require('./util/conformance')(function (str) { return str.indexOf('more_conformance') === 0 && BLACKLIST.indexOf(str) < 0 diff --git a/test/more_functions.js b/test/more_functions.js index 1df48ea3..3094fa25 100644 --- a/test/more_functions.js +++ b/test/more_functions.js @@ -1,4 +1,4 @@ -var BLACKLIST = { +const BLACKLIST = { more_functions_isTests: true, more_functions_texSubImage2DHTMLBadArgs: true, more_functions_texImage2DHTMLBadArgs: true, diff --git a/test/more_glsl.js b/test/more_glsl.js index e1f202a5..30052aa3 100644 --- a/test/more_glsl.js +++ b/test/more_glsl.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ 'more_glsl_arrayOutOfBounds' ] diff --git a/test/multiple-render-targets.js b/test/multiple-render-targets.js index bd62b9ee..04cf27ba 100644 --- a/test/multiple-render-targets.js +++ b/test/multiple-render-targets.js @@ -1,21 +1,21 @@ 'use strict' -var createContext = require('../index') -var tape = require('tape') +const createContext = require('../index') +const tape = require('tape') tape.skip('multiple-render-targets', function (t) { - var bufferWidth = 1 - var bufferHeight = 1 - var outputWidth = 4 - var outputHeight = 1 - var gl = createContext(outputWidth, outputHeight) - var drawBuffers = gl.getExtension('WEBGL_draw_buffers') - var textures = writeTextures() + const bufferWidth = 1 + const bufferHeight = 1 + const outputWidth = 4 + const outputHeight = 1 + const gl = createContext(outputWidth, outputHeight) + const drawBuffers = gl.getExtension('WEBGL_draw_buffers') + const textures = writeTextures() renderTextures(textures) - var pixels = toPixels() - var notZero = 0 - for (var i = 0; i < pixels.length; i++) { - var pixel = pixels[i] + const pixels = toPixels() + let notZero = 0 + for (let i = 0; i < pixels.length; i++) { + const pixel = pixels[i] if (pixel > 0) { notZero++ } @@ -25,12 +25,12 @@ tape.skip('multiple-render-targets', function (t) { t.end() function writeTextures () { - var vs = `void main() { + const vs = `void main() { gl_PointSize = 1.0; gl_Position = vec4(0, 0, 0, 1); }` - var fs = `#extension GL_EXT_draw_buffers : require + const fs = `#extension GL_EXT_draw_buffers : require precision mediump float; void main() { @@ -55,19 +55,19 @@ tape.skip('multiple-render-targets', function (t) { throw new Error('Error compiling fragment shader: ' + gl.getShaderInfoLog(fragShader)) } - var program = gl.createProgram() + const program = gl.createProgram() gl.attachShader(program, vertShader) gl.attachShader(program, fragShader) gl.linkProgram(program) - var textures = [] - var fb = gl.createFramebuffer() + const textures = [] + const fb = gl.createFramebuffer() gl.bindFramebuffer(gl.FRAMEBUFFER, fb) - for (var i = 0; i < 4; i++) { - var texture = gl.createTexture() + for (let i = 0; i < 4; i++) { + const texture = gl.createTexture() textures.push(texture) gl.bindTexture(gl.TEXTURE_2D, texture) - var level = 0 + const level = 0 gl.texImage2D(gl.TEXTURE_2D, level, gl.RGBA, bufferWidth, bufferHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null) // attach texture to framebuffer @@ -93,13 +93,13 @@ tape.skip('multiple-render-targets', function (t) { } function renderTextures () { - var vs = `void main() { + const vs = `void main() { gl_PointSize = 4.0; gl_Position = vec4(0, 0, 0, 1); }` // render the 4 textures - var fs = `precision mediump float; + const fs = `precision mediump float; uniform sampler2D tex[4]; void main() { vec4 color = vec4(0); @@ -111,11 +111,11 @@ tape.skip('multiple-render-targets', function (t) { gl_FragColor = vec4(color.rgb, 1.0); }` - var vertShader = gl.createShader(gl.VERTEX_SHADER) + const vertShader = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vertShader, vs) gl.compileShader(vertShader) - var fragShader = gl.createShader(gl.FRAGMENT_SHADER) + const fragShader = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fragShader, fs) gl.compileShader(fragShader) @@ -126,7 +126,7 @@ tape.skip('multiple-render-targets', function (t) { throw new Error('Error compiling fragment shader: ' + gl.getShaderInfoLog(fragShader)) } - var program = gl.createProgram() + const program = gl.createProgram() gl.attachShader(program, vertShader) gl.attachShader(program, fragShader) gl.linkProgram(program) @@ -134,8 +134,8 @@ tape.skip('multiple-render-targets', function (t) { gl.viewport(0, 0, outputWidth, outputHeight) gl.useProgram(program) // binds all the textures and set the uniforms - for (var i = 0; i < textures.length; i++) { - var texture = textures[i] + for (let i = 0; i < textures.length; i++) { + const texture = textures[i] gl.activeTexture(gl.TEXTURE0 + i) gl.bindTexture(gl.TEXTURE_2D, texture) } @@ -144,7 +144,7 @@ tape.skip('multiple-render-targets', function (t) { } function toPixels () { - var bytes = new Uint8Array(outputWidth * outputHeight * 4) + const bytes = new Uint8Array(outputWidth * outputHeight * 4) gl.readPixels(0, 0, outputWidth, outputHeight, gl.RGBA, gl.UNSIGNED_BYTE, bytes) // require('../example/common/utils').bufferToFile(gl, outputWidth, outputHeight, 'multiple-render-targets.ppm') return bytes diff --git a/test/ogles.js b/test/ogles.js index b6dfee04..6125e3f0 100644 --- a/test/ogles.js +++ b/test/ogles.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ // FIXME not sure what the hell is happening in these cases // ogles tests are completely nutzo impossible to trace :( 'ogles_GL_array_array_001_to_006', diff --git a/test/renderbuffer.js b/test/renderbuffer.js index 7c38f455..d66acb35 100644 --- a/test/renderbuffer.js +++ b/test/renderbuffer.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ 'renderbuffers_feedback-loop', 'renderbuffers_renderbuffer-initialization' ] diff --git a/test/rendering.js b/test/rendering.js index 9a12056a..b8892c6c 100644 --- a/test/rendering.js +++ b/test/rendering.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ // BROKEN Uses RGB texture FBOs 'rendering_framebuffer-texture-switch', 'rendering_framebuffer-switch', diff --git a/test/resize.js b/test/resize.js index 997fbfba..a09912cb 100644 --- a/test/resize.js +++ b/test/resize.js @@ -1,12 +1,12 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') +const tape = require('tape') +const createContext = require('../index') tape('resize', function (t) { - var width = 2 - var height = 2 - var gl = createContext(width, height) + const width = 2 + const height = 2 + const gl = createContext(width, height) function testColor (width, height, r, g, b, a) { gl.resize(width, height) @@ -17,12 +17,12 @@ tape('resize', function (t) { gl.clearColor(r / 255, g / 255, b / 255, a / 255) gl.clear(gl.COLOR_BUFFER_BIT) - var pixels = new Uint8Array((width + 2) * (height + 2) * 4) + const pixels = new Uint8Array((width + 2) * (height + 2) * 4) gl.readPixels(-1, -1, width + 2, height + 2, gl.RGBA, gl.UNSIGNED_BYTE, pixels) - var ptr = 0 - for (var row = -1; row <= height; ++row) { - for (var col = -1; col <= width; ++col) { + let ptr = 0 + for (let row = -1; row <= height; ++row) { + for (let col = -1; col <= width; ++col) { if (row < 0 || col < 0 || row === height || col === width) { t.equals(pixels[ptr++], 0, 'out of bounds red') t.equals(pixels[ptr++], 0, 'out of bounds green') diff --git a/test/simple-shader.js b/test/simple-shader.js index 3c7e469e..1aa37d07 100644 --- a/test/simple-shader.js +++ b/test/simple-shader.js @@ -1,36 +1,36 @@ 'use strict' -var tape = require('tape') -var createContext = require('../index') -var drawTriangle = require('./util/draw-triangle') -var makeShader = require('./util/make-program') +const tape = require('tape') +const createContext = require('../index') +const drawTriangle = require('./util/draw-triangle') +const makeShader = require('./util/make-program') tape('simple-shader', function (t) { - var width = 50 - var height = 50 - var gl = createContext(width, height) + const width = 50 + const height = 50 + const gl = createContext(width, height) - var vertexSrc = [ + const vertexSrc = [ 'attribute vec2 position;', 'void main() { gl_Position = vec4(position,0,1); }' ].join('\n') - var fragmentSrc = [ + const fragmentSrc = [ 'void main() { gl_FragColor = vec4(0,1,0,1); }' ].join('\n') gl.clearColor(0, 0, 0, 0) gl.clear(gl.COLOR_BUFFER_BIT) - var program = makeShader(gl, vertexSrc, fragmentSrc) + const program = makeShader(gl, vertexSrc, fragmentSrc) gl.useProgram(program) drawTriangle(gl) - var pixels = new Uint8Array(width * height * 4) + const pixels = new Uint8Array(width * height * 4) gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels) function checkPixels () { - for (var i = 0; i < width * height * 4; i += 4) { + for (let i = 0; i < width * height * 4; i += 4) { if (pixels[i] !== 0 || pixels[i + 1] !== 255 || pixels[i + 2] !== 0 || diff --git a/test/state.js b/test/state.js index e6357512..87c4a899 100644 --- a/test/state.js +++ b/test/state.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ // This test is fucking broken 'state_gl-get-calls' ] diff --git a/test/textures.js b/test/textures.js index 21b75bd7..a2c3ceeb 100644 --- a/test/textures.js +++ b/test/textures.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ 'textures_compressed-tex-image', 'textures_copy-tex-image-2d-formats', 'textures_copy-tex-image-and-sub-image-2d', diff --git a/test/uniforms.js b/test/uniforms.js index 66c88d63..0874c0aa 100644 --- a/test/uniforms.js +++ b/test/uniforms.js @@ -1,4 +1,4 @@ -var BLACKLIST = [ +const BLACKLIST = [ // This test is really fiddly. It relies on some weird antialiasing behavior // for GL_LINES 'uniforms_out-of-bounds-uniform-array-access', diff --git a/test/util/conformance.js b/test/util/conformance.js index 4787b1df..39d4d59b 100644 --- a/test/util/conformance.js +++ b/test/util/conformance.js @@ -1,6 +1,6 @@ -var tape = require('tape') -var runConformance = require('gl-conformance') -var createContext = require('../../index') +const tape = require('tape') +const runConformance = require('gl-conformance') +const createContext = require('../../index') // Inject WebGL types into global namespaces, required by some conformance tests WebGLRenderingContext = require('../../src/javascript/webgl-rendering-context').WebGLRenderingContext // eslint-disable-line @@ -19,7 +19,7 @@ module.exports = function (filter) { return runConformance({ tape: tape, createContext: function (width, height, options) { - var context = createContext(width, height, options) + const context = createContext(width, height, options) context.destroy = context.getExtension('STACKGL_destroy_context').destroy context.resize = context.getExtension('STACKGL_resize_drawingbuffer').resize return context diff --git a/test/util/draw-triangle.js b/test/util/draw-triangle.js index ce36289a..acef3afa 100644 --- a/test/util/draw-triangle.js +++ b/test/util/draw-triangle.js @@ -1,5 +1,5 @@ module.exports = function drawTriangle (gl) { - var buffer = gl.createBuffer() + const buffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, buffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-2, -2, -2, 4, 4, -2]), gl.STREAM_DRAW) gl.enableVertexAttribArray(0) diff --git a/test/util/make-program.js b/test/util/make-program.js index 27938302..44a09693 100644 --- a/test/util/make-program.js +++ b/test/util/make-program.js @@ -1,12 +1,12 @@ 'use strict' -var compileShader = require('./make-shader') +const compileShader = require('./make-shader') module.exports = function setupShader (gl, VERT_SRC, FRAG_SRC) { - var fragShader = compileShader(gl, gl.FRAGMENT_SHADER, FRAG_SRC) - var vertShader = compileShader(gl, gl.VERTEX_SHADER, VERT_SRC) + const fragShader = compileShader(gl, gl.FRAGMENT_SHADER, FRAG_SRC) + const vertShader = compileShader(gl, gl.VERTEX_SHADER, VERT_SRC) - var program = gl.createProgram() + const program = gl.createProgram() gl.attachShader(program, fragShader) gl.attachShader(program, vertShader) gl.linkProgram(program) diff --git a/test/util/make-shader.js b/test/util/make-shader.js index 52651cdc..ea53f51a 100644 --- a/test/util/make-shader.js +++ b/test/util/make-shader.js @@ -1,7 +1,7 @@ 'use strict' module.exports = function compileShader (gl, type, src) { - var shader = gl.createShader(type) + const shader = gl.createShader(type) gl.shaderSource(shader, src) gl.compileShader(shader) return shader diff --git a/test/util/stencil-check-cache.js b/test/util/stencil-check-cache.js index a5f5ec98..ba356559 100644 --- a/test/util/stencil-check-cache.js +++ b/test/util/stencil-check-cache.js @@ -1,16 +1,16 @@ -var tape = require('tape') -var { WebGLRenderingContext } = require('../../src/javascript/webgl-rendering-context') -var createContext = require('../../src/javascript/node-index') +const tape = require('tape') +const { WebGLRenderingContext } = require('../../src/javascript/webgl-rendering-context') +const createContext = require('../../src/javascript/node-index') tape('stencil check cache - gl.stencilFunc()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() t.equals(gl._checkStencil, undefined, 'gl._checkStencil starts undefined') gl.destroy() t.end() }) tape('stencil check cache - gl.stencilFunc()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.stencilFunc() t.equals(gl._checkStencil, true, 'gl.stencilFunc() calls set gl._checkStencil to true') gl.destroy() @@ -18,7 +18,7 @@ tape('stencil check cache - gl.stencilFunc()', function (t) { }) tape('stencil check cache - gl.stencilFuncSeparate()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.stencilFuncSeparate() t.equals(gl._checkStencil, true, 'gl.stencilFuncSeparate() calls set gl._checkStencil to true') gl.destroy() @@ -26,7 +26,7 @@ tape('stencil check cache - gl.stencilFuncSeparate()', function (t) { }) tape('stencil check cache - gl.stencilMask()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.stencilMask() t.equals(gl._checkStencil, true, 'gl.stencilMask() calls set gl._checkStencil to true') gl.destroy() @@ -34,7 +34,7 @@ tape('stencil check cache - gl.stencilMask()', function (t) { }) tape('stencil check cache - gl.stencilMaskSeparate()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.stencilMaskSeparate() t.equals(gl._checkStencil, true, 'gl.stencilMaskSeparate() calls set gl._checkStencil to true') gl.destroy() @@ -42,7 +42,7 @@ tape('stencil check cache - gl.stencilMaskSeparate()', function (t) { }) tape('stencil check cache - gl.stencilOp()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.stencilOp() t.equals(gl._checkStencil, true, 'gl.stencilOp() calls set gl._checkStencil to true') gl.destroy() @@ -50,7 +50,7 @@ tape('stencil check cache - gl.stencilOp()', function (t) { }) tape('stencil check cache - gl.stencilOpSeparate()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.stencilOpSeparate() t.equals(gl._checkStencil, true, 'gl.stencilOpSeparate() calls set gl._checkStencil to true') gl.destroy() @@ -58,7 +58,7 @@ tape('stencil check cache - gl.stencilOpSeparate()', function (t) { }) tape('stencil check cache - gl.clearStencil()', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl.clearStencil() t.equals(gl._checkStencil, false, 'gl.clearStencil() calls set gl._checkStencil to false') gl.destroy() @@ -66,7 +66,7 @@ tape('stencil check cache - gl.clearStencil()', function (t) { }) tape('stencil check cache - gl._checkStencilState() without errors', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl._checkStencil = true t.equals(gl._checkStencilState(), true, 'gl._checkStencilState() value is cached and returned') t.equals(gl._checkStencil, false, 'gl._checkStencilState() calls set gl._checkStencil to false') @@ -81,7 +81,7 @@ tape('stencil check cache - gl._checkStencilState() without errors', function (t }) tape('stencil check cache - gl._checkStencilState() with errors', function (t) { - var gl = new WebGLRenderingContext() + const gl = new WebGLRenderingContext() gl._checkStencil = true gl.getParameter = function (stencil) { if (stencil === gl.STENCIL_WRITEMASK) return 1 @@ -99,7 +99,7 @@ tape('stencil check cache - gl._checkStencilState() with errors', function (t) { }) tape('stencil check cache - createContext initial state', function (t) { - var gl = createContext(1, 1) + const gl = createContext(1, 1) gl.getParameter = function () { throw new Error('should not be called!') }