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.

136 lines
5.3KB

  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_OPENGLFRAMEBUFFER_JUCEHEADER__
  19. #define __JUCE_OPENGLFRAMEBUFFER_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Creates an openGL frame buffer.
  23. */
  24. class JUCE_API OpenGLFrameBuffer
  25. {
  26. public:
  27. /** Creates an uninitialised buffer.
  28. To actually allocate the buffer, use initialise().
  29. */
  30. OpenGLFrameBuffer();
  31. /** Destructor. */
  32. ~OpenGLFrameBuffer();
  33. //==============================================================================
  34. /** Tries to allocates a buffer of the given size.
  35. Note that a valid openGL context must be selected when you call this method,
  36. or it will fail.
  37. */
  38. bool initialise (int width, int height);
  39. /** Releases the buffer, if one has been allocated.
  40. Any saved state that was created with saveAndRelease() will also be freed by this call.
  41. */
  42. void release();
  43. /** If the framebuffer is active, this will save a stashed copy of its contents in main memory,
  44. and will release the GL buffer.
  45. After saving, the original state can be restored again by calling reloadSavedCopy().
  46. */
  47. void saveAndRelease();
  48. /** Restores the framebuffer content that was previously saved using saveAndRelease().
  49. After saving to main memory, the original state can be restored by calling restoreToGPUMemory().
  50. */
  51. bool reloadSavedCopy();
  52. //==============================================================================
  53. /** Returns true if a valid buffer has been allocated. */
  54. bool isValid() const noexcept { return pimpl != nullptr; }
  55. /** Returns the width of the buffer. */
  56. int getWidth() const noexcept;
  57. /** Returns the height of the buffer. */
  58. int getHeight() const noexcept;
  59. /** Returns the texture ID number for using this buffer as a texture. */
  60. unsigned int getTextureID() const noexcept;
  61. //==============================================================================
  62. /** Selects this buffer as the current OpenGL rendering target. */
  63. bool makeCurrentTarget();
  64. /** Deselects this buffer as the current OpenGL rendering target. */
  65. void releaseCurrentTarget();
  66. /** Clears the framebuffer with the specified colour. */
  67. void clear (const Colour& colour);
  68. /** Draws this framebuffer onto the current context, with the specified corner positions. */
  69. void draw2D (float x1, float y1,
  70. float x2, float y2,
  71. float x3, float y3,
  72. float x4, float y4,
  73. const Colour& colour) const;
  74. /** Draws this framebuffer onto the current context, with the specified corner positions. */
  75. void draw3D (float x1, float y1, float z1,
  76. float x2, float y2, float z2,
  77. float x3, float y3, float z3,
  78. float x4, float y4, float z4,
  79. const Colour& colour) const;
  80. /** Reads an area of pixels from the framebuffer into a specified pixel array. */
  81. bool readPixels (void* target, const Rectangle<int>& area);
  82. /** Writes an area of pixels into the framebuffer from a specified pixel array. */
  83. bool writePixels (const void* target, const Rectangle<int>& area);
  84. /** This will render an anti-aliased path into just the alpha channel of this framebuffer.
  85. The idea here is that you can clear a framebuffer, use this to set its alpha channel, then
  86. fill the RGB channels with some kind of fill-pattern, and then copy the whole thing onto
  87. a target, to produce a filled path with some kind of texture.
  88. Calling this will make changes to a lot of openGL state, including colour masks, blend
  89. functions, etc
  90. */
  91. void createAlphaChannelFromPath (const Path& path, int oversamplingLevel = 4);
  92. private:
  93. class Pimpl;
  94. friend class ScopedPointer<Pimpl>;
  95. ScopedPointer<Pimpl> pimpl;
  96. class SavedState;
  97. friend class ScopedPointer<SavedState>;
  98. ScopedPointer<SavedState> savedState;
  99. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLFrameBuffer);
  100. };
  101. #endif // __JUCE_OPENGLFRAMEBUFFER_JUCEHEADER__