65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
#ifndef SHADER_H
|
|
#define SHADER_H
|
|
|
|
#include <GL/glew.h>
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#define GLCALL(func) func
|
|
|
|
class Shader {
|
|
public:
|
|
Shader() : program(0) {}
|
|
Shader(const GLuint id) : program(id) {}
|
|
Shader(const char* vertexPath, const char* fragmentPath);
|
|
~Shader() { glDeleteProgram(program); }
|
|
|
|
void bind();
|
|
void unbind();
|
|
void setuniform(const GLchar* uName, unsigned int value);
|
|
void setuniform(const GLchar* uName, int value);
|
|
void setuniform(const GLchar* uName, GLfloat value);
|
|
void setuniform(const GLchar* uName, GLfloat x, GLfloat y);
|
|
void setuniform(const GLchar* uName, glm::vec2 vector);
|
|
void setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z);
|
|
void setuniform(const GLchar* uName, glm::vec3 vector);
|
|
void setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
|
void setuniform(const GLchar* uName, glm::vec4 vector);
|
|
void setuniform(const GLchar* uName, const glm::mat4& mtx);
|
|
void setuniform(const GLchar* uName, GLuint tex2d, GLint unit); // sample 2d
|
|
|
|
GLuint getuniform(const char* name);
|
|
GLuint GetProgram() { return program; }
|
|
|
|
private:
|
|
|
|
void checkCompileErrors(GLuint shader, std::string type)
|
|
{
|
|
GLint success;
|
|
GLchar infoLog[1024];
|
|
if(type != "PROGRAM")
|
|
{
|
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
|
if(!success)
|
|
{
|
|
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
|
|
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
glGetProgramiv(shader, GL_LINK_STATUS, &success);
|
|
if(!success)
|
|
{
|
|
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
|
|
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
GLuint program;
|
|
};
|
|
|
|
#endif |