I got a semi-philosophical question about LWJGL and GLFW, related to fragment shaders.

Now, OpenGL bundles all of its computed color values with meta data together and we call it a
fragment (yes, oversimplified). Fragments are written in framebuffers so that we can e.g. display them.
Each framebuffer can have a completely different structure, aka different color- and z-buffer-depth, it can have stencil-bits, and the whatnot...
Let's assume the following fragment shader is in effect:
#version 440
//results of the previous vertex-shader
in vec2 textureCoord;
//we will sample a texture unit with a bound texture
uniform sampler2DArray textureSampler;
//will hold the final result of this shader
out vec4 fragColor;
//very simple shader code, load color from texture given the coordinates:
void main() { fragColor = texture(textureSampler, textureCoord); }
I recently got interested in why this actually works, since
fragColor is not a build-in variable. Rather, to quote
khronos.org:
> User-defined outputs from a fragment shader represent a series of "colors". These color values are directed into specific buffers based on the glDrawBuffers state.Now, my shader above and half the internet never explicitly link any output variable to a buffer, let alone a specific part of that buffer, OpenGL auto-assigns this in a nice
do-what-I-meant-to-do sort of way, despite
khronos.org claiming:
> The fragment color assigned is completely arbitrary and may be different for different programs that are linked, even if they use the exact same fragment shader code.Now, obviously this is a spec-writer's point of view and in practice, this works good for most standard use-cases, otherwise all these tutorials out there would never work. But what happens if we start modifying the structure of the buffer?
In our LWJGL-Program, that means providing new hints to GLFW, By default, we use something like:
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_DEPTH_BITS, 24);
glfwWindowHint(GLFW_STENCIL_BITS, 8);
Let's say I do not want any stencil usage but put the bytes to other good usage:
glfwWindowHint(GLFW_DEPTH_BITS, 32);
glfwWindowHint(GLFW_STENCIL_BITS, 0);
Still works, at least for all my test scenes. If I half my color precision like this...
glfwWindowHint(GLFW_RED_BITS, 4);
glfwWindowHint(GLFW_GREEN_BITS, 4);
glfwWindowHint(GLFW_BLUE_BITS, 4);
glfwWindowHint(GLFW_ALPHA_BITS, 4);
...it still works nicely. And I found that pretty surprising
QUESTIONS:- do my hints actually have an effect or is this nonsense?
- does everybody just trust on the driver/device to assign fragment-shader output results in standard usecases? (I find that somewhat dangerous at the moment, just a feeling...)
- what exactly is the best practice with LWJGL and GLFW to make such output-result assignments?