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.

233 lines
7.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #ifdef JUCE_OPENGL_H_INCLUDED
  20. /* When you add this cpp file to your project, you mustn't include it in a file where you've
  21. already included any other headers - just put it inside a file on its own, possibly with your config
  22. flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
  23. header files that the compiler may be using.
  24. */
  25. #error "Incorrect use of JUCE cpp file"
  26. #endif
  27. #define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
  28. #define JUCE_CORE_INCLUDE_JNI_HELPERS 1
  29. #define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1
  30. #define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1
  31. #include "juce_opengl.h"
  32. //==============================================================================
  33. #if JUCE_IOS
  34. #import <QuartzCore/QuartzCore.h>
  35. //==============================================================================
  36. #elif JUCE_WINDOWS
  37. #include <windowsx.h>
  38. #if JUCE_MSVC && ! JUCE_DONT_AUTOLINK_TO_WIN32_LIBRARIES
  39. #pragma comment(lib, "OpenGL32.Lib")
  40. #endif
  41. //==============================================================================
  42. #elif JUCE_LINUX
  43. /* Got an include error here?
  44. If you want to install OpenGL support, the packages to get are "mesa-common-dev"
  45. and "freeglut3-dev".
  46. */
  47. #include <GL/glx.h>
  48. //==============================================================================
  49. #elif JUCE_MAC
  50. #include <OpenGL/CGLCurrent.h> // These are both just needed with the 10.5 SDK
  51. #include <OpenGL/OpenGL.h>
  52. //==============================================================================
  53. #elif JUCE_ANDROID
  54. #ifndef GL_GLEXT_PROTOTYPES
  55. #define GL_GLEXT_PROTOTYPES 1
  56. #endif
  57. #include <GLES2/gl2.h>
  58. #endif
  59. namespace juce
  60. {
  61. //==============================================================================
  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. JUCE_GL_BASE_FUNCTIONS (JUCE_INIT_GL_FUNCTION)
  69. #undef JUCE_INIT_GL_FUNCTION
  70. #define JUCE_INIT_GL_FUNCTION(name, returnType, params, callparams) \
  71. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (#name); \
  72. if (name == nullptr) \
  73. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (JUCE_STRINGIFY (name ## EXT));
  74. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_INIT_GL_FUNCTION)
  75. #if JUCE_OPENGL3
  76. JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_INIT_GL_FUNCTION)
  77. #endif
  78. #undef JUCE_INIT_GL_FUNCTION
  79. #endif
  80. }
  81. #if JUCE_OPENGL_ES
  82. #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) \
  83. returnType OpenGLExtensionFunctions::name params noexcept { return ::name callparams; }
  84. JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
  85. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
  86. #if JUCE_OPENGL3
  87. JUCE_GL_VERTEXBUFFER_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
  88. #endif
  89. #undef JUCE_DECLARE_GL_FUNCTION
  90. #endif
  91. #undef JUCE_GL_EXTENSION_FUNCTIONS
  92. #if JUCE_DEBUG && ! defined (JUCE_CHECK_OPENGL_ERROR)
  93. static const char* getGLErrorMessage (const GLenum e) noexcept
  94. {
  95. switch (e)
  96. {
  97. case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
  98. case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
  99. case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
  100. case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
  101. #ifdef GL_STACK_OVERFLOW
  102. case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
  103. #endif
  104. #ifdef GL_STACK_UNDERFLOW
  105. case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
  106. #endif
  107. #ifdef GL_INVALID_FRAMEBUFFER_OPERATION
  108. case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
  109. #endif
  110. default: break;
  111. }
  112. return "Unknown error";
  113. }
  114. static void checkGLError (const char* file, const int line)
  115. {
  116. for (;;)
  117. {
  118. const GLenum e = glGetError();
  119. if (e == GL_NO_ERROR)
  120. break;
  121. DBG ("***** " << getGLErrorMessage (e) << " at " << file << " : " << line);
  122. jassertfalse;
  123. }
  124. }
  125. #define JUCE_CHECK_OPENGL_ERROR checkGLError (__FILE__, __LINE__);
  126. #else
  127. #define JUCE_CHECK_OPENGL_ERROR ;
  128. #endif
  129. static void clearGLError() noexcept
  130. {
  131. while (glGetError() != GL_NO_ERROR) {}
  132. }
  133. struct OpenGLTargetSaver
  134. {
  135. OpenGLTargetSaver (const OpenGLContext& c) noexcept
  136. : context (c), oldFramebuffer (OpenGLFrameBuffer::getCurrentFrameBufferTarget())
  137. {
  138. glGetIntegerv (GL_VIEWPORT, oldViewport);
  139. }
  140. ~OpenGLTargetSaver() noexcept
  141. {
  142. context.extensions.glBindFramebuffer (GL_FRAMEBUFFER, oldFramebuffer);
  143. glViewport (oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
  144. }
  145. private:
  146. const OpenGLContext& context;
  147. GLuint oldFramebuffer;
  148. GLint oldViewport[4];
  149. OpenGLTargetSaver& operator= (const OpenGLTargetSaver&);
  150. };
  151. //==============================================================================
  152. #include "opengl/juce_OpenGLFrameBuffer.cpp"
  153. #include "opengl/juce_OpenGLGraphicsContext.cpp"
  154. #include "opengl/juce_OpenGLHelpers.cpp"
  155. #include "opengl/juce_OpenGLImage.cpp"
  156. #include "opengl/juce_OpenGLPixelFormat.cpp"
  157. #include "opengl/juce_OpenGLShaderProgram.cpp"
  158. #include "opengl/juce_OpenGLTexture.cpp"
  159. //==============================================================================
  160. #if JUCE_MAC || JUCE_IOS
  161. #if JUCE_CLANG
  162. #pragma clang diagnostic push
  163. #pragma clang diagnostic ignored "-Wundeclared-selector"
  164. #endif
  165. #if JUCE_MAC
  166. #include "native/juce_OpenGL_osx.h"
  167. #else
  168. #include "native/juce_OpenGL_ios.h"
  169. #endif
  170. #if JUCE_CLANG
  171. #pragma clang diagnostic pop
  172. #endif
  173. #elif JUCE_WINDOWS
  174. #include "native/juce_OpenGL_win32.h"
  175. #elif JUCE_LINUX
  176. #include "native/juce_OpenGL_linux_X11.h"
  177. #elif JUCE_ANDROID
  178. #include "native/juce_OpenGL_android.h"
  179. #endif
  180. #include "opengl/juce_OpenGLContext.cpp"
  181. #include "utils/juce_OpenGLAppComponent.cpp"
  182. }