Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
Wait until WebGL has drawn onto screen

I switched from using 2D context to using WebGL context. I'm trying to figure out a way to wait until pixels have been drawn onto the screen.

With 2D context I would do something like this

const handlePaintFrame = () => {
  const ctx: CanvasRenderingContext2D | any = videoCanvasRef?.current?.getContext("2d");

  if (video.current && videoCanvasRef.current && ctx) {
    if (chroma?.keyColor) {
      drawChromaFrame(ctx, width, height);
    } else {
      ctx.drawImage(video.current, 0, 0, width, height);
    }

    const rendered = () => {
      setTimeout(() => {
        onReady("video");
      }, 20);
    };

    const startRender = () => {
      requestAnimationFrame(rendered);
    };

    const img = new Image();

    img.onload = () => {
      requestAnimationFrame(startRender);
    };

    img.onerror = (e: any) => {
      console.log("Image error:", { e });
    };

    img.src = videoCanvasRef.current.toDataURL();
  }
};

Currently my draw code for the WebGL context is something like this

const drawTexture = () => {
  // render
  if (gl && video.current) {
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, video.current);
    drawScene(locationRef.current, buffersRef.current);
  }
};

const handlePaintFrame = () => {
  if (video.current) {
    if (chroma?.keyColor) {
      // drawChromaFrame(ctx, width, height);
    } else {
      drawTexture();

      // TODO: We need to wait until texture is drawn
      setTimeout(() => {
        onReady("video");
      }, 100);
    }
  }
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!