Fix some OpenGL warnings

This commit is contained in:
2021-01-15 10:20:04 +01:00
parent d0a3b5e9a0
commit b2774e57de
13 changed files with 242 additions and 105 deletions

View File

@@ -13,7 +13,7 @@ set(OpenGL_GL_PREFERENCE "GLVND")
find_package(GLFW3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Freetype REQUIRED)
#find_package(Freetype REQUIRED) Will be used in the future
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)

View File

@@ -45,7 +45,7 @@ struct PointLight {
#define NUM_POINT_LIGHTS 16
uniform PointLight u_pointLight[NUM_POINT_LIGHTS];
struct SpotLight {
/*struct SpotLight {
bool isActive;
vec3 position;
vec3 direction;
@@ -59,7 +59,7 @@ struct SpotLight {
vec3 diffuse;
vec3 specular;
};
uniform SpotLight u_spotLight;
uniform SpotLight u_spotLight;*/
uniform mat3 u_normalMatrix;
uniform vec3 u_viewPosition;
@@ -84,7 +84,7 @@ uniform float pointShadowDepthMapFarPlane;
vec3 directionalLightContribution(DirectionalLight light, vec3 normal, vec3 viewDir);
vec3 pointLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
vec3 spotLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
//vec3 spotLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
void computeShading(
vec3 light_ambient, vec3 light_diffuse, vec3 light_specular,
@@ -110,6 +110,7 @@ void main() {
fragmentColor += pointLightContribution(u_pointLight[i], normal, v_fragmentPosition, viewDir);
}
// There are currently no spotlights
//fragmentColor += spotLightContribution(u_spotLight, normal, v_fragmentPosition, viewDir);
f_color = vec4(fragmentColor, 1.0f);
@@ -157,7 +158,7 @@ vec3 pointLightContribution(PointLight light, vec3 normal, vec3 fragPos, vec3 vi
return (ambient + (1.0f - shadows) * (diffuse + specular));
}
vec3 spotLightContribution(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir) {
/*vec3 spotLightContribution(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir) {
// Only compute if light source is active
if(!light.isActive)
@@ -181,7 +182,7 @@ vec3 spotLightContribution(SpotLight light, vec3 normal, vec3 fragPos, vec3 view
specular *= intensity;
return (ambient + diffuse + specular);
}
}*/
void computeShading(
vec3 light_ambient, vec3 light_diffuse, vec3 light_specular,
@@ -232,14 +233,10 @@ float computeDirectionalShadows(vec4 fragPosLightSpace, vec3 normal, vec3 lightD
float shadow = 0.0;
vec2 texelSize = 1.0 / textureSize(u_texture_directionalShadowMap, 0);
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
float pcfDepth = texture(u_texture_directionalShadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
}
}
shadow /= 9.0f;

View File

@@ -34,8 +34,16 @@ Controller::Controller()
shaderPrograms = shaderParser.getShaderPrograms();
pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight(), getShaderProgramByName("postProcessingProgram"));
menu = new Menu(pp_framebuffer, getShaderProgramByName("menuProgram"));
// Show loading screen...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
menu->showLoadingScreen();
glfwSwapBuffers(gameWindow->getGLFWwindow());
world = new World(shaderPrograms);
#ifdef _DEBUG
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
@@ -62,6 +70,7 @@ Controller::~Controller()
delete *it;
}
delete world;
delete camera;
delete menu;
delete pp_framebuffer;
@@ -71,18 +80,9 @@ Controller::~Controller()
void Controller::run()
{
glClearColor(0.0015f, 0.0015f, 0.0015f, 1.0f);
updateExposure(getShaderProgramByName("postProcessingProgram"));
// Show loading screen...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
menu->showLoadingScreen();
glfwSwapBuffers(gameWindow->getGLFWwindow());
World world(shaderPrograms);
Entity *lightSource = world.getEntityByName("light");
Entity *lightSource = world->getEntityByName("light");
lightSource->setScale(0.1f);
lightSource->setRotation(glm::vec3(0.f));
lightSource->setPosition(glm::vec3(-2.f, 1.5f, 2.f));
@@ -92,6 +92,7 @@ void Controller::run()
// This is the game loop
while (!glfwWindowShouldClose(gameWindow->getGLFWwindow())) {
// --- Timing ---
limit_framerate();
@@ -101,15 +102,15 @@ void Controller::run()
if (rotateLightSource) {
float radius = 4.0;
glm::vec3 newPos = glm::vec3(-cos(glfwGetTime() * 0.5), 0.5f, sin(glfwGetTime() * 0.5)) * radius;
world.getEntityByName("light")->setPosition(newPos);
world->getEntityByName("light")->setPosition(newPos);
}
if (rotateEntity) {
world.getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * deltaTime);
world->getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * deltaTime);
}
static glm::vec3 lightColor = glm::vec3(1.f);
static float intensity = 20.f;
world.updatePointLight(0, true, world.getEntityByName("light")->getPosition(), lightColor * intensity);
world.updateDirectionalLight(true, glm::vec3(-0.2f, -1.0f, -0.3f), lightColor * 0.25f);
world->updatePointLight(0, true, world->getEntityByName("light")->getPosition(), lightColor * intensity);
world->updateDirectionalLight(true, glm::vec3(-0.2f, -1.0f, -0.3f), lightColor * 0.25f);
getShaderProgramByName("lightProgram")->bind();
getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f);
getShaderProgramByName("lightProgram")->unbind();
@@ -124,7 +125,7 @@ void Controller::run()
getShaderProgramByName("defaultProgram")->unbind();
if (drawShadows || firstRun) {
firstRun = false;
world.calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), getShaderProgramByName("pointShadowDepthProgram"));
world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), getShaderProgramByName("pointShadowDepthProgram"));
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -137,14 +138,14 @@ void Controller::run()
glViewport(0, 0, gameWindow->getWindowWidth(), gameWindow->getWindowHeight());
world.getSkybox()->draw(camera->getView(), camera->getProj());
world.draw(camera->getViewProj(), camera->getPosition());
world->getSkybox()->draw(camera->getView(), camera->getProj());
world->draw(camera->getViewProj(), camera->getPosition());
pp_framebuffer->unbind();
pp_framebuffer->render();
#ifdef _DEBUG
renderImGui(world, &world.getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
renderImGui(world, &world->getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
#endif
glfwSwapBuffers(gameWindow->getGLFWwindow());
@@ -228,7 +229,7 @@ void Controller::setMaxFps(uint16_t fps)
#ifdef _DEBUG
void Controller::renderImGui(World &world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows)
void Controller::renderImGui(World *world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows)
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
@@ -246,12 +247,12 @@ void Controller::renderImGui(World &world, PointLight *pointLight, glm::vec3 *li
ImGui::SliderFloat("Scale", &scale, 0.02, 2.0);
ImGui::Checkbox("Rotate Object", rotateEntity);
Entity *mainObject = world.getEntityById(0);
Entity *mainObject = world->getEntityById(0);
mainObject->setPosition(glm::vec3(translation[0], translation[1], translation[2]));
if (!*rotateEntity) {
//mainObject->setRotation(glm::vec3(0.f, 1.0f, 0.f), rotation);
mainObject->setRotation(glm::vec3(0.f, 1.0f, 0.f), rotation);
}
//mainObject->setScale(scale);
mainObject->setScale(scale);
// color picker
ImGui::Text("\nLight Source");

View File

@@ -34,18 +34,21 @@ private:
ShaderProgram* getShaderProgramByName(const char *name);
void renderImGui(World &world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows);
void renderImGui(World *world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows);
private:
Window *gameWindow;
EventHandler *gameEventHandler;
World *world;
Camera *camera;
Menu *menu;
std::vector<ShaderProgram*> shaderPrograms;
Framebuffer *pp_framebuffer;
Menu *menu;
uint16_t MAX_FPS = 60;
double deltaTime;

View File

@@ -9,12 +9,14 @@ Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderP
glGenFramebuffers(1, &FBO);
generateTextures(width, height);
setExposureCorrection(true);
}
Framebuffer::~Framebuffer()
{
glDeleteFramebuffers(1, &FBO);
glDeleteTextures(2, textures);
glDeleteTextures(1, &colorBuffer);
glDeleteRenderbuffers(1, &depthStencilBuffer);
}
void Framebuffer::bind()
@@ -55,31 +57,35 @@ void Framebuffer::render()
void Framebuffer::changeDimensions(uint32_t width, uint32_t height)
{
// Delete old textures
glDeleteTextures(2, textures);
glDeleteTextures(1, &colorBuffer);
glDeleteRenderbuffers(1, &depthStencilBuffer);
generateTextures(width, height);
}
void Framebuffer::generateTextures(uint32_t width, uint32_t height)
{
bind();
// Create new textures
glGenTextures(2, textures);
glGenTextures(1, &colorBuffer);
glGenRenderbuffers(1, &depthStencilBuffer);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, colorBuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textures[1], 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] Framebuffer is not complete!" << std::endl;
unbind();
}
@@ -93,18 +99,19 @@ void Framebuffer::setExposureCorrection(bool exposureCorrection)
GLuint Framebuffer::getTextureId()
{
return textures[0];
return colorBuffer;
}
DepthMap::DepthMap(int TYPE, int RESOLUTION) :
cubeMap(RESOLUTION)
DepthMap::DepthMap(int TYPE, int RESOLUTION)
{
glGenFramebuffers(1, &depthMapFBO);
bind();
if (TYPE == DEPTHMAP_NORMAL) {
glGenFramebuffers(1, &depthMapFBO);
glGenTextures(1, &depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -112,24 +119,31 @@ DepthMap::DepthMap(int TYPE, int RESOLUTION) :
glBindTexture(GL_TEXTURE_2D, 0);
bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
unbind();
} else if (TYPE == DEPTHMAP_CUBEMAP) {
glGenFramebuffers(1, &depthMapFBO);
cubeMap = new CubeMap(RESOLUTION);
// CubeMap is already created
bind();
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, cubeMap.getTextureId(), 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, cubeMap->getTextureId(), 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
unbind();
}
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] Framebuffer is not complete!" << std::endl;
unbind();
}
DepthMap::~DepthMap()
{
if(cubeMap)
delete cubeMap;
}
void DepthMap::bind()
{
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
@@ -152,5 +166,5 @@ GLuint DepthMap::getDepthMap()
GLuint DepthMap::getCubeMapId()
{
return cubeMap.getTextureId();
return cubeMap->getTextureId();
}

View File

@@ -25,7 +25,8 @@ private:
private:
GLuint FBO;
GLuint textures[2];
GLuint colorBuffer;
GLuint depthStencilBuffer;
ShaderProgram *shaderProgram;
};
@@ -38,6 +39,7 @@ class DepthMap
public:
// Normal depthMap with texture and point depthMap with cubeMap
DepthMap(int TYPE, int RESOLUTION);
~DepthMap();
void bind();
void unbind();
@@ -52,5 +54,5 @@ private:
// Either a normal depthMap is used (Directional shadows)
// or a cubeMap is used (Point shadows)
GLuint depthMap;
CubeMap cubeMap;
CubeMap *cubeMap;
};

