opengl - Why comment glBindFragDataLocation, the GL also works correctly? -


const glchar* vertexsource1 = "#version 330 core\n"     "layout (location = 0) in vec2 position;\n"     "layout (location = 1) in vec3 color;\n"     "out vec3 color;\n"     "void main()\n"     "{\n"     "gl_position = vec4(position, 0.0, 1.0);\n"     "color = color;\n"     "}\0"; const glchar* fragmentsource1 = "#version 330 core\n" "    in vec3 color;\n" "    out vec4 outcolor;\n" "    void main()\n" "    {\n" "        outcolor = vec4(color, 1.0);\n" "    }\n";   gluint shaderprogram1 = glcreateprogram(); glattachshader(shaderprogram1, vertexshader1); glattachshader(shaderprogram1, fragmentshader1); //    glbindfragdatalocation(shaderprogram1, 0, "color"); gllinkprogram(shaderprogram1); 

whether add glbindfragdatalocation or not, gl works correctly, why?

because you're "lucky". opengl specification provides no guarantees how fragment shader output locations assigned if don't assign them. says each 1 have separate location; locations implementation.

however, considering sheer volume of code writes single output variable without explicitly assigning location, it's highly unlikely opengl implementation ever assign first fs output location other 0. while isn't spec guarantee, @ point, de-facto requirement of implementations.

note: doesn't mean shouldn't assign location manually. it's best on safe , explicit side.

fyi: layout(location) works fragment shader outputs too. should use if you're using on vertex attributes. don't have worry doing code.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -