77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
#include "glclasses.hpp"
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
endofthejedi::VAO::VAO() { glGenVertexArrays(1, &m_name); }
|
|
|
|
endofthejedi::VAO::~VAO() { glDeleteVertexArrays(1, &m_name); }
|
|
|
|
void endofthejedi::VAO::bind() { glBindVertexArray(m_name); }
|
|
|
|
void endofthejedi::VAO::fill(GLuint index, GLint size, GLenum type,
|
|
GLboolean normalized, GLsizei stride,
|
|
const GLvoid *pointer) {
|
|
glEnableVertexAttribArray(index);
|
|
glVertexAttribPointer(index, size, GL_FLOAT, normalized, stride, pointer);
|
|
}
|
|
|
|
endofthejedi::Shader::Shader() { m_program = glCreateProgram(); }
|
|
|
|
endofthejedi::Shader::~Shader() {}
|
|
|
|
bool endofthejedi::Shader::check() {
|
|
GLint len = 0;
|
|
GLint result = 0;
|
|
|
|
glGetProgramiv(m_program, GL_LINK_STATUS, &result);
|
|
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &len);
|
|
if (len > 1) {
|
|
char *error = (char *)malloc(len);
|
|
glGetProgramInfoLog(m_program, len, NULL, error);
|
|
std::string str(error);
|
|
std::cout << str << "\n";
|
|
}
|
|
std::cout << "checked program"
|
|
<< "\n";
|
|
|
|
return (bool)result;
|
|
}
|
|
|
|
bool endofthejedi::Shader::checkShader(GLuint shader) {
|
|
GLint len = 0;
|
|
GLint result = 0;
|
|
|
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
|
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
|
|
if (len > 1) {
|
|
char *error = (char *)malloc(len+1);
|
|
glGetShaderInfoLog(shader, 0, &len, error);
|
|
std::string str(error, error + len);
|
|
std::cout << str << "\n";
|
|
}
|
|
std::cout << "checked shader"
|
|
<< "\n";
|
|
|
|
return (bool)result;
|
|
}
|
|
|
|
void endofthejedi::Shader::bind() { glUseProgram(m_program); }
|
|
|
|
void endofthejedi::Shader::unbind() { glUseProgram(0); }
|
|
|
|
void endofthejedi::Shader::load(std::string path, GLenum shadertype) {
|
|
GLuint cheddar = glCreateShader(shadertype);
|
|
const char *cheddardata = path.c_str();
|
|
glShaderSource(cheddar, 1, &cheddardata, NULL);
|
|
glCompileShader(cheddar);
|
|
checkShader(cheddar);
|
|
glAttachShader(m_program, cheddar);
|
|
glLinkProgram(m_program);
|
|
check();
|
|
glDeleteShader(cheddar);
|
|
}
|
|
|
|
GLuint endofthejedi::Shader::location(std::string name) {
|
|
return glGetUniformLocation(m_program, name.c_str());
|
|
}
|