From 72bf0d813e00e61f27365f5ebb1088252890dc73 Mon Sep 17 00:00:00 2001 From: dkaraush Date: Fri, 8 Sep 2023 22:00:13 +0400 Subject: [PATCH] google pixel strange behaviour fix --- main.js | 20 ++++++++++++++------ vertex.glsl | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index c914806..a894f27 100644 --- a/main.js +++ b/main.js @@ -6,8 +6,8 @@ let W, H const resize = () => { const sz = Math.min(700, Math.min(canvasParent.clientWidth, canvasParent.clientHeight) * .9) canvas.style.width = canvas.style.height = sz + 'px' - canvas.width = W = sz * window.devicePixelRatio - canvas.height = H = sz * window.devicePixelRatio + canvas.width = W = Math.floor(sz * window.devicePixelRatio) + canvas.height = H = Math.floor(sz * window.devicePixelRatio) } window.onresize = resize resize() @@ -71,7 +71,7 @@ const genBuffer = () => { const compileShader = async (type, path) => { const shader = gl.createShader(type) - gl.shaderSource(shader, await (await fetch(path)).text()) + gl.shaderSource(shader, await (await fetch(path)).text() + '\n//' + Math.random()) gl.compileShader(shader) if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { throw 'compile shader error:\n' + gl.getShaderInfoLog(shader) @@ -81,9 +81,6 @@ const compileShader = async (type, path) => { const init = async () => { - transformFeedback = gl.createTransformFeedback() - gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, transformFeedback) - genBuffer() const vertexShader = await compileShader(gl.VERTEX_SHADER, './vertex.glsl') @@ -96,6 +93,8 @@ const init = async () => { if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { throw 'program link error:\n' + gl.getProgramInfoLog(program) } + gl.deleteShader(vertexShader) + gl.deleteShader(fragmentShader) timeHandle = gl.getUniformLocation(program, 'time') deltaTimeHandle = gl.getUniformLocation(program, 'deltaTime') @@ -165,6 +164,14 @@ const loop = () => { gl.vertexAttribPointer(3, 1, gl.FLOAT, false, 24, 20) gl.enableVertexAttribArray(3) gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, buffer[1 - bufferIndex]) + gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 24, 0) + gl.enableVertexAttribArray(0) + gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 24, 8) + gl.enableVertexAttribArray(1) + gl.vertexAttribPointer(2, 1, gl.FLOAT, false, 24, 16) + gl.enableVertexAttribArray(2) + gl.vertexAttribPointer(3, 1, gl.FLOAT, false, 24, 20) + gl.enableVertexAttribArray(3) gl.beginTransformFeedback(gl.POINTS) gl.drawArrays(gl.POINTS, 0, GUI.particlesCount) gl.endTransformFeedback() @@ -173,6 +180,7 @@ const loop = () => { bufferIndex = 1 - bufferIndex stats.end(); + requestAnimationFrame(loop) } diff --git a/vertex.glsl b/vertex.glsl index e172a43..60e2d1a 100644 --- a/vertex.glsl +++ b/vertex.glsl @@ -133,3 +133,5 @@ void main() { gl_Position = vec4((position / size * 2.0 - vec2(1.0)), 0.0, 1.0); alpha = sin(particleTime * 3.14) * (.3 + .7 * rand(vec2(gl_VertexID))); } + +// @dkaraush \ No newline at end of file