KiCad PCB EDA Suite
utils.h File Reference
#include <string>

Go to the source code of this file.

Functions

int checkGlError (const std::string &aInfo, const char *aFile, int aLine, bool aThrow=true)
 Check if a recent OpenGL operation has failed. More...
 
void enableGlDebug (bool aEnable)
 Enable or disable OpenGL driver messages output. More...
 

Function Documentation

◆ checkGlError()

int checkGlError ( const std::string &  aInfo,
const char *  aFile,
int  aLine,
bool  aThrow = true 
)

Check if a recent OpenGL operation has failed.

If so, display the appropriate message starting with aInfo string to give more details.

Parameters
aInfois the beginning of the error message.
aFileis the file where the error occurred defined by the C FILE variable.
aLineis the line in aFile where the error occurred defined by the C LINE variable.
aThrowan exception is thrown when true, otherwise only an error message is displayed.
Returns
GL_NO_ERROR in case of no errors or one of GL_ constants returned by glGetError().

Definition at line 45 of file utils.cpp.

46{
47 int result = glGetError();
48 wxString errorMsg;
49
50 switch( result )
51 {
52 case GL_NO_ERROR:
53 // all good
54 break;
55
56 case GL_INVALID_ENUM:
57 errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo );
58 break;
59
60 case GL_INVALID_VALUE:
61 errorMsg = wxString::Format( "Error: %s: invalid value", aInfo );
62 break;
63
64 case GL_INVALID_OPERATION:
65 errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo );
66 break;
67
68 case GL_INVALID_FRAMEBUFFER_OPERATION:
69 {
70 GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
71
72 if( status != GL_FRAMEBUFFER_COMPLETE_EXT )
73 {
74 switch( status )
75 {
76 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
77 errorMsg = "The framebuffer attachment points are incomplete.";
78 break;
79
80 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
81 errorMsg = "No images attached to the framebuffer.";
82 break;
83
84 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
85 errorMsg = "The framebuffer does not have at least one image attached to it.";
86 break;
87
88 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
89 errorMsg = "The framebuffer read buffer is incomplete.";
90 break;
91
92 case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
93 errorMsg = "The combination of internal formats of the attached images violates "
94 "an implementation dependent set of restrictions.";
95 break;
96
97 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
98 errorMsg = "GL_RENDERBUFFER_SAMPLES is not the same for all attached render "
99 "buffers.";
100 break;
101
102 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT:
103 errorMsg = "Framebuffer incomplete layer targets errors.";
104 break;
105
106 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
107 errorMsg = "Framebuffer attachments have different dimensions";
108 break;
109
110 default:
111 errorMsg.Printf( "Unknown incomplete framebuffer error id %X", status );
112 }
113 }
114 else
115 {
116 errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo );
117 }
118 }
119 break;
120
121 case GL_OUT_OF_MEMORY:
122 errorMsg = wxString::Format( "Error: %s: out of memory", aInfo );
123 break;
124
125 case GL_STACK_UNDERFLOW:
126 errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo );
127 break;
128
129 case GL_STACK_OVERFLOW:
130 errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo );
131 break;
132
133 default:
134 errorMsg = wxString::Format( "Error: %s: unknown error", aInfo );
135 break;
136 }
137
138 if( result != GL_NO_ERROR )
139 {
140 if( aThrow )
141 {
142 wxLogTrace( traceGalOpenGlError, wxT( "Throwing exception for glGetError() '%s' "
143 "in file '%s' on line %d." ),
144 errorMsg,
145 aFile,
146 aLine );
147
148 throw std::runtime_error( (const char*) errorMsg.char_str() );
149 }
150 else
151 {
152 wxString msg = wxString::Format( wxT( "glGetError() '%s' in file '%s' on line %d." ),
153 errorMsg,
154 aFile,
155 aLine );
156
157 DisplayErrorMessage( nullptr, "OpenGL Error", errorMsg );
158 }
159 }
160
161 return result;
162}
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
static const wxChar *const traceGalOpenGlError
Flag to enable debug output of the GAL OpenGL error checking.
Definition: utils.cpp:42
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References DisplayErrorMessage(), Format(), and traceGalOpenGlError.

Referenced by KIGFX::OPENGL_GAL::BeginDrawing(), KIGFX::OPENGL_COMPOSITOR::bindFb(), KIGFX::CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU(), KIGFX::CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM(), KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), KIGFX::CACHED_CONTAINER_GPU::defragmentResize(), KIGFX::CACHED_CONTAINER_GPU::defragmentResizeMemcpy(), KIGFX::OPENGL_COMPOSITOR::Initialize(), KIGFX::ANTIALIASING_SMAA::loadShaders(), KIGFX::CACHED_CONTAINER_GPU::Map(), KIGFX::ANTIALIASING_SMAA::Present(), KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::CACHED_CONTAINER_GPU::Unmap(), KIGFX::CACHED_CONTAINER_RAM::Unmap(), and KIGFX::ANTIALIASING_SMAA::updateUniforms().

◆ enableGlDebug()

void enableGlDebug ( bool  aEnable)

Enable or disable OpenGL driver messages output.

Parameters
aEnabledecides whether the message should be shown.

Definition at line 183 of file utils.cpp.

184{
185 if( aEnable )
186 {
187 glEnable( GL_DEBUG_OUTPUT );
188 glDebugMessageCallback( (GLDEBUGPROC) debugMsgCallback, nullptr );
189 }
190 else
191 {
192 glDisable( GL_DEBUG_OUTPUT );
193 }
194}
static void GLAPIENTRY debugMsgCallback(GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, GLsizei aLength, const GLchar *aMessage, const void *aUserParam)
Definition: utils.cpp:167

References debugMsgCallback().

Referenced by KIGFX::OPENGL_GAL::init().