I’ve been welcomed with quite a lot of ignorance on the subject of “questioning the API” on the OpenGL IRC channels
If by “ignorance,” you mean “hostility,” it’s probably because many OpenGL users are simply tired of people questioning the API. The API is what it is. People can either accept it or reject it, but it’s not going to magically conform to your expectations. Nor are arguments on a forum likely to cause it to change.
So many people would prefer people not waste time debating pointless questions and focus on actually productive issues of using the API rather than questioning it.
Or How I Stopped Worrying and Learned to Love the OpenGL API.
What’s the rationale behind specifying UB layouts in the GLSL, rather than in the GL by something like a fictional
I could easily ask the opposite: why would you ever want that?
nor does the shader, which should remain as “pluggable” as possible
Oh, that’s why. Yeah, that’s not practical. In general, most people who use shaders know where they came from. They know what they contain, and they have very specific expectations about the interface of that shader.
Even your suggested code has expectations. That blockindex
had to come from somewhere. So you probably would get a block index by querying some block name. That means your code expects there to be a uniform block with that name in the program.
Shaders are written against certain expectations of the code that runs them, not the other way around. That’s why we have explicit attribute and fragment data locations. That’s why we have in-shader uniform block index and bindings for opaque types. That’s why we can specify uniform locations from shaders now.
This is how most people want to use shaders nowadays. The idea is not that you download someone’s random shader and have your code use introspection to figure out how to interface with it. The idea is that your shader is written against specific in-code requirements.
Now, GLSL does provide all of the information you need to be able to write code that can conform (to some degree) to arbitrary shaders. But each of those features I mentioned above was explicitly requested by important OpenGL users. Most of them are features that D3D has had since day 1, and GLSL has been missing for near on 10 years. Features people like.
In short, OpenGL does it this way because the majority of OpenGL users want it that way.