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, bool aThrow=true)
 Checks if one of recent OpenGL operations has failed. More...
 
void enableGlDebug (bool aEnable)
 Enables/disables OpenGL driver messages output. More...
 

Function Documentation

int checkGlError ( const std::string &  aInfo,
bool  aThrow = true 
)

Checks if one of recent OpenGL operations has failed.

If so, it displays appropriate message, starting with aInfo string to give more details.

Parameters
aInfois the beginning of the error message.
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 30 of file utils.cpp.

References DisplayErrorMessage(), and Format().

Referenced by KIGFX::GPU_CACHED_MANAGER::BeginDrawing(), 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::ANTIALIASING_SUPERSAMPLING::Init(), KIGFX::OPENGL_COMPOSITOR::Initialize(), KIGFX::ANTIALIASING_SMAA::loadShaders(), KIGFX::CACHED_CONTAINER_GPU::Map(), KIGFX::ANTIALIASING_SUPERSAMPLING::Present(), KIGFX::ANTIALIASING_SMAA::Present(), KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::CACHED_CONTAINER_RAM::Unmap(), KIGFX::CACHED_CONTAINER_GPU::Unmap(), and KIGFX::ANTIALIASING_SMAA::updateUniforms().

31 {
32  int result = glGetError();
33  wxString errorMsg;
34 
35  switch( result )
36  {
37  case GL_NO_ERROR:
38  // all good
39  break;
40 
41  case GL_INVALID_ENUM:
42  errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo );
43  break;
44 
45  case GL_INVALID_VALUE:
46  errorMsg = wxString::Format( "Error: %s: invalid value", aInfo );
47  break;
48 
49  case GL_INVALID_OPERATION:
50  errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo );
51  break;
52 
53  case GL_INVALID_FRAMEBUFFER_OPERATION:
54  {
55  GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
56 
57  if( status != GL_FRAMEBUFFER_COMPLETE_EXT )
58  {
59  switch( status )
60  {
61  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
62  errorMsg = "The framebuffer attachment points are incomplete.";
63  break;
64  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
65  errorMsg = "No images attached to the framebuffer.";
66  break;
67  case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
68  errorMsg = "The framebuffer does not have at least one image attached to it.";
69  break;
70  case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
71  errorMsg = "The framebuffer read buffer is incomplete.";
72  break;
73  case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
74  errorMsg = "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions.";
75  break;
76  case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
77  errorMsg = "GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers.";
78  break;
79  case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT:
80  errorMsg = "Framebuffer incomplete layer targets errors.";
81  break;
82  case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
83  errorMsg = "Framebuffer attachments have different dimensions";
84  break;
85  default:
86  errorMsg = "Unknown incomplete framebufer error";
87  }
88  }
89  else
90  errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo );
91  }
92  break;
93 
94  case GL_OUT_OF_MEMORY:
95  errorMsg = wxString::Format( "Error: %s: out of memory", aInfo );
96  break;
97 
98  case GL_STACK_UNDERFLOW:
99  errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo );
100  break;
101 
102  case GL_STACK_OVERFLOW:
103  errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo );
104  break;
105 
106  default:
107  errorMsg = wxString::Format( "Error: %s: unknown error", aInfo );
108  break;
109  }
110 
111  if( result != GL_NO_ERROR )
112  {
113  if( aThrow )
114  throw std::runtime_error( (const char*) errorMsg.char_str() );
115  else
116  DisplayErrorMessage( nullptr, "OpenGL error occurred", errorMsg );
117  }
118 
119  return result;
120 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void enableGlDebug ( bool  aEnable)

Enables/disables OpenGL driver messages output.

Parameters
aEnabledecides whether the message should be shown.

Definition at line 140 of file utils.cpp.

References debugMsgCallback().

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

141 {
142  if( aEnable )
143  {
144  glEnable( GL_DEBUG_OUTPUT );
145  glDebugMessageCallback( (GLDEBUGPROC) debugMsgCallback, nullptr );
146  }
147  else
148  {
149  glDisable( GL_DEBUG_OUTPUT );
150  }
151 }
static void GLAPIENTRY debugMsgCallback(GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, GLsizei aLength, const GLchar *aMessage, const void *aUserParam)
Definition: utils.cpp:125