const work = new Uint8Array(8)
let start: DOMHighResTimeStamp
const draw = (): void => {
- start = performance.now()
if (PowGl.#gl == null) throw new Error('WebGL 2 is required')
if (PowGl.#query == null) throw new Error('WebGL 2 is required to run queries')
PowGl.#gl.clear(PowGl.#gl.COLOR_BUFFER_BIT)
function checkQueryResult () {
if (PowGl.#gl == null) throw new Error('WebGL 2 is required to check query results')
if (PowGl.#query == null) throw new Error('Query not found')
- console.log(`checking (${performance.now() - start} ms)`)
if (PowGl.#gl.getQueryParameter(PowGl.#query, PowGl.#gl.QUERY_RESULT_AVAILABLE)) {
- console.log(`AVAILABLE (${performance.now() - start} ms)`)
const anySamplesPassed = PowGl.#gl.getQueryParameter(PowGl.#query, PowGl.#gl.QUERY_RESULT)
if (anySamplesPassed) {
// A valid nonce was found
readBackResult()
} else {
- console.log(`not found (${performance.now() - start} ms)`)
// No valid nonce found, start the next draw call
requestAnimationFrame(draw)
}
} else {
- console.log(`not ready (${performance.now() - start} ms)`)
// Query result not yet available, check again in the next frame
requestAnimationFrame(checkQueryResult)
}
// Check the pixels for any success
for (let i = 0; i < PowGl.#pixels.length; i += 4) {
if (PowGl.#pixels[i] !== 0) {
- console.log(`FOUND (${performance.now() - start} ms)`)
const hex = PowGl.#hexify(work.subarray(4, 8)) + PowGl.#hexify([
PowGl.#pixels[i + 2],
PowGl.#pixels[i + 3],