Working version, no shadows
This commit is contained in:
+60
-17
@@ -3,32 +3,32 @@
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
void check_compile_error(GLuint shaderId) {
|
||||
void check_compile_error(GLuint shader_id) {
|
||||
GLint isCompiled = 0;
|
||||
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (isCompiled == GL_FALSE) {
|
||||
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (!isCompiled) {
|
||||
GLint maxLength = 0;
|
||||
glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
//The maxLength includes the NULL character
|
||||
char errorLog[maxLength];
|
||||
glGetShaderInfoLog(shaderId, maxLength, &maxLength, &errorLog[0]);
|
||||
glGetShaderInfoLog(shader_id, maxLength, &maxLength, &errorLog[0]);
|
||||
|
||||
LOG(ERROR) << "Shader compile error: " << "(id: " << shaderId << ", code: " << isCompiled << ", bytes: "
|
||||
LOG(ERROR) << "Shader compile error: " << "(id: " << shader_id << ", code: " << isCompiled << ", bytes: "
|
||||
<< maxLength << ") - " << std::string(errorLog, maxLength);
|
||||
|
||||
//Provide the infolog in whatever manor you deem best.
|
||||
//Exit with failure.
|
||||
glDeleteShader(shaderId); //Don't leak the shader.
|
||||
glDeleteShader(shader_id); //Don't leak the shader.
|
||||
} else {
|
||||
LOG(INFO) << "Shader successfully compiled";
|
||||
LOG(INFO) << "Shader " << shader_id << " successfully compiled";
|
||||
}
|
||||
}
|
||||
|
||||
void check_link_error(GLuint program_id) {
|
||||
GLint is_linked = 0;
|
||||
glGetShaderiv(program_id, GL_LINK_STATUS, &is_linked);
|
||||
if (is_linked == GL_FALSE) {
|
||||
if (!is_linked) {
|
||||
GLint maxLength = 0;
|
||||
glGetShaderiv(program_id, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
@@ -43,35 +43,78 @@ void check_link_error(GLuint program_id) {
|
||||
//Exit with failure.
|
||||
glDeleteShader(program_id); //Don't leak the program shader.
|
||||
} else {
|
||||
LOG(INFO) << "Shader program successfully linked";
|
||||
LOG(INFO) << "Shader program " << program_id << " successfully linked";
|
||||
}
|
||||
}
|
||||
|
||||
shader::shader(const char *vs_content, const char *ps_content)
|
||||
: shader_ids{0, 0},
|
||||
program_id{0} {
|
||||
|
||||
|
||||
shader::shader(const char *vs_content, const char *ps_content) {
|
||||
shader_ids[0] = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(shader_ids[0], 1, &vs_content, nullptr);
|
||||
glShaderSource(shader_ids[0], 1, &vs_content, NULL);
|
||||
glCompileShader(shader_ids[0]);
|
||||
check_compile_error(shader_ids[0]);
|
||||
int success;
|
||||
char infoLog[512];
|
||||
glGetShaderiv(shader_ids[0], GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(shader_ids[0], 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
|
||||
shader_ids[1] = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(shader_ids[1], 1, &ps_content, nullptr);
|
||||
glShaderSource(shader_ids[1], 1, &ps_content, NULL);
|
||||
glCompileShader(shader_ids[1]);
|
||||
check_compile_error(shader_ids[1]);
|
||||
glGetShaderiv(shader_ids[1], GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(shader_ids[1], 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
|
||||
program_id = glCreateProgram();
|
||||
glAttachShader(program_id, shader_ids[0]);
|
||||
glAttachShader(program_id, shader_ids[1]);
|
||||
|
||||
// TODO Adrian: these should come from an external enumeration
|
||||
glBindAttribLocation(program_id, 0, "position");
|
||||
glBindAttribLocation(program_id, 1, "normal");
|
||||
glBindAttribLocation(program_id, 2, "texCoords");
|
||||
|
||||
glLinkProgram(program_id);
|
||||
check_link_error(program_id);
|
||||
|
||||
glGetProgramiv(program_id, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(program_id, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::PROGRAM::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
|
||||
glUseProgram(program_id);
|
||||
// glDeleteShader(shader_ids[0]);
|
||||
// glDeleteShader(shader_ids[1]);
|
||||
|
||||
// shader_ids[0] = glCreateShader(GL_VERTEX_SHADER);
|
||||
// glShaderSource(shader_ids[0], 1, &vs_content, nullptr);
|
||||
// glCompileShader(shader_ids[0]);
|
||||
// check_compile_error(shader_ids[0]);
|
||||
//
|
||||
// shader_ids[1] = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
// glShaderSource(shader_ids[1], 1, &ps_content, nullptr);
|
||||
// glCompileShader(shader_ids[1]);
|
||||
// check_compile_error(shader_ids[1]);
|
||||
//
|
||||
// program_id = glCreateProgram();
|
||||
// glAttachShader(program_id, shader_ids[0]);
|
||||
// glAttachShader(program_id, shader_ids[1]);
|
||||
|
||||
// TODO Adrian: these should come from an external enumeration
|
||||
// glBindAttribLocation(program_id, 0, "position");
|
||||
// glBindAttribLocation(program_id, 1, "normal");
|
||||
// glBindAttribLocation(program_id, 2, "texCoords");
|
||||
|
||||
// glLinkProgram(program_id);
|
||||
// check_link_error(program_id);
|
||||
|
||||
// glUseProgram(program_id);
|
||||
}
|
||||
|
||||
shader::~shader() {
|
||||
|
||||
Reference in New Issue
Block a user