OpenGL将着色器附加到程序 [英] OpenGL Getting Shader Attached to Program
问题描述
是否可以访问程序附带的着色器?也就是说,给定程序,我可以做类似的事情吗?
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.)
推荐答案
-
glGetAttachedShaders()
以获取名称附加到给定程序对象的着色器的数量.
glGetAttachedShaders()
to get the names of the shaders attached to the given program object.
glGetShaderiv( ..., GL_SHADER_TYPE, ... )
以获取类型着色器(顶点,几何形状,片段).
glGetShaderiv( ..., GL_SHADER_TYPE, ... )
to get the type (vertex, geometry, fragment) of shader.
glGetShaderiv( ..., GL_SHADER_SOURCE_LENGTH, ... )
找出来源有多久.
glGetShaderiv( ..., GL_SHADER_SOURCE_LENGTH, ... )
on each shader name to figure out how long the source is.
glGetShaderSource()
来获取源每个附加的着色器的字符串.
glGetShaderSource()
to get the source string for each attached shader.
编辑:如果您需要的只是着色器名称&您可以在步骤2之后停止的类型.
EDIT: If all you need are the shader names & types you can stop after step 2.
这篇关于OpenGL将着色器附加到程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!