I have a function createShader inside a Shader class that takes the filepaths of two vertex and fragment shaders as arguments, loads and compiles them, and uses glCreateProgram to create a shader program out of them. The latter part looks like this:
char const * vsSourcePtr = vsCode.c_str();
glShaderSource(vsId, 1, &vsSourcePtr, NULL);
glCompileShader(vsId);
char const * fsSourcePtr = fsCode.c_str();
glShaderSource(fsId, 1, &fsSourcePtr, NULL);
glCompileShader(fsId);
this->progId = glCreateProgram();
glAttachShader(this->progId, vsId);
glAttachShader(this->progId, fsId);
glBindAttribLocation(this->progId, 0, "in_Position");
glLinkProgram(this->progId);
glDeleteShader(vsId);
glDeleteShader(fsId);
}
The Shader class also has a method for deleting the generated shaders when the program is closed:
void Shader::deleteShader(){
glUseProgram(0);
glDeleteProgram(this->progId);
}
My question is, is it correct to put the two glDeleteShader calls where they are? Can I delete the vertex and fragment shaders once I’ve already linked the shader program?
If so, what about glDetachShader? Does that need to go in my deleteShader function?
This seems to work without errors, but there may be a memory leak somewhere in the program, and I’m wondering if this is it.