/** Used to set canvas size. Must be a multiple of 256. */
static #WORKLOAD: number = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency / 2))
- static #work0 = new Uint8Array(4)
- static #work1 = new Uint8Array(4)
static #hexify (arr: number[] | Uint8Array): string {
let out = ''
view.setUint8(i / 2, parseInt(byte, 16))
}
const hashBytes = new Uint32Array(view.buffer)
+ const work0 = new Uint8Array(4)
+ const work1 = new Uint8Array(4)
// Draw output until success or progressCallback says to stop
let n = 0
n++
if (Pow.#gl == null) throw new Error('WebGL 2 is required')
performance.mark('start')
- crypto.getRandomValues(Pow.#work0)
- crypto.getRandomValues(Pow.#work1)
+ crypto.getRandomValues(work0)
+ crypto.getRandomValues(work1)
- Pow.#gl.uniform4uiv(Pow.#work0Location, this.#work0)
- Pow.#gl.uniform4uiv(Pow.#work1Location, this.#work1)
+ Pow.#gl.uniform4uiv(Pow.#work0Location, work0)
+ Pow.#gl.uniform4uiv(Pow.#work1Location, work1)
Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes)
Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold)
- Pow.#gl.uniform1f(Pow.#workloadLocation, this.#WORKLOAD - 1)
+ Pow.#gl.uniform1f(Pow.#workloadLocation, Pow.#WORKLOAD - 1)
Pow.#gl.clear(Pow.#gl.COLOR_BUFFER_BIT)
Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6)
performance.clearMarks()
console.log(`average frame time: ${(frameTimes.reduce((a, b) => a + b)) / frameTimes.length} ms`)
console.log(`frames calculated: ${n}`)
- const hex = this.#hexify(this.#work1) + this.#hexify([
+ const hex = this.#hexify(work1) + this.#hexify([
pixels[i + 2],
pixels[i + 3],
- this.#work0[2] ^ (pixels[i] - 1),
- this.#work0[3] ^ (pixels[i + 1] - 1)
+ work0[2] ^ (pixels[i] - 1),
+ work0[3] ^ (pixels[i + 1] - 1)
])
// Return the work value with the custom bits
typeof callback === 'function' && callback(hex)