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.

120 lines
4.5KB

  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_OPENGLCONTEXT_JUCEHEADER__
  19. #define __JUCE_OPENGLCONTEXT_JUCEHEADER__
  20. #include "juce_OpenGLPixelFormat.h"
  21. //==============================================================================
  22. /**
  23. A base class for types of OpenGL context.
  24. An OpenGLComponent will supply its own context for drawing in its window.
  25. */
  26. class JUCE_API OpenGLContext
  27. {
  28. public:
  29. //==============================================================================
  30. /** Destructor. */
  31. virtual ~OpenGLContext();
  32. //==============================================================================
  33. /** Makes this context the currently active one. */
  34. virtual bool makeActive() const noexcept = 0;
  35. /** If this context is currently active, it is disactivated. */
  36. virtual bool makeInactive() const noexcept = 0;
  37. /** Returns true if this context is currently active. */
  38. virtual bool isActive() const noexcept = 0;
  39. /** Swaps the buffers (if the context can do this). */
  40. virtual void swapBuffers() = 0;
  41. /** Sets whether the context checks the vertical sync before swapping.
  42. The value is the number of frames to allow between buffer-swapping. This is
  43. fairly system-dependent, but 0 turns off syncing, 1 makes it swap on frame-boundaries,
  44. and greater numbers indicate that it should swap less often.
  45. Returns true if it sets the value successfully.
  46. */
  47. virtual bool setSwapInterval (int numFramesPerSwap) = 0;
  48. /** Returns the current swap-sync interval.
  49. See setSwapInterval() for info about the value returned.
  50. */
  51. virtual int getSwapInterval() const = 0;
  52. //==============================================================================
  53. /** Returns the pixel format being used by this context. */
  54. virtual OpenGLPixelFormat getPixelFormat() const = 0;
  55. /** For windowed contexts, this moves the context within the bounds of
  56. its parent window.
  57. */
  58. virtual void updateWindowPosition (const Rectangle<int>& bounds) = 0;
  59. /** For windowed contexts, this triggers a repaint of the window.
  60. (Not relevent on all platforms).
  61. */
  62. virtual void repaint() = 0;
  63. /** Returns an OS-dependent handle to the raw GL context.
  64. On win32, this will be a HGLRC; on the Mac, an AGLContext; on Linux,
  65. a GLXContext.
  66. */
  67. virtual void* getRawContext() const noexcept = 0;
  68. /** Deletes the context.
  69. This must only be called on the message thread, or will deadlock.
  70. On background threads, call getCurrentContext()->deleteContext(), but be careful not
  71. to call any other OpenGL function afterwards.
  72. This doesn't touch other resources, such as window handles, etc.
  73. You'll probably never have to call this method directly.
  74. */
  75. virtual void deleteContext() = 0;
  76. //==============================================================================
  77. /** Returns the context that's currently in active use by the calling thread.
  78. Returns 0 if there isn't an active context.
  79. */
  80. static OpenGLContext* getCurrentContext();
  81. protected:
  82. //==============================================================================
  83. OpenGLContext() noexcept;
  84. private:
  85. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLContext);
  86. };
  87. #endif // __JUCE_OPENGLCONTEXT_JUCEHEADER__