Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d1321ad

Browse files
committedMay 12, 2024·
CHECK_GL_ERROR additions
1 parent f60cd86 commit d1321ad

12 files changed

+157
-52
lines changed
 

‎src/libprojectM/Renderer/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ add_custom_command(OUTPUT
3131
add_library(Renderer OBJECT
3232
${CMAKE_CURRENT_BINARY_DIR}/BuiltInTransitionsResources.hpp
3333
BuiltInTransitionsResources.hpp.in
34+
Debug.cpp
35+
Debug.hpp
3436
CopyTexture.cpp
3537
CopyTexture.hpp
3638
FileScanner.cpp

‎src/libprojectM/Renderer/Debug.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "Debug.hpp"
2+
3+
4+
namespace libprojectM::Renderer {
5+
6+
void check_gl_error(const char* file, int line)
7+
{
8+
GLenum err(glGetError());
9+
10+
while (err != GL_NO_ERROR)
11+
{
12+
std::string error;
13+
14+
switch (err)
15+
{
16+
case GL_INVALID_OPERATION:
17+
error = "INVALID_OPERATION";
18+
break;
19+
case GL_INVALID_ENUM:
20+
error = "INVALID_ENUM";
21+
break;
22+
case GL_INVALID_VALUE:
23+
error = "INVALID_VALUE";
24+
break;
25+
case GL_OUT_OF_MEMORY:
26+
error = "OUT_OF_MEMORY";
27+
break;
28+
case GL_INVALID_FRAMEBUFFER_OPERATION:
29+
error = "INVALID_FRAMEBUFFER_OPERATION";
30+
break;
31+
}
32+
33+
std::cerr << "GL_" << error.c_str() << " - " << file << ":" << line << std::endl;
34+
err = glGetError();
35+
}
36+
}
37+
38+
} // namespace libprojectM::Renderer

‎src/libprojectM/Renderer/Debug.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#pragma once
3+
4+
#include <iostream>
5+
#include <projectM-opengl.h>
6+
7+
#define CHECK_GL_ERROR check_gl_error(__FILE__, __LINE__)
8+
9+
10+
namespace libprojectM::Renderer {
11+
12+
void check_gl_error(const char* file, int line);
13+
14+
} // namespace libprojectM::Renderer

‎src/libprojectM/Renderer/MilkdropNoise.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "MilkdropNoise.hpp"
22

3+
#include "Debug.hpp"
34
#include "projectM-opengl.h"
45

56
#include <chrono>
@@ -22,6 +23,7 @@ auto MilkdropNoise::LowQuality() -> std::shared_ptr<Texture>
2223
glGenTextures(1, &texture);
2324
glBindTexture(GL_TEXTURE_2D, texture);
2425
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
26+
CHECK_GL_ERROR;
2527
}
2628
return std::make_shared<Texture>("noise_lq", texture, GL_TEXTURE_2D, 256, 256, false);
2729
}
@@ -36,6 +38,7 @@ auto MilkdropNoise::LowQualityLite() -> std::shared_ptr<Texture>
3638
glGenTextures(1, &texture);
3739
glBindTexture(GL_TEXTURE_2D, texture);
3840
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
41+
CHECK_GL_ERROR;
3942
}
4043

4144
return std::make_shared<Texture>("noise_lq_lite", texture, GL_TEXTURE_2D, 32, 32, false);
@@ -51,6 +54,7 @@ auto MilkdropNoise::MediumQuality() -> std::shared_ptr<Texture>
5154
glGenTextures(1, &texture);
5255
glBindTexture(GL_TEXTURE_2D, texture);
5356
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
57+
CHECK_GL_ERROR;
5458
}
5559
return std::make_shared<Texture>("noise_mq", texture, GL_TEXTURE_2D, 256, 256, false);
5660
}
@@ -65,6 +69,7 @@ auto MilkdropNoise::HighQuality() -> std::shared_ptr<Texture>
6569
glGenTextures(1, &texture);
6670
glBindTexture(GL_TEXTURE_2D, texture);
6771
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
72+
CHECK_GL_ERROR;
6873
}
6974

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

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

100107
return std::make_shared<Texture>("noisevol_hq", texture, GL_TEXTURE_3D, 32, 32, false);
@@ -106,7 +113,9 @@ auto MilkdropNoise::GetPreferredInternalFormat() -> int
106113
// Query preferred internal texture format. GLES 3 only supports GL_RENDERBUFFER here, no texture targets.
107114
// That's why we use GL_BGRA as default, as this is the best general-use format according to Khronos.
108115
GLint preferredInternalFormat{GL_BGRA};
116+
CHECK_GL_ERROR;
109117
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_TEXTURE_IMAGE_FORMAT, sizeof(preferredInternalFormat), &preferredInternalFormat);
118+
CHECK_GL_ERROR;
110119
#else
111120
// GLES only supports GL_RGB and GL_RGBA, so we always use the latter.
112121
GLint preferredInternalFormat{GL_RGBA};

