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