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.

135 lines
5.0KB

  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. #ifndef JUCE_OPENGLFRAMEBUFFER_H_INCLUDED
  18. #define JUCE_OPENGLFRAMEBUFFER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Creates an openGL frame buffer.
  22. */
  23. class JUCE_API OpenGLFrameBuffer
  24. {
  25. public:
  26. /** Creates an uninitialised buffer.
  27. To actually allocate the buffer, use initialise().
  28. */
  29. OpenGLFrameBuffer();
  30. /** Destructor. */
  31. ~OpenGLFrameBuffer();
  32. //==============================================================================
  33. /** Tries to allocates a buffer of the given size.
  34. Note that a valid openGL context must be selected when you call this method,
  35. or it will fail.
  36. */
  37. bool initialise (OpenGLContext& context, int width, int height);
  38. /** Tries to allocates a buffer containing a copy of a given image.
  39. Note that a valid openGL context must be selected when you call this method,
  40. or it will fail.
  41. */
  42. bool initialise (OpenGLContext& context, const Image& content);
  43. /** Tries to allocate a copy of another framebuffer.
  44. */
  45. bool initialise (OpenGLFrameBuffer& other);
  46. /** Releases the buffer, if one has been allocated.
  47. Any saved state that was created with saveAndRelease() will also be freed by this call.
  48. */
  49. void release();
  50. /** If the framebuffer is active, this will save a stashed copy of its contents in main memory,
  51. and will release the GL buffer.
  52. After saving, the original state can be restored again by calling reloadSavedCopy().
  53. */
  54. void saveAndRelease();
  55. /** Restores the framebuffer content that was previously saved using saveAndRelease().
  56. After saving to main memory, the original state can be restored by calling restoreToGPUMemory().
  57. */
  58. bool reloadSavedCopy (OpenGLContext& context);
  59. //==============================================================================
  60. /** Returns true if a valid buffer has been allocated. */
  61. bool isValid() const noexcept { return pimpl != nullptr; }
  62. /** Returns the width of the buffer. */
  63. int getWidth() const noexcept;
  64. /** Returns the height of the buffer. */
  65. int getHeight() const noexcept;
  66. /** Returns the texture ID number for using this buffer as a texture. */
  67. GLuint getTextureID() const noexcept;
  68. //==============================================================================
  69. /** Selects this buffer as the current OpenGL rendering target. */
  70. bool makeCurrentRenderingTarget();
  71. /** Deselects this buffer as the current OpenGL rendering target. */
  72. void releaseAsRenderingTarget();
  73. /** Returns the ID of this framebuffer, or 0 if it isn't initialised. */
  74. GLuint getFrameBufferID() const noexcept;
  75. /** Returns the current frame buffer ID for the current context. */
  76. static GLuint getCurrentFrameBufferTarget() noexcept;
  77. /** Clears the framebuffer with the specified colour. */
  78. void clear (Colour colour);
  79. /** Selects the framebuffer as the current target, and clears it to transparent. */
  80. void makeCurrentAndClear();
  81. /** Reads an area of pixels from the framebuffer into a 32-bit ARGB pixel array.
  82. The lineStride is measured as a number of pixels, not bytes - pass a stride
  83. of 0 to indicate a packed array.
  84. */
  85. bool readPixels (PixelARGB* targetData, const Rectangle<int>& sourceArea);
  86. /** Writes an area of pixels into the framebuffer from a specified pixel array.
  87. The lineStride is measured as a number of pixels, not bytes - pass a stride
  88. of 0 to indicate a packed array.
  89. */
  90. bool writePixels (const PixelARGB* srcData, const Rectangle<int>& targetArea);
  91. private:
  92. class Pimpl;
  93. friend struct ContainerDeletePolicy<Pimpl>;
  94. ScopedPointer<Pimpl> pimpl;
  95. class SavedState;
  96. friend struct ContainerDeletePolicy<SavedState>;
  97. ScopedPointer<SavedState> savedState;
  98. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLFrameBuffer)
  99. };
  100. #endif // JUCE_OPENGLFRAMEBUFFER_H_INCLUDED