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.

189 lines
8.0KB

  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. namespace
  19. {
  20. #if JUCE_WINDOWS
  21. #define JUCE_DECLARE_GL_EXTENSION_FUNCTION(name, returnType, params) \
  22. typedef returnType (__stdcall *type_ ## name) params; static type_ ## name name = nullptr;
  23. #else
  24. #define JUCE_DECLARE_GL_EXTENSION_FUNCTION(name, returnType, params) \
  25. typedef returnType (*type_ ## name) params; static type_ ## name name = nullptr;
  26. #endif
  27. #ifndef GL_BGRA_EXT
  28. enum { GL_BGRA_EXT = 0x80e1 };
  29. #endif
  30. #ifndef GL_CLAMP_TO_EDGE
  31. enum { GL_CLAMP_TO_EDGE = 0x812f };
  32. #endif
  33. #ifndef GL_RGBA8
  34. #define GL_RGBA8 GL_RGBA
  35. #endif
  36. #ifndef GL_DEPTH24_STENCIL8
  37. #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
  38. #endif
  39. #if JUCE_WINDOWS
  40. enum
  41. {
  42. WGL_NUMBER_PIXEL_FORMATS_ARB = 0x2000,
  43. WGL_DRAW_TO_WINDOW_ARB = 0x2001,
  44. WGL_ACCELERATION_ARB = 0x2003,
  45. WGL_SWAP_METHOD_ARB = 0x2007,
  46. WGL_SUPPORT_OPENGL_ARB = 0x2010,
  47. WGL_PIXEL_TYPE_ARB = 0x2013,
  48. WGL_DOUBLE_BUFFER_ARB = 0x2011,
  49. WGL_COLOR_BITS_ARB = 0x2014,
  50. WGL_RED_BITS_ARB = 0x2015,
  51. WGL_GREEN_BITS_ARB = 0x2017,
  52. WGL_BLUE_BITS_ARB = 0x2019,
  53. WGL_ALPHA_BITS_ARB = 0x201B,
  54. WGL_DEPTH_BITS_ARB = 0x2022,
  55. WGL_STENCIL_BITS_ARB = 0x2023,
  56. WGL_FULL_ACCELERATION_ARB = 0x2027,
  57. WGL_ACCUM_RED_BITS_ARB = 0x201E,
  58. WGL_ACCUM_GREEN_BITS_ARB = 0x201F,
  59. WGL_ACCUM_BLUE_BITS_ARB = 0x2020,
  60. WGL_ACCUM_ALPHA_BITS_ARB = 0x2021,
  61. WGL_STEREO_ARB = 0x2012,
  62. WGL_SAMPLE_BUFFERS_ARB = 0x2041,
  63. WGL_SAMPLES_ARB = 0x2042,
  64. WGL_TYPE_RGBA_ARB = 0x202B,
  65. GL_OPERAND0_RGB = 0x8590,
  66. GL_OPERAND1_RGB = 0x8591,
  67. GL_OPERAND0_ALPHA = 0x8598,
  68. GL_OPERAND1_ALPHA = 0x8599,
  69. GL_SRC0_RGB = 0x8580,
  70. GL_SRC1_RGB = 0x8581,
  71. GL_SRC0_ALPHA = 0x8588,
  72. GL_SRC1_ALPHA = 0x8589,
  73. GL_TEXTURE0 = 0x84C0,
  74. GL_TEXTURE1 = 0x84C1,
  75. GL_TEXTURE2 = 0x84C2,
  76. GL_COMBINE = 0x8570,
  77. GL_COMBINE_RGB = 0x8571,
  78. GL_COMBINE_ALPHA = 0x8572,
  79. GL_PREVIOUS = 0x8578,
  80. GL_COMPILE_STATUS = 0x8B81,
  81. GL_LINK_STATUS = 0x8B82,
  82. GL_SHADING_LANGUAGE_VERSION = 0x8B8C,
  83. GL_FRAGMENT_SHADER = 0x8B30,
  84. GL_VERTEX_SHADER = 0x8B31,
  85. GL_FRAMEBUFFER = 0x8D40,
  86. GL_RENDERBUFFER = 0x8D41,
  87. GL_FRAMEBUFFER_BINDING = 0x8CA6,
  88. GL_COLOR_ATTACHMENT0 = 0x8CE0,
  89. GL_DEPTH_ATTACHMENT = 0x8D00,
  90. GL_STENCIL_ATTACHMENT = 0x8D20,
  91. GL_FRAMEBUFFER_COMPLETE = 0x8CD5,
  92. GL_DEPTH24_STENCIL8 = 0x88F0,
  93. GL_RENDERBUFFER_DEPTH_SIZE = 0x8D54
  94. };
  95. typedef char GLchar;
  96. #define WGL_FUNCTION_LIST(USE_FUNCTION) \
  97. USE_FUNCTION (wglChoosePixelFormatARB, BOOL, (HDC, const int*, const FLOAT*, UINT, int*, UINT*))\
  98. USE_FUNCTION (wglSwapIntervalEXT, BOOL, (int))\
  99. USE_FUNCTION (wglGetSwapIntervalEXT, int, ())\
  100. WGL_FUNCTION_LIST (JUCE_DECLARE_GL_EXTENSION_FUNCTION)
  101. #endif
  102. #if JUCE_WINDOWS || JUCE_LINUX
  103. #define GL_EXTENSIONS_LIST(USE_FUNCTION) \
  104. USE_FUNCTION (glActiveTexture, void, (GLenum))\
  105. USE_FUNCTION (glClientActiveTexture, void, (GLenum))\
  106. USE_FUNCTION (glCreateProgram, GLuint, ())\
  107. USE_FUNCTION (glDeleteProgram, void, (GLuint))\
  108. USE_FUNCTION (glCreateShader, GLuint, (GLenum))\
  109. USE_FUNCTION (glDeleteShader, void, (GLuint))\
  110. USE_FUNCTION (glShaderSource, void, (GLuint, GLsizei, const GLchar**, const GLint*))\
  111. USE_FUNCTION (glCompileShader, void, (GLuint))\
  112. USE_FUNCTION (glAttachShader, void, (GLuint, GLuint))\
  113. USE_FUNCTION (glLinkProgram, void, (GLuint))\
  114. USE_FUNCTION (glUseProgram, void, (GLuint))\
  115. USE_FUNCTION (glGetShaderiv, void, (GLuint, GLenum, GLint*))\
  116. USE_FUNCTION (glGetShaderInfoLog, void, (GLuint, GLsizei, GLsizei*, GLchar*))\
  117. USE_FUNCTION (glGetProgramiv, void, (GLuint, GLenum, GLint*))\
  118. USE_FUNCTION (glGetUniformLocation, GLint, (GLuint, const GLchar*))\
  119. USE_FUNCTION (glUniform1f, void, (GLint, GLfloat))\
  120. USE_FUNCTION (glUniform1i, void, (GLint, GLint))\
  121. USE_FUNCTION (glUniform2f, void, (GLint, GLfloat, GLfloat))\
  122. USE_FUNCTION (glUniform3f, void, (GLint, GLfloat, GLfloat, GLfloat))\
  123. USE_FUNCTION (glUniform4f, void, (GLint, GLfloat, GLfloat, GLfloat, GLfloat))\
  124. USE_FUNCTION (glUniform4i, void, (GLint, GLint, GLint, GLint, GLint))\
  125. USE_FUNCTION (glUniform1fv, void, (GLint, GLsizei, const GLfloat*))\
  126. USE_FUNCTION (glIsRenderbuffer, GLboolean, (GLuint))\
  127. USE_FUNCTION (glBindRenderbuffer, void, (GLenum, GLuint))\
  128. USE_FUNCTION (glDeleteRenderbuffers, void, (GLsizei, const GLuint*))\
  129. USE_FUNCTION (glGenRenderbuffers, void, (GLsizei, GLuint*))\
  130. USE_FUNCTION (glRenderbufferStorage, void, (GLenum, GLenum, GLsizei, GLsizei))\
  131. USE_FUNCTION (glGetRenderbufferParameteriv, void, (GLenum, GLenum, GLint*))\
  132. USE_FUNCTION (glIsFramebuffer, GLboolean, (GLuint))\
  133. USE_FUNCTION (glBindFramebuffer, void, (GLenum, GLuint))\
  134. USE_FUNCTION (glDeleteFramebuffers, void, (GLsizei, const GLuint*))\
  135. USE_FUNCTION (glGenFramebuffers, void, (GLsizei, GLuint*))\
  136. USE_FUNCTION (glCheckFramebufferStatus, GLenum, (GLenum))\
  137. USE_FUNCTION (glFramebufferTexture1D, void, (GLenum, GLenum, GLenum, GLuint, GLint))\
  138. USE_FUNCTION (glFramebufferTexture2D, void, (GLenum, GLenum, GLenum, GLuint, GLint))\
  139. USE_FUNCTION (glFramebufferTexture3D, void, (GLenum, GLenum, GLenum, GLuint, GLint, GLint))\
  140. USE_FUNCTION (glFramebufferRenderbuffer, void, (GLenum, GLenum, GLenum, GLuint))\
  141. USE_FUNCTION (glGetFramebufferAttachmentParameteriv, void, (GLenum, GLenum, GLenum, GLint*))\
  142. GL_EXTENSIONS_LIST (JUCE_DECLARE_GL_EXTENSION_FUNCTION)
  143. void initialiseGLExtensions()
  144. {
  145. if (glActiveTexture == nullptr)
  146. {
  147. #define FIND_FUNCTION(name, returnType, params) name = (type_ ## name) OpenGLHelpers::getExtensionFunction (#name);
  148. #if JUCE_WINDOWS
  149. WGL_FUNCTION_LIST (FIND_FUNCTION)
  150. #endif
  151. GL_EXTENSIONS_LIST (FIND_FUNCTION)
  152. #undef FIND_FUNCTION
  153. }
  154. }
  155. #undef GL_EXTENSIONS_LIST
  156. #undef WGL_FUNCTION_LIST
  157. #else
  158. void initialiseGLExtensions() {}
  159. #endif
  160. }