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.

103 lines
3.8KB

  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_OPENGLTEXTURE_H_INCLUDED
  18. #define JUCE_OPENGLTEXTURE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Creates an openGL texture from an Image.
  22. */
  23. class JUCE_API OpenGLTexture
  24. {
  25. public:
  26. OpenGLTexture();
  27. ~OpenGLTexture();
  28. /** Creates a texture from the given image.
  29. Note that if the image's dimensions aren't a power-of-two, the texture may
  30. be created with a larger size.
  31. The image will be arranged so that its top-left corner is at texture
  32. coordinate (0, 1).
  33. */
  34. void loadImage (const Image& image);
  35. /** Creates a texture from a raw array of pixels.
  36. If width and height are not powers-of-two, the texture will be created with a
  37. larger size, and only the subsection (0, 0, width, height) will be initialised.
  38. The data is sent directly to the OpenGL driver without being flipped vertically,
  39. so the first pixel will be mapped onto texture coordinate (0, 0).
  40. */
  41. void loadARGB (const PixelARGB* pixels, int width, int height);
  42. /** Creates a texture from a raw array of pixels.
  43. This is like loadARGB, but will vertically flip the data so that the first
  44. pixel ends up at texture coordinate (0, 1), and if the width and height are
  45. not powers-of-two, it will compensate by using a larger texture size.
  46. */
  47. void loadARGBFlipped (const PixelARGB* pixels, int width, int height);
  48. /** Creates an alpha-channel texture from an array of alpha values.
  49. If width and height are not powers-of-two, the texture will be created with a
  50. larger size, and only the subsection (0, 0, width, height) will be initialised.
  51. The data is sent directly to the OpenGL driver without being flipped vertically,
  52. so the first pixel will be mapped onto texture coordinate (0, 0).
  53. */
  54. void loadAlpha (const uint8* pixels, int width, int height);
  55. /** Frees the texture, if there is one. */
  56. void release();
  57. /** Binds the texture to the currently active openGL context. */
  58. void bind() const;
  59. /** Unbinds the texture to the currently active openGL context. */
  60. void unbind() const;
  61. /** Returns the GL texture ID number. */
  62. GLuint getTextureID() const noexcept { return textureID; }
  63. int getWidth() const noexcept { return width; }
  64. int getHeight() const noexcept { return height; }
  65. /** Returns true if a texture can be created with the given size.
  66. Some systems may require that the sizes are powers-of-two.
  67. */
  68. static bool isValidSize (int width, int height);
  69. private:
  70. GLuint textureID;
  71. int width, height;
  72. OpenGLContext* ownerContext;
  73. void create (int w, int h, const void*, GLenum, bool topLeft);
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLTexture)
  75. };
  76. #endif // JUCE_OPENGLTEXTURE_H_INCLUDED