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.

154 lines
5.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_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;
  75. /** Returns the current frame buffer ID for the current context. */
  76. static GLuint getCurrentFrameBufferTarget();
  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. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  82. /** Draws this framebuffer onto the current context, with the specified corner positions. */
  83. void draw2D (float x1, float y1,
  84. float x2, float y2,
  85. float x3, float y3,
  86. float x4, float y4,
  87. Colour colour) const;
  88. /** Draws this framebuffer onto the current context, with the specified corner positions. */
  89. void draw3D (float x1, float y1, float z1,
  90. float x2, float y2, float z2,
  91. float x3, float y3, float z3,
  92. float x4, float y4, float z4,
  93. Colour colour) const;
  94. /** Draws the framebuffer at a given position. */
  95. void drawAt (float x1, float y1) const;
  96. #endif
  97. /** Reads an area of pixels from the framebuffer into a 32-bit ARGB pixel array.
  98. The lineStride is measured as a number of pixels, not bytes - pass a stride
  99. of 0 to indicate a packed array.
  100. */
  101. bool readPixels (PixelARGB* targetData, const Rectangle<int>& sourceArea);
  102. /** Writes an area of pixels into the framebuffer from a specified pixel array.
  103. The lineStride is measured as a number of pixels, not bytes - pass a stride
  104. of 0 to indicate a packed array.
  105. */
  106. bool writePixels (const PixelARGB* srcData, const Rectangle<int>& targetArea);
  107. private:
  108. class Pimpl;
  109. friend class ScopedPointer<Pimpl>;
  110. ScopedPointer<Pimpl> pimpl;
  111. class SavedState;
  112. friend class ScopedPointer<SavedState>;
  113. ScopedPointer<SavedState> savedState;
  114. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLFrameBuffer)
  115. };
  116. #endif // JUCE_OPENGLFRAMEBUFFER_H_INCLUDED