28 if (itsId) glDeleteShader(itsId);
38 if (itsId) { glDeleteShader(itsId); itsId = 0; }
41 FILE * f = fopen(filename,
"rb");
if (f ==
nullptr)
PLFATAL(
"Failed to read file " << filename);
42 fseek(f, 0, SEEK_END);
44 fseek(f, 0, SEEK_SET);
45 char * src =
new GLchar[sz+1];
46 if (fread(src, 1, sz, f) != 1) { fclose(f);
LFATAL(
"Failed to read " << filename); }
59 if (itsId) { glDeleteShader(itsId); itsId = 0; }
62 GL_CHECK(itsId = glCreateShader(type));
63 GL_CHECK(glShaderSource(itsId, 1, (
const GLchar**)&str, 0));
67 GLint compiled; glGetShaderiv(itsId, GL_COMPILE_STATUS, &compiled);
70 GLint loglen = 4096;
char log[loglen];
71 glGetShaderInfoLog(itsId, loglen, &loglen, &log[0]); log[loglen] =
'\0';
72 glDeleteShader(itsId);
73 LFATAL(
"Failed to compile shader [" << name <<
"], Log: " << &log[0]);
76 LDEBUG(
"Compiled shader [" << name <<
']');
#define GL_CHECK(stmt)
Simple macro to check for OpenGL errors.
void load(char const *filename, GLuint type)
Load a shader from file.
void set(char const *name, char const *str, GLuint type)
Load a shader from inlined code in a C-string.
GLuint id() const
Get the shader's ID.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level.
std::string warnAndIgnoreException(std::string const &prefix="")
Convenience function to catch an exception, issue some LERROR (depending on type),...
#define PLFATAL(msg)
Like LDEBUG but appends errno and strerror(errno), to be used when some system call fails.