Skip to content

Commit 9af911e

Browse files
committed
Cleanup OpenGL3 use, log shader compilation errors
1 parent a5ea01f commit 9af911e

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

dgl/src/OpenGL3.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
#include "../Color.hpp"
2424
#include "../ImageWidgets.hpp"
2525

26-
// #include "SubWidgetPrivateData.hpp"
27-
// #include "TopLevelWidgetPrivateData.hpp"
28-
// #include "WidgetPrivateData.hpp"
2926
#include "WindowPrivateData.hpp"
3027

3128
// templated classes
@@ -100,6 +97,8 @@ void Line<T>::draw(const GraphicsContext& context, const T width)
10097

10198
const GLubyte order[] = { 0, 1 };
10299
glDrawElements(GL_LINES, ARRAY_SIZE(order), GL_UNSIGNED_BYTE, order);
100+
101+
glDisableVertexAttribArray(gl3context.pos);
103102
}
104103

105104
#ifdef DGL_ALLOW_DEPRECATED_METHODS
@@ -182,6 +181,8 @@ static void drawCircle(const GraphicsContext& context,
182181

183182
glDrawElements(GL_TRIANGLES, numSegments * 3, GL_UNSIGNED_SHORT, order);
184183
}
184+
185+
glDisableVertexAttribArray(gl3context.pos);
185186
}
186187

187188
template<typename T>
@@ -253,6 +254,8 @@ static void drawTriangle(const GraphicsContext& context,
253254
{
254255
glDrawArrays(GL_TRIANGLES, 0, 3);
255256
}
257+
258+
glDisableVertexAttribArray(gl3context.pos);
256259
}
257260

258261
template<typename T>
@@ -319,6 +322,8 @@ static void drawRectangle(const GraphicsContext& context, const Rectangle<T>& re
319322
const GLubyte order[] = { 0, 1, 2, 0, 2, 3 };
320323
glDrawElements(GL_TRIANGLES, ARRAY_SIZE(order), GL_UNSIGNED_BYTE, order);
321324
}
325+
326+
glDisableVertexAttribArray(gl3context.pos);
322327
}
323328

324329
template<typename T>
@@ -463,6 +468,8 @@ void OpenGLImage::drawAt(const GraphicsContext& context, const Point<int>& pos)
463468
const GLubyte order[] = { 0, 1, 2, 0, 2, 3 };
464469
glDrawElements(GL_TRIANGLES, ARRAY_SIZE(order), GL_UNSIGNED_BYTE, order);
465470

471+
glDisableVertexAttribArray(gl3context.tex);
472+
glDisableVertexAttribArray(gl3context.pos);
466473
glUniform1i(gl3context.texok, 0);
467474
glBindTexture(GL_TEXTURE_2D, 0);
468475
}
@@ -614,8 +621,19 @@ template class ImageBaseSwitch<OpenGLImage>;
614621

615622
// --------------------------------------------------------------------------------------------------------------------
616623

617-
static const GraphicsContext& contextCreationFail(const OpenGL3GraphicsContext& gl3context)
624+
static const GraphicsContext& contextCreationFail(const OpenGL3GraphicsContext& gl3context, GLuint shaderErr = 0)
618625
{
626+
if (shaderErr != 0)
627+
{
628+
GLint len = 0;
629+
glGetShaderiv(shaderErr, GL_INFO_LOG_LENGTH, &len);
630+
631+
std::vector<GLchar> errorLog(len);
632+
glGetShaderInfoLog(shaderErr, len, &len, errorLog.data());
633+
634+
d_stderr2("OpenGL3 shader compilation error: %s", errorLog.data());
635+
}
636+
619637
gl3context.prog = -1;
620638
return gl3context;
621639
}
@@ -665,7 +683,7 @@ const GraphicsContext& Window::PrivateData::getGraphicsContext() const noexcept
665683
glCompileShader(fragment);
666684

667685
glGetShaderiv(fragment, GL_COMPILE_STATUS, &status);
668-
DISTRHO_SAFE_ASSERT_RETURN(status != 0, contextCreationFail(gl3context));
686+
DISTRHO_SAFE_ASSERT_RETURN(status != 0, contextCreationFail(gl3context, fragment));
669687
}
670688

671689
{
@@ -679,7 +697,7 @@ const GraphicsContext& Window::PrivateData::getGraphicsContext() const noexcept
679697
glCompileShader(vertex);
680698

681699
glGetShaderiv(vertex, GL_COMPILE_STATUS, &status);
682-
DISTRHO_SAFE_ASSERT_RETURN(status != 0, contextCreationFail(gl3context));
700+
DISTRHO_SAFE_ASSERT_RETURN(status != 0, contextCreationFail(gl3context, vertex));
683701
}
684702

685703
glAttachShader(program, fragment);

distrho/src/jackbridge/JackBridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JackBridge for DPF
3-
* Copyright (C) 2013-2024 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2013-2025 Filipe Coelho <falktx@falktx.com>
44
*
55
* Permission to use, copy, modify, and/or distribute this software for any purpose with
66
* or without fee is hereby granted, provided that the above copyright notice and this

0 commit comments

Comments
 (0)