I am following a "Learn OpenGL" book, and it is said that after linking individual shaders and compiling a shader program, we do not need the individual shaders anymore. Although it may be not entirely true in the more complex world of computer graphics, assume it is.
Now, when building the Shader
and ShaderProgram
classes, I want to implement this "destruct after not needed" behaviour, that is after ShaderProgram
constructor finishes its job, vertex and fragment shader objects destructor should be called.
I can easily achieve such by using std::unique_ptr<Shader>
and moving it into the ShaderProgram
constructor.
I am just curious if there is a way to do it without using std::unique_ptr
.
This is the example code I currently have:
class Shader {
public:
Shader(){\\creating a shader}
~Shader(){glDeleteShader(id);}
/* some methods */
private:
unsigned int id;
};
class ShaderProgram {
public:
ShaderProgram(std::unique_ptr<Shader> vertex, std::unique_ptr<Shader> fragment){\\create a shader}
~ShaderProgram(){glDeleteProgram(id);}
/*some methods*/
private:
unsigned int id;
};