Skip to content

CHECK_GL_ERROR additions #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libprojectM/Renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ add_custom_command(OUTPUT
add_library(Renderer OBJECT
${CMAKE_CURRENT_BINARY_DIR}/BuiltInTransitionsResources.hpp
BuiltInTransitionsResources.hpp.in
Debug.cpp
Debug.hpp
CopyTexture.cpp
CopyTexture.hpp
FileScanner.cpp
Expand Down
38 changes: 38 additions & 0 deletions src/libprojectM/Renderer/Debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "Debug.hpp"


namespace libprojectM::Renderer {

void check_gl_error(const char* file, int line)
{
GLenum err(glGetError());

while (err != GL_NO_ERROR)
{
std::string error;

switch (err)
{
case GL_INVALID_OPERATION:
error = "INVALID_OPERATION";
break;
case GL_INVALID_ENUM:
error = "INVALID_ENUM";
break;
case GL_INVALID_VALUE:
error = "INVALID_VALUE";
break;
case GL_OUT_OF_MEMORY:
error = "OUT_OF_MEMORY";
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
error = "INVALID_FRAMEBUFFER_OPERATION";
break;
}

std::cerr << "GL_" << error.c_str() << " - " << file << ":" << line << std::endl;
err = glGetError();
}
}

} // namespace libprojectM::Renderer
14 changes: 14 additions & 0 deletions src/libprojectM/Renderer/Debug.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#pragma once

#include <iostream>
#include <projectM-opengl.h>

#define CHECK_GL_ERROR check_gl_error(__FILE__, __LINE__)


namespace libprojectM::Renderer {

void check_gl_error(const char* file, int line);

} // namespace libprojectM::Renderer
9 changes: 9 additions & 0 deletions src/libprojectM/Renderer/MilkdropNoise.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MilkdropNoise.hpp"

#include "Debug.hpp"
#include "projectM-opengl.h"

#include <chrono>
Expand All @@ -22,6 +23,7 @@ auto MilkdropNoise::LowQuality() -> std::shared_ptr<Texture>
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
CHECK_GL_ERROR;
}
return std::make_shared<Texture>("noise_lq", texture, GL_TEXTURE_2D, 256, 256, false);
}
Expand All @@ -36,6 +38,7 @@ auto MilkdropNoise::LowQualityLite() -> std::shared_ptr<Texture>
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
CHECK_GL_ERROR;
}

return std::make_shared<Texture>("noise_lq_lite", texture, GL_TEXTURE_2D, 32, 32, false);
Expand All @@ -51,6 +54,7 @@ auto MilkdropNoise::MediumQuality() -> std::shared_ptr<Texture>
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
CHECK_GL_ERROR;
}
return std::make_shared<Texture>("noise_mq", texture, GL_TEXTURE_2D, 256, 256, false);
}
Expand All @@ -65,6 +69,7 @@ auto MilkdropNoise::HighQuality() -> std::shared_ptr<Texture>
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
CHECK_GL_ERROR;
}

return std::make_shared<Texture>("noise_hq", texture, GL_TEXTURE_2D, 256, 256, false);
Expand All @@ -80,6 +85,7 @@ auto MilkdropNoise::LowQualityVolume() -> std::shared_ptr<Texture>
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
CHECK_GL_ERROR;
}

return std::make_shared<Texture>("noisevol_lq", texture, GL_TEXTURE_3D, 32, 32, false);
Expand All @@ -95,6 +101,7 @@ auto MilkdropNoise::HighQualityVolume() -> std::shared_ptr<Texture>
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
CHECK_GL_ERROR;
}

return std::make_shared<Texture>("noisevol_hq", texture, GL_TEXTURE_3D, 32, 32, false);
Expand All @@ -106,7 +113,9 @@ auto MilkdropNoise::GetPreferredInternalFormat() -> int
// Query preferred internal texture format. GLES 3 only supports GL_RENDERBUFFER here, no texture targets.
// That's why we use GL_BGRA as default, as this is the best general-use format according to Khronos.
GLint preferredInternalFormat{GL_BGRA};
CHECK_GL_ERROR;
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_TEXTURE_IMAGE_FORMAT, sizeof(preferredInternalFormat), &preferredInternalFormat);
CHECK_GL_ERROR;
#else
// GLES only supports GL_RGB and GL_RGBA, so we always use the latter.
GLint preferredInternalFormat{GL_RGBA};
Expand Down
2 changes: 1 addition & 1 deletion src/libprojectM/Renderer/MilkdropNoise.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <Renderer/Debug.hpp>
#include <Renderer/Texture.hpp>

#include <cstdint>
Expand Down Expand Up @@ -66,7 +67,6 @@ class MilkdropNoise
static auto HighQualityVolume() -> std::shared_ptr<Texture>;

protected:

static auto GetPreferredInternalFormat() -> int;

