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.

131 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_OPENGLCONTEXT_JUCEHEADER__
  19. #define __JUCE_OPENGLCONTEXT_JUCEHEADER__
  20. #include "juce_OpenGLPixelFormat.h"
  21. #include "../native/juce_OpenGLExtensions.h"
  22. //==============================================================================
  23. /**
  24. A base class for types of OpenGL context.
  25. An OpenGLComponent will supply its own context for drawing in its window.
  26. */
  27. class JUCE_API OpenGLContext
  28. {
  29. public:
  30. //==============================================================================
  31. /** Destructor. */
  32. virtual ~OpenGLContext();
  33. //==============================================================================
  34. /** Makes this context the currently active one. */
  35. virtual bool makeActive() const noexcept = 0;
  36. /** If this context is currently active, it is disactivated. */
  37. virtual bool makeInactive() const noexcept = 0;
  38. /** Returns true if this context is currently active. */
  39. virtual bool isActive() const noexcept = 0;
  40. /** Swaps the buffers (if the context can do this). */
  41. virtual void swapBuffers() = 0;
  42. /** Sets whether the context checks the vertical sync before swapping.
  43. The value is the number of frames to allow between buffer-swapping. This is
  44. fairly system-dependent, but 0 turns off syncing, 1 makes it swap on frame-boundaries,
  45. and greater numbers indicate that it should swap less often.
  46. Returns true if it sets the value successfully.
  47. */
  48. virtual bool setSwapInterval (int numFramesPerSwap) = 0;
  49. /** Returns the current swap-sync interval.
  50. See setSwapInterval() for info about the value returned.
  51. */
  52. virtual int getSwapInterval() const = 0;
  53. //==============================================================================
  54. /** Returns an OS-dependent handle to the raw GL context.
  55. On win32, this will be a HGLRC; on the Mac, an NSOpenGLContext; on Linux,
  56. a GLXContext.
  57. */
  58. virtual void* getRawContext() const noexcept = 0;
  59. /** Returns the width of this context */
  60. virtual int getWidth() const = 0;
  61. /** Returns the height of this context */
  62. virtual int getHeight() const = 0;
  63. /** If this context is backed by a frame buffer, this returns its ID number, or
  64. 0 if the context has no accessible framebuffer.
  65. */
  66. virtual unsigned int getFrameBufferID() const = 0;
  67. /** Checks whether the current context supports the specified extension. */
  68. bool isExtensionSupported (const char* const extensionName);
  69. /** Returns true if shaders can be used in this context. */
  70. virtual bool areShadersAvailable() const;
  71. //==============================================================================
  72. /** Returns the context that's currently in active use by the calling thread.
  73. Returns 0 if there isn't an active context.
  74. */
  75. static OpenGLContext* getCurrentContext();
  76. /** This property set allows you to attach persisent values to the context. */
  77. NamedValueSet properties;
  78. /** This structure holds a set of dynamically loaded GL functions for use on this context. */
  79. OpenGLExtensionFunctions extensions;
  80. //==============================================================================
  81. /** Draws the currently selected texture into this context at its original size.
  82. @param targetClipArea the target area to draw into (in top-left origin coords)
  83. @param anchorPosAndTextureSize the position of this rectangle is the texture's top-left
  84. anchor position in the target space, and the size must be
  85. the total size of the texture.
  86. */
  87. void copyTexture (const Rectangle<int>& targetClipArea,
  88. const Rectangle<int>& anchorPosAndTextureSize);
  89. protected:
  90. //==============================================================================
  91. OpenGLContext() noexcept;
  92. private:
  93. mutable int shaderLanguageAvailable;
  94. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLContext);
  95. };
  96. #endif // __JUCE_OPENGLCONTEXT_JUCEHEADER__