2016-05-02 13:56:14 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-13 15:46:02 +00:00
|
|
|
* Copyright (C) 2016-2017 CERN
|
2016-05-02 13:56:14 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2017-01-13 15:46:02 +00:00
|
|
|
#include <confirm.h> // DisplayError
|
2016-05-02 13:56:14 +00:00
|
|
|
|
2016-05-02 14:12:14 +00:00
|
|
|
#include <GL/glew.h>
|
2017-01-13 16:15:32 +00:00
|
|
|
#include <stdexcept>
|
2016-05-02 13:56:14 +00:00
|
|
|
|
2017-01-13 15:46:02 +00:00
|
|
|
int checkGlError( const std::string& aInfo, bool aThrow )
|
2016-05-02 13:56:14 +00:00
|
|
|
{
|
|
|
|
int result = glGetError();
|
2017-01-13 15:46:02 +00:00
|
|
|
wxString errorMsg;
|
2016-05-02 13:56:14 +00:00
|
|
|
|
|
|
|
switch( result )
|
|
|
|
{
|
|
|
|
case GL_NO_ERROR:
|
|
|
|
// all good
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_INVALID_ENUM:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_INVALID_VALUE:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: invalid value", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_INVALID_OPERATION:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_OUT_OF_MEMORY:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: out of memory", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_STACK_UNDERFLOW:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_STACK_OVERFLOW:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-01-13 15:46:02 +00:00
|
|
|
errorMsg = wxString::Format( "Error: %s: unknown error", aInfo );
|
2016-05-02 13:56:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-13 15:46:02 +00:00
|
|
|
if( result != GL_NO_ERROR )
|
|
|
|
{
|
|
|
|
if( aThrow )
|
2017-01-13 21:48:26 +00:00
|
|
|
throw std::runtime_error( (const char*) errorMsg.char_str() );
|
2017-01-13 15:46:02 +00:00
|
|
|
else
|
2017-08-01 11:12:59 +00:00
|
|
|
DisplayErrorMessage( nullptr, "OpenGL error occurred", errorMsg );
|
2017-01-13 15:46:02 +00:00
|
|
|
}
|
2016-05-02 13:56:14 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-08-04 08:07:39 +00:00
|
|
|
|
2017-08-09 12:04:46 +00:00
|
|
|
// debugMsgCallback is a callback function for glDebugMessageCallback.
|
2017-08-09 13:30:01 +00:00
|
|
|
// It must have the right type ( GLAPIENTRY )
|
|
|
|
static void GLAPIENTRY debugMsgCallback( GLenum aSource, GLenum aType, GLuint aId,
|
2017-08-09 12:04:46 +00:00
|
|
|
GLenum aSeverity, GLsizei aLength, const GLchar* aMessage, const void* aUserParam )
|
2017-08-04 08:07:39 +00:00
|
|
|
{
|
2018-02-09 15:19:25 +00:00
|
|
|
switch( aSeverity )
|
|
|
|
{
|
|
|
|
case GL_DEBUG_SEVERITY_HIGH: printf( "OpenGL ERROR: " ); break;
|
|
|
|
case GL_DEBUG_SEVERITY_MEDIUM: printf( "OpenGL WARNING: " ); break;
|
|
|
|
case GL_DEBUG_SEVERITY_LOW: printf( "OpenGL INFO: " ); break;
|
|
|
|
case GL_DEBUG_SEVERITY_NOTIFICATION: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf( "%s\n", aMessage );
|
2017-08-04 08:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void enableGlDebug( bool aEnable )
|
|
|
|
{
|
|
|
|
if( aEnable )
|
|
|
|
{
|
|
|
|
glEnable( GL_DEBUG_OUTPUT );
|
2017-08-08 13:26:50 +00:00
|
|
|
glDebugMessageCallback( (GLDEBUGPROC) debugMsgCallback, nullptr );
|
2017-08-04 08:07:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable( GL_DEBUG_OUTPUT );
|
|
|
|
}
|
|
|
|
}
|