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

  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. OpenGLShaderProgram::OpenGLShaderProgram() noexcept
  19. {
  20. // This object can only be created and used when the current thread has an active OpenGL context.
  21. jassert (OpenGLHelpers::isContextActive());
  22. programID = glCreateProgram();
  23. }
  24. OpenGLShaderProgram::~OpenGLShaderProgram() noexcept
  25. {
  26. glDeleteProgram (programID);
  27. }
  28. double OpenGLShaderProgram::getLanguageVersion()
  29. {
  30. return String ((const char*) glGetString (GL_SHADING_LANGUAGE_VERSION))
  31. .upToFirstOccurrenceOf (" ", false, false).getDoubleValue();
  32. }
  33. void OpenGLShaderProgram::addShader (const char* const code, GLenum type)
  34. {
  35. GLuint shaderID = glCreateShader (type);
  36. glShaderSource (shaderID, 1, (const GLchar**) &code, nullptr);
  37. glCompileShader (shaderID);
  38. #if JUCE_DEBUG
  39. GLint status = 0;
  40. glGetShaderiv (shaderID, GL_COMPILE_STATUS, &status);
  41. if (status == GL_FALSE)
  42. {
  43. GLchar infoLog [16384];
  44. GLsizei infologLength = 0;
  45. glGetShaderInfoLog (shaderID, sizeof (infoLog), &infologLength, infoLog);
  46. DBG (String (infoLog, infologLength));
  47. jassertfalse;
  48. }
  49. #endif
  50. glAttachShader (programID, shaderID);
  51. glDeleteShader (shaderID);
  52. }
  53. void OpenGLShaderProgram::link() noexcept
  54. {
  55. glLinkProgram (programID);
  56. #if JUCE_DEBUG
  57. GLint status = 0;
  58. glGetProgramiv (programID, GL_LINK_STATUS, &status);
  59. jassert (status != GL_FALSE);
  60. #endif
  61. }
  62. OpenGLShaderProgram::Uniform::Uniform (const OpenGLShaderProgram& program, const char* const name)
  63. : uniformID (glGetUniformLocation (program.programID, name))
  64. {
  65. jassert (uniformID >= 0);
  66. }
  67. void OpenGLShaderProgram::Uniform::set (GLfloat n1) const noexcept { glUniform1f (uniformID, n1); }
  68. void OpenGLShaderProgram::Uniform::set (GLint n1) const noexcept { glUniform1i (uniformID, n1); }
  69. void OpenGLShaderProgram::Uniform::set (GLfloat n1, GLfloat n2) const noexcept { glUniform2f (uniformID, n1, n2); }
  70. void OpenGLShaderProgram::Uniform::set (GLfloat n1, GLfloat n2, GLfloat n3) const noexcept { glUniform3f (uniformID, n1, n2, n3); }
  71. void OpenGLShaderProgram::Uniform::set (GLfloat n1, GLfloat n2, GLfloat n3, float n4) const noexcept { glUniform4f (uniformID, n1, n2, n3, n4); }
  72. void OpenGLShaderProgram::Uniform::set (GLint n1, GLint n2, GLint n3, GLint n4) const noexcept { glUniform4i (uniformID, n1, n2, n3, n4); }
  73. void OpenGLShaderProgram::Uniform::set (const GLfloat* values, GLsizei numValues) const noexcept { glUniform1fv (uniformID, numValues, values); }