Hacker News
points by socalgal2 3 days ago | 0 comments
Personally I wouldn't teach OpenGL ES 3.0 or any OpenGL because its state machine (https://webgl2fundamentals.org/webgl/lessons/resources/webgl...) and horrible error system means tracking down bugs is hard. Instead I'd teach WebGPU as it's portable and has great error messaging.

I'm sure people will objected but I'd argue WebGPU is easier to understand, has better errors, has no state machine, works C++, Rust, JS/TS and other languages, and closer to modern GPU programming if you want to move to Metal or D3D12 or Vulkan later.

Further, OpenGL (and ES) are a nightmare of bugs and incompatibilities students might run into that WebGPU fixes.

That said, the article mentions Apple platforms where you can use ANGLE if you happened to have students stuck there.

[–] flohofwoe 3 days ago
I mostly agree regarding GL's programming model, but tbf some problems have been fixed by WebGL2 (much better validation and error reporting - e.g. very helpful error messages right on the browser console - and it's probably the least buggy and most portable 3D API implementation of them all, including the current state of WebGPU.

For teaching I would generally use the web browser via WebGL2 or WebGPU, just because those APIs require much less boilerplate in the browser environment to get to your first triangle and the edit-test-loop is pretty much instant.

[–] whatthejesus 2 days ago
In real life there’s lots of bugs around and difficult to read error messages.

Re. the boilerplate just have students clone a pre-fabbed repo with the boilerplate handled for them.

The real question should be whether you want students to know how to program in a low programming language or not. Whether they should see what the reality of programming is or not.

If they can’t program in C/C++ and debug the error messages how are they going to survive in the wild? I guess they’ll use an LLM.

[–] flohofwoe 2 days ago
> If they can’t program in C/C++ and debug the error messages how are they going to survive in the wild?

The problem is that you don't get *any* error messages from native GL in the first place (unless you wire up a debug-message callback via the optional KHR_debug extension which isn't available everywhere), and the builtin error system via glGetError() is pretty much completely useless.

Other APIs don't suffer from this problem, D3D, Vulkan and Metal all have excellent validation layers which give very helpful messages, and WebGL or WebGPU running in browsers basically implement such a validation layer out of the box.

[–] Pannoniae 2 days ago
small nit, that's not true, since GL4.3 the modern debug message callback is core so you can rely on it. Sure that won't save you on MacOS but if you can target modern OpenGL this isn't a problem in practice
[–] lightedman 2 days ago
"unless you wire up a debug-message callback via the optional KHR_debug extension which isn't available everywhere"

The beauty of OpenGL versus say Direct3D is that OpenGL is extensible and thus you can add that feature should you so choose.

[–] flohofwoe 2 days ago
Fortunately "beauty lies in the eye of the beholder" ;) I definitely prefer the D3D model instead of the extension soup of GL or Vulkan.
[–] klodolph 2 days ago
The KHR_debug is also kind of a pain to use because it gets called asynchronously (which is what you want, yes, but the difficulty is still there).
[–] pjmlp 3 days ago
WebGPU will however always suffer from being an API designed for the Web, and targeting 2015 thereabouts hardware.

Better than OpenGL, but don't expect that much improvements coming into their way, other than what the Chrome team might feel like pushing, as I doubt Firefox or Safari teams have much left to say about where it goes beyond version 1.0.

[–] criddell 2 days ago
> but don't expect that much improvements

What improvements are needed? It sees pretty much complete to me and I think it's a good thing for it to be in maintenance mode (ie stable).

[–] flohofwoe 2 days ago
The rigid resource binding model via BindGroup objects in WebGPU is already outdated (and funny enough, an area where WebGPU is actually slower than WebGL2, at least when assuming that bindings need to change frequently and unpredictably).

This was a restriction of the Vulkan 1.0 API and modelling the WebGPU resource binding model around that was a quite predictable problem. It would have been better to come up with a slim abstraction that might cost some performance on Vulkan (which is only really relevant on Android phones and Linux desktops), but at least would not slow down WebGPU across all platforms.

And now even the Vulkan maintainers have realized the problem and are introducing the much more flexible descriptor-heap extension (about a decade late, but better late than never).

WebGPU is essentially the frozen cross-section of 3D APIs from about a decade ago, and the state of GPU hardware from about 15 to 20 years ago (but tbf, apart from the broken binding model there wasn't much that could be done, because most restrictions are coming from mobile GPUs which a browser 3D API simply must support).

[–] Pannoniae 2 days ago
1. monolithic pipelines, pretty much no hardware works like that, the hash-and-cache design makes your design inflexible and adds a ton of overhead

2. WGSL, like come on

3. Hilariously outdated feature set, no mesh shaders, no HWRT, cooperative matrices/tensors, etc.

4. It's security-focused because web untrusted code:tm: so most of the calls are hilariously slow. Yes even the desktop implementations. There's no good webGPU implementation out there

5. it's also not simple to either implement or use. it's basically vulkan's difficulty without any of the advantages....

[–] CamperBob2 2 days ago
I have never understood and will never understand why so many programming luminaries fell in love with OpenGL. It violates the most important engineering precept that I try to follow when I design a library: minimize hidden state. OpenGL is nothing but hidden state. You have no way to tell what a piece of code is going to render without seeing everything that set up the internal stack beforehand, perhaps thousands of lines away, or in entirely different modules that you might not even have access to.
[–] Someone 2 days ago
At least partly, it’s a form of choice-supportive bias (https://en.wikipedia.org/wiki/Choice-supportive_bias).

Your mind cannot live with the idea that you spent many, many hours learning an ugly API, so it makes you think it is better than it is.

[–] genxy 2 days ago
Sounds like C++ and OpenGL are BFFs.
[–] AnthonBerg 1 day ago
The quip is that C++ is fool's gold; Flying around in code and getting all the little mechanical details right really feels like getting things done. (It's just wizard- or mastery-flavored busywork. Glitter.)

I've later come to suspect that this glittering is sometimes useful as… fuel? Feeling-of-progress hands-on motivation-fuel.

[–] Cloudef 2 days ago
I disagree. Webgpu is completely useleless middleware that is already outdated, and it bugs me it killed compute shaders for WebGL proposal. In addition webgpu still does not work on browsers out of box.

Interacting with webgpu from wasm is also often slower than webgl because the api is lower level and causes more gc overhead on js side.