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.

97 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /** Creates a graphics context object that will render into the given OpenGL target. */
  21. std::unique_ptr<LowLevelGraphicsContext> createOpenGLGraphicsContext (OpenGLContext&, int width, int height);
  22. /** Creates a graphics context object that will render into the given OpenGL framebuffer. */
  23. std::unique_ptr<LowLevelGraphicsContext> createOpenGLGraphicsContext (OpenGLContext&, OpenGLFrameBuffer&);
  24. /** Creates a graphics context object that will render into the given OpenGL framebuffer,
  25. with the given size.
  26. */
  27. std::unique_ptr<LowLevelGraphicsContext> createOpenGLGraphicsContext (OpenGLContext&,
  28. unsigned int frameBufferID,
  29. int width, int height);
  30. //==============================================================================
  31. /**
  32. Used to create custom shaders for use with an openGL 2D rendering context.
  33. Given a GL-based rendering context, you can write a fragment shader that applies some
  34. kind of per-pixel effect.
  35. @tags{OpenGL}
  36. */
  37. struct JUCE_API OpenGLGraphicsContextCustomShader
  38. {
  39. /** Creates a custom shader.
  40. The shader code will not be compiled until actually needed, so it's OK to call this
  41. constructor when no GL context is active.
  42. The code should be a normal fragment shader. As well as the usual GLSL variables, there is
  43. also an automatically declared varying vec2 called "pixelPos", which indicates the pixel
  44. position within the graphics context of the pixel being drawn. There is also a varying value
  45. "pixelAlpha", which indicates the alpha by which the pixel should be multiplied, so that the
  46. edges of any clip-region masks are anti-aliased correctly.
  47. */
  48. OpenGLGraphicsContextCustomShader (const String& fragmentShaderCode);
  49. /** Destructor. */
  50. ~OpenGLGraphicsContextCustomShader();
  51. /** Returns the program, if it has been linked and is active.
  52. This can be called when you're about to use fillRect, to set up any uniforms/textures that
  53. the program may require.
  54. */
  55. OpenGLShaderProgram* getProgram (LowLevelGraphicsContext&) const;
  56. /** Applies the shader to a rectangle within the graphics context. */
  57. void fillRect (LowLevelGraphicsContext&, Rectangle<int> area) const;
  58. /** Attempts to compile the program if necessary, and returns an error message if it fails. */
  59. Result checkCompilation (LowLevelGraphicsContext&);
  60. /** Returns the code that was used to create this object. */
  61. const String& getFragmentShaderCode() const noexcept { return code; }
  62. /** Optional lambda that will be called when the shader is activated, to allow
  63. user code to do setup tasks.
  64. */
  65. std::function<void (OpenGLShaderProgram&)> onShaderActivated;
  66. private:
  67. String code, hashName;
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLGraphicsContextCustomShader)
  69. };
  70. } // namespace juce