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.

91 lines
3.1KB

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