I have a class Shader
, in it's constructor there are statements to compile shader, bind attributes and then link the shader program.
The problem is I'd want a child class to have different attributes, but that must happen before the linking. Virtual methods don't work here. What should I do?
Shader::Shader(const char* v, const char* f) {
program = glCreateProgram();
const char* vsrc = nullptr;
const char* fsrc = nullptr;
tls::readTextFile(std::ifstream(v, std::ios::binary), vsrc);
tls::readTextFile(std::ifstream(f, std::ios::binary), fsrc);
m_vertShader = compile(vsrc, GL_VERTEX_SHADER);
m_fragShader = compile(fsrc, GL_FRAGMENT_SHADER);
glAttachShader(program, m_vertShader);
glAttachShader(program, m_fragShader);
bindAttribs(); // it must happen before linking, in child class too.
glLinkProgram(program);
getUniforms();
setUniforms();
}
and child class:
void BasicShader::bindAttribs() {
bindAttribute(0, "pos");
bindAttribute(2, "vt");
} // this method is not called