Closed JacobMango closed 9 years ago
I have to constantly re create the program every glUseProgram.
How are you recreating the program? Post some code. I'm not sure what you mean.
I mean that I have to re call the load method every frame.
GLint Shader::load() {
GLuint program = glCreateProgram();
GLuint vertex = glCreateShader(GL_VERTEX_SHADER);
GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);
std::string vertSourceString = utils::FileUtils::read_file(m_VertPath);
std::string fragSourceString = utils::FileUtils::read_file(m_FragPath);
const char* vertSource = vertSourceString.c_str();
const char* fragSource = fragSourceString.c_str();
glShaderSource(vertex, 1, &vertSource, NULL);
glCompileShader(vertex);
GLint result;
glGetShaderiv(vertex, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE) {
GLint length;
glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length);
std::vector<char> error(length);
glGetShaderInfoLog(vertex, length, &length, &error[0]);
std::cout << "Failed to compile vertex shader!" << std::endl << &error[0] << std::endl;
glDeleteShader(vertex);
return 0;
}
glShaderSource(fragment, 1, &fragSource, NULL);
glCompileShader(fragment);
glGetShaderiv(fragment, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE){
GLint length;
glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length);
std::vector<char> error(length);
glGetShaderInfoLog(fragment, length, &length, &error[0]);
std::cout << "Failed to compile fragment shader!" << std::endl << &error[0] << std::endl;
glDeleteShader(fragment);
return 0;
}
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
glValidateProgram(program);
glDeleteShader(vertex);
glDeleteShader(fragment);
return program;
}
void Shader::start() {
if (glIsProgram(m_ShaderID) == GL_FALSE) {
load();
}
glUseProgram(m_ShaderID);
}
void Shader::stop() {
glUseProgram(0);
}
Yes, but why are you checking for loading in false? This isn't Sparky code. Please post your own code to http://thecherno.com/forums in the Sparky General section.
Refresh the page
I am checking that because it keeps deleting the program.
To re-enable the shader you would have to re create the shader again which I believe is bad and hurts CPU and GPU performance.
EDIT: I should mention I copied the code directly from here. "Stealing" as you stated.