1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 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 | |
40 | #include "qshaderimage.h" |
41 | #include "qshaderimage_p.h" |
42 | #include <Qt3DRender/qabstracttexture.h> |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | namespace Qt3DRender { |
47 | |
48 | QShaderImagePrivate::QShaderImagePrivate() |
49 | : Qt3DCore::QNodePrivate() |
50 | , m_texture(nullptr) |
51 | , m_mipLevel(0) |
52 | , m_layer(0) |
53 | , m_access(QShaderImage::ReadWrite) |
54 | , m_format(QShaderImage::Automatic) |
55 | , m_layered(false) |
56 | { |
57 | } |
58 | |
59 | QShaderImagePrivate::~QShaderImagePrivate() |
60 | { |
61 | } |
62 | |
63 | /*! |
64 | \qmltype ShaderImage |
65 | \instantiates Qt3DRender::QShaderImage |
66 | \inqmlmodule Qt3D.Render |
67 | \since 5.14 |
68 | \brief Provides Image access to shader programs. |
69 | |
70 | To make the content of textures available for read and write operations in |
71 | a shader, they need to exposed as ShaderImage. Textures can be composed of |
72 | several mip levels, layers and faces. Additionally declaring a ShaderImage |
73 | allows specifying which level, layer or face of the texture content we want |
74 | to access. |
75 | |
76 | ShaderImage has to be assigned as a Parameter's value and reference a valid |
77 | Qt3D.Render.AbstractTexture to work properly. |
78 | |
79 | If the referenced texture is a one-dimensional array, two-dimensional array, |
80 | three-dimensional, cube map, cube map array, or two-dimensional multisample |
81 | array texture, it is possible to bind either the entire texture level or a |
82 | single layer or face of the texture level. This can be controlled with the |
83 | \l layered property. |
84 | |
85 | Support for ShaderImage is only supported with OpenGL 4 and partially with |
86 | OpenGL ES 3.1 and 3.2. |
87 | |
88 | OpenGL 4 supports the following image types: |
89 | \table |
90 | \header |
91 | \li GLSL Type |
92 | \li OpenGL Type Enum |
93 | \li Texture Type |
94 | \row |
95 | \li image1D |
96 | \li GL_IMAGE_1D |
97 | \li Texture1D |
98 | \row |
99 | \li image2D |
100 | \li GL_IMAGE_2D |
101 | \li Texture2D |
102 | \row |
103 | \li image3D |
104 | \li GL_IMAGE_3D |
105 | \li Texture3D |
106 | \row |
107 | \li image2DRect |
108 | \li GL_IMAGE_2D_RECT |
109 | \li TextureRectangle |
110 | \row |
111 | \li imageCube |
112 | \li GL_IMAGE_CUBE |
113 | \li TextureCubeMap |
114 | \row |
115 | \li imageBuffer |
116 | \li GL_IMAGE_BUFFER |
117 | \li TextureBuffer |
118 | \row |
119 | \li image1DArray |
120 | \li GL_IMAGE_1D_ARRAY |
121 | \li Texture1DArray |
122 | \row |
123 | \li image2DArray |
124 | \li GL_IMAGE_2D_ARRAY |
125 | \li Texture2DArray |
126 | \row |
127 | \li imageCubeArray |
128 | \li GL_IMAGE_CUBE_MAP_ARRAY |
129 | \li TextureCubeMapArray |
130 | \row |
131 | \li image2DMS |
132 | \li GL_IMAGE_2D_MULTISAMPLE |
133 | \li Texture2DMultisample |
134 | \row |
135 | \li image2DMSArray |
136 | \li GL_IMAGE_2D_MULTISAMPLE_ARRAY |
137 | \li Texture2DMultisampleArray |
138 | \row |
139 | \li iimage1D |
140 | \li GL_INT_IMAGE_1D |
141 | \li Texture1D |
142 | \row |
143 | \li iimage2D |
144 | \li GL_INT_IMAGE_2D |
145 | \li Texture2D |
146 | \row |
147 | \li iimage3D |
148 | \li GL_INT_IMAGE_3D |
149 | \li Texture3D |
150 | \row |
151 | \li iimage2DRect |
152 | \li GL_INT_IMAGE_2D_RECT |
153 | \li TextureRectangle |
154 | \row |
155 | \li iimageCube |
156 | \li GL_INT_IMAGE_CUBE |
157 | \li TextureCubeMap |
158 | \row |
159 | \li iimageBuffer |
160 | \li GL_INT_IMAGE_BUFFER |
161 | \li TextureBuffer |
162 | \row |
163 | \li iimage1DArray |
164 | \li GL_INT_IMAGE_1D_ARRAY |
165 | \li Texture1DArray |
166 | \row |
167 | \li iimage2DArray |
168 | \li GL_INT_IMAGE_2D_ARRAY |
169 | \li Texture2DArray |
170 | \row |
171 | \li iimageCubeArray |
172 | \li GL_INT_IMAGE_CUBE_MAP_ARRAY |
173 | \li TextureCubeMapArray |
174 | \row |
175 | \li iimage2DMS |
176 | \li GL_INT_IMAGE_2D_MULTISAMPLE |
177 | \li Texture2DMultisample |
178 | \row |
179 | \li iimage2DMSArray |
180 | \li GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY |
181 | \li Texture2DMultisampleArray |
182 | \row |
183 | \li uimage1D |
184 | \li GL_UNSIGNED_INT_IMAGE_1D |
185 | \li Texture1D |
186 | \row |
187 | \li uimage2D |
188 | \li GL_UNSIGNED_INT_IMAGE_2D |
189 | \li Texture2D |
190 | \row |
191 | \li uimage3D |
192 | \li GL_UNSIGNED_INT_IMAGE_3D |
193 | \li Texture3D |
194 | \row |
195 | \li uimage2DRect |
196 | \li GL_UNSIGNED_INT_IMAGE_2D_RECT |
197 | \li TextureRectangle |
198 | \row |
199 | \li uimageCube |
200 | \li GL_UNSIGNED_INT_IMAGE_CUBE |
201 | \li TextureCubeMap |
202 | \row |
203 | \li uimageBuffer |
204 | \li GL_UNSIGNED_INT_IMAGE_BUFFER |
205 | \li TextureBuffer |
206 | \row |
207 | \li uimage1DArray |
208 | \li GL_UNSIGNED_INT_IMAGE_1D_ARRAY |
209 | \li Texture1DArray |
210 | \row |
211 | \li uimage2DArray |
212 | \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY |
213 | \li Texture2DArray |
214 | \row |
215 | \li uimageCubeArray |
216 | \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY |
217 | \li TextureCubeMapArray |
218 | \row |
219 | \li uimage2DMS |
220 | \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE |
221 | \li Texture2DMultisample |
222 | \row |
223 | \li uimage2DMSArray |
224 | \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY |
225 | \li Texture2DMultisampleArray |
226 | \endtable |
227 | |
228 | OpenGL ES 3.1 supports the following image types: |
229 | \table |
230 | \header |
231 | \li GLSL Type |
232 | \li OpenGL Type Enum |
233 | \li Texture Type |
234 | \row |
235 | \li image2D |
236 | \li GL_IMAGE_2D |
237 | \li Texture2D |
238 | \row |
239 | \li image3D |
240 | \li GL_IMAGE_3D |
241 | \li Texture3D |
242 | \row |
243 | \li imageCube |
244 | \li GL_IMAGE_CUBE |
245 | \li TextureCubeMap |
246 | \row |
247 | \li image2DArray |
248 | \li GL_IMAGE_2D_ARRAY |
249 | \li Texture2DArray |
250 | \row |
251 | \li iimage2D |
252 | \li GL_INT_IMAGE_2D |
253 | \li Texture2D |
254 | \row |
255 | \li iimage3D |
256 | \li GL_INT_IMAGE_3D |
257 | \li Texture3D |
258 | \row |
259 | \li iimageCube |
260 | \li GL_INT_IMAGE_CUBE |
261 | \li TextureCubeMap |
262 | \row |
263 | \li iimage2DArray |
264 | \li GL_INT_IMAGE_2D_ARRAY |
265 | \li Texture2DArray |
266 | \row |
267 | \li uimage2D |
268 | \li GL_UNSIGNED_INT_IMAGE_2D |
269 | \li Texture2D |
270 | \row |
271 | \li uimage3D |
272 | \li GL_UNSIGNED_INT_IMAGE_3D |
273 | \li Texture3D |
274 | \row |
275 | \li uimageCube |
276 | \li GL_UNSIGNED_INT_IMAGE_CUBE |
277 | \li TextureCubeMap |
278 | \row |
279 | \li uimage2DArray |
280 | \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY |
281 | \li Texture2DArray |
282 | \endtable |
283 | |
284 | OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the |
285 | following: |
286 | \table |
287 | \header |
288 | \li GLSL Type |
289 | \li OpenGL Type Enum |
290 | \li Texture Type |
291 | \row |
292 | \li imageBuffer |
293 | \li GL_IMAGE_BUFFER |
294 | \li TextureBuffer |
295 | \row |
296 | \li imageCubeArray |
297 | \li GL_IMAGE_CUBE_MAP_ARRAY |
298 | \li TextureCubeMapArray |
299 | \row |
300 | \li iimageBuffer |
301 | \li GL_IMAGE_BUFFER |
302 | \li TextureBuffer |
303 | \row |
304 | \li iimageCubeArray |
305 | \li GL_INT_IMAGE_CUBE_MAP_ARRAY |
306 | \li TextureCubeMapArray |
307 | \row |
308 | \li uimageBuffer |
309 | \li GL_UNSIGNED_INT_IMAGE_BUFFER |
310 | \li TextureBuffer |
311 | \row |
312 | \li uimageCubeArray |
313 | \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY |
314 | \li TextureCubeMapArray |
315 | \endtable |
316 | |
317 | Expected use would look like: |
318 | |
319 | \badcode |
320 | |
321 | import Qt3D.Render 2.14 |
322 | |
323 | Entity { |
324 | ... |
325 | Texture2D { |
326 | id: tex2D |
327 | ... |
328 | } |
329 | |
330 | Material { |
331 | parameters: Parameter { |
332 | name: "imageUniformName" |
333 | value: ShaderImage { |
334 | texture: tex2D |
335 | } |
336 | } |
337 | ... |
338 | } |
339 | ... |
340 | } |
341 | \endcode |
342 | */ |
343 | |
344 | /*! |
345 | \qmlproperty int Qt3D.Render::ShaderImage::mipLevel |
346 | |
347 | Holds which mipLevel out of the referenced texture should be used for the |
348 | ShaderImage. |
349 | |
350 | The default value is 0. |
351 | */ |
352 | |
353 | /*! |
354 | \qmlproperty int Qt3D.Render::ShaderImage::layer |
355 | |
356 | Holds which layer out of the referenced texture should be used for the |
357 | ShaderImage. This property does nothing if \a layered is set to true or if |
358 | the reference texture's type isn't compatible with layers. |
359 | |
360 | \note When the referenced texture is of type cube map or cube map array and |
361 | \a ĺayered is set to false, the face and layer are retrieved in the |
362 | following manner: |
363 | \badcode |
364 | cubeMapLayer = layer / 6 |
365 | cubeMapFace = layer - (cubeMapLayer * 6) |
366 | \endcode |
367 | |
368 | The default value is 0. |
369 | */ |
370 | |
371 | /*! |
372 | * \qmlproperty bool Qt3D.Render::ShaderImage::layered |
373 | |
374 | If set to true, if the referenced texture is a one-dimensional array, |
375 | two-dimensional array, three-dimensional, cube map, cube map array, or |
376 | two-dimensional multisample array texture, the entire level will be bound |
377 | for all layers. If set to false, only the single layer specified by the \a |
378 | layer property will be bound. |
379 | |
380 | The default value is \c false. |
381 | */ |
382 | |
383 | /*! |
384 | \qmlproperty enumeration Qt3D.Render::ShaderImage::access |
385 | |
386 | Specifies the type of access we want to allow from our shader instances to |
387 | the image. If a shader tries to write or read from an image that has |
388 | incompatible access, the behavior is undefined. |
389 | |
390 | \value ShaderImage.ReadOnly |
391 | Read-only access. |
392 | \value ShaderImage.WriteOnly |
393 | Write-only access. |
394 | \value ShaderImage.ReadWrite |
395 | Read-write access. |
396 | |
397 | The default value is ShaderImage.ReadWrite. |
398 | */ |
399 | |
400 | /*! |
401 | \qmlproperty enumeration Qt3D.Render::ShaderImage::format |
402 | |
403 | Specifies the image format, which is essentially important when storing values |
404 | in the ShaderImage from a shader. |
405 | |
406 | The format doesn't have to be the same as the referenced texture's format. |
407 | It however has to be compatible (matching in size but not necessarily by |
408 | class type). For instance a texture of format R32F (size 32bits, class |
409 | 1x32) could be used with an image of format RGBA8I (size 32bits, class |
410 | 4x8). Table 8.27 of the |
411 | \l{https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf}{OpenGL specifications} |
412 | shows the size and class for all supported image formats. |
413 | |
414 | By default Qt3D will try to set the image format to match that of the |
415 | referenced texture. |
416 | |
417 | The default value is ShaderImage.Automatic. |
418 | */ |
419 | |
420 | /*! |
421 | \class Qt3DRender::QShaderImage |
422 | \inmodule Qt3DRender |
423 | \since 5.14 |
424 | \brief Provides Image access to shader programs. |
425 | |
426 | To make the content of textures available for read and write operations in |
427 | a shader, they need to exposed as QShaderImage. Textures can be composed of |
428 | several mip levels, layers and faces. Additionally declaring a QShaderImage |
429 | allows specifying which level, layer or face of the texture content we want |
430 | to access. |
431 | |
432 | QShaderImage has to be assigned as a QParameter's value and reference a valid |
433 | Qt3DRender::QAbstractTexture to work properly. |
434 | |
435 | If the referenced texture is a one-dimensional array, two-dimensional array, |
436 | three-dimensional, cube map, cube map array, or two-dimensional multisample |
437 | array texture, it is possible to bind either the entire texture level or a |
438 | single layer or face of the texture level. This can be controlled with the |
439 | \l layered property. |
440 | |
441 | Support for QShaderImage is only supported with OpenGL 4 and partially with |
442 | OpenGL ES 3.1 and 3.2. |
443 | |
444 | OpenGL 4 supports the following image types: |
445 | \table |
446 | \header |
447 | \li GLSL Type |
448 | \li OpenGL Type Enum |
449 | \li Texture Type |
450 | \row |
451 | \li image1D |
452 | \li GL_IMAGE_1D |
453 | \li QTexture1D |
454 | \row |
455 | \li image2D |
456 | \li GL_IMAGE_2D |
457 | \li QTexture2D |
458 | \row |
459 | \li image3D |
460 | \li GL_IMAGE_3D |
461 | \li QTexture3D |
462 | \row |
463 | \li image2DRect |
464 | \li GL_IMAGE_2D_RECT |
465 | \li QTextureRectangle |
466 | \row |
467 | \li imageCube |
468 | \li GL_IMAGE_CUBE |
469 | \li QTextureCubeMap |
470 | \row |
471 | \li imageBuffer |
472 | \li GL_IMAGE_BUFFER |
473 | \li QTextureBuffer |
474 | \row |
475 | \li image1DArray |
476 | \li GL_IMAGE_1D_ARRAY |
477 | \li QTexture1DArray |
478 | \row |
479 | \li image2DArray |
480 | \li GL_IMAGE_2D_ARRAY |
481 | \li QTexture2DArray |
482 | \row |
483 | \li imageCubeArray |
484 | \li GL_IMAGE_CUBE_MAP_ARRAY |
485 | \li QTextureCubeMapArray |
486 | \row |
487 | \li image2DMS |
488 | \li GL_IMAGE_2D_MULTISAMPLE |
489 | \li QTexture2DMultisample |
490 | \row |
491 | \li image2DMSArray |
492 | \li GL_IMAGE_2D_MULTISAMPLE_ARRAY |
493 | \li QTexture2DMultisampleArray |
494 | \row |
495 | \li iimage1D |
496 | \li GL_INT_IMAGE_1D |
497 | \li QTexture1D |
498 | \row |
499 | \li iimage2D |
500 | \li GL_INT_IMAGE_2D |
501 | \li QTexture2D |
502 | \row |
503 | \li iimage3D |
504 | \li GL_INT_IMAGE_3D |
505 | \li QTexture3D |
506 | \row |
507 | \li iimage2DRect |
508 | \li GL_INT_IMAGE_2D_RECT |
509 | \li QTextureRectangle |
510 | \row |
511 | \li iimageCube |
512 | \li GL_INT_IMAGE_CUBE |
513 | \li QTextureCubeMap |
514 | \row |
515 | \li iimageBuffer |
516 | \li GL_INT_IMAGE_BUFFER |
517 | \li QTextureBuffer |
518 | \row |
519 | \li iimage1DArray |
520 | \li GL_INT_IMAGE_1D_ARRAY |
521 | \li QTexture1DArray |
522 | \row |
523 | \li iimage2DArray |
524 | \li GL_INT_IMAGE_2D_ARRAY |
525 | \li QTexture2DArray |
526 | \row |
527 | \li iimageCubeArray |
528 | \li GL_INT_IMAGE_CUBE_MAP_ARRAY |
529 | \li QTextureCubeMapArray |
530 | \row |
531 | \li iimage2DMS |
532 | \li GL_INT_IMAGE_2D_MULTISAMPLE |
533 | \li QTexture2DMultisample |
534 | \row |
535 | \li iimage2DMSArray |
536 | \li GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY |
537 | \li QTexture2DMultisampleArray |
538 | \row |
539 | \li uimage1D |
540 | \li GL_UNSIGNED_INT_IMAGE_1D |
541 | \li QTexture1D |
542 | \row |
543 | \li uimage2D |
544 | \li GL_UNSIGNED_INT_IMAGE_2D |
545 | \li QTexture2D |
546 | \row |
547 | \li uimage3D |
548 | \li GL_UNSIGNED_INT_IMAGE_3D |
549 | \li QTexture3D |
550 | \row |
551 | \li uimage2DRect |
552 | \li GL_UNSIGNED_INT_IMAGE_2D_RECT |
553 | \li QTextureRectangle |
554 | \row |
555 | \li uimageCube |
556 | \li GL_UNSIGNED_INT_IMAGE_CUBE |
557 | \li QTextureCubeMap |
558 | \row |
559 | \li uimageBuffer |
560 | \li GL_UNSIGNED_INT_IMAGE_BUFFER |
561 | \li QTextureBuffer |
562 | \row |
563 | \li uimage1DArray |
564 | \li GL_UNSIGNED_INT_IMAGE_1D_ARRAY |
565 | \li QTexture1DArray |
566 | \row |
567 | \li uimage2DArray |
568 | \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY |
569 | \li QTexture2DArray |
570 | \row |
571 | \li uimageCubeArray |
572 | \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY |
573 | \li QTextureCubeMapArray |
574 | \row |
575 | \li uimage2DMS |
576 | \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE |
577 | \li QTexture2DMultisample |
578 | \row |
579 | \li uimage2DMSArray |
580 | \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY |
581 | \li QTexture2DMultisampleArray |
582 | \endtable |
583 | |
584 | OpenGL ES 3.1 supports the following image types: |
585 | \table |
586 | \header |
587 | \li GLSL Type |
588 | \li OpenGL Type Enum |
589 | \li Texture Type |
590 | \row |
591 | \li image2D |
592 | \li GL_IMAGE_2D |
593 | \li QTexture2D |
594 | \row |
595 | \li image3D |
596 | \li GL_IMAGE_3D |
597 | \li QTexture3D |
598 | \row |
599 | \li imageCube |
600 | \li GL_IMAGE_CUBE |
601 | \li QTextureCubeMap |
602 | \row |
603 | \li image2DArray |
604 | \li GL_IMAGE_2D_ARRAY |
605 | \li QTexture2DArray |
606 | \row |
607 | \li iimage2D |
608 | \li GL_INT_IMAGE_2D |
609 | \li QTexture2D |
610 | \row |
611 | \li iimage3D |
612 | \li GL_INT_IMAGE_3D |
613 | \li QTexture3D |
614 | \row |
615 | \li iimageCube |
616 | \li GL_INT_IMAGE_CUBE |
617 | \li QTextureCubeMap |
618 | \row |
619 | \li iimage2DArray |
620 | \li GL_INT_IMAGE_2D_ARRAY |
621 | \li QTexture2DArray |
622 | \row |
623 | \li uimage2D |
624 | \li GL_UNSIGNED_INT_IMAGE_2D |
625 | \li QTexture2D |
626 | \row |
627 | \li uimage3D |
628 | \li GL_UNSIGNED_INT_IMAGE_3D |
629 | \li QTexture3D |
630 | \row |
631 | \li uimageCube |
632 | \li GL_UNSIGNED_INT_IMAGE_CUBE |
633 | \li QTextureCubeMap |
634 | \row |
635 | \li uimage2DArray |
636 | \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY |
637 | \li QTexture2DArray |
638 | \endtable |
639 | |
640 | OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the |
641 | following: |
642 | \table |
643 | \header |
644 | \li GLSL Type |
645 | \li OpenGL Type Enum |
646 | \li Texture Type |
647 | \row |
648 | \li imageBuffer |
649 | \li GL_IMAGE_BUFFER |
650 | \li QTextureBuffer |
651 | \row |
652 | \li imageCubeArray |
653 | \li GL_IMAGE_CUBE_MAP_ARRAY |
654 | \li QTextureCubeMapArray |
655 | \row |
656 | \li iimageBuffer |
657 | \li GL_IMAGE_BUFFER |
658 | \li QTextureBuffer |
659 | \row |
660 | \li iimageCubeArray |
661 | \li GL_INT_IMAGE_CUBE_MAP_ARRAY |
662 | \li QTextureCubeMapArray |
663 | \row |
664 | \li uimageBuffer |
665 | \li GL_UNSIGNED_INT_IMAGE_BUFFER |
666 | \li QTextureBuffer |
667 | \row |
668 | \li uimageCubeArray |
669 | \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY |
670 | \li QTextureCubeMapArray |
671 | \endtable |
672 | |
673 | Expected use would look like: |
674 | |
675 | \badcode |
676 | Qt3DRender::QTexture2D *tex2D = new Qt3DRender::QTexture2D(); |
677 | ... |
678 | Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial(); |
679 | ... |
680 | Qt3DRender::QParameter *imageParameter = new Qt3DRender::QParameter(); |
681 | Qt3DRender::QShaderImage *shaderImage = new Qt3DRender::QShaderImage(); |
682 | |
683 | shaderImage->setTexture(tex2D); |
684 | |
685 | imageParameter->setName("imageUniformName"); |
686 | imageParameter->setValue(QVariant::fromValue(shaderImage)); |
687 | |
688 | material->addParameter(imageParamenter); |
689 | \endcode |
690 | */ |
691 | |
692 | /*! |
693 | \property Qt3DRender::QShaderImage::mipLevel |
694 | |
695 | Holds which mipLevel out of the referenced texture should be used for the |
696 | QShaderImage. |
697 | |
698 | The default value is 0. |
699 | */ |
700 | |
701 | /*! |
702 | \property Qt3DRender::QShaderImage::layer |
703 | |
704 | Holds which layer out of the referenced texture should be used for the |
705 | QShaderImage. This property does nothing if \a layered is set to true or if the |
706 | reference texture's type isn't compatible with layers. |
707 | |
708 | \note When the referenced texture is of type cube map or cube map array and |
709 | \a ĺayered is set to false, the face and layer are retrieved in the |
710 | following manner: |
711 | \badcode |
712 | cubeMapLayer = layer / 6 |
713 | cubeMapFace = layer - (cubeMapLayer * 6) |
714 | \endcode |
715 | |
716 | The default value is 0. |
717 | */ |
718 | |
719 | /*! |
720 | * \property Qt3DRender::QShaderImage::layered |
721 | |
722 | If set to true, if the referenced texture is a one-dimensional array, |
723 | two-dimensional array, three-dimensional, cube map, cube map array, or |
724 | two-dimensional multisample array texture, the entire level will be bound |
725 | for all layers. If set to false, only the single layer specified by the \a |
726 | layer property will be bound. |
727 | |
728 | The default value is \c false. |
729 | */ |
730 | |
731 | /*! |
732 | \property Qt3DRender::QShaderImage::access |
733 | |
734 | Specifies the type of access we want to allow from our shader instances to |
735 | the image. If a shader tries to write or read from an image that has |
736 | incompatible access, the behavior is undefined. |
737 | |
738 | The default value is QShaderImage::ReadWrite. |
739 | */ |
740 | |
741 | /*! |
742 | \property Qt3DRender::QShaderImage::format |
743 | |
744 | Specifies the image format, which is essentially important when storing values |
745 | in the Image from a shader. |
746 | |
747 | The format doesn't have to be the same as the referenced texture's format. |
748 | It however has to be compatible (matching in size but not necessarily by |
749 | class type). For instance a texture of format R32F (size 32bits, class |
750 | 1x32) could be used with an image of format RGBA8I (size 32bits, class |
751 | 4x8). Table 8.27 of the |
752 | \l{https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf}{OpenGL specifications} |
753 | shows the size and class for all supported Image formats. |
754 | |
755 | By default Qt3D will try to set the image format to match that of the |
756 | referenced texture. |
757 | |
758 | The default value is QShaderImage::Automatic. |
759 | */ |
760 | |
761 | /*! |
762 | \enum Qt3DRender::QShaderImage::Access |
763 | |
764 | \value ReadOnly |
765 | Image will only be read from in shaders |
766 | \value WriteOnly |
767 | Image will only be written into from shaders |
768 | \value ReadWrite |
769 | Image will only be read and written into from shaders |
770 | */ |
771 | |
772 | /*! |
773 | \enum Qt3DRender::QShaderImage::ImageFormat |
774 | |
775 | This list describes all possible image formats |
776 | |
777 | \value NoFormat |
778 | GL_NONE |
779 | \value Automatic |
780 | Qt 3D will try to determine the format automatically based on |
781 | the referenced texture. |
782 | \value R8_UNorm |
783 | GL_R8 (GLSL type r8, supported by OpenGL 4.2+) |
784 | \value RG8_UNorm |
785 | GL_RG8 (GLSL type rg8, supported by OpenGL 4.2+) |
786 | \value RGBA8_UNorm |
787 | GL_RGBA8 (GLSL type rgba8, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
788 | \value R16_UNorm |
789 | GL_R16 (GLSL type r16, supported by OpenGL 4.2+) |
790 | \value RG16_UNorm |
791 | GL_RG16 (GLSL type rg16, supported by OpenGL 4.2+) |
792 | \value RGBA16_UNorm |
793 | GL_RGBA16 (GLSL type rgba16, supported by OpenGL 4.2+) |
794 | \value R8_SNorm |
795 | GL_R8_SNORM (GLSL type r8_snorm, supported by OpenGL 4.2+) |
796 | \value RG8_SNorm |
797 | GL_RG8_SNORM (GLSL type rg8_snorm, supported by OpenGL 4.2+) |
798 | \value RGBA8_SNorm |
799 | GL_RGBA8_SNORM (GLSL type rgba8_snorm, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
800 | \value R16_SNorm |
801 | GL_R16_SNORM (GLSL type r16_snorm, supported by OpenGL 4.2+) |
802 | \value RG16_SNorm |
803 | GL_RG16_SNORM (GLSL type rg16_snorm, supported by OpenGL 4.2+) |
804 | \value RGBA16_SNorm |
805 | GL_RGBA16_SNORM (GLSL type rgba16_snorm, supported by OpenGL 4.2+) |
806 | \value R8U |
807 | GL_R8UI (GLSL type r8ui, supported by OpenGL 4.2+) |
808 | \value RG8U |
809 | GL_RG8UI (GLSL type rg8ui, supported by OpenGL 4.2+) |
810 | \value RGBA8U |
811 | GL_RGBA8UI (GLSL type rgba8ui, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
812 | \value R16U |
813 | GL_R16UI (GLSL type r16ui, supported by OpenGL 4.2+) |
814 | \value RG16U |
815 | GL_RG16UI (GLSL type rg16ui, supported by OpenGL 4.2+) |
816 | \value RGBA16U |
817 | GL_RGBA16UI (GLSL type rgba16ui, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
818 | \value R32U |
819 | GL_R32UI (GLSL type r32ui, supported by OpenGL 4.2+, OpenGL ES 3.1) |
820 | \value RG32U |
821 | GL_RG32UI (GLSL type rg32ui, supported by OpenGL 4.2+) |
822 | \value RGBA32U |
823 | GL_RGBA32UI (GLSL type rgba32ui, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
824 | \value R8I |
825 | GL_R8I (GLSL type r8i, supported by OpenGL 4.2+) |
826 | \value RG8I |
827 | GL_RG8I (GLSL type rg8i, supported by OpenGL 4.2+) |
828 | \value RGBA8I |
829 | GL_RGBA8I (GLSL type rgba8i, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
830 | \value R16I |
831 | GL_R16I (GLSL type r16i, supported by OpenGL 4.2+) |
832 | \value RG16I |
833 | GL_RG16I (GLSL type rg16i, supported by OpenGL 4.2+) |
834 | \value RGBA16I |
835 | GL_RGBA16I (GLSL type rgba16i, supported by OpenGL 4.2+, OpenGL ES 3.1) |
836 | \value R32I |
837 | GL_R32I (GLSL type r32i, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
838 | \value RG32I |
839 | GL_RG32I (GLSL type rg32i, supported by OpenGL 4.2+) |
840 | \value RGBA32I |
841 | GL_RGBA32I (GLSL type rgba32i, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
842 | \value R16F |
843 | GL_R16F (GLSL type r16f, supported by OpenGL 4.2+) |
844 | \value RG16F |
845 | GL_RG16F (GLSL type rg16f, supported by OpenGL 4.2+) |
846 | \value RGBA16F |
847 | GL_RGBA16F (GLSL type rgba16f, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
848 | \value R32F |
849 | GL_R32F (GLSL type r32f, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
850 | \value RG32F |
851 | GL_RG32F (GLSL type rg32f, supported by OpenGL 4.2+) |
852 | \value RGBA32F |
853 | GL_RGBA32F (GLSL type rgba32f, supported by OpenGL 4.2+, OpenGL ES 3.1+) |
854 | \value RG11B10F |
855 | GL_R11F_G11F_B10F (GLSL type r11f_g11f_b10f, supported by OpenGL 4.2+) |
856 | \value RGB10A2 |
857 | GL_RGB10_A2 (GLSL type rgb10_a2, supported by OpenGL 4.2+) |
858 | \value RGB10A2U |
859 | GL_RGB10_A2UI (GLSL type rgb10_a2ui, supported by OpenGL 4.2+) |
860 | */ |
861 | |
862 | |
863 | QShaderImage::QShaderImage(Qt3DCore::QNode *parent) |
864 | : Qt3DCore::QNode(*new QShaderImagePrivate, parent) |
865 | { |
866 | } |
867 | |
868 | QShaderImage::~QShaderImage() |
869 | { |
870 | |
871 | } |
872 | |
873 | QAbstractTexture *QShaderImage::texture() const |
874 | { |
875 | Q_D(const QShaderImage); |
876 | return d->m_texture; |
877 | } |
878 | |
879 | bool QShaderImage::layered() const |
880 | { |
881 | Q_D(const QShaderImage); |
882 | return d->m_layered; |
883 | } |
884 | |
885 | int QShaderImage::mipLevel() const |
886 | { |
887 | Q_D(const QShaderImage); |
888 | return d->m_mipLevel; |
889 | } |
890 | |
891 | int QShaderImage::layer() const |
892 | { |
893 | Q_D(const QShaderImage); |
894 | return d->m_layer; |
895 | } |
896 | |
897 | QShaderImage::Access QShaderImage::access() const |
898 | { |
899 | Q_D(const QShaderImage); |
900 | return d->m_access; |
901 | } |
902 | |
903 | QShaderImage::ImageFormat QShaderImage::format() const |
904 | { |
905 | Q_D(const QShaderImage); |
906 | return d->m_format; |
907 | } |
908 | |
909 | void QShaderImage::setTexture(QAbstractTexture *texture) |
910 | { |
911 | Q_D(QShaderImage); |
912 | if (texture == d->m_texture) |
913 | return; |
914 | |
915 | if (d->m_texture) |
916 | d->unregisterDestructionHelper(node: d->m_texture); |
917 | |
918 | if (texture && !texture->parent()) |
919 | texture->setParent(this); |
920 | |
921 | d->m_texture = texture; |
922 | |
923 | if (d->m_texture) |
924 | d->registerDestructionHelper(node: d->m_texture, func: &QShaderImage::setTexture, d->m_texture); |
925 | |
926 | Q_EMIT textureChanged(texture); |
927 | } |
928 | |
929 | void QShaderImage::setLayered(bool layered) |
930 | { |
931 | Q_D(QShaderImage); |
932 | if (layered == d->m_layered) |
933 | return; |
934 | d->m_layered = layered; |
935 | Q_EMIT layeredChanged(layered); |
936 | } |
937 | |
938 | void QShaderImage::setMipLevel(int mipLevel) |
939 | { |
940 | Q_D(QShaderImage); |
941 | if (mipLevel == d->m_mipLevel) |
942 | return; |
943 | d->m_mipLevel = mipLevel; |
944 | Q_EMIT mipLevelChanged(mipLevel); |
945 | } |
946 | |
947 | void QShaderImage::setLayer(int layer) |
948 | { |
949 | Q_D(QShaderImage); |
950 | if (layer == d->m_layer) |
951 | return; |
952 | d->m_layer = layer; |
953 | Q_EMIT layerChanged(layer); |
954 | } |
955 | |
956 | void QShaderImage::setAccess(QShaderImage::Access access) |
957 | { |
958 | Q_D(QShaderImage); |
959 | if (access == d->m_access) |
960 | return; |
961 | d->m_access = access; |
962 | Q_EMIT accessChanged(access); |
963 | } |
964 | |
965 | void QShaderImage::setFormat(QShaderImage::ImageFormat format) |
966 | { |
967 | Q_D(QShaderImage); |
968 | if (format == d->m_format) |
969 | return; |
970 | d->m_format = format; |
971 | Q_EMIT formatChanged(format); |
972 | } |
973 | |
974 | Qt3DCore::QNodeCreatedChangeBasePtr Qt3DRender::QShaderImage::createNodeCreationChange() const |
975 | { |
976 | auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QShaderImageData>::create(arguments: this); |
977 | QShaderImageData &data = creationChange->data; |
978 | Q_D(const QShaderImage); |
979 | data.textureId = Qt3DCore::qIdForNode(node: d->m_texture); |
980 | data.layer = d->m_layer; |
981 | data.mipLevel = d->m_mipLevel; |
982 | data.access = d->m_access; |
983 | data.format = d->m_format; |
984 | data.layered = d->m_layered; |
985 | return creationChange; |
986 | |
987 | } |
988 | |
989 | } // namespace Qt3DRender |
990 | |
991 | QT_END_NAMESPACE |
992 | |