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.

222 lines
6.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifdef JUCE_OPENGL_H_INCLUDED
  18. /* When you add this cpp file to your project, you mustn't include it in a file where you've
  19. already included any other headers - just put it inside a file on its own, possibly with your config
  20. flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
  21. header files that the compiler may be using.
  22. */
  23. #error "Incorrect use of JUCE cpp file"
  24. #endif
  25. #define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
  26. #define JUCE_CORE_INCLUDE_JNI_HELPERS 1
  27. #define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1
  28. #define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1
  29. #include "juce_opengl.h"
  30. //==============================================================================
  31. #if JUCE_IOS
  32. #import <QuartzCore/QuartzCore.h>
  33. //==============================================================================
  34. #elif JUCE_WINDOWS
  35. #include <windowsx.h>
  36. #if JUCE_MSVC && ! JUCE_DONT_AUTOLINK_TO_WIN32_LIBRARIES
  37. #pragma comment(lib, "OpenGL32.Lib")
  38. #endif
  39. //==============================================================================
  40. #elif JUCE_LINUX
  41. /* Got an include error here?
  42. If you want to install OpenGL support, the packages to get are "mesa-common-dev"
  43. and "freeglut3-dev".
  44. */
  45. #include <GL/glx.h>
  46. //==============================================================================
  47. #elif JUCE_MAC
  48. #include <OpenGL/CGLCurrent.h> // These are both just needed with the 10.5 SDK
  49. #include <OpenGL/OpenGL.h>
  50. //==============================================================================
  51. #elif JUCE_ANDROID
  52. #ifndef GL_GLEXT_PROTOTYPES
  53. #define GL_GLEXT_PROTOTYPES 1
  54. #endif
  55. #include <GLES2/gl2.h>
  56. #endif
  57. namespace juce
  58. {
  59. //==============================================================================
  60. #include "native/juce_OpenGLExtensions.h"
  61. void OpenGLExtensionFunctions::initialise()
  62. {
  63. #if JUCE_WINDOWS || JUCE_LINUX
  64. #define JUCE_INIT_GL_FUNCTION(name, returnType, params, callparams) \
  65. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (#name);
  66. JUCE_GL_BASE_FUNCTIONS (JUCE_INIT_GL_FUNCTION)
  67. #undef JUCE_INIT_GL_FUNCTION
  68. #define JUCE_INIT_GL_FUNCTION(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)
  73. #if JUCE_OPENGL3
  74. JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_INIT_GL_FUNCTION)
  75. #endif
  76. #undef JUCE_INIT_GL_FUNCTION
  77. #endif
  78. }
  79. #if JUCE_OPENGL_ES
  80. #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) \
  81. returnType OpenGLExtensionFunctions::name params noexcept { return ::name callparams; }
  82. JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
  83. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
  84. #if JUCE_OPENGL3
  85. JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
  86. #endif
  87. #undef JUCE_DECLARE_GL_FUNCTION
  88. #endif
  89. #undef JUCE_GL_EXTENSION_FUNCTIONS
  90. #if JUCE_DEBUG && ! defined (JUCE_CHECK_OPENGL_ERROR)
  91. static const char* getGLErrorMessage (const GLenum e) noexcept
  92. {
  93. switch (e)
  94. {
  95. case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
  96. case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
  97. case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
  98. case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
  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. #ifdef GL_INVALID_FRAMEBUFFER_OPERATION
  106. case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
  107. #endif
  108. default: break;
  109. }
  110. return "Unknown error";
  111. }
  112. static void checkGLError (const char* file, const int line)
  113. {
  114. for (;;)
  115. {
  116. const GLenum e = glGetError();
  117. if (e == GL_NO_ERROR)
  118. break;
  119. DBG ("***** " << getGLErrorMessage (e) << " at " << file << " : " << line);
  120. jassertfalse;
  121. }
  122. }
  123. #define JUCE_CHECK_OPENGL_ERROR checkGLError (__FILE__, __LINE__);
  124. #else
  125. #define JUCE_CHECK_OPENGL_ERROR ;
  126. #endif
  127. static void clearGLError() noexcept
  128. {
  129. while (glGetError() != GL_NO_ERROR) {}
  130. }
  131. struct OpenGLTargetSaver
  132. {
  133. OpenGLTargetSaver (const OpenGLContext& c) noexcept
  134. : context (c), oldFramebuffer (OpenGLFrameBuffer::getCurrentFrameBufferTarget())
  135. {
  136. glGetIntegerv (GL_VIEWPORT, oldViewport);
  137. }
  138. ~OpenGLTargetSaver() noexcept
  139. {
  140. context.extensions.glBindFramebuffer (GL_FRAMEBUFFER, oldFramebuffer);
  141. glViewport (oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
  142. }
  143. private:
  144. const OpenGLContext& context;
  145. GLuint oldFramebuffer;
  146. GLint oldViewport[4];
  147. OpenGLTargetSaver& operator= (const OpenGLTargetSaver&);
  148. };
  149. //==============================================================================
  150. #include "opengl/juce_OpenGLFrameBuffer.cpp"
  151. #include "opengl/juce_OpenGLGraphicsContext.cpp"
  152. #include "opengl/juce_OpenGLHelpers.cpp"
  153. #include "opengl/juce_OpenGLImage.cpp"
  154. #include "opengl/juce_OpenGLPixelFormat.cpp"
  155. #include "opengl/juce_OpenGLShaderProgram.cpp"
  156. #include "opengl/juce_OpenGLTexture.cpp"
  157. //==============================================================================
  158. #if JUCE_MAC || JUCE_IOS
  159. #if JUCE_MAC
  160. #include "native/juce_OpenGL_osx.h"
  161. #else
  162. #include "native/juce_OpenGL_ios.h"
  163. #endif
  164. #elif JUCE_WINDOWS
  165. #include "native/juce_OpenGL_win32.h"
  166. #elif JUCE_LINUX
  167. #include "native/juce_OpenGL_linux.h"
  168. #elif JUCE_ANDROID
  169. #include "native/juce_OpenGL_android.h"
  170. #endif
  171. #include "opengl/juce_OpenGLContext.cpp"
  172. #include "utils/juce_OpenGLAppComponent.cpp"
  173. }