if (this.gl == null) throw new Error('webgl2_required')
this.gl.clearColor(0, 0, 0, 1)
- const blockHashArray: number[] = []
- for (let i = 0; i < 8; i++) {
- blockHashArray.push(parseInt(reverseHex.slice(i * 8, (i + 1) * 8), 16))
- }
- const blockHashComponents: Uint32Array = new Uint32Array(blockHashArray)
-
// Vertext Shader
const vsSource = `#version 300 es
precision highp float;
uniform uvec4 u_work0;
// Last 4 bytes remain as generated externally
uniform uvec4 u_work1;
- // Precalculated block hash components
- uniform uint blockHash[8];
// Defined separately from uint v[32] below as the original value is required
// to calculate the second uint32 of the digest for threshold comparison
m[1] = (u_work1.r ^ (u_work1.g << 8) ^ (u_work1.b << 16) ^ (u_work1.a << 24));
// Block hash
- m[2] = blockHash[0];
- m[3] = blockHash[1];
- m[4] = blockHash[2];
- m[5] = blockHash[3];
- m[6] = blockHash[4];
- m[7] = blockHash[5];
- m[8] = blockHash[6];
- m[9] = blockHash[7];
+ m[2] = 0x${reverseHex.slice(56, 64)}u;
+ m[3] = 0x${reverseHex.slice(48, 56)}u;
+ m[4] = 0x${reverseHex.slice(40, 48)}u;
+ m[5] = 0x${reverseHex.slice(32, 40)}u;
+ m[6] = 0x${reverseHex.slice(24, 32)}u;
+ m[7] = 0x${reverseHex.slice(16, 24)}u;
+ m[8] = 0x${reverseHex.slice(8, 16)}u;
+ m[9] = 0x${reverseHex.slice(0, 8)}u;
// twelve rounds of mixing
for(i=0;i<12;i++) {
const work0Location = this.gl.getUniformLocation(program, 'u_work0')
const work1Location = this.gl.getUniformLocation(program, 'u_work1')
- const blockHashLocation = this.gl.getUniformLocation(program, "blockHash")
// Draw output until success or progressCallback says to stop
let n = 0
this.gl.uniform4uiv(work0Location, this.work0)
this.gl.uniform4uiv(work1Location, this.work1)
- this.gl.uniform1uiv(blockHashLocation, blockHashComponents)
this.gl.clear(this.gl.COLOR_BUFFER_BIT)
this.gl.drawArrays(this.gl.TRIANGLES, 0, 6)