The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #if defined (__JUCE_OPENGL_JUCEHEADER__) && ! JUCE_AMALGAMATED_INCLUDE
  19. /* When you add this cpp file to your project, you mustn't include it in a file where you've
  20. already included any other headers - just put it inside a file on its own, possibly with your config
  21. flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
  22. header files that the compiler may be using.
  23. */
  24. #error "Incorrect use of JUCE cpp file"
  25. #endif
  26. // Your project must contain an AppConfig.h file with your project-specific settings in it,
  27. // and your header search path must make it accessible to the module's files.
  28. #include "AppConfig.h"
  29. #include "../juce_core/native/juce_BasicNativeHeaders.h"
  30. #include "juce_opengl.h"
  31. //==============================================================================
  32. #if JUCE_IOS
  33. #import <QuartzCore/QuartzCore.h>
  34. //==============================================================================
  35. #elif JUCE_WINDOWS
  36. #include <windowsx.h>
  37. #if JUCE_MSVC && ! JUCE_DONT_AUTOLINK_TO_WIN32_LIBRARIES
  38. #pragma comment(lib, "OpenGL32.Lib")
  39. #endif
  40. //==============================================================================
  41. #elif JUCE_LINUX
  42. /* Got an include error here?
  43. If you want to install OpenGL support, the packages to get are "mesa-common-dev"
  44. and "freeglut3-dev".
  45. */
  46. #include <GL/glx.h>
  47. //==============================================================================
  48. #elif JUCE_MAC
  49. #include <OpenGL/CGLCurrent.h> // These are both just needed with the 10.5 SDK
  50. #include <OpenGL/OpenGL.h>
  51. //==============================================================================
  52. #elif JUCE_ANDROID
  53. #ifndef GL_GLEXT_PROTOTYPES
  54. #define GL_GLEXT_PROTOTYPES 1
  55. #endif
  56. #include <GLES2/gl2.h>
  57. #endif
  58. namespace juce
  59. {
  60. //==============================================================================
  61. #include "native/juce_MissingGLDefinitions.h"
  62. #include "native/juce_OpenGLExtensions.h"
  63. void OpenGLExtensionFunctions::initialise()
  64. {
  65. #if JUCE_WINDOWS || JUCE_LINUX
  66. #define JUCE_INIT_GL_FUNCTION(name, returnType, params, callparams) \
  67. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (#name);
  68. #define JUCE_INIT_GL_FUNCTION_EXT(name, returnType, params, callparams) \
  69. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (#name); \
  70. if (name == nullptr) \
  71. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (JUCE_STRINGIFY (name ## EXT));
  72. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_INIT_GL_FUNCTION, JUCE_INIT_GL_FUNCTION_EXT)
  73. #undef JUCE_INIT_GL_FUNCTION
  74. #undef JUCE_INIT_GL_FUNCTION_EXT
  75. #endif
  76. }
  77. #if JUCE_OPENGL_ES
  78. #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) \
  79. inline returnType OpenGLExtensionFunctions::name params { return ::name callparams; }
  80. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION)
  81. #undef JUCE_DECLARE_GL_FUNCTION
  82. #endif
  83. #undef JUCE_GL_EXTENSION_FUNCTIONS
  84. #if JUCE_OPENGL_ES
  85. #define JUCE_MEDIUMP "mediump"
  86. #define JUCE_HIGHP "highp"
  87. #else
  88. #define JUCE_MEDIUMP
  89. #define JUCE_HIGHP
  90. #endif
  91. #if JUCE_DEBUG && ! defined (JUCE_CHECK_OPENGL_ERROR)
  92. static const char* getGLErrorMessage (const GLenum e)
  93. {
  94. switch (e)
  95. {
  96. case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
  97. case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
  98. case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
  99. #ifdef GL_STACK_OVERFLOW
  100. case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
  101. #endif
  102. #ifdef GL_STACK_UNDERFLOW
  103. case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
  104. #endif
  105. case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
  106. default: break;
  107. }
  108. return "Unknown error";
  109. }
  110. static void checkGLError (const char* file, const int line)
  111. {
  112. for (;;)
  113. {
  114. const GLenum e = glGetError();
  115. if (e == GL_NO_ERROR)
  116. break;
  117. DBG ("***** " << getGLErrorMessage (e) << " at " << file << " : " << line);
  118. jassertfalse;
  119. }
  120. }
  121. #define JUCE_CHECK_OPENGL_ERROR checkGLError (__FILE__, __LINE__);
  122. #else
  123. #define JUCE_CHECK_OPENGL_ERROR ;
  124. #endif
  125. static void clearGLError()
  126. {
  127. while (glGetError() != GL_NO_ERROR) {}
  128. }
  129. //==============================================================================
  130. #include "opengl/juce_OpenGLFrameBuffer.cpp"
  131. #include "opengl/juce_OpenGLGraphicsContext.cpp"
  132. #include "opengl/juce_OpenGLHelpers.cpp"
  133. #include "opengl/juce_OpenGLImage.cpp"
  134. #include "opengl/juce_OpenGLPixelFormat.cpp"
  135. #include "opengl/juce_OpenGLShaderProgram.cpp"
  136. #include "opengl/juce_OpenGLTexture.cpp"
  137. //==============================================================================
  138. #if JUCE_MAC || JUCE_IOS
  139. #include "../juce_core/native/juce_osx_ObjCHelpers.h"
  140. #include "../juce_graphics/native/juce_mac_CoreGraphicsHelpers.h"
  141. #if JUCE_MAC
  142. #include "native/juce_OpenGL_osx.h"
  143. #else
  144. #include "native/juce_OpenGL_ios.h"
  145. #endif
  146. #elif JUCE_WINDOWS
  147. #include "native/juce_OpenGL_win32.h"
  148. #elif JUCE_LINUX
  149. #include "native/juce_OpenGL_linux.h"
  150. #elif JUCE_ANDROID
  151. #include "../juce_core/native/juce_android_JNIHelpers.h"
  152. #include "native/juce_OpenGL_android.h"
  153. #endif
  154. #include "opengl/juce_OpenGLContext.cpp"
  155. }