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
4.1KB

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