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.

155 lines
6.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_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 (OpenGLContext& context, int width, int height);
  39. /** Tries to allocates a buffer containing a copy of a given image.
  40. Note that a valid openGL context must be selected when you call this method,
  41. or it will fail.
  42. */
  43. bool initialise (OpenGLContext& context, const Image& content);
  44. /** Tries to allocate a copy of another framebuffer.
  45. */
  46. bool initialise (OpenGLFrameBuffer& other);
  47. /** Releases the buffer, if one has been allocated.
  48. Any saved state that was created with saveAndRelease() will also be freed by this call.
  49. */
  50. void release();
  51. /** If the framebuffer is active, this will save a stashed copy of its contents in main memory,
  52. and will release the GL buffer.
  53. After saving, the original state can be restored again by calling reloadSavedCopy().
  54. */
  55. void saveAndRelease();
  56. /** Restores the framebuffer content that was previously saved using saveAndRelease().
  57. After saving to main memory, the original state can be restored by calling restoreToGPUMemory().
  58. */
  59. bool reloadSavedCopy (OpenGLContext& context);
  60. //==============================================================================
  61. /** Returns true if a valid buffer has been allocated. */
  62. bool isValid() const noexcept { return pimpl != nullptr; }
  63. /** Returns the width of the buffer. */
  64. int getWidth() const noexcept;
  65. /** Returns the height of the buffer. */
  66. int getHeight() const noexcept;
  67. /** Returns the texture ID number for using this buffer as a texture. */
  68. GLuint getTextureID() const noexcept;
  69. //==============================================================================
  70. /** Selects this buffer as the current OpenGL rendering target. */
  71. bool makeCurrentRenderingTarget();
  72. /** Deselects this buffer as the current OpenGL rendering target. */
  73. void releaseAsRenderingTarget();
  74. /** Returns the ID of this framebuffer, or 0 if it isn't initialised. */
  75. GLuint getFrameBufferID() const;
  76. /** Returns the current frame buffer ID for the current context. */
  77. static GLuint getCurrentFrameBufferTarget();
  78. /** Clears the framebuffer with the specified colour. */
  79. void clear (const Colour& colour);
  80. /** Selects the framebuffer as the current target, and clears it to transparent. */
  81. void makeCurrentAndClear();
  82. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  83. /** Draws this framebuffer onto the current context, with the specified corner positions. */
  84. void draw2D (float x1, float y1,
  85. float x2, float y2,
  86. float x3, float y3,
  87. float x4, float y4,
  88. const Colour& colour) const;
  89. /** Draws this framebuffer onto the current context, with the specified corner positions. */
  90. void draw3D (float x1, float y1, float z1,
  91. float x2, float y2, float z2,
  92. float x3, float y3, float z3,
  93. float x4, float y4, float z4,
  94. const Colour& colour) const;
  95. /** Draws the framebuffer at a given position. */
  96. void drawAt (float x1, float y1) const;
  97. #endif
  98. /** Reads an area of pixels from the framebuffer into a 32-bit ARGB pixel array.
  99. The lineStride is measured as a number of pixels, not bytes - pass a stride
  100. of 0 to indicate a packed array.
  101. */
  102. bool readPixels (PixelARGB* targetData, const Rectangle<int>& sourceArea);
  103. /** Writes an area of pixels into the framebuffer from a specified pixel array.
  104. The lineStride is measured as a number of pixels, not bytes - pass a stride
  105. of 0 to indicate a packed array.
  106. */
  107. bool writePixels (const PixelARGB* srcData, const Rectangle<int>& targetArea);
  108. private:
  109. class Pimpl;
  110. friend class ScopedPointer<Pimpl>;
  111. ScopedPointer<Pimpl> pimpl;
  112. class SavedState;
  113. friend class ScopedPointer<SavedState>;
  114. ScopedPointer<SavedState> savedState;
  115. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLFrameBuffer)
  116. };
  117. #endif // __JUCE_OPENGLFRAMEBUFFER_JUCEHEADER__