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.

213 lines
6.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #if defined (JUCE_OPENGL_H_INCLUDED) && ! JUCE_AMALGAMATED_INCLUDE
  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. // Your project must contain an AppConfig.h file with your project-specific settings in it,
  26. // and your header search path must make it accessible to the module's files.
  27. #include "AppConfig.h"
  28. #include "../juce_core/native/juce_BasicNativeHeaders.h"
  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. #define JUCE_INIT_GL_FUNCTION_EXT(name, returnType, params, callparams) \
  67. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (#name); \
  68. if (name == nullptr) \
  69. name = (type_ ## name) OpenGLHelpers::getExtensionFunction (JUCE_STRINGIFY (name ## EXT));
  70. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_INIT_GL_FUNCTION, JUCE_INIT_GL_FUNCTION_EXT)
  71. #undef JUCE_INIT_GL_FUNCTION
  72. #undef JUCE_INIT_GL_FUNCTION_EXT
  73. #endif
  74. }
  75. #if JUCE_OPENGL_ES
  76. #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) \
  77. returnType OpenGLExtensionFunctions::name params { return ::name callparams; }
  78. JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION)
  79. #undef JUCE_DECLARE_GL_FUNCTION
  80. #endif
  81. #undef JUCE_GL_EXTENSION_FUNCTIONS
  82. #if JUCE_DEBUG && ! defined (JUCE_CHECK_OPENGL_ERROR)
  83. static const char* getGLErrorMessage (const GLenum e)
  84. {
  85. switch (e)
  86. {
  87. case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
  88. case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
  89. case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
  90. case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
  91. #ifdef GL_STACK_OVERFLOW
  92. case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
  93. #endif
  94. #ifdef GL_STACK_UNDERFLOW
  95. case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
  96. #endif
  97. #ifdef GL_INVALID_FRAMEBUFFER_OPERATION
  98. case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
  99. #endif
  100. default: break;
  101. }
  102. return "Unknown error";
  103. }
  104. static void checkGLError (const char* file, const int line)
  105. {
  106. for (;;)
  107. {
  108. const GLenum e = glGetError();
  109. if (e == GL_NO_ERROR)
  110. break;
  111. DBG ("***** " << getGLErrorMessage (e) << " at " << file << " : " << line);
  112. jassertfalse;
  113. }
  114. }
  115. #define JUCE_CHECK_OPENGL_ERROR checkGLError (__FILE__, __LINE__);
  116. #else
  117. #define JUCE_CHECK_OPENGL_ERROR ;
  118. #endif
  119. static void clearGLError()
  120. {
  121. while (glGetError() != GL_NO_ERROR) {}
  122. }
  123. struct OpenGLTargetSaver
  124. {
  125. OpenGLTargetSaver (const OpenGLContext& c)
  126. : context (c), oldFramebuffer (OpenGLFrameBuffer::getCurrentFrameBufferTarget())
  127. {
  128. glGetIntegerv (GL_VIEWPORT, oldViewport);
  129. }
  130. ~OpenGLTargetSaver()
  131. {
  132. context.extensions.glBindFramebuffer (GL_FRAMEBUFFER, oldFramebuffer);
  133. glViewport (oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
  134. }
  135. private:
  136. const OpenGLContext& context;
  137. GLuint oldFramebuffer;
  138. GLint oldViewport[4];
  139. OpenGLTargetSaver& operator= (const OpenGLTargetSaver&);
  140. };
  141. //==============================================================================
  142. #include "opengl/juce_OpenGLFrameBuffer.cpp"
  143. #include "opengl/juce_OpenGLGraphicsContext.cpp"
  144. #include "opengl/juce_OpenGLHelpers.cpp"
  145. #include "opengl/juce_OpenGLImage.cpp"
  146. #include "opengl/juce_OpenGLPixelFormat.cpp"
  147. #include "opengl/juce_OpenGLShaderProgram.cpp"
  148. #include "opengl/juce_OpenGLTexture.cpp"
  149. //==============================================================================
  150. #if JUCE_MAC || JUCE_IOS
  151. #include "../juce_core/native/juce_osx_ObjCHelpers.h"
  152. #include "../juce_graphics/native/juce_mac_CoreGraphicsHelpers.h"
  153. #if JUCE_MAC
  154. #include "native/juce_OpenGL_osx.h"
  155. #else
  156. #include "native/juce_OpenGL_ios.h"
  157. #endif
  158. #elif JUCE_WINDOWS
  159. #include "native/juce_OpenGL_win32.h"
  160. #elif JUCE_LINUX
  161. #include "native/juce_OpenGL_linux.h"
  162. #elif JUCE_ANDROID
  163. #include "../juce_core/native/juce_android_JNIHelpers.h"
  164. #include "native/juce_OpenGL_android.h"
  165. #endif
  166. #include "opengl/juce_OpenGLContext.cpp"
  167. #include "utils/juce_OpenGLAppComponent.cpp"
  168. }