PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 3ms app.codeStats 1ms

/libs/glfw/src/error.c

https://github.com/Queatz/pygrafix
C | 126 lines | 51 code | 21 blank | 54 comment | 3 complexity | 41bc043bd8072309d5d303122e7a038e MD5 | raw file
  1//========================================================================
  2// GLFW - An OpenGL library
  3// Platform:    All
  4// API version: 3.0
  5// WWW:         http://www.glfw.org/
  6//------------------------------------------------------------------------
  7// Copyright (c) 2008-2010 Camilla Berglund <elmindreda@elmindreda.org>
  8//
  9// This software is provided 'as-is', without any express or implied
 10// warranty. In no event will the authors be held liable for any damages
 11// arising from the use of this software.
 12//
 13// Permission is granted to anyone to use this software for any purpose,
 14// including commercial applications, and to alter it and redistribute it
 15// freely, subject to the following restrictions:
 16//
 17// 1. The origin of this software must not be misrepresented; you must not
 18//    claim that you wrote the original software. If you use this software
 19//    in a product, an acknowledgment in the product documentation would
 20//    be appreciated but is not required.
 21//
 22// 2. Altered source versions must be plainly marked as such, and must not
 23//    be misrepresented as being the original software.
 24//
 25// 3. This notice may not be removed or altered from any source
 26//    distribution.
 27//
 28//========================================================================
 29
 30#include "internal.h"
 31
 32
 33//////////////////////////////////////////////////////////////////////////
 34//////                       GLFW internal API                      //////
 35//////////////////////////////////////////////////////////////////////////
 36
 37//========================================================================
 38// The current error value and callback
 39// These are not in _glfwLibrary since they need to be initialized and
 40// accessible before glfwInit so it can report errors
 41//========================================================================
 42
 43static int _glfwError = GLFW_NO_ERROR;
 44static GLFWerrorfun _glfwErrorCallback = NULL;
 45
 46
 47//========================================================================
 48// Sets the current error value
 49// This function may be called without GLFW having been initialized
 50//========================================================================
 51
 52void _glfwSetError(int error, const char* description)
 53{
 54    if (_glfwErrorCallback)
 55    {
 56        if (!description)
 57            description = glfwErrorString(error);
 58
 59        _glfwErrorCallback(error, description);
 60    }
 61    else
 62        _glfwError = error;
 63}
 64
 65
 66//////////////////////////////////////////////////////////////////////////
 67//////                        GLFW public API                       //////
 68//////////////////////////////////////////////////////////////////////////
 69
 70//========================================================================
 71// Returns the current error value
 72// This function may be called without GLFW having been initialized
 73//========================================================================
 74
 75GLFWAPI int glfwGetError(void)
 76{
 77    int error = _glfwError;
 78    _glfwError = GLFW_NO_ERROR;
 79    return error;
 80}
 81
 82
 83//========================================================================
 84// Returns a string representation of the specified error value
 85// This function may be called without GLFW having been initialized
 86//========================================================================
 87
 88GLFWAPI const char* glfwErrorString(int error)
 89{
 90    switch (error)
 91    {
 92        case GLFW_NO_ERROR:
 93            return "No error";
 94        case GLFW_NOT_INITIALIZED:
 95            return "The GLFW library is not initialized";
 96        case GLFW_NO_CURRENT_WINDOW:
 97            return "There is no current GLFW window";
 98        case GLFW_INVALID_ENUM:
 99            return "Invalid argument for enum parameter";
100        case GLFW_INVALID_VALUE:
101            return "Invalid value for parameter";
102        case GLFW_OUT_OF_MEMORY:
103            return "Out of memory";
104        case GLFW_OPENGL_UNAVAILABLE:
105            return "OpenGL is not available on this machine";
106        case GLFW_VERSION_UNAVAILABLE:
107            return "The requested OpenGL version is unavailable";
108        case GLFW_PLATFORM_ERROR:
109            return "A platform-specific error occurred";
110        case GLFW_WINDOW_NOT_ACTIVE:
111            return "The specified window is not active";
112    }
113
114    return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
115}
116
117
118//========================================================================
119// Sets the callback function for GLFW errors
120//========================================================================
121
122GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun)
123{
124    _glfwErrorCallback = cbfun;
125}
126