KhronosGroup / OpenGL-API

OpenGL and OpenGL ES API Issue Tracker
34 stars 5 forks source link

What is the shader source string after calling glShaderSource with count=0 #80

Open ianromanick opened 3 years ago

ianromanick commented 3 years ago

What should be in buf when the code below is executed? The second call to glShaderSource should not generate an error, so it should presumably replace the existing shader source with... nothing?

    const GLchar *source = "/* Testing 1... 2... 3... */";
    const GLchar *junk = "/* Just some junk. */";

    glShaderSource(shader, 1, &source, NULL);

    glShaderSource(shader, 0, &junk, NULL);

    GLchar buf[512];
    GLsizei length;

    glGetShaderSource(shader, sizeof(buf), &length, buf);

See also https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/521 and https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10477.

tarceri commented 3 years ago

Just while we are discussing glShaderSource() we also have ES tests e.g. [1] that test to make sure a GL_INVALID_VALUE error is returned if the source string is NULL. But neither the ES or desktop GL specs say that this is an error.

We should update the specs to include this error.

[1] dEQP-GLES2.functional.negative_api.shader.shader_source

ianromanick commented 3 years ago

Just while we are discussing glShaderSource() we also have ES tests e.g. [1] that test to make sure a GL_INVALID_VALUE error is returned if the source string is NULL. But neither the ES or desktop GL specs say that this is an error.

I thought this was one of the generic error conditions described in section 2.3.1 (Errors), but I don't see that language there. Many commands specifically call out the NULL pointer behavior (e.g. glTexImage3D), so perhaps this condition should be added to section 2.3.1?

pdaniell-nv commented 3 years ago

There is a generic error for count being less than 0, which returns GL_INVALID_VALUE, but I don't think there is anything that requires count to be greater than 0. For NVIDIA the call to glShaderSource(shader, 0, ) doesn't return an error and replaces the shader source for that object with an empty string so glGetShaderSource() sets buf[0]=0.

Note that I think the original question is about the "count" parameter to glShaderSource being zero, and not about the "string" parameter being NULL.