if (typeof threshold === 'number') threshold = '0x' + threshold.toString(16)
if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) throw new Error(`invalid_hash ${hashHex}`)
let reverseHex = ''
- for (let i = hashHex.length; i > 0; i -= 2) {
- reverseHex += hashHex.slice(i - 2, i)
- }
-
- if (this.gl == null)
- throw new Error('webgl2_required')
-
+ for (let i = hashHex.length; i > 0; i -= 2) reverseHex += hashHex.slice(i - 2, i)
+ if (this.gl == null) throw new Error('webgl2_required')
this.gl.clearColor(0, 0, 0, 1)
// Vertext Shader
this.gl.drawArrays(this.gl.TRIANGLES, 0, 6)
const pixels = new Uint8Array(this.gl.drawingBufferWidth * this.gl.drawingBufferHeight * 4)
- console.log(`start readPixels: ${performance.now()}`)
this.gl.readPixels(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight, this.gl.RGBA, this.gl.UNSIGNED_BYTE, pixels)
- console.log(`end readPixels: ${performance.now()}`)
// Check the pixels for any success
for (let i = pixels.length - 4; i >= 0; i -= 4) {
if (pixels[i] !== 0) {
console.log(`frame time: ${performance.now() - start}`)
+ const hex = this.hexify(this.work1) + this.hexify([
+ pixels[i + 2],
+ pixels[i + 3],
+ this.work0[2] ^ (pixels[i] - 1),
+ this.work0[3] ^ (pixels[i + 1] - 1)
+ ])
// Return the work value with the custom bits
- typeof callback === 'function' &&
- callback(this.hexify(this.work1) + this.hexify([
- pixels[i + 2],
- pixels[i + 3],
- this.work0[2] ^ (pixels[i] - 1),
- this.work0[3] ^ (pixels[i + 1] - 1)
- ]))
+ typeof callback === 'function' && callback(hex)
return
}
}