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.

93 lines
4.0KB

  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. /** Creates a graphics context object that will render into the given OpenGL target.
  19. The caller is responsible for deleting this object when no longer needed.
  20. */
  21. LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& target,
  22. int width, int height);
  23. /** Creates a graphics context object that will render into the given OpenGL target.
  24. The caller is responsible for deleting this object when no longer needed.
  25. */
  26. LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context,
  27. OpenGLFrameBuffer& target);
  28. /** Creates a graphics context object that will render into the given OpenGL target.
  29. The caller is responsible for deleting this object when no longer needed.
  30. */
  31. LowLevelGraphicsContext* createOpenGLGraphicsContext (OpenGLContext& context,
  32. unsigned int frameBufferID,
  33. int width, int height);
  34. //==============================================================================
  35. /**
  36. Used to create custom shaders for use with an openGL 2D rendering context.
  37. Given a GL-based rendering context, you can write a fragment shader that applies some
  38. kind of per-pixel effect.
  39. */
  40. struct JUCE_API OpenGLGraphicsContextCustomShader
  41. {
  42. /** Creates a custom shader.
  43. The shader code will not be compiled until actually needed, so it's OK to call this
  44. constructor when no GL context is active.
  45. The code should be a normal fragment shader. As well as the usual GLSL variables, there is
  46. also an automatically declared varying vec2 called "pixelPos", which indicates the pixel
  47. position within the graphics context of the pixel being drawn. There is also a varying value
  48. "pixelAlpha", which indicates the alpha by which the pixel should be multiplied, so that the
  49. edges of any clip-region masks are anti-aliased correctly.
  50. */
  51. OpenGLGraphicsContextCustomShader (const String& fragmentShaderCode);
  52. /** Destructor. */
  53. ~OpenGLGraphicsContextCustomShader();
  54. /** Returns the program, if it has been linked and is active.
  55. This can be called when you're about to use fillRect, to set up any uniforms/textures that
  56. the program may require.
  57. */
  58. OpenGLShaderProgram* getProgram (LowLevelGraphicsContext&) const;
  59. /** Applies the shader to a rectangle within the graphics context. */
  60. void fillRect (LowLevelGraphicsContext&, const Rectangle<int>& area) const;
  61. /** Attempts to compile the program if necessary, and returns an error message if it fails. */
  62. Result checkCompilation (LowLevelGraphicsContext&);
  63. /** Returns the code that was used to create this object. */
  64. const String& getFragmentShaderCode() const noexcept { return code; }
  65. private:
  66. String code, hashName;
  67. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLGraphicsContextCustomShader)
  68. };