View File

@@ -14,7 +14,7 @@ void Mesh::draw(ShaderProgram *shaderProgram)
glBindTexture(GL_TEXTURE_2D, 0);
// Bind all textures in order to its texture unit
for (auto it = textures.begin(); it != textures.end(); it++) {
int i = it - textures.begin();
const int i = it - textures.begin();
uint8_t currentTextureType = (*it)->getTextureType();

View File

@@ -9,9 +9,22 @@ Texture::Texture(const char *texturePath, uint8_t textureType)
this->textureType = textureType;
stbi_set_flip_vertically_on_load(1);
auto *textureBuffer = stbi_load(texturePath, &textureWidth, &textureHeight, &bitsPerPixel, STBI_rgb_alpha);
auto *textureBuffer = stbi_load(texturePath, &textureWidth, &textureHeight, &numComponents, 0);
// Push texture to grahics card;
GLenum internalFormat;
GLenum dataFormat;
if (numComponents == 1) {
internalFormat = GL_RED;
dataFormat = GL_RED;
} else if (numComponents == 3) {
internalFormat = (textureType == texture_diffuse) ? GL_SRGB8 : GL_RGB8;
dataFormat = GL_RGB;
} else if (numComponents == 4) {
internalFormat = (textureType == texture_diffuse) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
dataFormat = GL_RGBA;
}
// Push texture to grahics card
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
@@ -28,11 +41,7 @@ Texture::Texture(const char *texturePath, uint8_t textureType)
return;
}
if (textureType == texture_diffuse) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureBuffer);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureBuffer);
}
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE, textureBuffer);
//glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(textureBuffer);
@@ -114,14 +123,28 @@ CubeMap::CubeMap(const char *texturePseudoPath)
for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) {
auto *textureBuffer = stbi_load(texturePaths[i].c_str(), &textureWidth, &textureHeight, &bitsPerPixel, STBI_rgb_alpha);
int32_t numComponents;
auto *textureBuffer = stbi_load(texturePaths[i].c_str(), &textureWidth, &textureHeight, &numComponents, 0);
GLenum internalFormat;
GLenum dataFormat;
if (numComponents == 1) {
internalFormat = GL_RED;
dataFormat = GL_RED;
} else if (numComponents == 3) {
internalFormat = GL_SRGB8;
dataFormat = GL_RGB;
} else if (numComponents == 4) {
internalFormat = GL_SRGB8_ALPHA8;
dataFormat = GL_RGBA;
}
if (!textureBuffer) {
std::cout << "[Warning] CubeMap Texture " << texturePaths[i].c_str() << " not found!" << std::endl;
return;
}
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB8_ALPHA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureBuffer);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE, textureBuffer);
stbi_image_free(textureBuffer);
@@ -144,9 +167,9 @@ CubeMap::CubeMap(int RESOLUTION) :
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
const int CUBEMAP_NUM_FACES = 6;
const unsigned int CUBEMAP_NUM_FACES = 6;
for (unsigned int i = 0; i < CUBEMAP_NUM_FACES; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
}
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

