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.

112 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_OPENGLSHADERPROGRAM_JUCEHEADER__
  19. #define __JUCE_OPENGLSHADERPROGRAM_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Manages an OpenGL shader program.
  23. */
  24. class JUCE_API OpenGLShaderProgram
  25. {
  26. public:
  27. OpenGLShaderProgram() noexcept;
  28. ~OpenGLShaderProgram() noexcept;
  29. /** Returns the version of GLSL that the current context supports.
  30. E.g.
  31. @code
  32. if (OpenGLShaderProgram::getLanguageVersion() > 1.199)
  33. {
  34. // ..do something that requires GLSL 1.2 or above..
  35. }
  36. @endcode
  37. */
  38. static double getLanguageVersion();
  39. /** Compiles and adds a shader to this program.
  40. After adding all your shaders, remember to call link() to link them into
  41. a usable program.
  42. If your app is built in debug mode, this method will assert if the program
  43. fails to compile correctly.
  44. The shaderType parameter could be GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc.
  45. */
  46. void addShader (const char* const shaderSourceCode, GLenum shaderType);
  47. /** Links all the compiled shaders into a usable program.
  48. If your app is built in debug mode, this method will assert if the program
  49. fails to link correctly.
  50. */
  51. void link() noexcept;
  52. /** Represents an openGL uniform value.
  53. After a program has been linked, you can create Uniform objects to let you
  54. set the uniforms that your shaders use.
  55. Be careful not to call the set() functions unless the appropriate program
  56. is loaded into the current context.
  57. */
  58. struct Uniform
  59. {
  60. /** Initialises a uniform.
  61. The program must have been successfully linked when this
  62. constructor is called.
  63. */
  64. Uniform (const OpenGLShaderProgram& program, const char* uniformName);
  65. /** Sets a float uniform. */
  66. void set (GLfloat n1) const noexcept;
  67. /** Sets an int uniform. */
  68. void set (GLint n1) const noexcept;
  69. /** Sets a vec2 uniform. */
  70. void set (GLfloat n1, GLfloat n2) const noexcept;
  71. /** Sets a vec3 uniform. */
  72. void set (GLfloat n1, GLfloat n2, GLfloat n3) const noexcept;
  73. /** Sets a vec4 uniform. */
  74. void set (GLfloat n1, GLfloat n2, GLfloat n3, float n4) const noexcept;
  75. /** Sets an ivec4 uniform. */
  76. void set (GLint n1, GLint n2, GLint n3, GLint n4) const noexcept;
  77. /** Sets a vector float uniform. */
  78. void set (const GLfloat* values, int numValues) const noexcept;
  79. /** The uniform's ID number.
  80. If the uniform couldn't be found, this value will be < 0.
  81. */
  82. GLint uniformID;
  83. };
  84. /** The ID number of the compiled program. */
  85. GLuint programID;
  86. private:
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLShaderProgram);
  88. };
  89. #endif // __JUCE_OPENGLSHADERPROGRAM_JUCEHEADER__