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.

99 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A base class for writing simple one-page graphical apps.
  24. A subclass can inherit from this and implement just a few methods such as
  25. paint() and mouse-handling. The base class provides some simple abstractions
  26. to take care of continuously repainting itself.
  27. @tags{OpenGL}
  28. */
  29. class JUCE_API OpenGLAppComponent : public Component,
  30. private OpenGLRenderer
  31. {
  32. public:
  33. OpenGLAppComponent();
  34. /** Destructor. */
  35. ~OpenGLAppComponent() override;
  36. /** Returns the number of times that the render method has been called since
  37. the component started running.
  38. */
  39. int getFrameCounter() const noexcept { return frameCounter; }
  40. /** This must be called from your subclass's destructor, to shut down
  41. the GL system and stop it calling render() before your class is destroyed.
  42. */
  43. void shutdownOpenGL();
  44. /** Implement this method to set up any GL objects that you need for rendering.
  45. The GL context will be active when this method is called.
  46. Note that because the GL context could be destroyed and re-created ad-hoc by
  47. the underlying platform, the shutdown() and initialise() calls could be called
  48. multiple times while your app is running. So don't make your code assume that
  49. this will only be called once!
  50. */
  51. virtual void initialise() = 0;
  52. /** Implement this method to free any GL objects that you created during rendering.
  53. The GL context will still be active when this method is called.
  54. Note that because the GL context could be destroyed and re-created ad-hoc by
  55. the underlying platform, the shutdown() and initialise() calls could be called
  56. multiple times while your app is running. So don't make your code assume that
  57. this will only be called once!
  58. */
  59. virtual void shutdown() = 0;
  60. /** Called to render your openGL.
  61. @see OpenGLRenderer::render()
  62. */
  63. virtual void render() = 0;
  64. /** The GL context */
  65. OpenGLContext openGLContext;
  66. private:
  67. //==============================================================================
  68. int frameCounter = 0;
  69. void newOpenGLContextCreated() override;
  70. void renderOpenGL() override;
  71. void openGLContextClosing() override;
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLAppComponent)
  73. };
  74. } // namespace juce