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.

129 lines
4.7KB

  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. #ifndef JUCE_OPENGLHELPERS_H_INCLUDED
  18. #define JUCE_OPENGLHELPERS_H_INCLUDED
  19. class OpenGLTexture;
  20. class OpenGLFrameBuffer;
  21. //==============================================================================
  22. /**
  23. A set of miscellaneous openGL helper functions.
  24. */
  25. class JUCE_API OpenGLHelpers
  26. {
  27. public:
  28. /** Clears the GL error state. */
  29. static void resetErrorState();
  30. /** Returns true if the current thread has an active OpenGL context. */
  31. static bool isContextActive();
  32. /** Clears the current context using the given colour. */
  33. static void clear (Colour colour);
  34. static void enableScissorTest (const Rectangle<int>& clip);
  35. /** Checks whether the current context supports the specified extension. */
  36. static bool isExtensionSupported (const char* extensionName);
  37. /** Returns the address of a named GL extension function */
  38. static void* getExtensionFunction (const char* functionName);
  39. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  40. /** Sets the current colour using a JUCE colour. */
  41. static void setColour (Colour colour);
  42. /** Gives the current context an orthoganal rendering mode for 2D drawing into the given size. */
  43. static void prepareFor2D (int width, int height);
  44. /** This does the same job as gluPerspective(). */
  45. static void setPerspective (double fovy, double aspect, double zNear, double zFar);
  46. static void applyTransform (const AffineTransform& t);
  47. static void applyMatrix (const float matrixValues[16]);
  48. #if ! JUCE_OPENGL_ES
  49. static void applyMatrix (const double matrixValues[16]);
  50. #endif
  51. /** Draws a 2D quad with the specified corner points. */
  52. static void drawQuad2D (float x1, float y1,
  53. float x2, float y2,
  54. float x3, float y3,
  55. float x4, float y4,
  56. Colour colour);
  57. /** Draws a 3D quad with the specified corner points. */
  58. static void drawQuad3D (float x1, float y1, float z1,
  59. float x2, float y2, float z2,
  60. float x3, float y3, float z3,
  61. float x4, float y4, float z4,
  62. Colour colour);
  63. static void drawTriangleStrip (const GLfloat* const vertices, const GLfloat* const textureCoords, const int numVertices) noexcept;
  64. static void drawTriangleStrip (const GLfloat* const vertices, const GLfloat* const textureCoords,
  65. const int numVertices, const GLuint textureID) noexcept;
  66. static void drawTextureQuad (GLuint textureID, const Rectangle<int>& rect);
  67. static void fillRectWithTexture (const Rectangle<int>& rect, GLuint textureID, const float alpha);
  68. /** Fills a rectangle with the specified colour. */
  69. static void fillRectWithColour (const Rectangle<int>& rect,
  70. Colour colour);
  71. static void fillRect (const Rectangle<int>& rect);
  72. #endif
  73. };
  74. //==============================================================================
  75. /**
  76. Used as a local object while rendering, this will create a temporary texture ID
  77. from an image in the quickest way possible.
  78. If the image is backed by an OpenGL framebuffer, it will use that directly; otherwise,
  79. this object will create a temporary texture or framebuffer and copy the image.
  80. */
  81. class JUCE_API OpenGLTextureFromImage
  82. {
  83. public:
  84. OpenGLTextureFromImage (const Image& image);
  85. ~OpenGLTextureFromImage();
  86. GLuint textureID;
  87. const int imageWidth, imageHeight;
  88. float fullWidthProportion, fullHeightProportion;
  89. private:
  90. ScopedPointer<OpenGLTexture> texture;
  91. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLTextureFromImage)
  92. };
  93. #endif // JUCE_OPENGLHELPERS_H_INCLUDED