qabstracttexture.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt3D module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QT3DRENDER_QABSTRACTTEXTURE_H
  40. #define QT3DRENDER_QABSTRACTTEXTURE_H
  41. #include <Qt3DRender/qtextureimagedata.h>
  42. #include <Qt3DRender/qt3drender_global.h>
  43. #include <Qt3DCore/qnode.h>
  44. QT_BEGIN_NAMESPACE
  45. namespace Qt3DRender {
  46. class QAbstractTexturePrivate;
  47. class QTextureWrapMode;
  48. class QAbstractTextureImage;
  49. class QTextureGenerator;
  50. typedef QSharedPointer<QTextureGenerator> QTextureGeneratorPtr;
  51. class QT3DRENDERSHARED_EXPORT QAbstractTexture : public Qt3DCore::QNode
  52. {
  53. Q_OBJECT
  54. Q_PROPERTY(Target target READ target CONSTANT)
  55. Q_PROPERTY(TextureFormat format READ format WRITE setFormat NOTIFY formatChanged)
  56. Q_PROPERTY(bool generateMipMaps READ generateMipMaps WRITE setGenerateMipMaps NOTIFY generateMipMapsChanged)
  57. Q_PROPERTY(Qt3DRender::QTextureWrapMode *wrapMode READ wrapMode CONSTANT)
  58. Q_PROPERTY(Status status READ status NOTIFY statusChanged)
  59. Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
  60. Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
  61. Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY depthChanged)
  62. Q_PROPERTY(Filter magnificationFilter READ magnificationFilter WRITE setMagnificationFilter NOTIFY magnificationFilterChanged)
  63. Q_PROPERTY(Filter minificationFilter READ minificationFilter WRITE setMinificationFilter NOTIFY minificationFilterChanged)
  64. Q_PROPERTY(float maximumAnisotropy READ maximumAnisotropy WRITE setMaximumAnisotropy NOTIFY maximumAnisotropyChanged)
  65. Q_PROPERTY(ComparisonFunction comparisonFunction READ comparisonFunction WRITE setComparisonFunction NOTIFY comparisonFunctionChanged)
  66. Q_PROPERTY(ComparisonMode comparisonMode READ comparisonMode WRITE setComparisonMode NOTIFY comparisonModeChanged)
  67. Q_PROPERTY(int layers READ layers WRITE setLayers NOTIFY layersChanged)
  68. public:
  69. enum Status {
  70. None = 0,
  71. Loading,
  72. Ready,
  73. Error
  74. };
  75. Q_ENUM(Status)
  76. enum Target {
  77. TargetAutomatic = 0, // Target will be determined by the Qt3D engine
  78. Target1D = 0x0DE0, // GL_TEXTURE_1D
  79. Target1DArray = 0x8C18, // GL_TEXTURE_1D_ARRAY
  80. Target2D = 0x0DE1, // GL_TEXTURE_2D
  81. Target2DArray = 0x8C1A, // GL_TEXTURE_2D_ARRAY
  82. Target3D = 0x806F, // GL_TEXTURE_3D
  83. TargetCubeMap = 0x8513, // GL_TEXTURE_CUBE_MAP
  84. TargetCubeMapArray = 0x9009, // GL_TEXTURE_CUBE_MAP_ARRAY
  85. Target2DMultisample = 0x9100, // GL_TEXTURE_2D_MULTISAMPLE
  86. Target2DMultisampleArray = 0x9102, // GL_TEXTURE_2D_MULTISAMPLE_ARRAY
  87. TargetRectangle = 0x84F5, // GL_TEXTURE_RECTANGLE
  88. TargetBuffer = 0x8C2A // GL_TEXTURE_BUFFER
  89. };
  90. Q_ENUM(Target)
  91. enum TextureFormat {
  92. NoFormat = 0, // GL_NONE
  93. Automatic = 1, // The Qt3D engine automatically determines the best format
  94. // Unsigned normalized formats
  95. R8_UNorm = 0x8229, // GL_R8
  96. RG8_UNorm = 0x822B, // GL_RG8
  97. RGB8_UNorm = 0x8051, // GL_RGB8
  98. RGBA8_UNorm = 0x8058, // GL_RGBA8
  99. R16_UNorm = 0x822A, // GL_R16
  100. RG16_UNorm = 0x822C, // GL_RG16
  101. RGB16_UNorm = 0x8054, // GL_RGB16
  102. RGBA16_UNorm = 0x805B, // GL_RGBA16
  103. // Signed normalized formats
  104. R8_SNorm = 0x8F94, // GL_R8_SNORM
  105. RG8_SNorm = 0x8F95, // GL_RG8_SNORM
  106. RGB8_SNorm = 0x8F96, // GL_RGB8_SNORM
  107. RGBA8_SNorm = 0x8F97, // GL_RGBA8_SNORM
  108. R16_SNorm = 0x8F98, // GL_R16_SNORM
  109. RG16_SNorm = 0x8F99, // GL_RG16_SNORM
  110. RGB16_SNorm = 0x8F9A, // GL_RGB16_SNORM
  111. RGBA16_SNorm = 0x8F9B, // GL_RGBA16_SNORM
  112. // Unsigned integer formats
  113. R8U = 0x8232, // GL_R8UI
  114. RG8U = 0x8238, // GL_RG8UI
  115. RGB8U = 0x8D7D, // GL_RGB8UI
  116. RGBA8U = 0x8D7C, // GL_RGBA8UI
  117. R16U = 0x8234, // GL_R16UI
  118. RG16U = 0x823A, // GL_RG16UI
  119. RGB16U = 0x8D77, // GL_RGB16UI
  120. RGBA16U = 0x8D76, // GL_RGBA16UI
  121. R32U = 0x8236, // GL_R32UI
  122. RG32U = 0x823C, // GL_RG32UI
  123. RGB32U = 0x8D71, // GL_RGB32UI
  124. RGBA32U = 0x8D70, // GL_RGBA32UI
  125. // Signed integer formats
  126. R8I = 0x8231, // GL_R8I
  127. RG8I = 0x8237, // GL_RG8I
  128. RGB8I = 0x8D8F, // GL_RGB8I
  129. RGBA8I = 0x8D8E, // GL_RGBA8I
  130. R16I = 0x8233, // GL_R16I
  131. RG16I = 0x8239, // GL_RG16I
  132. RGB16I = 0x8D89, // GL_RGB16I
  133. RGBA16I = 0x8D88, // GL_RGBA16I
  134. R32I = 0x8235, // GL_R32I
  135. RG32I = 0x823B, // GL_RG32I
  136. RGB32I = 0x8D83, // GL_RGB32I
  137. RGBA32I = 0x8D82, // GL_RGBA32I
  138. // Floating point formats
  139. R16F = 0x822D, // GL_R16F
  140. RG16F = 0x822F, // GL_RG16F
  141. RGB16F = 0x881B, // GL_RGB16F
  142. RGBA16F = 0x881A, // GL_RGBA16F
  143. R32F = 0x822E, // GL_R32F
  144. RG32F = 0x8230, // GL_RG32F
  145. RGB32F = 0x8815, // GL_RGB32F
  146. RGBA32F = 0x8814, // GL_RGBA32F
  147. // Packed formats
  148. RGB9E5 = 0x8C3D, // GL_RGB9_E5
  149. RG11B10F = 0x8C3A, // GL_R11F_G11F_B10F
  150. RG3B2 = 0x2A10, // GL_R3_G3_B2
  151. R5G6B5 = 0x8D62, // GL_RGB565
  152. RGB5A1 = 0x8057, // GL_RGB5_A1
  153. RGBA4 = 0x8056, // GL_RGBA4
  154. RGB10A2 = 0x906F, // GL_RGB10_A2UI
  155. // Depth formats
  156. D16 = 0x81A5, // GL_DEPTH_COMPONENT16
  157. D24 = 0x81A6, // GL_DEPTH_COMPONENT24
  158. D24S8 = 0x88F0, // GL_DEPTH24_STENCIL8
  159. D32 = 0x81A7, // GL_DEPTH_COMPONENT32
  160. D32F = 0x8CAC, // GL_DEPTH_COMPONENT32F
  161. D32FS8X24 = 0x8CAD, // GL_DEPTH32F_STENCIL8
  162. // Compressed formats
  163. RGB_DXT1 = 0x83F0, // GL_COMPRESSED_RGB_S3TC_DXT1_EXT
  164. RGBA_DXT1 = 0x83F1, // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
  165. RGBA_DXT3 = 0x83F2, // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
  166. RGBA_DXT5 = 0x83F3, // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
  167. R_ATI1N_UNorm = 0x8DBB, // GL_COMPRESSED_RED_RGTC1
  168. R_ATI1N_SNorm = 0x8DBC, // GL_COMPRESSED_SIGNED_RED_RGTC1
  169. RG_ATI2N_UNorm = 0x8DBD, // GL_COMPRESSED_RG_RGTC2
  170. RG_ATI2N_SNorm = 0x8DBE, // GL_COMPRESSED_SIGNED_RG_RGTC2
  171. RGB_BP_UNSIGNED_FLOAT = 0x8E8F, // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
  172. RGB_BP_SIGNED_FLOAT = 0x8E8E, // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
  173. RGB_BP_UNorm = 0x8E8C, // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
  174. R11_EAC_UNorm = 0x9270, // GL_COMPRESSED_R11_EAC
  175. R11_EAC_SNorm = 0x9271, // GL_COMPRESSED_SIGNED_R11_EAC
  176. RG11_EAC_UNorm = 0x9272, // GL_COMPRESSED_RG11_EAC
  177. RG11_EAC_SNorm = 0x9273, // GL_COMPRESSED_SIGNED_RG11_EAC
  178. RGB8_ETC2 = 0x9274, // GL_COMPRESSED_RGB8_ETC2
  179. SRGB8_ETC2 = 0x9275, // GL_COMPRESSED_SRGB8_ETC2
  180. RGB8_PunchThrough_Alpha1_ETC2 = 0x9276, // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
  181. SRGB8_PunchThrough_Alpha1_ETC2 = 0x9277, // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
  182. RGBA8_ETC2_EAC = 0x9278, // GL_COMPRESSED_RGBA8_ETC2_EAC
  183. SRGB8_Alpha8_ETC2_EAC = 0x9279, // GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
  184. RGB8_ETC1 = 0x8D64, // GL_ETC1_RGB8_OES
  185. // sRGB formats
  186. SRGB8 = 0x8C41, // GL_SRGB8
  187. SRGB8_Alpha8 = 0x8C43, // GL_SRGB8_ALPHA8
  188. SRGB_DXT1 = 0x8C4C, // GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
  189. SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
  190. SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
  191. SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
  192. SRGB_BP_UNorm = 0x8E8D, // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
  193. // ES 2 formats
  194. DepthFormat = 0x1902, // GL_DEPTH_COMPONENT
  195. AlphaFormat = 0x1906, // GL_ALPHA
  196. RGBFormat = 0x1907, // GL_RGB
  197. RGBAFormat = 0x1908, // GL_RGBA
  198. LuminanceFormat = 0x1909, // GL_LUMINANCE
  199. LuminanceAlphaFormat = 0x190A
  200. };
  201. Q_ENUM(TextureFormat)
  202. enum Filter {
  203. Nearest = 0x2600, // GL_NEAREST
  204. Linear = 0x2601, // GL_LINEAR
  205. NearestMipMapNearest = 0x2700, // GL_NEAREST_MIPMAP_NEAREST
  206. NearestMipMapLinear = 0x2702, // GL_NEAREST_MIPMAP_LINEAR
  207. LinearMipMapNearest = 0x2701, // GL_LINEAR_MIPMAP_NEAREST
  208. LinearMipMapLinear = 0x2703 // GL_LINEAR_MIPMAP_LINEAR
  209. };
  210. Q_ENUM(Filter)
  211. enum CubeMapFace {
  212. CubeMapPositiveX = 0x8515, // GL_TEXTURE_CUBE_MAP_POSITIVE_X
  213. CubeMapNegativeX = 0x8516, // GL_TEXTURE_CUBE_MAP_NEGATIVE_X
  214. CubeMapPositiveY = 0x8517, // GL_TEXTURE_CUBE_MAP_POSITIVE_Y
  215. CubeMapNegativeY = 0x8518, // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
  216. CubeMapPositiveZ = 0x8519, // GL_TEXTURE_CUBE_MAP_POSITIVE_Z
  217. CubeMapNegativeZ = 0x851A // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
  218. };
  219. Q_ENUM(CubeMapFace)
  220. enum ComparisonFunction {
  221. CompareLessEqual = 0x0203, // GL_LEQUAL
  222. CompareGreaterEqual = 0x0206, // GL_GEQUAL
  223. CompareLess = 0x0201, // GL_LESS
  224. CompareGreater = 0x0204, // GL_GREATER
  225. CompareEqual = 0x0202, // GL_EQUAL
  226. CommpareNotEqual = 0x0205, // GL_NOTEQUAL
  227. CompareAlways = 0x0207, // GL_ALWAYS
  228. CompareNever = 0x0200 // GL_NEVER
  229. };
  230. Q_ENUM(ComparisonFunction)
  231. enum ComparisonMode {
  232. CompareRefToTexture = 0x884E, // GL_COMPARE_REF_TO_TEXTURE
  233. CompareNone = 0x0000 // GL_NONE
  234. };
  235. Q_ENUM(ComparisonMode)
  236. ~QAbstractTexture();
  237. Target target() const;
  238. TextureFormat format() const;
  239. bool generateMipMaps() const;
  240. Status status() const;
  241. void addTextureImage(QAbstractTextureImage *textureImage);
  242. void removeTextureImage(QAbstractTextureImage *textureImage);
  243. QVector<QAbstractTextureImage *> textureImages() const;
  244. // sampler data - in the future proxy to a Sampler helper
  245. void setWrapMode(const QTextureWrapMode &wrapMode);
  246. QTextureWrapMode *wrapMode();
  247. void setSize(int width, int height=1, int depth=1);
  248. Filter minificationFilter() const;
  249. Filter magnificationFilter() const;
  250. float maximumAnisotropy() const;
  251. ComparisonFunction comparisonFunction() const;
  252. ComparisonMode comparisonMode() const;
  253. int width() const;
  254. int height() const;
  255. int depth() const;
  256. int layers() const;
  257. QTextureGeneratorPtr dataGenerator() const;
  258. public Q_SLOTS:
  259. void setFormat(TextureFormat format);
  260. void setGenerateMipMaps(bool gen);
  261. void setWidth(int width);
  262. void setHeight(int height);
  263. void setDepth(int depth);
  264. void setMinificationFilter(Filter f);
  265. void setMagnificationFilter(Filter f);
  266. void setMaximumAnisotropy(float anisotropy);
  267. void setComparisonFunction(ComparisonFunction function);
  268. void setComparisonMode(ComparisonMode mode);
  269. void setLayers(int layers);
  270. Q_SIGNALS:
  271. void formatChanged(TextureFormat format);
  272. void statusChanged(Status status);
  273. void generateMipMapsChanged(bool generateMipMaps);
  274. void widthChanged(int width);
  275. void heightChanged(int height);
  276. void depthChanged(int depth);
  277. void magnificationFilterChanged(Filter magnificationFilter);
  278. void minificationFilterChanged(Filter minificationFilter);
  279. void maximumAnisotropyChanged(float maximumAnisotropy);
  280. void comparisonFunctionChanged(ComparisonFunction comparisonFunction);
  281. void comparisonModeChanged(ComparisonMode comparisonMode);
  282. void layersChanged(int layers);
  283. protected:
  284. explicit QAbstractTexture(Qt3DCore::QNode *parent = nullptr);
  285. explicit QAbstractTexture(Target target, Qt3DCore::QNode *parent = nullptr);
  286. explicit QAbstractTexture(QAbstractTexturePrivate &dd, Qt3DCore::QNode *parent = nullptr);
  287. void setStatus(Status status);
  288. private:
  289. Q_DECLARE_PRIVATE(QAbstractTexture)
  290. Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
  291. };
  292. } // namespace Qt3DRender
  293. QT_END_NAMESPACE
  294. Q_DECLARE_METATYPE(Qt3DRender::QAbstractTexture *)
  295. #endif // QT3DRENDER_QABSTRACTTEXTURE_H