OpenGL Getting Shader Attached to Program

社会主义新天地 提交于 2019-12-06 02:33:56

问题


Is there a way to access the shaders attached to a program? That is, given a program, can I do something like:

vertexShader = getVertexShaderFromProgram(program);

(I would like to log shader compilation status within my function that validates my program, but I only keep a reference to the program, not the shaders.)


回答1:


  1. glGetAttachedShaders() to get the names of the shaders attached to the given program object.

  2. glGetShaderiv( ..., GL_SHADER_TYPE, ... ) to get the type (vertex, geometry, fragment) of shader.

  3. glGetShaderiv( ..., GL_SHADER_SOURCE_LENGTH, ... ) on each shader name to figure out how long the source is.

  4. glGetShaderSource() to get the source string for each attached shader.

EDIT: If all you need are the shader names & types you can stop after step 2.



来源:https://stackoverflow.com/questions/15537415/opengl-getting-shader-attached-to-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!