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.

104 lines
3.3KB

  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. void OpenGLHelpers::resetErrorState()
  18. {
  19. while (glGetError() != GL_NO_ERROR) {}
  20. }
  21. void* OpenGLHelpers::getExtensionFunction (const char* functionName)
  22. {
  23. #if JUCE_WINDOWS
  24. return (void*) wglGetProcAddress (functionName);
  25. #elif JUCE_LINUX
  26. return (void*) glXGetProcAddress ((const GLubyte*) functionName);
  27. #else
  28. static void* handle = dlopen (nullptr, RTLD_LAZY);
  29. return dlsym (handle, functionName);
  30. #endif
  31. }
  32. bool OpenGLHelpers::isExtensionSupported (const char* const extensionName)
  33. {
  34. jassert (extensionName != nullptr); // you must supply a genuine string for this.
  35. jassert (isContextActive()); // An OpenGL context will need to be active before calling this.
  36. const char* extensions = (const char*) glGetString (GL_EXTENSIONS);
  37. jassert (extensions != nullptr); // Perhaps you didn't activate an OpenGL context before calling this?
  38. for (;;)
  39. {
  40. const char* found = strstr (extensions, extensionName);
  41. if (found == nullptr)
  42. break;
  43. extensions = found + strlen (extensionName);
  44. if (extensions[0] == ' ' || extensions[0] == 0)
  45. return true;
  46. }
  47. return false;
  48. }
  49. void OpenGLHelpers::clear (Colour colour)
  50. {
  51. glClearColor (colour.getFloatRed(), colour.getFloatGreen(),
  52. colour.getFloatBlue(), colour.getFloatAlpha());
  53. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  54. }
  55. void OpenGLHelpers::enableScissorTest (const Rectangle<int>& clip)
  56. {
  57. glEnable (GL_SCISSOR_TEST);
  58. glScissor (clip.getX(), clip.getY(), clip.getWidth(), clip.getHeight());
  59. }
  60. String OpenGLHelpers::translateVertexShaderToV3 (const String& code)
  61. {
  62. #if JUCE_OPENGL3
  63. if (OpenGLShaderProgram::getLanguageVersion() > 1.2)
  64. return JUCE_GLSL_VERSION "\n" + code.replace ("attribute", "in")
  65. .replace ("varying", "out");
  66. #endif
  67. return code;
  68. }
  69. String OpenGLHelpers::translateFragmentShaderToV3 (const String& code)
  70. {
  71. #if JUCE_OPENGL3
  72. if (OpenGLShaderProgram::getLanguageVersion() > 1.2)
  73. return JUCE_GLSL_VERSION "\n"
  74. "out vec4 fragColor;\n"
  75. + code.replace ("varying", "in")
  76. .replace ("texture2D", "texture")
  77. .replace ("gl_FragColor", "fragColor");
  78. #endif
  79. return code;
  80. }