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.

139 lines
5.8KB

  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. /** Updates the native context's area within its parent. */
  64. virtual void updateWindowPosition (const Rectangle<int>&) = 0;
  65. /** If this context is backed by a frame buffer, this returns its ID number, or
  66. 0 if the context has no accessible framebuffer.
  67. */
  68. virtual unsigned int getFrameBufferID() const = 0;
  69. /** Checks whether the current context supports the specified extension. */
  70. bool isExtensionSupported (const char* const extensionName);
  71. /** Returns true if shaders can be used in this context. */
  72. virtual bool areShadersAvailable() const;
  73. //==============================================================================
  74. /** Returns the context that's currently in active use by the calling thread.
  75. Returns 0 if there isn't an active context.
  76. */
  77. static OpenGLContext* getCurrentContext();
  78. /** This property set allows you to attach persisent values to the context. */
  79. NamedValueSet properties;
  80. /** This structure holds a set of dynamically loaded GL functions for use on this context. */
  81. OpenGLExtensionFunctions extensions;
  82. //==============================================================================
  83. /** Draws the currently selected texture into this context at its original size.
  84. @param targetClipArea the target area to draw into (in top-left origin coords)
  85. @param anchorPosAndTextureSize the position of this rectangle is the texture's top-left
  86. anchor position in the target space, and the size must be
  87. the total size of the texture.
  88. @param contextWidth the width of the context or framebuffer that is being drawn into,
  89. used for scaling of the coordinates.
  90. @param contextHeight the height of the context or framebuffer that is being drawn into,
  91. used for vertical flipping of the y coordinates.
  92. */
  93. void copyTexture (const Rectangle<int>& targetClipArea,
  94. const Rectangle<int>& anchorPosAndTextureSize,
  95. int contextWidth, int contextHeight);
  96. protected:
  97. //==============================================================================
  98. OpenGLContext() noexcept;
  99. private:
  100. mutable int shaderLanguageAvailable;
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLContext);
  102. };
  103. #endif // __JUCE_OPENGLCONTEXT_JUCEHEADER__