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.6KB

  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. #ifndef __JUCE_OPENGLTEXTURE_JUCEHEADER__
  19. #define __JUCE_OPENGLTEXTURE_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Creates an openGL texture from an Image.
  23. */
  24. class JUCE_API OpenGLTexture
  25. {
  26. public:
  27. OpenGLTexture();
  28. ~OpenGLTexture();
  29. /** Creates a texture from the given image.
  30. Note that if the image's dimensions aren't a power-of-two, the texture may
  31. be created with a larger size.
  32. The image will be arranged so that its top-left corner is at texture
  33. coordinate (0, 1).
  34. */
  35. void loadImage (const Image& image);
  36. /** Creates a texture from a raw array of pixels.
  37. The width and height provided must be valid - i.e. power-of-two unless
  38. the underlying GL system allows otherwise.
  39. The data is sent directly to the OpenGL driver without being flipped vertically,
  40. so the first pixel will be mapped onto texture coordinate (0, 0).
  41. bottom-left corner of the texture
  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. The width and height provided must be valid - i.e. power-of-two unless
  52. the underlying GL system allows otherwise.
  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. bottom-left corner of the texture
  56. */
  57. void loadAlpha (const uint8* pixels, int width, int height);
  58. /** Frees the texture, if there is one. */
  59. void release();
  60. /** Binds the texture to the currently selected openGL context. */
  61. void bind() const;
  62. /** Unbinds the texture to the currently selected openGL context. */
  63. void unbind() const;
  64. /** Draws this texture into the current context, with the specified corner positions. */
  65. void draw2D (float x1, float y1,
  66. float x2, float y2,
  67. float x3, float y3,
  68. float x4, float y4,
  69. const Colour& colour) const;
  70. /** Draws this texture into the current context, with the specified corner positions. */
  71. void draw3D (float x1, float y1, float z1,
  72. float x2, float y2, float z2,
  73. float x3, float y3, float z3,
  74. float x4, float y4, float z4,
  75. const Colour& colour) const;
  76. /** Returns the GL texture ID number. */
  77. GLuint getTextureID() const noexcept { return textureID; }
  78. int getWidth() const noexcept { return width; }
  79. int getHeight() const noexcept { return height; }
  80. /** Returns true if a texture can be created with the given size.
  81. Some systems may require that the sizes are powers-of-two.
  82. */
  83. static bool isValidSize (int width, int height);
  84. private:
  85. GLuint textureID;
  86. int width, height;
  87. void create (int w, int h, const void*, GLenum type);
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenGLTexture);
  89. };
  90. #endif // __JUCE_OPENGLTEXTURE_JUCEHEADER__