static #fragmentShader: WebGLShader | null
static #positionBuffer: WebGLBuffer | null
static #uvBuffer: WebGLBuffer | null
+ static #pixels: Uint8Array
// Vertex Positions, 2 triangles
static #positions = new Float32Array([
-1, -1, 0, -1, 1, 0, 1, 1, 0,
this.#blockHashLocation = this.#gl.getUniformLocation(this.#program, "blockHash")
this.#thresholdLocation = this.#gl.getUniformLocation(this.#program, "threshold")
this.#workloadLocation = this.#gl.getUniformLocation(this.#program, "workload")
+ this.#pixels = new Uint8Array(this.#gl.drawingBufferWidth * this.#gl.drawingBufferHeight * 4)
}
static #calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number): void {
Pow.#gl.clear(Pow.#gl.COLOR_BUFFER_BIT)
Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6)
- const pixels = new Uint8Array(Pow.#gl.drawingBufferWidth * Pow.#gl.drawingBufferHeight * 4)
- Pow.#gl.readPixels(0, 0, Pow.#gl.drawingBufferWidth, Pow.#gl.drawingBufferHeight, Pow.#gl.RGBA, Pow.#gl.UNSIGNED_BYTE, pixels)
+ Pow.#gl.readPixels(0, 0, Pow.#gl.drawingBufferWidth, Pow.#gl.drawingBufferHeight, Pow.#gl.RGBA, Pow.#gl.UNSIGNED_BYTE, Pow.#pixels)
// Check the pixels for any success
- for (let i = 0; i < pixels.length; i += 4) {
- if (pixels[i] !== 0) {
+ for (let i = 0; i < Pow.#pixels.length; i += 4) {
+ if (Pow.#pixels[i] !== 0) {
performance.mark('end')
frameTimes.push(performance.measure('draw', 'start', 'end').duration)
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(work1) + this.#hexify([
- pixels[i + 2],
- pixels[i + 3],
- work0[2] ^ (pixels[i] - 1),
- work0[3] ^ (pixels[i + 1] - 1)
+ Pow.#pixels[i + 2],
+ Pow.#pixels[i + 3],
+ work0[2] ^ (Pow.#pixels[i] - 1),
+ work0[3] ^ (Pow.#pixels[i + 1] - 1)
])
// Return the work value with the custom bits
typeof callback === 'function' && callback(hex)