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.

99 lines
3.7KB

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