‎src/libprojectM/Renderer/MilkdropNoise.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <Renderer/Debug.hpp>
34
#include <Renderer/Texture.hpp>
45

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

6869
protected:
69-
7070
static auto GetPreferredInternalFormat() -> int;
7171

7272
/**

‎src/libprojectM/Renderer/PresetTransition.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "PresetTransition.hpp"
22

3+
#include "Debug.hpp"
34
#include "TextureManager.hpp"
45

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

2122
RenderItem::Init();
23+
CHECK_GL_ERROR;
2224
}
2325

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

3639
auto PresetTransition::IsDone() const -> bool
@@ -69,6 +72,7 @@ void PresetTransition::Draw(const Preset& oldPreset,
6972
}
7073

7174
m_transitionShader->Bind();
75+
CHECK_GL_ERROR;
7276

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

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

121127
// Clean up
122128
oldPreset.OutputTexture()->Unbind(0);
123129
newPreset.OutputTexture()->Unbind(1);
130+
CHECK_GL_ERROR;
124131

125132
for (int i = 2; i < textureUnit; i++)
126133
{
127134
noiseDescriptors[i - 2].Unbind(textureUnit);
128135
}
129136

130137
Shader::Unbind();
138+
CHECK_GL_ERROR;
131139

132140
// Update last frame time.
133141
m_lastFrameTime = std::chrono::system_clock::now();

‎src/libprojectM/Renderer/PresetTransition.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Renderer/RenderItem.hpp"
44
#include "Renderer/Shader.hpp"
55
#include "Renderer/TextureSamplerDescriptor.hpp"
6+
#include <Renderer/Debug.hpp>
67

78
#include <Preset.hpp>
89

‎src/libprojectM/Renderer/Texture.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ Texture::~Texture()
5454

5555
void Texture::Bind(GLint slot, const Sampler::Ptr& sampler) const
5656
{
57+
std::cout << "Texture::Bind" << std::endl;
5758
glActiveTexture(GL_TEXTURE0 + slot);
59+
CHECK_GL_ERROR;
5860
glBindTexture(m_target, m_textureId);
61+
CHECK_GL_ERROR;
5962

6063
if (sampler)
6164
{

‎src/libprojectM/Renderer/Texture.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
*/
55
#pragma once
66

7+
#include "Renderer/Debug.hpp"
78
#include "Renderer/Sampler.hpp"
89

10+
#include <iostream>
911
#include <string>
1012

1113
namespace libprojectM {

‎src/libprojectM/Renderer/TextureManager.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "TextureManager.hpp"
22

3+
#include "Debug.hpp"
34
#include "FileScanner.hpp"
45
#include "IdleTextures.hpp"
56
#include "MilkdropNoise.hpp"
@@ -79,16 +80,19 @@ void TextureManager::Preload()
7980
SOIL_CREATE_NEW_ID,
8081
SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
8182

82-
m_textures["idlem"] = std::make_shared<Texture>("idlem", tex, GL_TEXTURE_2D, width, height, false);;
83+
m_textures["idlem"] = std::make_shared<Texture>("idlem", tex, GL_TEXTURE_2D, width, height, false);
84+
;
8385

8486
tex = SOIL_load_OGL_texture_from_memory(
8587
headphones_data,
8688
headphones_bytes,
8789
SOIL_LOAD_AUTO,
8890
SOIL_CREATE_NEW_ID,
8991
SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
92+
CHECK_GL_ERROR;
9093

91-
m_textures["idleheadphones"] = std::make_shared<Texture>("idleheadphones", tex, GL_TEXTURE_2D, width, height, false);;
94+
m_textures["idleheadphones"] = std::make_shared<Texture>("idleheadphones", tex, GL_TEXTURE_2D, width, height, false);
95+
;
9296

9397
// Noise textures
9498
m_textures["noise_lq_lite"] = MilkdropNoise::LowQualityLite();
@@ -224,6 +228,7 @@ auto TextureManager::LoadTexture(const std::string& fileName, const std::string&
224228
SOIL_LOAD_RGBA,
225229
SOIL_CREATE_NEW_ID,
226230
SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
231+
CHECK_GL_ERROR;
227232

228233
if (tex == 0)
229234
{

‎src/libprojectM/Renderer/TextureManager.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "Renderer/Debug.hpp"
34
#include "Renderer/TextureSamplerDescriptor.hpp"
45

56
#include <map>

0 commit comments

Comments
 (0)
Please sign in to comment.