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.

105 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Creates an openGL texture from an Image.
  23. @tags{OpenGL}
  24. */
  25. class JUCE_API OpenGLTexture
  26. {
  27. public:
  28. OpenGLTexture();
  29. ~OpenGLTexture();
  30. /** Creates a texture from the given image.
  31. Note that if the image's dimensions aren't a power-of-two, the texture may
  32. be created with a larger size.
  33. The image will be arranged so that its top-left corner is at texture
  34. coordinate (0, 1).
  35. */
  36. void loadImage (const Image& image);
  37. /** Creates a texture from a raw array of pixels.
  38. If width and height are not powers-of-two, the texture will be created with a
  39. larger size, and only the subsection (0, 0, width, height) will be initialised.
  40. The data is sent directly to the OpenGL driver without being flipped vertically,
  41. so the first pixel will be mapped onto texture coordinate (0, 0).
  42. */
  43. void loadARGB (const PixelARGB* pixels, int width, int height);
  44. /** Creates a texture from a raw array of pixels.
  45. This is like loadARGB, but will vertically flip the data so that the first
  46. pixel ends up at texture coordinate (0, 1), and if the width and height are
  47. not powers-of-two, it will compensate by using a larger texture size.
  48. */
  49. void loadARGBFlipped (const PixelARGB* pixels, int width, int height);
  50. /** Creates an alpha-channel texture from an array of alpha values.
  51. If width and height are not powers-of-two, the texture will be created with a
  52. larger size, and only the subsection (0, 0, width, height) will be initialised.
  53. The data is sent directly to the OpenGL driver without being flipped vertically,
  54. so the first pixel will be mapped onto texture coordinate (0, 0).
  55. */
  56. void loadAlpha (const uint8* pixels, int width, int height);
  57. /** Frees the texture, if there is one. */
  58. void release();
  59. /** Binds the texture to the currently active openGL context. */
  60. void bind() const;
  61. /** Unbinds the texture to the currently active openGL context. */
  62. void unbind() const;
  63. /** Returns the GL texture ID number. */
  64. GLuint getTextureID() const noexcept { return textureID; }
  65. int getWidth() const noexcept { return width; }
  66. int getHeight() const noexcept { return height; }
  67. /** Returns true if a texture can be created with the given size.
  68. Some systems may require that the sizes are powers-of-two.
  69. */
  70. static bool isValidSize (int width, int height);
  71. private:
  72. GLuint textureID;
  73. int width, height;
  74. OpenGLContext* ownerContext;
  75. void create (int w, int h, const void*, GLenum, bool topLeft);
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLTexture)
  77. };
  78. } // namespace juce