25 #include "glfShader.hh"
26 #include "glfException.hh"
58 id_ = glCreateShader(type);
61 GLF_THROW_ON_OPENGL_ERROR;
67 id_ = glCreateShader(type);
79 const char* sourceString = sourceCode.c_str();
80 glShaderSource(id_, 1, &sourceString, NULL);
84 GLint compilationSuccess;
85 glGetShaderiv(id_, GL_COMPILE_STATUS, &compilationSuccess);
87 if (compilationSuccess != GL_TRUE) {
88 GLF_THROW_EXCEPTION(
"Failed to compile shader: " <<
89 endl << GetInfoLog());
91 GLF_THROW_ON_OPENGL_ERROR;
96 ifstream ifs(fileName.c_str());
98 GLF_THROW_EXCEPTION(
"Failed to load shader source file: " << fileName);
105 source += line+
"\r\n";
108 return Create(type, source);
113 BIASASSERT(id_ != 0);
116 glGetShaderiv(id_, GL_INFO_LOG_LENGTH, &logLength);
117 char* infoLog =
new char[logLength];
118 glGetShaderInfoLog(id_, logLength, NULL, infoLog);
119 std::string out = infoLog;
122 GLF_THROW_ON_OPENGL_ERROR;
void CreateFromFile(GLenum type, const std::string &fileName)
Creates the shader from GLSL source code loaded from a file.
void Create(GLenum type)
Creates the shader without the GLSL source code, use other Create() methods to upload source afterwar...
GLuint GetShaderID() const
Returns the OpenGL id of the shader.
A GLSL vertex shader or fragment shader, which must be linked in a shader program.
std::string GetInfoLog() const
Returns the info log containing information about the compilation of the shader.