/**
Expand Down
8 changes: 8 additions & 0 deletions src/libprojectM/Renderer/PresetTransition.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "PresetTransition.hpp"

#include "Debug.hpp"
#include "TextureManager.hpp"

#include <array>
Expand All @@ -19,6 +20,7 @@ PresetTransition::PresetTransition(const std::shared_ptr<Shader>& transitionShad
m_staticRandomValues = {rand32(), rand32(), rand32(), rand32()};

RenderItem::Init();
CHECK_GL_ERROR;
}

void PresetTransition::InitVertexAttrib()
Expand All @@ -31,6 +33,7 @@ void PresetTransition::InitVertexAttrib()
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x))); // Position
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW);
CHECK_GL_ERROR;
}

auto PresetTransition::IsDone() const -> bool
Expand Down Expand Up @@ -69,6 +72,7 @@ void PresetTransition::Draw(const Preset& oldPreset,
}

m_transitionShader->Bind();
CHECK_GL_ERROR;

// Numerical parameters
m_transitionShader->SetUniformFloat3("iResolution", {static_cast<float>(context.viewportSizeX),
Expand Down Expand Up @@ -103,6 +107,7 @@ void PresetTransition::Draw(const Preset& oldPreset,
oldPreset.OutputTexture()->Bind(0, m_presetSampler);
m_transitionShader->SetUniformInt("iChannel1", 1);
newPreset.OutputTexture()->Bind(1, m_presetSampler);
CHECK_GL_ERROR;

int textureUnit = 2;
std::vector<TextureSamplerDescriptor> noiseDescriptors(m_noiseTextureNames.size());
Expand All @@ -117,17 +122,20 @@ void PresetTransition::Draw(const Preset& oldPreset,
glBindVertexArray(m_vaoID);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
CHECK_GL_ERROR;

// Clean up
oldPreset.OutputTexture()->Unbind(0);
newPreset.OutputTexture()->Unbind(1);
CHECK_GL_ERROR;

for (int i = 2; i < textureUnit; i++)
{
noiseDescriptors[i - 2].Unbind(textureUnit);
}

Shader::Unbind();
CHECK_GL_ERROR;

// Update last frame time.
m_lastFrameTime = std::chrono::system_clock::now();
Expand Down
1 change: 1 addition & 0 deletions src/libprojectM/Renderer/PresetTransition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Renderer/RenderItem.hpp"
#include "Renderer/Shader.hpp"
#include "Renderer/TextureSamplerDescriptor.hpp"
#include <Renderer/Debug.hpp>

#include <Preset.hpp>

Expand Down
3 changes: 3 additions & 0 deletions src/libprojectM/Renderer/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ Texture::~Texture()

void Texture::Bind(GLint slot, const Sampler::Ptr& sampler) const
{
std::cout << "Texture::Bind" << std::endl;
glActiveTexture(GL_TEXTURE0 + slot);
CHECK_GL_ERROR;
glBindTexture(m_target, m_textureId);
CHECK_GL_ERROR;

if (sampler)
{
Expand Down
2 changes: 2 additions & 0 deletions src/libprojectM/Renderer/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/
#pragma once

#include "Renderer/Debug.hpp"
#include "Renderer/Sampler.hpp"

#include <iostream>
#include <string>

namespace libprojectM {
Expand Down
9 changes: 7 additions & 2 deletions src/libprojectM/Renderer/TextureManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "TextureManager.hpp"

#include "Debug.hpp"
#include "FileScanner.hpp"
#include "IdleTextures.hpp"
#include "MilkdropNoise.hpp"
Expand Down Expand Up @@ -79,16 +80,19 @@ void TextureManager::Preload()
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);

m_textures["idlem"] = std::make_shared<Texture>("idlem", tex, GL_TEXTURE_2D, width, height, false);;
m_textures["idlem"] = std::make_shared<Texture>("idlem", tex, GL_TEXTURE_2D, width, height, false);
;

tex = SOIL_load_OGL_texture_from_memory(
headphones_data,
headphones_bytes,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
CHECK_GL_ERROR;

m_textures["idleheadphones"] = std::make_shared<Texture>("idleheadphones", tex, GL_TEXTURE_2D, width, height, false);;
m_textures["idleheadphones"] = std::make_shared<Texture>("idleheadphones", tex, GL_TEXTURE_2D, width, height, false);
;

// Noise textures
m_textures["noise_lq_lite"] = MilkdropNoise::LowQualityLite();
Expand Down Expand Up @@ -224,6 +228,7 @@ auto TextureManager::LoadTexture(const std::string& fileName, const std::string&
SOIL_LOAD_RGBA,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
CHECK_GL_ERROR;

if (tex == 0)
{
Expand Down
1 change: 1 addition & 0 deletions src/libprojectM/Renderer/TextureManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Renderer/Debug.hpp"
#include "Renderer/TextureSamplerDescriptor.hpp"

#include <map>
Expand Down
Loading