Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Getting Shader Attached to Program

Tags:

opengl

glsl

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.)

like image 248
Little Endian Avatar asked Mar 21 '13 00:03

Little Endian


1 Answers

  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.

like image 194
genpfault Avatar answered Sep 23 '22 16:09

genpfault