refactor: format code

This commit is contained in:
2021-09-19 17:33:16 +02:00
parent 52a143769e
commit 0856ca47ca
71 changed files with 1102 additions and 1110 deletions

View File

@@ -15,58 +15,58 @@
using namespace gl;
ShaderProgram::ShaderProgram():
programID(0), vertexShaderID(0), fragmentShaderID(0){
ShaderProgram::ShaderProgram() :
programID(0), vertexShaderID(0), fragmentShaderID(0) {
}
ShaderProgram::~ShaderProgram(){
ShaderProgram::~ShaderProgram() {
cleanUp();
}
void ShaderProgram::start() const{
void ShaderProgram::start() const {
glUseProgram(programID);
}
void ShaderProgram::stop() const{
void ShaderProgram::stop() const {
glUseProgram(0);
}
int ShaderProgram::getUniformLocation(const std::string& uniformName) const{
int ShaderProgram::getUniformLocation(const std::string& uniformName) const {
const int location = glGetUniformLocation(programID, uniformName.c_str());
if (location == -1){
if (location == -1) {
std::cout << "Warning ! Uniform variable " << uniformName << " not found !\n";
}
return location;
}
void ShaderProgram::loadFloat(const int location, const float value) const{
void ShaderProgram::loadFloat(const int location, const float value) const {
glUniform1f(location, value);
}
void ShaderProgram::loadInt(const int& location, const int& value) const{
void ShaderProgram::loadInt(const int& location, const int& value) const {
glUniform1i(location, value);
}
void ShaderProgram::loadVector(const int& location,
const glm::vec2& vector) const{
const glm::vec2& vector) const {
glUniform2f(location, vector.x, vector.y);
}
void ShaderProgram::loadVector(const int& location,
const glm::vec3& vector) const{
const glm::vec3& vector) const {
glUniform3f(location, vector.x, vector.y, vector.z);
}
void ShaderProgram::loadVector(const int& location,
const glm::vec4& vector) const{
const glm::vec4& vector) const {
glUniform4f(location, vector.x, vector.y, vector.z, vector.w);
}
void ShaderProgram::loadBoolean(const int& location, const bool& value) const{
void ShaderProgram::loadBoolean(const int& location, const bool& value) const {
glUniform1i(location, value);
}
void ShaderProgram::cleanUp() const{
void ShaderProgram::cleanUp() const {
stop();
glDetachShader(programID, vertexShaderID);
glDetachShader(programID, fragmentShaderID);
@@ -76,7 +76,7 @@ void ShaderProgram::cleanUp() const{
}
void ShaderProgram::loadProgramFile(const std::string& vertexFile,
const std::string& fragmentFile){
const std::string& fragmentFile) {
vertexShaderID = loadShaderFromFile(vertexFile, GL_VERTEX_SHADER);
fragmentShaderID = loadShaderFromFile(fragmentFile, GL_FRAGMENT_SHADER);
programID = glCreateProgram();
@@ -88,7 +88,7 @@ void ShaderProgram::loadProgramFile(const std::string& vertexFile,
}
void ShaderProgram::loadProgram(const std::string& vertexSource,
const std::string& fragmentSource){
const std::string& fragmentSource) {
vertexShaderID = loadShader(vertexSource, GL_VERTEX_SHADER);
fragmentShaderID = loadShader(fragmentSource, GL_FRAGMENT_SHADER);
programID = glCreateProgram();
@@ -99,7 +99,7 @@ void ShaderProgram::loadProgram(const std::string& vertexSource,
getAllUniformLocation();
}
int ShaderProgram::loadShader(const std::string& source, GLenum type){
int ShaderProgram::loadShader(const std::string& source, GLenum type) {
unsigned int shaderID = glCreateShader(type);
const char* c_str = source.c_str();
@@ -108,7 +108,7 @@ int ShaderProgram::loadShader(const std::string& source, GLenum type){
glCompileShader(shaderID);
GLint compilesuccessful;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compilesuccessful);
if (compilesuccessful == false){
if (compilesuccessful == false) {
std::cout << "Could not compile shader !\n";
GLsizei size;
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &size);
@@ -119,12 +119,12 @@ int ShaderProgram::loadShader(const std::string& source, GLenum type){
return shaderID;
}
int ShaderProgram::loadShaderFromFile(const std::string& file, GLenum type){
int ShaderProgram::loadShaderFromFile(const std::string& file, GLenum type) {
std::string shaderSource = "";
std::ifstream fileStream(file);
if (fileStream.is_open()){
if (fileStream.is_open()) {
std::string line;
while (getline(fileStream, line)){
while (getline(fileStream, line)) {
shaderSource += line + "\n";
}
fileStream.close();
@@ -137,7 +137,7 @@ int ShaderProgram::loadShaderFromFile(const std::string& file, GLenum type){
glCompileShader(shaderID);
GLint compilesuccessful;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compilesuccessful);
if (compilesuccessful == false){
if (compilesuccessful == false) {
std::cout << "Could not compile shader !\n";
GLsizei size;
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &size);
@@ -148,6 +148,6 @@ int ShaderProgram::loadShaderFromFile(const std::string& file, GLenum type){
return shaderID;
}
void ShaderProgram::loadMatrix(const int& location, const glm::mat4& matrix){
void ShaderProgram::loadMatrix(const int& location, const glm::mat4& matrix) {
glUniformMatrix4fv(location, 1, false, glm::value_ptr(matrix));
}