View File

@@ -30,7 +30,7 @@ private:
int32_t textureWidth;
int32_t textureHeight;
int32_t bitsPerPixel;
int32_t numComponents;
GLuint textureId;
@@ -60,5 +60,4 @@ private:
int32_t textureWidth;
int32_t textureHeight;
int32_t bitsPerPixel;
};

View File

@@ -22,7 +22,7 @@ Window::Window()
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef _DEBUG
glfwSetErrorCallback(error_callback);
glfwSetErrorCallback(glfw_error_callback);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
#else
// Maximize in release build
@@ -50,13 +50,12 @@ Window::Window()
}
#ifdef _DEBUG
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(Helper::gl_debug_callback, NULL);
// Disable mouse cursor
mouseCatched = false;
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(openGLDebugCallback, NULL);
#endif
// Enable z buffer
@@ -134,7 +133,7 @@ void Window::handleActionRegister(bool *windowActionRegister)
}
// GLFW error function
void Window::error_callback(int error, const char *description)
void Window::glfw_error_callback(int error, const char *description)
{
fprintf(stderr, "[Error] GLFW Error %d: %s\n", error, description);
}
@@ -146,21 +145,6 @@ void Window::framebuffer_size_callback(GLFWwindow *window, int width, int height
glViewport(0, 0, width, height);
}
void Window::openGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
{
(void)length;
(void)userParam;
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM)
std::cout << "[OpenGL Error]" << std::endl
<< "Message: " << message << std::endl
<< "Source: " << source << std::endl
<< "Type: " << type << std::endl
<< "ID: " << id << std::endl
<< "Severity: " << severity << std::endl
<< std::endl;
}
GLFWwindow* Window::getGLFWwindow()
{
return window;

View File

@@ -21,9 +21,8 @@ public:
void handleActionRegister(bool *windowActionRegister);
private:
static void error_callback(int error, const char *description);
static void glfw_error_callback(int error, const char *description);
static void framebuffer_size_callback(GLFWwindow *window, int width, int height);
static void openGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam);
void setCatchedCursor(bool value);
private:

