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.

83 lines
2.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. //==============================================================================
  19. /**
  20. A base class for writing simple one-page graphical apps.
  21. A subclass can inherit from this and implement just a few methods such as
  22. paint() and mouse-handling. The base class provides some simple abstractions
  23. to take care of continuously repainting itself.
  24. */
  25. class JUCE_API OpenGLAppComponent : public Component,
  26. private OpenGLRenderer
  27. {
  28. public:
  29. OpenGLAppComponent();
  30. /** Destructor. */
  31. ~OpenGLAppComponent();
  32. /** Returns the number of times that the render method has been called since
  33. the component started running.
  34. */
  35. int getFrameCounter() const noexcept { return frameCounter; }
  36. /** This must be called from your subclass's destructor, to shut down
  37. the GL system and stop it calling render() before your class is destroyed.
  38. */
  39. void shutdownOpenGL();
  40. /** Implement this method to set up any GL objects that you need for rendering.
  41. The GL context will be active when this method is called.
  42. */
  43. virtual void initialise() = 0;
  44. /** Implement this method to free any GL objects that you created during rendering.
  45. The GL context will still be active when this method is called.
  46. */
  47. virtual void shutdown() = 0;
  48. /** Called to render your openGL.
  49. @see OpenGLRenderer::render()
  50. */
  51. virtual void render() = 0;
  52. /** The GL context */
  53. OpenGLContext openGLContext;
  54. private:
  55. //==============================================================================
  56. int frameCounter = 0;
  57. void newOpenGLContextCreated() override;
  58. void renderOpenGL() override;
  59. void openGLContextClosing() override;
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLAppComponent)
  61. };