DISTRHO Plugin Framework
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.

Image.hpp 3.5KB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_IMAGE_HPP_INCLUDED
  17. #define DGL_IMAGE_HPP_INCLUDED
  18. #include "ImageBase.hpp"
  19. #include "OpenGL.hpp"
  20. START_NAMESPACE_DGL
  21. // -----------------------------------------------------------------------
  22. /**
  23. OpenGL Image class.
  24. This is an Image class that handles raw image data in pixels.
  25. You can init the image data on the contructor or later on by calling loadFromMemory().
  26. To generate raw data useful for this class see the utils/png2rgba.py script.
  27. Be careful when using a PNG without alpha channel, for those the format is 'GL_BGR'
  28. instead of the default 'GL_BGRA'.
  29. Images are drawn on screen via 2D textures.
  30. */
  31. class Image : public ImageBase
  32. {
  33. public:
  34. /**
  35. Constructor for a null Image.
  36. */
  37. Image();
  38. /**
  39. Constructor using raw image data.
  40. @note @a rawData must remain valid for the lifetime of this Image.
  41. */
  42. Image(const char* const rawData,
  43. const uint width,
  44. const uint height,
  45. const GLenum format = GL_BGRA,
  46. const GLenum type = GL_UNSIGNED_BYTE);
  47. /**
  48. Constructor using raw image data.
  49. @note @a rawData must remain valid for the lifetime of this Image.
  50. */
  51. Image(const char* const rawData,
  52. const Size<uint>& size,
  53. const GLenum format = GL_BGRA,
  54. const GLenum type = GL_UNSIGNED_BYTE);
  55. /**
  56. Constructor using another image data.
  57. */
  58. Image(const Image& image);
  59. /**
  60. Destructor.
  61. */
  62. ~Image() override;
  63. /**
  64. Load image data from memory.
  65. @note @a rawData must remain valid for the lifetime of this Image.
  66. */
  67. void loadFromMemory(const char* const rawData,
  68. const uint width,
  69. const uint height,
  70. const GLenum format = GL_BGRA,
  71. const GLenum type = GL_UNSIGNED_BYTE) noexcept;
  72. /**
  73. Load image data from memory.
  74. @note @a rawData must remain valid for the lifetime of this Image.
  75. */
  76. void loadFromMemory(const char* const rawData,
  77. const Size<uint>& size,
  78. const GLenum format = GL_BGRA,
  79. const GLenum type = GL_UNSIGNED_BYTE) noexcept;
  80. /**
  81. Get the image format.
  82. */
  83. GLenum getFormat() const noexcept;
  84. /**
  85. Get the image type.
  86. */
  87. GLenum getType() const noexcept;
  88. /**
  89. TODO document this.
  90. */
  91. Image& operator=(const Image& image) noexcept;
  92. protected:
  93. /** @internal */
  94. void _drawAt(const Point<int>& pos) override;
  95. private:
  96. GLenum fFormat;
  97. GLenum fType;
  98. GLuint fTextureId;
  99. bool fIsReady;
  100. };
  101. // -----------------------------------------------------------------------
  102. END_NAMESPACE_DGL
  103. #endif