View File

@@ -6,7 +6,7 @@
World::World(std::vector<ShaderProgram*> shaderPrograms) :
shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")),
directionalLight(shaderProgram), // wtf is this
directionalLight(shaderProgram),
depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES)
{
// PointLights

View File

@@ -1,5 +1,8 @@
#pragma once
#include <stdint.h>
#include <string>
#include <algorithm>
#ifdef __linux__
#include <unistd.h>
@@ -10,12 +13,124 @@
namespace Helper
{
static void sleep(uint32_t us) {
static void sleep(uint32_t us)
{
#ifdef __linux__
usleep(us);
usleep(us);
#endif
#ifdef _WIN32
Sleep(us/1000);
// I really don't know why I have to divide by 2000 and not 1000 but this way it works even on Windows
Sleep(us / 2000);
#endif
}
static void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
{
(void)length;
(void)userParam;
const char* _source;
const char* _type;
const char* _severity;
// Remove unwanted newline characters from message string
std::string _message = message;
_message.erase(std::remove(_message.begin(), _message.end(), '\n'), _message.end());
switch (source) {
case GL_DEBUG_SOURCE_API:
_source = "API";
break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
_source = "WINDOW SYSTEM";
break;
case GL_DEBUG_SOURCE_SHADER_COMPILER:
_source = "SHADER COMPILER";
break;
case GL_DEBUG_SOURCE_THIRD_PARTY:
_source = "THIRD PARTY";
break;
case GL_DEBUG_SOURCE_APPLICATION:
_source = "APPLICATION";
break;
case GL_DEBUG_SOURCE_OTHER:
_source = "UNKNOWN";
break;
default:
_source = "UNKNOWN";
break;
}
};
switch (type) {
case GL_DEBUG_TYPE_ERROR:
_type = "ERROR";
break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
_type = "DEPRECATED BEHAVIOR";
break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
_type = "UDEFINED BEHAVIOR";
break;
case GL_DEBUG_TYPE_PORTABILITY:
_type = "PORTABILITY";
break;
case GL_DEBUG_TYPE_PERFORMANCE:
_type = "PERFORMANCE";
break;
case GL_DEBUG_TYPE_OTHER:
_type = "OTHER";
break;
case GL_DEBUG_TYPE_MARKER:
_type = "MARKER";
break;
default:
_type = "UNKNOWN";
break;
}
switch (severity) {
case GL_DEBUG_SEVERITY_HIGH:
_severity = "HIGH";
break;
case GL_DEBUG_SEVERITY_MEDIUM:
_severity = "MEDIUM";
break;
case GL_DEBUG_SEVERITY_LOW:
_severity = "LOW";
break;
case GL_DEBUG_SEVERITY_NOTIFICATION:
_severity = "NOTIFICATION";
break;
default:
_severity = "UNKNOWN";
break;
}
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM)
std::cout << "[OpenGL Debug Message]" << std::endl
<< "Message: " << _message << std::endl
<< "Source: " << _source << std::endl
<< "Type: " << _type << std::endl
<< "ID: " << id << std::endl
<< "Severity: " << _severity << std::endl
<< std::endl;
}
}