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.

131 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_OPENGLHELPERS_JUCEHEADER__
  19. #define __JUCE_OPENGLHELPERS_JUCEHEADER__
  20. class OpenGLTexture;
  21. class OpenGLFrameBuffer;
  22. //==============================================================================
  23. /**
  24. A set of miscellaneous openGL helper functions.
  25. */
  26. class JUCE_API OpenGLHelpers
  27. {
  28. public:
  29. /** Clears the GL error state. */
  30. static void resetErrorState();
  31. /** Returns true if the current thread has an active OpenGL context. */
  32. static bool isContextActive();
  33. /** Clears the current context using the given colour. */
  34. static void clear (const Colour& colour);
  35. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  36. /** Sets the current colour using a JUCE colour. */
  37. static void setColour (const Colour& colour);
  38. /** Gives the current context an orthoganal rendering mode for 2D drawing into the given size. */
  39. static void prepareFor2D (int width, int height);
  40. /** This does the same job as gluPerspective(). */
  41. static void setPerspective (double fovy, double aspect, double zNear, double zFar);
  42. static void applyTransform (const AffineTransform& t);
  43. static void applyMatrix (const float matrixValues[16]);
  44. #if ! JUCE_OPENGL_ES
  45. static void applyMatrix (const double matrixValues[16]);
  46. #endif
  47. #endif
  48. static void enableScissorTest (const Rectangle<int>& clip);
  49. /** Draws a 2D quad with the specified corner points. */
  50. static void drawQuad2D (float x1, float y1,
  51. float x2, float y2,
  52. float x3, float y3,
  53. float x4, float y4,
  54. const Colour& colour);
  55. /** Draws a 3D quad with the specified corner points. */
  56. static void drawQuad3D (float x1, float y1, float z1,
  57. float x2, float y2, float z2,
  58. float x3, float y3, float z3,
  59. float x4, float y4, float z4,
  60. const Colour& colour);
  61. static void drawTriangleStrip (const GLfloat* const vertices, const GLfloat* const textureCoords, const int numVertices) noexcept;
  62. static void drawTriangleStrip (const GLfloat* const vertices, const GLfloat* const textureCoords,
  63. const int numVertices, const GLuint textureID) noexcept;
  64. static void drawTextureQuad (GLuint textureID, const Rectangle<int>& rect);
  65. static void fillRectWithTexture (const Rectangle<int>& rect, GLuint textureID, const float alpha);
  66. static void fillRect (const Rectangle<int>& rect);
  67. /** Fills a rectangle with the specified colour. */
  68. static void fillRectWithColour (const Rectangle<int>& rect,
  69. const Colour& colour);
  70. /** Checks whether the current context supports the specified extension. */
  71. static bool isExtensionSupported (const char* extensionName);
  72. /** Returns the address of a named GL extension function */
  73. static void* getExtensionFunction (const char* functionName);
  74. };
  75. //==============================================================================
  76. /**
  77. Used as a local object while rendering, this will create a temporary texture ID
  78. from an image in the quickest way possible.
  79. If the image is backed by an OpenGL framebuffer, it will use that directly; otherwise,
  80. this object will create a temporary texture or framebuffer and copy the image.
  81. */
  82. class JUCE_API OpenGLTextureFromImage
  83. {
  84. public:
  85. OpenGLTextureFromImage (const Image& image);
  86. ~OpenGLTextureFromImage();
  87. GLuint textureID;
  88. const int imageWidth, imageHeight;
  89. float fullWidthProportion, fullHeightProportion;
  90. private:
  91. ScopedPointer<OpenGLTexture> texture;
  92. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLTextureFromImage);
  93. };
  94. #endif // __JUCE_OPENGLHELPERS_JUCEHEADER__