Can glGetProgramiv get the number of shaders that are created by glCreateShaderProgramv?

If I’m using glCreateShaderProgramv and glUseProgramStages to create a program without glAttachShader, should glGetProgramiv get the correct number of attached shaders?

pseudo code:

GLint attached_shaders;

program0 = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &glsl_vs);
program1 = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &glsl_fs);

glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT, program0);
glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, program1);

glGetProgramiv(program, GL_ATTACHED_SHADERS, &attched_shaders);

Should attached_shaders be 2?

program isn’t a valid program object based on the code you’ve shown.

Even if that parameter were program0 or program1, the number of attached shaders would still be 0. glCreateShaderProgram is defined to unattach (and delete) any shader objects after compilation (assuming the implementation bothers to create such things, which they don’t have to). So at no point will you ever see any shader objects attached to those programs.

@Alfonse_Reinheart Thanks for your reply. It means there is no way to glGetAttachedShaders and further perform the operations like glGetShaderiv or glGetShaderSource if you call glCreateShaderProgramv to create program at the beginning. Doesn’t it?

… so what? glCreateShaderProgramv is for when you want to create a separable program, for a single shader stage, from a specific set of (NUL-terminated) text strings. If that’s the case, you don’t need to do any of those things.

What would you do with glGetShaderiv anyway? If there is a compile error rather than a link error, the program log will contain that error.

I just want to get the shader source code by glGetShaderSource. As you’ve explained. It’s impossible in this case. I’ve learned a lot and thank you.

Note that it’s also impossible for conventional (non-separable) program objects if the shaders have been explicitly detached with glDetachShader. Shaders only need to be attached for linking; they can be detached afterwards without affecting the validity of the program. Keeping them attached simplifies re-linking if you change e.g. attribute/uniform/etc locations, but that’s not particularly common. Usually they remain attached simply because there is no compelling reason to detach them (their memory consumption is usually trivial).

Also: the online glGetProgramiv doesn’t appear to have been updated in a while. It’s missing the parameters added in later versions, including GL_PROGRAM_SEPARABLE.