DEV Community

Adam Crockett 🌀
Adam Crockett 🌀

Posted on

Context2D Canvas question. But is it Webgl?

When canvas came out, you might or rather I might be forgiven for what I am about to say.

For the longest time I had believed that 2D context was somehow less powerful and slower than webgl and webgl2 contexts and perhaps even rendered on the CPU 😣, now that I write this I can see how silly this might sound. But I wonder if you can clear this up. Is context2d just webgl aka opengl but higher level and an API that is specific to JavaScript.

Next if context 2D is not transferable to other environments which utilize shaders, then the reasons to learn glsl are ....

And lastly, can you use webgl and webgl2 in JavaScript without ever writing a line of glsl?

Top comments (6)

Collapse
 
mateiadrielrafael profile image
Matei Adriel

Context2d is platform sependent, but from what I heard some modern brossers have gpu accelerated canvas, but it will never be anywhere close to actual webgl

You cak use webgl without glsl if you ise a library, but usually you need to write custom shaders if you want more unusual effects. I think there was also a package in the thi.ng/umbrella repo which compiled a subset of typescript to webgl or something, but don't quote me on thst one

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Interesting, I had thought about a DSL in ts, this might solve one problem at least. The main problem with glsl is absolutely 0 debugging for V.ES 3.0. there are some tools that I could attempt to port but that's a really big ask for one person. I also have enough projects on the go already. I should really get on with Jess Lang.

Collapse
 
mateiadrielrafael profile image
Matei Adriel

Yep, better debugging would be super nice to have, maybe just a sandbox which allows you to see all the variables at any step, or allowing printing to the console, but I'm guessing this would only be possible by compiling glsl itself to a spower js version

Collapse
 
gmartigny profile image
Guillaume Martigny

2D Context and WebGL are two separate things. WebGL (and GLSL) are way more powerful and allow to render 3D environments (QuakeII in the browser without plugin ? sure, why not.)
Working with GLSL can be a real hassle and I don't know any abstraction to avoid that. However, performance wise, shaders are incredibles.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

That's what I thought, so is 2d still GPU?

Collapse
 
gmartigny profile image
Guillaume Martigny

It must depend of the browser, but I'll say yes it is. Not sure tho