片段着色器输出数量

4

OpenGL提供API以获取片段着色器输出的数量吗?

我找到了一些函数,如glBindFragDataLocationglBindFragDataLocationIndexedglGetFragDataIndexglGetFragDataLocation,但它们都是用于设置已知名称的FragData的索引或位置。

我认为我正在寻找类似于glGetProgram(handle, GL_NUM_FRAGDATA, &i)的东西。有什么想法吗?

有一个非常类似的API可用于获取Uniforms和Attributes的数量:

  • glGetProgramiv(handle, GL_ACTIVE_UNIFORMS, &numUniforms)
  • glGetProgramiv(handle, GL_ACTIVE_ATTRIBUTES, &numAttribs)

谢谢提前。

1个回答

4

你要找的是关于程序接口的API部分:

int num_frag_outputs;           //Where GL will write the number of outputs
glGetProgramInterfaceiv(program_handle, GL_PROGRAM_OUTPUT,
    GL_ACTIVE_RESOURCES, &num_frag_outputs);

//Now you can query for the names and indices of the outputs

for (int i = 0; i < num_frag_outs; i++)
{
    int identifier_length;
    char identifier[128];            //Where GL will write the variable name
    glGetProgramResourceName(program_handle, GL_PROGRAM_OUTPUT,
        i, 128, &identifier_length, identifier);

    if (identifier_length > 128) {
      //If this happens then the variable name had more than 128 characters
      //You will need to query again with an array of size identifier_length 
    }
    unsigned int output_index = glGetProgramResourceIndex(program_handle,
    GL_PROGRAM_OUTPUT, identifier);

    //Use output_index to bind data to the parameter called identifier
}

您可以使用GL_PROGRAM_OUTPUT来指定您希望从最终着色器阶段获得输出。使用其他值,您可以查询其他程序接口以查找其他阶段的着色器输出。有关更多信息,请参见OpenGL 4.5规范的第7.3.1节。

谢谢。这正是我正在寻找的。 - t91

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接