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
|
|
|
|
DisplayError( nullptr, errorMsg );
|
|
|
|
}
|
2016-05-02 13:56:14 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|