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.

119 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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 selected openGL context. */
  58. void bind() const;
  59. /** Unbinds the texture to the currently selected openGL context. */
  60. void unbind() const;
  61. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  62. /** Draws this texture into the current context, with the specified corner positions. */
  63. void draw2D (float x1, float y1,
  64. float x2, float y2,
  65. float x3, float y3,
  66. float x4, float y4,
  67. Colour colour) const;
  68. /** Draws this texture into the current context, with the specified corner positions. */
  69. void draw3D (float x1, float y1, float z1,
  70. float x2, float y2, float z2,
  71. float x3, float y3, float z3,
  72. float x4, float y4, float z4,
  73. Colour colour) const;
  74. #endif
  75. /** Returns the GL texture ID number. */
  76. GLuint getTextureID() const noexcept { return textureID; }
  77. int getWidth() const noexcept { return width; }
  78. int getHeight() const noexcept { return height; }
  79. /** Returns true if a texture can be created with the given size.
  80. Some systems may require that the sizes are powers-of-two.
  81. */
  82. static bool isValidSize (int width, int height);
  83. private:
  84. GLuint textureID;
  85. int width, height;
  86. OpenGLContext* ownerContext;
  87. void create (int w, int h, const void*, GLenum, bool topLeft);
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLTexture)
  89. };
  90. #endif // JUCE_OPENGLTEXTURE_H_INCLUDED