PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/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. #include "internal.h"
  30. //////////////////////////////////////////////////////////////////////////
  31. ////// GLFW internal API //////
  32. //////////////////////////////////////////////////////////////////////////
  33. //========================================================================
  34. // The current error value and callback
  35. // These are not in _glfwLibrary since they need to be initialized and
  36. // accessible before glfwInit so it can report errors
  37. //========================================================================
  38. static int _glfwError = GLFW_NO_ERROR;
  39. static GLFWerrorfun _glfwErrorCallback = NULL;
  40. //========================================================================
  41. // Sets the current error value
  42. // This function may be called without GLFW having been initialized
  43. //========================================================================
  44. void _glfwSetError(int error, const char* description)
  45. {
  46. if (_glfwErrorCallback)
  47. {
  48. if (!description)
  49. description = glfwErrorString(error);
  50. _glfwErrorCallback(error, description);
  51. }
  52. else
  53. _glfwError = error;
  54. }
  55. //////////////////////////////////////////////////////////////////////////
  56. ////// GLFW public API //////
  57. //////////////////////////////////////////////////////////////////////////
  58. //========================================================================
  59. // Returns the current error value
  60. // This function may be called without GLFW having been initialized
  61. //========================================================================
  62. GLFWAPI int glfwGetError(void)
  63. {
  64. int error = _glfwError;
  65. _glfwError = GLFW_NO_ERROR;
  66. return error;
  67. }
  68. //========================================================================
  69. // Returns a string representation of the specified error value
  70. // This function may be called without GLFW having been initialized
  71. //========================================================================
  72. GLFWAPI const char* glfwErrorString(int error)
  73. {
  74. switch (error)
  75. {
  76. case GLFW_NO_ERROR:
  77. return "No error";
  78. case GLFW_NOT_INITIALIZED:
  79. return "The GLFW library is not initialized";
  80. case GLFW_NO_CURRENT_WINDOW:
  81. return "There is no current GLFW window";
  82. case GLFW_INVALID_ENUM:
  83. return "Invalid argument for enum parameter";
  84. case GLFW_INVALID_VALUE:
  85. return "Invalid value for parameter";
  86. case GLFW_OUT_OF_MEMORY:
  87. return "Out of memory";
  88. case GLFW_OPENGL_UNAVAILABLE:
  89. return "OpenGL is not available on this machine";
  90. case GLFW_VERSION_UNAVAILABLE:
  91. return "The requested OpenGL version is unavailable";
  92. case GLFW_PLATFORM_ERROR:
  93. return "A platform-specific error occurred";
  94. case GLFW_WINDOW_NOT_ACTIVE:
  95. return "The specified window is not active";
  96. }
  97. return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
  98. }
  99. //========================================================================
  100. // Sets the callback function for GLFW errors
  101. //========================================================================
  102. GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun)
  103. {
  104. _glfwErrorCallback = cbfun;
  105. }