RenderingPipeline

from geometry to pixels

glGetActiveFragmentOut

glGetActiveFragmentOut can be a useful OpenGL call, similar to glGetActiveAttrib and glGetActiveUniform it can query the names of the fragment shader outputs from a shader program. It’s useful for rapid prototyping or shader IDE where the program has to check user-generated (or not well-tested) shaders whether they match the provided geometry data and attributes (glGetActiveAttrib), uniforms and uniform buffer objects (glGetActiveUniform) or fragment outputs (glGetActiveFragmentOut). It just has one disadvantage – this call does not exist. There also does not exist an alternative way of getting the same information.

While the shader compiler can check which attributes and uniforms are read by the program, all fragment outputs that are not written are defined as undefined, so you can argue that the ‘active’ in the name might not be useful (or on the other hand only outputs that are written to should get listed but the others are undefined never the less). The specs are also talking of fragment varyings so glGetFragmentVaryingOut could also be a possible name.

But naming aside, I’d imagine this API to work like the attribute/uniform equivalents:

GLuint shaderProgram;
...
GLint fragmentOutCount;
glGetProgramiv( shaderProgram, GL_ACTIVE_FRAGMENT_OUT, &fragmentOutCount );
GLint longestFragmentOutName;
glGetProgramiv( shaderProgram, GL_ACTIVE_FRAGMENT_OUT_MAX_LENGTH, &longestFragmentOutName );
char *name = new char[longestFragmentOutName];
 
for (int i = 0; i < fragmentOutCount; ++i) {
	GLenum  type;
	GLint   size;
	GLsizei length;
	glGetActiveFragmentOut( shaderProgram, i, longestFragmentOutName, &length, &size, &type, name );
	GLint fragDataLocation = glGetFragDataLocation(shaderProgram, name);
	printf("fragment shader has output named %s at location %d\n", name, fragDataLocation );
}

At the OpenGL forums you can read a discussion about this and I hope some people involved in the ARB will pick up this discussion and consider filling this hole in the specs as all it needs is one new call and two new tokens. Also, the GLSL compiler probably already has all the information needed…

 

,

3 thoughts on “glGetActiveFragmentOut

Leave a Reply

Your email address will not be published. Required fields are marked *

*