Hello,
I’d like to propose an extension of the current API to allow querying of named fragment shader varying out variables of shader programs. As to my knowledge it is not possible yet to get the user defined names of the fragment shader outputs, this is how it could get used:
GLuint shaderProgram;
...
GLint fragmentVaryingOutCount;
glGetProgramiv( shaderProgram, GL_FRAGMENT_VARYING_OUT_ARB, &fragmentVaryingOutCount );
GLint longestFragmentVaryingOutName;
glGetProgramiv( shaderProgram, GL_FRAGMENT_VARYING_OUT_MAX_LENGTH_ARB, &longestFragmentVaryingOutName );
char *name = new char[longestFragmentVaryingOutName];
for (int i = 0; i < fragmentVaryingOutCount; ++i) {
GLenum type;
GLint size;
GLsizei length;
glGetFragmentVaryingOut( shaderProgram, i, longestFragmentVaryingOutName, &length, &size, &type, name );
GLint fragDataLocation = glGetFragDataLocation(shaderProgram, name);
printf("fragment shader has output named %s at location %d
", name, fragDataLocation );
}
The functionality is oriented at the uniform/attribute query functions. I’m aware that _ARB might not be the correct extension and the acual numeric values for the new tokens are just placeholders.
Is this plausible? Who would I have to address to get a chance of this functionality becoming a part of OpenGL (NVidia/AMD/Intel driver development team?)?
Name
ARB_query_fragment_varying_out
Dependencies
OpenGL 3.0 is required.
Overview
This extension allows the GL to query a list of names and types of fragment shader varying out variables. APIs already exist to query vertex shader inputs (attributes) as well as uniform specifications, fragment varying out variables however can not be queried.
New Procedures and Functions
void GetFragmentVaryingOut(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name);
New Tokens
Tokens accepted by GetProgramiv:
FRAGMENT_VARYING_OUT_ARB 0xABCD
FRAGMENT_VARYING_OUT_MAX_LENGTH_ARB 0xABCE
New State
None.
Additions to Chapter 3 of the OpenGL 3.0 Specification (Fragment Shaders)
In section 3.12 - Shader Outputs:
Add to the end of the section: "To determine the set of fragment shader varying out variables used by a program and to determine their sizes and types, use the command:
void GetFragmentVaryingOut(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name);
This command provides information about the varying out variable selected by index. An index of 0 selects the first fragment varying out variable, and an index of FRAGMENT_VARYING_OUT_ARB-1 selects the last fragment varying out variable. The value of FRAGMENT_VARYING_OUT_ARB can be queried with GetProgramiv. If index is greater than or equal to FRAGMENT_VARYING_OUT_ARB, the error INVALID_VALUE is generated. Note that index simply indentifies a member in a list of fragment varying out variables, and has no relation to the assigned fragment data location.
The parameter program is a name of a program object for which the command LinkProgram has been issued in the past. It is not necessary for program to have been linked successfully.
If an error occurred, the return parameters length, size, type and name will be unmodified.
For the selected fragment varying out variable, the user defined name is returned into name. The string name will be null terminated. The actual number of characters written into name, excluding the null terminator, is returned in length. If length is NULL, no length is returned. The maximum number of characters that may be written into name, including the null terminator, is specified by bufSize.
The length of the longest fragment varying out variable name in program is given by FRAGMENT_VARYING_OUT_MAX_LENGTH_ARB, which can be queried with GetProgramiv.
For the selected fragment varying out variable, the type is returned into type. The size of the fragment varying out variable is returned into size. The value in size is in units of the type returned in type. The type returned can be any of FLOAT, FLOAT_VEC2, FLOAT_VEC3, FLOAT_VEC4, INT, INT_VEC2, INT_VEC3, INT_VEC4.
Issues
(1) What name gets returned if the fragment varying out variable does not have a user defined name, but a build-in name?
There are two options: if the fragment varying out variable has no user defined name, the build-in name gets returned (e.g. ‘gl_FragData[0]’) or varying out variables without a user defined name will get ignored. In the later case FRAGMENT_VARYING_OUT_ARB will only return the number of user defined varying out variables.