question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canvas2D renderer faster than WebGL for sprites?

See original GitHub issue

Expected Behavior

WebGL rendering would be faster than Canvas2D

Current Behavior

Canvas2D appears faster than WebGL rendering.

I’m noticing ~21FPS on WebGL and ~32FPS on Canvas2D My friend is noticing ~22FPS on WebGL and ~45FPS on Canvas2D

Steps to Reproduce

  1. Visit the following demo: https://codepen.io/mudcube/pen/RwVNvLb
  2. See benchmark FPS on top left of screen.
  3. Toggle forceCanvas to true (at top of demo), and repeat step two.

Environment

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
mudcubecommented, Jul 2, 2021

I created a new test with smaller elements, and 10,000 sprites, and WebGL definitely had the advantage!

Closing this issue, as it sounds like this is a non-issue, due to my graphics card, and Sprite being a feature which has similar parity between implementations. Thanks again for all the great comments / suggestions 😃

0reactions
GoodBoyDigitalcommented, Jul 1, 2021

I believe this is a fill rate issue. Canvas and WebGL are likely going to behave roughly the same as nothing too complex is happening for either to really shine.

The objects are just massive 😃 so there is loads of pixels being written - which is a GPU bottleneck. In then end the Canvas + WebGL hitting the same GPU issue here and so both slowing down in roughly the same way

I bet if you make those elements smaller - you will start to see differences in perf.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Canvas 2d context or WebGL for 2D game - Stack Overflow
The short answer is yes. WebGL can be quite a bit more efficient if you use it well. A naive implementation will either...
Read more >
Is WebGL fast than Canvas API for drawing a bunch of 2D ...
My understanding is that WebGL performs better for 3D rendering because it used GPU to do matrix multiplication, which is fast than CPU....
Read more >
Which has better performance between Canvas and WebGL?
I thought WebGL is faster, but Canvas is faster (higher frame rate) on my development environment, even there is more draw call than...
Read more >
Game works better in Canvas than in WebGL - Phaser 2
Hi, I've recently created a game (http://deeeep.io) and while I was finishing it, I realized that the FPS were lower than they should....
Read more >
Canvas 2D vs. WebGL vs. C++ | Hacker News
Everything better go just right, or it's going to end up remotely exploitable. The same could be said for practically any program or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found