feat: run clang-tidy fix on repo

This commit is contained in:
Krzysztof Rudnicki 2023-07-06 17:35:25 +02:00
parent 140fbbc4a1
commit a88c7a2cab
12 changed files with 276 additions and 325 deletions

View File

@ -1,38 +1,12 @@
---
Checks: '*'
Checks: '*,-llvmlibc-implementation-in-namespace'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: kuchy
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.LineThreshold
value: '16'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

View File

@ -17,6 +17,7 @@
"ms-vscode.cpptools-themes",
"twxs.cmake",
"ms-vscode.cmake-tools",
"mine.cpplint"
"mine.cpplint",
"ms-vscode.cpptools"
]
}

View File

@ -1,121 +1,120 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_CPP
#define BREAKOUT_CPP
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_BREAKOUT_CPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_BREAKOUT_CPP
#include <GLFW/glfw3.h>
#include <iostream>
#include "../dependencies/include/glad/glad.h"
#include "./game.hpp"
#include "./resourceManager.hpp"
// GLFW function declarations
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void key_callback(GLFWwindow* window, int key,
int scancode, int action, int mode);
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void key_callback(GLFWwindow *window, int key, int scancode, int action,
int mode);
// The Width of the screen
const unsigned int SCREEN_WIDTH = 800;
constexpr int SCREEN_WIDTH = 800;
// The height of the screen
const unsigned int SCREEN_HEIGHT = 600;
constexpr int SCREEN_HEIGHT = 600;
Game Breakout(SCREEN_WIDTH, SCREEN_HEIGHT);
Game &getBreakoutInstance() {
static Game Breakout(SCREEN_WIDTH, SCREEN_HEIGHT);
return Breakout;
}
int main(int argc, char *argv[]) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
int main(int /*argc*/, char * /*argv*/[]) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
glfwWindowHint(GLFW_RESIZABLE, false);
glfwWindowHint(GLFW_RESIZABLE, 0);
GLFWwindow* window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT,
"Breakout", nullptr, nullptr);
glfwMakeContextCurrent(window);
GLFWwindow *window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Breakout",
nullptr, nullptr);
glfwMakeContextCurrent(window);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// glad: load all OpenGL function pointers
// ---------------------------------------
if (gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)) ==
0) {
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
glfwSetKeyCallback(window, key_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetKeyCallback(window, bugprone-easily-swappable-parameters
// --------------------
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// OpenGL configuration
// initialize game
// ---------------
Breakout.Init();
// deltaTime variables
// -------------------
float deltaTime = 0.0F;
float lastFrame = 0.0F;
while (glfwWindowShouldClose(window) == 0) {
// calculate delta time
// --------------------
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float const currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents();
// initialize game
// ---------------
Breakout.Init();
// manage user input
// -----------------
Breakout.ProcessInput(deltaTime);
// deltaTime variables
// -------------------
float deltaTime = 0.0f;
float lastFrame = 0.0f;
// update game state
// -----------------
Breakout.Update(deltaTime);
while (!glfwWindowShouldClose(window)) {
// calculate delta time
// --------------------
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents();
// render
// ------
glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
glClear(GL_COLOR_BUFFER_BIT);
Breakout.Render();
// manage user input
// -----------------
Breakout.ProcessInput(deltaTime);
glfwSwapBuffers(window);
}
// update game state
// -----------------
Breakout.Update(deltaTime);
// delete all resources as loaded using the resource manager
// ---------------------------------------------------------
ResourceManager::Clear();
// render
// ------
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
Breakout.Render();
glfwTerminate();
return 0;
}
glfwSwapBuffers(window);
void key_callback(GLFWwindow *window, int key, int /*scancode*/, int action,
int /*mode*/) {
// when a user presses the escape key, we set the
// WindowShouldClose property to true, closing the application
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, 1);
}
if (key >= 0 && key < 1024) {
if (action == GLFW_PRESS) {
Breakout.Keys[key] = true;
} else if (action == GLFW_RELEASE) {
Breakout.Keys[key] = false;
}
// delete all resources as loaded using the resource manager
// ---------------------------------------------------------
ResourceManager::Clear();
glfwTerminate();
return 0;
}
}
void key_callback(GLFWwindow* window, int key,
int scancode, int action, int mode) {
// when a user presses the escape key, we set the
// WindowShouldClose property to true, closing the application
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (key >= 0 && key < 1024) {
if (action == GLFW_PRESS)
Breakout.Keys[key] = true;
else if (action == GLFW_RELEASE)
Breakout.Keys[key] = false;
}
void framebuffer_size_callback(GLFWwindow * /*window*/, int width, int height) {
// make sure the viewport matches the new window dimensions;
// note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
// make sure the viewport matches the new window dimensions;
// note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
#endif
// BREAKOUT_CPP

View File

@ -1,27 +1,20 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef GAME_CPP
#define GAME_CPP
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_CPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_CPP
#include "../breakout/game.hpp"
Game::Game(unsigned int width, unsigned int height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height) {
}
: State(GAME_ACTIVE), Keys(), Width(width), Height(height) {}
Game::~Game() {
}
Game::~Game() = default;
void Game::Init() {
}
void Game::Init() {}
void Game::Update(float dt) {
}
void Game::Update(float dt) {}
void Game::ProcessInput(float dt) {
}
void Game::Render() {
}
void Game::ProcessInput(float dt) {}
void Game::Render() {}
#endif
// GAME_CPP

View File

@ -1,6 +1,6 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_GAME_HPP_
#define BREAKOUT_GAME_HPP_
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_HPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_HPP
#include <GLFW/glfw3.h>
@ -26,4 +26,4 @@ public:
void Render();
};
#endif // BREAKOUT_GAME_HPP_
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_HPP

View File

@ -1,116 +1,110 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_RESOURCE_MANAGER_HPP_
#define BREAKOUT_RESOURCE_MANAGER_HPP_
#include <iostream>
#include <sstream>
#include <fstream>
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_CPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_CPP
#include "../breakout/resourceManager.hpp"
#include "./shader.hpp"
#include "./texture.hpp"
#include "./stb_image.h"
#include "./texture.hpp"
// Instantiate static variables
std::map<std::string, Texture2D> ResourceManager::Textures;
std::map<std::string, Shader> ResourceManager::Shaders;
std::map<std::string, Texture2D> ResourceManager::Textures;
std::map<std::string, Shader> ResourceManager::Shaders;
Shader ResourceManager::LoadShader(
const char *vShaderFile,
const char *fShaderFile,
const char *gShaderFile,
std::string name) {
Shaders[name] = loadShaderFromFile(vShaderFile, fShaderFile, gShaderFile);
return Shaders[name];
auto ResourceManager::LoadShader(const char *vShaderFile,
const char *fShaderFile,
const char *gShaderFile,
const std::string &name) -> Shader {
Shaders[name] = loadShaderFromFile(vShaderFile, fShaderFile, gShaderFile);
return Shaders[name];
}
Shader ResourceManager::GetShader(std::string name) {
return Shaders[name];
auto ResourceManager::GetShader(const std::string &name) -> Shader {
return Shaders[name];
}
Texture2D ResourceManager::LoadTexture(
const char *file,
bool alpha,
std::string name) {
Textures[name] = loadTextureFromFile(file, alpha);
return Textures[name];
auto ResourceManager::LoadTexture(const char *file, bool alpha,
const std::string &name) -> Texture2D {
Textures[name] = loadTextureFromFile(file, alpha);
return Textures[name];
}
Texture2D ResourceManager::GetTexture(std::string name) {
return Textures[name];
auto ResourceManager::GetTexture(const std::string &name) -> Texture2D {
return Textures[name];
}
void ResourceManager::Clear() {
// (properly) delete all shaders
for (auto iter : Shaders)
glDeleteProgram(iter.second.ID);
// (properly) delete all textures
for (auto iter : Textures)
glDeleteTextures(1, &iter.second.ID);
// (properly) delete all shaders
for (const auto &iter : Shaders) {
glDeleteProgram(iter.second.ID);
}
// (properly) delete all textures
for (const auto &iter : Textures) {
glDeleteTextures(1, &iter.second.ID);
}
}
Shader ResourceManager::loadShaderFromFile(
const char *vShaderFile,
const char *fShaderFile,
const char *gShaderFile) {
// 1. retrieve the vertex/fragment source code from filePath
std::string vertexCode;
std::string fragmentCode;
std::string geometryCode;
try {
// open files
std::ifstream vertexShaderFile(vShaderFile);
std::ifstream fragmentShaderFile(fShaderFile);
std::stringstream vShaderStream, fShaderStream;
// read file's buffer contents into streams
vShaderStream << vertexShaderFile.rdbuf();
fShaderStream << fragmentShaderFile.rdbuf();
// close file handlers
vertexShaderFile.close();
fragmentShaderFile.close();
// convert stream into string
vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
// if geometry shader path is present, also load a geometry shader
if (gShaderFile != nullptr) {
std::ifstream geometryShaderFile(gShaderFile);
std::stringstream gShaderStream;
gShaderStream << geometryShaderFile.rdbuf();
geometryShaderFile.close();
geometryCode = gShaderStream.str();
}
auto ResourceManager::loadShaderFromFile(const char *vShaderFile,
const char *fShaderFile,
const char *gShaderFile) -> Shader {
// 1. retrieve the vertex/fragment source code from filePath
std::string vertexCode;
std::string fragmentCode;
std::string geometryCode;
try {
// open files
std::ifstream vertexShaderFile(vShaderFile);
std::ifstream fragmentShaderFile(fShaderFile);
std::stringstream vShaderStream;
std::stringstream fShaderStream;
// read file's buffer contents into streams
vShaderStream << vertexShaderFile.rdbuf();
fShaderStream << fragmentShaderFile.rdbuf();
// close file handlers
vertexShaderFile.close();
fragmentShaderFile.close();
// convert stream into string
vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
// if geometry shader path is present, also load a geometry shader
if (gShaderFile != nullptr) {
std::ifstream geometryShaderFile(gShaderFile);
std::stringstream gShaderStream;
gShaderStream << geometryShaderFile.rdbuf();
geometryShaderFile.close();
geometryCode = gShaderStream.str();
}
catch (std::exception const&) {
std::cout << "ERROR::SHADER: Failed to read shader files" << std::endl;
}
const char *vShaderCode = vertexCode.c_str();
const char *fShaderCode = fragmentCode.c_str();
const char *gShaderCode = geometryCode.c_str();
// 2. now create shader object from source code
Shader shader;
shader.Compile(vShaderCode,
fShaderCode, gShaderFile != nullptr ? gShaderCode : nullptr);
return shader;
} catch (std::exception const &) {
std::cout << "ERROR::SHADER: Failed to read shader files" << std::endl;
}
const char *vShaderCode = vertexCode.c_str();
const char *fShaderCode = fragmentCode.c_str();
const char *gShaderCode = geometryCode.c_str();
// 2. now create shader object from source code
Shader shader;
shader.Compile(vShaderCode, fShaderCode,
gShaderFile != nullptr ? gShaderCode : nullptr);
return shader;
}
Texture2D ResourceManager::loadTextureFromFile(const char *file, bool alpha) {
// create texture object
Texture2D texture;
if (alpha) {
texture.Internal_Format = GL_RGBA;
texture.Image_Format = GL_RGBA;
}
// load image
int width, height, nrChannels;
unsigned char* data = stbi_load(file, &width, &height, &nrChannels, 0);
// now generate texture
texture.Generate(width, height, data);
// and finally free image data
stbi_image_free(data);
return texture;
auto ResourceManager::loadTextureFromFile(const char *file, bool alpha)
-> Texture2D {
// create texture object
Texture2D texture;
if (alpha) {
texture.Internal_Format = GL_RGBA;
texture.Image_Format = GL_RGBA;
}
// load image
int width;
int height;
int nrChannels;
unsigned char *data = stbi_load(file, &width, &height, &nrChannels, 0);
// now generate texture
texture.Generate(width, height, data);
// and finally free image data
stbi_image_free(data);
return texture;
}
#endif

View File

@ -7,16 +7,14 @@
** Creative Commons, either version 4 of the License, or (at your
** option) any later version.
******************************************************************/
#ifndef BREAKOUT_RESOURCEMANAGER_HPP_
#define BREAKOUT_RESOURCEMANAGER_HPP_
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_HPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_HPP
#include <map>
#include <string>
#include "../dependencies/include/glad/glad.h"
#include "../breakout/texture.hpp"
#include "../breakout/shader.hpp"
#include "../breakout/texture.hpp"
// A static singleton ResourceManager class that hosts several
@ -27,25 +25,25 @@
class ResourceManager {
public:
// resource storage
static std::map<std::string, Shader> Shaders;
static std::map<std::string, Texture2D> Textures;
static std::max<std::string, Shader> Shaders;
static std::max<std::string, Texture2D> Textures;
// loads (and generates) a shader program from file loading vertex,
// fragment (and geometry) shader's source code.
// If gShaderFile is not nullptr, it also loads a geometry shader
static Shader LoadShader(
static auto LoadShader(
const char *vShaderFile,
const char *fShaderFile,
const char *gShaderFile,
std::string name);
const std::string& name) -> Shader;
// retrieves a stored sader
static Shader GetShader(std::string name);
static auto GetShader(const std::string& name) -> Shader;
// loads (and generates) a texture from file
static Texture2D LoadTexture(
static auto LoadTexture(
const char *file,
bool alpha,
std::string name);
const std::string& name) -> Texture2D;
// retrieves a stored texture
static Texture2D GetTexture(std::string name);
static auto GetTexture(const std::string& name) -> Texture2D;
// properly de-allocates all loaded resources
static void Clear();
@ -53,14 +51,14 @@ class ResourceManager {
// private constructor,
// that is we do not want any actual resource manager objects.
// Its members and functions should be publicly available (static).
ResourceManager() { }
ResourceManager() = default;
// loads and generates a shader from file
static Shader loadShaderFromFile(
static auto loadShaderFromFile(
const char *vShaderFile,
const char *fShaderFile,
const char *gShaderFile = nullptr);
const char *gShaderFile) -> Shader;
// loads a single texture from file
static Texture2D loadTextureFromFile(const char *file, bool alpha);
static auto loadTextureFromFile(const char *file, bool alpha) -> Texture2D;
};
#endif // BREAKOUT_RESOURCEMANAGER_HPP_
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_RESOURCEMANAGER_HPP

View File

@ -1,32 +1,32 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_SHADER_CPP
#define BREAKOUT_SHADER_CPP
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_SHADER_CPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_SHADER_CPP
#include "../breakout/shader.hpp"
#include <iostream>
Shader &Shader::Use() {
auto Shader::Use() -> Shader & {
glUseProgram(this->ID);
return *this;
}
void Shader::Compile(const char *vertexSource, const char *fragmentSource,
const char *geometrySource) {
unsigned int sVertex, sFragment, gShader;
unsigned int sVertex;
unsigned int sFragment;
unsigned int gShader;
// vertex Shader
sVertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(sVertex, 1, &vertexSource, NULL);
glShaderSource(sVertex, 1, &vertexSource, nullptr);
glCompileShader(sVertex);
checkCompileErrors(sVertex, "VERTEX");
// fragment Shader
sFragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(sFragment, 1, &fragmentSource, NULL);
glShaderSource(sFragment, 1, &fragmentSource, nullptr);
glCompileShader(sFragment);
checkCompileErrors(sFragment, "FRAGMENT");
// if geometry shader source code is given, also compile geometry shader
if (geometrySource != nullptr) {
gShader = glCreateShader(GL_GEOMETRY_SHADER);
glShaderSource(gShader, 1, &geometrySource, NULL);
glShaderSource(gShader, 1, &geometrySource, nullptr);
glCompileShader(gShader);
checkCompileErrors(gShader, "GEOMETRY");
}
@ -34,79 +34,90 @@ void Shader::Compile(const char *vertexSource, const char *fragmentSource,
this->ID = glCreateProgram();
glAttachShader(this->ID, sVertex);
glAttachShader(this->ID, sFragment);
if (geometrySource != nullptr)
if (geometrySource != nullptr) {
glAttachShader(this->ID, gShader);
}
glLinkProgram(this->ID);
checkCompileErrors(this->ID, "PROGRAM");
// delete the shaders as they're linked into our
// program now and no longer necessary
glDeleteShader(sVertex);
glDeleteShader(sFragment);
if (geometrySource != nullptr)
if (geometrySource != nullptr) {
glDeleteShader(gShader);
}
}
void Shader::SetFloat(const char *name, float value, bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform1f(glGetUniformLocation(this->ID, name), value);
}
void Shader::SetInteger(const char *name, int value, bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform1i(glGetUniformLocation(this->ID, name), value);
}
void Shader::SetVector2f(const char *name, float x, float y, bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform2f(glGetUniformLocation(this->ID, name), x, y);
}
void Shader::SetVector2f(const char *name, const glm::vec2 &value,
bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y);
}
void Shader::SetVector3f(const char *name, float x, float y, float z,
bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform3f(glGetUniformLocation(this->ID, name), x, y, z);
}
void Shader::SetVector3f(const char *name, const glm::vec3 &value,
bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform3f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z);
}
void Shader::SetVector4f(const char *name, float x, float y, float z, float w,
bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w);
}
void Shader::SetVector4f(const char *name, const glm::vec4 &value,
bool useShader) {
if (useShader)
if (useShader) {
this->Use();
}
glUniform4f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z,
value.w);
}
void Shader::SetMatrix4(const char *name, const glm::mat4 &matrix,
bool useShader) {
if (useShader)
if (useShader) {
this->Use();
glUniformMatrix4fv(glGetUniformLocation(this->ID, name), 1, false,
}
glUniformMatrix4fv(glGetUniformLocation(this->ID, name), 1, 0u,
glm::value_ptr(matrix));
}
void Shader::checkCompileErrors(unsigned int object, std::string type) {
int success;
void Shader::checkCompileErrors(unsigned int object, const std::string &type) {
int success = 0;
char infoLog[1024];
if (type != "PROGRAM") {
glGetShaderiv(object, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(object, 1024, NULL, infoLog);
if (success == 0) {
glGetShaderInfoLog(object, 1024, nullptr, infoLog);
std::cout
<< "| ERROR::SHADER: Compile-time error: Type: " << type << "\n"
<< infoLog
@ -115,8 +126,8 @@ void Shader::checkCompileErrors(unsigned int object, std::string type) {
}
} else {
glGetProgramiv(object, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(object, 1024, NULL, infoLog);
if (success == 0) {
glGetProgramInfoLog(object, 1024, nullptr, infoLog);
std::cout
<< "| ERROR::Shader: Link-time error: Type: " << type << "\n"
<< infoLog
@ -126,4 +137,4 @@ void Shader::checkCompileErrors(unsigned int object, std::string type) {
}
}
#endif // BREAKOUT_SHADER_CPP
#endif

View File

@ -1,59 +1,41 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_SHADER_HPP_
#define BREAKOUT_SHADER_HPP_
#include <string>
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_SHADER_HPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_SHADER_HPP
#include "../dependencies/include/glad/glad.h"
#include "../dependencies/include/glm/glm/glm.hpp"
#include "../dependencies/include/glm/glm/gtc/type_ptr.hpp"
// General purpose shader object. Compiles from file, generates
// compile/link-time error messages and hosts several utility
// functions for easy management.
class Shader {
public:
// state
unsigned int ID;
// constructor
Shader() { }
// sets the current shader as active
Shader &Use();
// compiles the shader from given source code
void Compile(
const char *vertexSource,
const char *fragmentSource,
const char *geometrySource = nullptr);
// note: geometrysource code is optional
// utility functions
void SetFloat(
const char *name,
float value,
bool useShader = false);
void SetInteger(const char *name,
int value,
bool useShader = false);
void SetVector2f(const char *name,
float x, float y, bool useShader = false);
void SetVector2f(
const char *name, const glm::vec2 &value, bool useShader = false);
void SetVector3f(
const char *name, float x, float y, float z, bool useShader = false);
void SetVector3f(
const char *name, const glm::vec3 &value, bool useShader = false);
void SetVector4f(
const char *name,
float x, float y, float z, float w,
bool useShader = false);
void SetVector4f(
const char *name, const glm::vec4 &value, bool useShader = false);
void SetMatrix4(
const char *name, const glm::mat4 &matrix, bool useShader = false);
public:
// state
unsigned int ID{};
// constructor
Shader() = default;
// sets the current shader as active
auto Use() -> Shader &;
// compiles the shader from given source code
void Compile(const char *vertexSource, const char *fragmentSource,
const char *geometrySource);
// note: geometrysource code is optional
// utility functions
void SetFloat(const char *name, float value, bool useShader);
void SetInteger(const char *name, int value, bool useShader);
void SetVector2f(const char *name, float x, float y, bool useShader);
void SetVector2f(const char *name, const glm::vec2 &value, bool useShader);
void SetVector3f(const char *name, float x, float y, float z, bool useShader);
void SetVector3f(const char *name, const glm::vec3 &value, bool useShader);
void SetVector4f(const char *name, float x, float y, float z, float w,
bool useShader);
void SetVector4f(const char *name, const glm::vec4 &value, bool useShader);
void SetMatrix4(const char *name, const glm::mat4 &matrix, bool useShader);
private:
// checks if compilation or linking failed and if so, print the error logs
void checkCompileErrors(unsigned int object, std::string type);
private:
// checks if compilation or linking failed and if so, print the error logs
static void checkCompileErrors(unsigned int object, const std::string &type);
};
#endif // BREAKOUT_SHADER_HPP_
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_SHADER_HPP

View File

@ -1,8 +1,7 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_TEXTURE_CPP_
#define BREAKOUT_TEXTURE_CPP_
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_TEXTURE_CPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_TEXTURE_CPP
#include <iostream>
#include "../breakout/texture.hpp"
@ -44,4 +43,4 @@ void Texture2D::Bind() const {
glBindTexture(GL_TEXTURE_2D, this->ID);
}
#endif // BREAKOUT_TEXTURE_CPP
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_TEXTURE_CPP

View File

@ -1,6 +1,6 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_TEXTURE_HPP_
#define BREAKOUT_TEXTURE_HPP_
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_TEXTURE_HPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_TEXTURE_HPP
#include "../dependencies/include/glad/glad.h"
@ -10,7 +10,7 @@ class Texture2D {
public:
// holds the ID of the texture object,
// used for all texture operations to reference to this particular texture
unsigned int ID;
unsigned int ID{};
// texture image dimensions
unsigned int Width, Height;
// width and height of loaded image in pixels
@ -36,4 +36,4 @@ public:
void Bind() const;
};
#endif // BREAKOUT_TEXTURE_HPP_
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_TEXTURE_HPP

View File

@ -1,4 +1,4 @@
#!/bin/sh
clang-tidy --config-file=./.clang-tidy --fix-errors --fix-notes -p ./build/compile_commands.json ./breakout/breakout.cpp ./breakout/game.cpp ./breakout/game.hpp ./breakout/resourceManager.cpp ./breakout/resourceManager.hpp ./breakout/shader.cpp ./breakout/shader.hpp ./breakout/texture.cpp ./breakout/texture.hpp
clang-tidy --config-file=./.clang-tidy --fix-errors --fix-notes -p ./build/compile_commands.json ./breakout/breakout.cpp
cpplint ./breakout/breakout.cpp ./breakout/game.cpp ./breakout/game.hpp ./breakout/resourceManager.cpp ./breakout/resourceManager.hpp ./breakout/shader.cpp ./breakout/shader.hpp ./breakout/texture.cpp ./breakout/texture.hpp
cpplint ./breakout/breakout.cpp