1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2008-2012 NVIDIA Corporation. 4 ** Copyright (C) 2019 The Qt Company Ltd. 5 ** Contact: https://www.qt.io/licensing/ 6 ** 7 ** This file is part of Qt Quick 3D. 8 ** 9 ** $QT_BEGIN_LICENSE:GPL$ 10 ** Commercial License Usage 11 ** Licensees holding valid commercial Qt licenses may use this file in 12 ** accordance with the commercial license agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and The Qt Company. For licensing terms 15 ** and conditions see https://www.qt.io/terms-conditions. For further 16 ** information use the contact form at https://www.qt.io/contact-us. 17 ** 18 ** GNU General Public License Usage 19 ** Alternatively, this file may be used under the terms of the GNU 20 ** General Public License version 3 or (at your option) any later version 21 ** approved by the KDE Free Qt Foundation. The licenses are as published by 22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3 23 ** included in the packaging of this file. Please review the following 24 ** information to ensure the GNU General Public License requirements will 25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 26 ** 27 ** $QT_END_LICENSE$ 28 ** 29 ****************************************************************************/ 30 31 #ifndef QSSG_RENDER_BACKEND_H 32 #define QSSG_RENDER_BACKEND_H 33 34 // 35 // W A R N I N G 36 // ------------- 37 // 38 // This file is not part of the Qt API. It exists purely as an 39 // implementation detail. This header file may change from version to 40 // version without notice, or even be removed. 41 // 42 // We mean it. 43 // 44 45 #include <QtQuick3DRender/private/qtquick3drenderglobal_p.h> 46 #include <QtQuick3DRender/private/qssgrenderbasetypes_p.h> 47 #include <QtQuick3DUtils/private/qssgbounds3_p.h> 48 49 #include <QtGui/qsurfaceformat.h> 50 51 QT_BEGIN_NAMESPACE 52 53 #define HandleToID_cast(staticType, dynamicType, handle) static_cast<staticType>(reinterpret_cast<dynamicType>(handle)) 54 55 class Q_QUICK3DRENDER_EXPORT QSSGRenderBackend 56 { 57 QSSGRenderBackend(const QSSGRenderBackend &) = delete; 58 QSSGRenderBackend &operator=(const QSSGRenderBackend &) = delete; 59 60 public: 61 QAtomicInt ref; 62 63 QSSGRenderBackend() = default; ~QSSGRenderBackend()64 virtual ~QSSGRenderBackend() {} 65 /// opaque buffer object handle 66 typedef struct _QSSGRenderBackendBufferObject *QSSGRenderBackendBufferObject; 67 /// opaque attribute layout object handle 68 typedef struct _QSSGRenderBackendAttribLayoutObject *QSSGRenderBackendAttribLayoutObject; 69 /// opaque input assembler object handle 70 typedef struct _QSSGRenderBackendInputAssemblerObject *QSSGRenderBackendInputAssemblerObject; 71 /// opaque texture object handle 72 typedef struct _QSSGRenderBackendTextureObject *QSSGRenderBackendTextureObject; 73 /// opaque sampler object handle 74 typedef struct _QSSGRenderBackendSamplerObject *QSSGRenderBackendSamplerObject; 75 /// opaque renderbuffer object handle 76 typedef struct _QSSGRenderBackendRenderbufferObject *QSSGRenderBackendRenderbufferObject; 77 /// opaque framebuffer object handle 78 typedef struct _QSSGRenderBackendRenderTargetObject *QSSGRenderBackendRenderTargetObject; 79 /// opaque vertex shader object handle 80 typedef struct _QSSGRenderBackendVertexShaderObject *QSSGRenderBackendVertexShaderObject; 81 /// opaque fragment shader object handle 82 typedef struct _QSSGRenderBackendFragmentShaderObject *QSSGRenderBackendFragmentShaderObject; 83 /// opaque tesselation control shader object handle 84 typedef struct _QSSGRenderBackendTessControlShaderObject *QSSGRenderBackendTessControlShaderObject; 85 /// opaque tesselation evaluation shader object handle 86 typedef struct _QSSGRenderBackendTessEvaluationShaderObject *QSSGRenderBackendTessEvaluationShaderObject; 87 /// opaque geometry shader object handle 88 typedef struct _QSSGRenderBackendGeometryShaderObject *QSSGRenderBackendGeometryShaderObject; 89 /// opaque compute shader object handle 90 typedef struct _QSSGRenderBackendComputeShaderObject *QSSGRenderBackendComputeShaderObject; 91 /// opaque shader program object handle 92 typedef struct _QSSGRenderBackendShaderProgramObject *QSSGRenderBackendShaderProgramObject; 93 /// opaque depth stencil state object handle 94 typedef struct _QSSGRenderBackendDepthStencilStateObject *QSSGRenderBackendDepthStencilStateObject; 95 /// opaque rasterizer state object handle 96 typedef struct _QSSGRenderBackendRasterizerStateObject *QSSGRenderBackendRasterizerStateObject; 97 /// opaque query object handle 98 typedef struct _QSSGRenderBackendQueryObject *QSSGRenderBackendQueryObject; 99 /// opaque sync object handle 100 typedef struct _QSSGRenderBackendSyncObject *QSSGRenderBackendSyncObject; 101 /// opaque sync object handle 102 typedef struct _QSSGRenderBackendProgramPipeline *QSSGRenderBackendProgramPipeline; 103 /// opaque sync object handle 104 typedef struct _QSSGRenderBackendPathObject *QSSGRenderBackendPathObject; 105 106 // backend capability caps 107 enum class QSSGRenderBackendCaps 108 { 109 ConstantBuffer, ///< Constant buffer support query 110 DepthStencilTexture, ///< depth stencil texture format suport query 111 DxtImages, ///< DXT image support query 112 FpRenderTarget, ///< render to floating point target support query 113 MsTexture, ///< Multisample texture support query 114 TexSwizzle, ///< Texture swizzle support query 115 FastBlits, ///< Hardware supports fast blits 116 Tessellation, ///< Hardware supports tessellation 117 Compute, ///< Hardware supports compute shader 118 Geometry, ///< Hardware supports geometry shader 119 SampleQuery, ///< Hardware supports query calls of type samples 120 TimerQuery, ///< Hardware supports query calls of type timer 121 CommandSync, ///< Hardware supports command sync object 122 TextureArray, ///< Hardware supports texture arrays 123 StorageBuffer, ///< Hardware supports shader storage buffers 124 ShaderImageLoadStore, ///< Hardware supports shader image load store operations 125 ProgramPipeline, ///< Driver supports separate programs 126 AdvancedBlend, ///< Driver supports advanced blend modes 127 BlendCoherency, ///< Hardware supports blend coherency 128 gpuShader5, // for high precision sampling 129 AdvancedBlendKHR, ///< Driver supports advanced blend modes 130 VertexArrayObject, 131 StandardDerivatives, 132 TextureLod 133 }; 134 135 // backend queries 136 enum class QSSGRenderBackendQuery 137 { 138 MaxTextureSize, ///< Return max supported texture size 139 MaxTextureArrayLayers, ///< Return max supported layer count for texture arrays 140 MaxConstantBufferSlots, ///< Return max supported constant buffe slots for a single 141 /// shader stage 142 MaxConstantBufferBlockSize ///< Return max supported size for a single constant 143 /// buffer block 144 }; 145 146 /// backend interface 147 148 /** 149 * @brief get the backend type 150 * 151 * @return true backend type 152 */ 153 virtual QSSGRenderContextType getRenderContextType() const = 0; 154 155 /** 156 * @brief get the version of the shading language 157 * @return version string. 158 */ 159 virtual QByteArray getShadingLanguageVersion() = 0; 160 161 /** 162 * @brief get maximum supported texture image units that 163 * can be used to access texture maps from the vertex shader and the fragment processor 164 *combined. 165 * 166 * @return max texture size 167 */ 168 virtual qint32 getMaxCombinedTextureUnits() = 0; 169 170 /** 171 * @brief query Backend capabilities 172 * 173 * @param[in] inCap CAPS flag to query 174 * @ConstantBuffer, @DepthStencilTexture, ... 175 * 176 * @return true if supported 177 */ 178 virtual bool getRenderBackendCap(QSSGRenderBackendCaps inCap) const = 0; 179 180 /** 181 * @brief query Backend values 182 * 183 * @param[in] inQuery Query flag to get value for 184 * @MaxTextureSize, @MaxTextureArrayLayers, 185 *... 186 * @param[in/out] params the query result is stored here 187 * 188 * @return no return 189 */ 190 virtual void getRenderBackendValue(QSSGRenderBackendQuery inQuery, qint32 *params) const = 0; 191 192 /** 193 * @brief query for bit depth of the depth buffer 194 * 195 * @return depth buffer bitplanes 196 */ 197 virtual qint32 getDepthBits() const = 0; 198 199 /** 200 * @brief query for bit depth of the stencil buffer 201 * 202 * @return stencil buffer bitplanes 203 */ 204 virtual qint32 getStencilBits() const = 0; 205 206 /** 207 * @brief query for maximum supported number of samples for multisampling. 208 * 209 * @return maximum samples. The value must be at least 4. 210 */ 211 virtual qint32 getMaxSamples() const = 0; 212 213 /* 214 * @brief set a backend rende state 215 * 216 * @param[in] bEnable enable/disable state 217 * @param[in] value type of state 218 * 219 * @return no return 220 */ 221 virtual void setRenderState(bool bEnable, const QSSGRenderState value) = 0; 222 223 /** 224 * @brief get a backend rende state 225 * 226 * @param[in] value type of state 227 * 228 * @return true if state enabled otherwise false 229 */ 230 virtual bool getRenderState(const QSSGRenderState value) = 0; 231 232 /** 233 * @brief get current depth function 234 * 235 * @return active depth function 236 */ 237 virtual QSSGRenderBoolOp getDepthFunc() = 0; 238 239 /** 240 * @brief create a depth stencil state object 241 * 242 * @param[in] enableDepth enable depth test 243 * @param[in] depthMask enable depth writes 244 * @param[in] depthFunc depth compare function 245 * @param[in] enableStencil enable stencil test 246 * @param[in] stencilFuncFront stencil setup front faces 247 * @param[in] stencilFuncBack stencil setup back faces 248 * @param[in] depthStencilOpFront depth/stencil operations front faces 249 * @param[in] depthStencilOpBack depth/stencil operations back faces 250 * 251 * @return opaque handle to state object 252 */ 253 virtual QSSGRenderBackendDepthStencilStateObject createDepthStencilState( 254 bool enableDepth, 255 bool depthMask, 256 QSSGRenderBoolOp depthFunc, 257 bool enableStencil, 258 QSSGRenderStencilFunction &stencilFuncFront, 259 QSSGRenderStencilFunction &stencilFuncBack, 260 QSSGRenderStencilOperation &depthStencilOpFront, 261 QSSGRenderStencilOperation &depthStencilOpBack) = 0; 262 263 /** 264 * @brief release a depth stencil state object 265 * 266 * @param[in] depthStencilState pointer to state object 267 * 268 * @return none 269 */ 270 virtual void releaseDepthStencilState(QSSGRenderBackendDepthStencilStateObject depthStencilState) = 0; 271 272 /** 273 * @brief create a rasterizer state object 274 * 275 * @param[in] depthBias any othe value than 0 enables depth bias 276 * @param[in] depthScale any othe value than 0 enables depth scale 277 * 278 * @return opaque handle to state object 279 */ 280 virtual QSSGRenderBackendRasterizerStateObject createRasterizerState(float depthBias, 281 float depthScale) = 0; 282 283 /** 284 * @brief release a rasterizer state object 285 * 286 * @param[in] rasterizerState pointer to state object 287 * 288 * @return none 289 */ 290 virtual void releaseRasterizerState(QSSGRenderBackendRasterizerStateObject rasterizerState) = 0; 291 292 /** 293 * @brief set depth stencil state 294 * 295 * @param[in] depthStencilState pointer to state object 296 * 297 * @return none 298 */ 299 virtual void setDepthStencilState(QSSGRenderBackendDepthStencilStateObject depthStencilState) = 0; 300 301 /** 302 * @brief set rasterizer state 303 * 304 * @param[in] rasterizerState pointer to state object 305 * 306 * @return none 307 */ 308 virtual void setRasterizerState(QSSGRenderBackendRasterizerStateObject rasterizerState) = 0; 309 310 /** 311 * @brief set current depth function 312 * 313 * @param[in] func type of function 314 * 315 * @return no return 316 */ 317 virtual void setDepthFunc(const QSSGRenderBoolOp func) = 0; 318 319 /** 320 * @brief query if depth write is enabled 321 * 322 * @return true if enabled 323 */ 324 virtual bool getDepthWrite() = 0; 325 326 /** 327 * @brief enable / disable depth writes 328 * 329 * @param[in] bEnable true for enable 330 * 331 * @return no return 332 */ 333 virtual void setDepthWrite(bool bEnable) = 0; 334 335 /** 336 * @brief enable / disable color channel writes 337 * 338 * @param[in] bRed true for enable red channel 339 * @param[in] bGreen true for enable green channel 340 * @param[in] bBlue true for enable blue channel 341 * @param[in] bAlpha true for enable alpha channel 342 * 343 * @return no return 344 */ 345 virtual void setColorWrites(bool bRed, bool bGreen, bool bBlue, bool bAlpha) = 0; 346 347 /** 348 * @brief enable / disable multisample rendering 349 * 350 * @param[in] bEnable true for enable 351 * 352 * @return no return 353 */ 354 virtual void setMultisample(bool bEnable) = 0; 355 356 /** 357 * @brief query blend functions 358 * 359 * @param[out] pBlendFuncArg blending functions 360 * 361 * @return no return 362 */ 363 virtual void getBlendFunc(QSSGRenderBlendFunctionArgument *pBlendFuncArg) = 0; 364 365 /** 366 * @brief set blend functions 367 * 368 * @param[in] pBlendFuncArg blending functions 369 * 370 * @return no return 371 */ 372 virtual void setBlendFunc(const QSSGRenderBlendFunctionArgument &blendFuncArg) = 0; 373 374 /** 375 * @brief set blend equation 376 * 377 * @param[in] pBlendEquArg blending equation 378 * 379 * @return no return 380 */ 381 virtual void setBlendEquation(const QSSGRenderBlendEquationArgument &pBlendEquArg) = 0; 382 383 /** 384 * @brief guarantee blend coherency 385 * 386 * 387 * @return no return 388 */ 389 virtual void setBlendBarrier(void) = 0; 390 391 /** 392 * @brief query cull face mode 393 * 394 * @return cull face mode 395 */ 396 virtual QSSGCullFaceMode getCullFaceMode() = 0; 397 398 /** 399 * @brief set cull face mode 400 * 401 * @param[in] cullFaceMode 402 * 403 * @return no return 404 */ 405 virtual void setCullFaceMode(const QSSGCullFaceMode cullFaceMode) = 0; 406 407 /** 408 * @brief query scissor rectangle 409 * 410 * @param[out] pRect contains scissor rect 411 * 412 * @return no return 413 */ 414 virtual void getScissorRect(QRect *pRect) = 0; 415 416 /** 417 * @brief set scissor rectangle 418 * 419 * @param[out] pRect contains scissor rect 420 * 421 * @return no return 422 */ 423 virtual void setScissorRect(const QRect &rect) = 0; 424 425 /** 426 * @brief query viewport rectangle 427 * 428 * @param[out] pRect contains viewport rect 429 * 430 * @return no return 431 */ 432 virtual void getViewportRect(QRect *pRect) = 0; 433 434 /** 435 * @brief set viewport rectangle 436 * 437 * @param[out] pRect contains viewport rect 438 * 439 * @return no return 440 */ 441 virtual void setViewportRect(const QRect &rect) = 0; 442 443 /** 444 * @brief query viewport rectangle 445 * 446 * @param[in] clearColor clear color 447 * 448 * @return no return 449 */ 450 virtual void setClearColor(const QVector4D *pClearColor) = 0; 451 452 /** 453 * @brief query viewport rectangle 454 * 455 * @param[in] flags clear flags 456 * 457 * @return no return 458 */ 459 virtual void clear(QSSGRenderClearFlags flags) = 0; 460 461 /** 462 * @brief create a buffer object 463 * 464 * @param[in] size Size of the buffer 465 * @param[in] bindFlags Where to bind this buffer (e.g. vertex, index, ...) 466 * For OpenGL this should be a single 467 *value 468 * @param[in] usage Usage of the buffer (e.g. static, dynamic...) 469 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 470 *application. 471 * 472 * @return The created buffer object or nullptr if the creation failed. 473 */ 474 virtual QSSGRenderBackendBufferObject createBuffer(QSSGRenderBufferType bindFlags, 475 QSSGRenderBufferUsageType usage, 476 QSSGByteView hostData) = 0; 477 478 /** 479 * @brief bind a buffer object 480 * 481 * @param[in] bo Pointer to buffer object 482 * @param[in] bindFlags Where to bind this buffer (e.g. vertex, index, ...) 483 * For OpenGL this should be a single 484 *value 485 * 486 * @return no return. 487 */ 488 virtual void bindBuffer(QSSGRenderBackendBufferObject bo, QSSGRenderBufferType bindFlags) = 0; 489 490 /** 491 * @brief Release a single buffer object 492 * 493 * @param[in] bo Pointer to buffer object 494 * 495 * @return no return. 496 */ 497 virtual void releaseBuffer(QSSGRenderBackendBufferObject bo) = 0; 498 499 /** 500 * @brief update a whole buffer object 501 * 502 * @param[in] bo Pointer to buffer object 503 * @param[in] bindFlags Where to bind this buffer (e.g. vertex, index, ...) 504 * For OpenGL this should be a single 505 *value 506 * @param[in] size Size of the data buffer 507 * @param[in] usage Usage of the buffer (e.g. static, dynamic...) 508 * @param[in] data A pointer to the buffer data that is allocated by the 509 *application. 510 * 511 * @return no return. 512 */ 513 virtual void updateBuffer(QSSGRenderBackendBufferObject bo, 514 QSSGRenderBufferType bindFlags, 515 QSSGRenderBufferUsageType usage, 516 QSSGByteView data) = 0; 517 518 /** 519 * @brief update a range of a buffer object 520 * 521 * @param[in] bo Pointer to buffer object 522 * @param[in] bindFlags Where to bind this buffer (e.g. vertex, index, ...) 523 * For OpenGL this should be a single 524 *value 525 * @param[in] size Size of the data buffer 526 * @param[in] usage Usage of the buffer (e.g. static, dynamic...) 527 * @param[in] data A pointer to the buffer data that is allocated by the 528 *application. 529 * 530 * @return no return. 531 */ 532 virtual void updateBufferRange(QSSGRenderBackendBufferObject bo, 533 QSSGRenderBufferType bindFlags, 534 size_t offset, 535 QSSGByteView data) = 0; 536 537 /** 538 * @brief Get a pointer to the buffer data ( GL(ES) >= 3 only ) 539 * 540 * @param[in] bo Pointer to buffer object 541 * @param[in] bindFlags Where to bind this buffer (e.g. vertex, index, ...) 542 * For OpenGL this should be a single 543 *value 544 * @param[in] offset Byte offset into the data buffer 545 * @param[in] length Byte length of mapping size 546 * @param[in] access Access of the buffer (e.g. read, write, ...) 547 * 548 * @return pointer to mapped data or null. 549 */ 550 virtual void *mapBuffer(QSSGRenderBackendBufferObject bo, 551 QSSGRenderBufferType bindFlags, 552 size_t offset, 553 size_t length, 554 QSSGRenderBufferAccessFlags accessFlags) = 0; 555 556 /** 557 * @brief Unmap a previously mapped buffer ( GL(ES) >= 3 only ) 558 * This functions transfers the content to the hardware buffer 559 * 560 * @param[in] bo Pointer to buffer object 561 * @param[in] bindFlags Where to bind this buffer (e.g. vertex, index, ...) 562 * For OpenGL this should be a single 563 *value 564 * 565 * @return true if successful 566 */ 567 virtual bool unmapBuffer(QSSGRenderBackendBufferObject bo, QSSGRenderBufferType bindFlags) = 0; 568 569 /** 570 * @brief Set a memory barrier 571 * 572 * @param[in] barriers Flags for barriers 573 * 574 * @return no return. 575 */ 576 virtual void setMemoryBarrier(QSSGRenderBufferBarrierFlags barriers) = 0; 577 578 /** 579 * @brief create a query object 580 * 581 * @return The created query object or nullptr if the creation failed. 582 */ 583 virtual QSSGRenderBackendQueryObject createQuery() = 0; 584 585 /** 586 * @brief delete query objects 587 * 588 * @param[in] qo Handle to query object 589 * 590 * @return no return 591 */ 592 virtual void releaseQuery(QSSGRenderBackendQueryObject qo) = 0; 593 594 /** 595 * @brief Start query recording 596 * 597 * @param[in] qo Handle to query object 598 * @param[in] type Type of query 599 * 600 * @return no return 601 */ 602 virtual void beginQuery(QSSGRenderBackendQueryObject qo, QSSGRenderQueryType type) = 0; 603 604 /** 605 * @brief End query recording 606 * 607 * @param[in] qo Handle to query object 608 * @param[in] type Type of query 609 * 610 * @return no return 611 */ 612 virtual void endQuery(QSSGRenderBackendQueryObject qo, QSSGRenderQueryType type) = 0; 613 614 /** 615 * @brief Get a query result 616 * 617 * @param[in] qo Handle to query object 618 * @param[in] type Type of query 619 * @param[out] params Contains result of query regarding query type 620 * 621 * @return no return 622 */ 623 virtual void getQueryResult(QSSGRenderBackendQueryObject qo, QSSGRenderQueryResultType resultType, quint32 *params) = 0; 624 625 /** 626 * @brief Get a query result 627 * 628 * @param[in] qo Handle to query object 629 * @param[in] type Type of query 630 * @param[out] params Contains result of query regarding query type 64 bit returns 631 * 632 * @return no return 633 */ 634 virtual void getQueryResult(QSSGRenderBackendQueryObject qo, QSSGRenderQueryResultType resultType, quint64 *params) = 0; 635 636 /** 637 * @brief Record the GPU time using the query object 638 * 639 * @param[in] qo Handle to query object 640 * 641 * @return no return 642 */ 643 virtual void setQueryTimer(QSSGRenderBackendQueryObject qo) = 0; 644 645 /** 646 * @brief create a sync object and place it in the command queue 647 * 648 * @param[in] tpye Type to sync 649 * @param[in] syncFlags Currently unused 650 * 651 * @return The created sync object or nullptr if the creation failed. 652 */ 653 virtual QSSGRenderBackendSyncObject createSync(QSSGRenderSyncType tpye, QSSGRenderSyncFlags syncFlags) = 0; 654 655 /** 656 * @brief delete sync object 657 * 658 * @param[in] so Handle to sync object 659 * 660 * @return no return 661 */ 662 virtual void releaseSync(QSSGRenderBackendSyncObject so) = 0; 663 664 /** 665 * @brief wait for sync object to be signaled 666 * 667 * @param[in] so Handle to sync object 668 * @param[in] syncFlags Currently unused 669 * @param[in] timeout Currently ignored 670 * 671 * @return no return 672 */ 673 virtual void waitSync(QSSGRenderBackendSyncObject so, QSSGRenderCommandFlushFlags syncFlags, quint64 timeout) = 0; 674 675 /** 676 * @brief create a render target object 677 * 678 * 679 * @return The created render target object or nullptr if the creation failed. 680 */ 681 virtual QSSGRenderBackendRenderTargetObject createRenderTarget() = 0; 682 683 /** 684 * @brief Release a single render target object 685 * 686 * @param[in] rto Pointer to render target object 687 * 688 * @return no return. 689 */ 690 virtual void releaseRenderTarget(QSSGRenderBackendRenderTargetObject rto) = 0; 691 692 /** 693 * @brief Attach a renderbuffer object to the framebuffer 694 * 695 * @param[in] rto Pointer to render target object 696 * @param[in] attachment Attachment point (e.g COLOR0, DEPTH) 697 * @param[in] rbo Pointer to renderbuffer object 698 * 699 * @return no return. 700 */ 701 virtual void renderTargetAttach(QSSGRenderBackendRenderTargetObject rto, 702 QSSGRenderFrameBufferAttachment attachment, 703 QSSGRenderBackendRenderbufferObject rbo) = 0; 704 705 /** 706 * @brief Attach a texture object to the render target 707 * 708 * @param[in] rto Pointer to render target object 709 * @param[in] attachment Attachment point (e.g COLOR0, DEPTH) 710 * @param[in] to Pointer to texture object 711 * @param[in] target Attachment texture target 712 * 713 * @return no return. 714 */ 715 virtual void renderTargetAttach(QSSGRenderBackendRenderTargetObject rto, 716 QSSGRenderFrameBufferAttachment attachment, 717 QSSGRenderBackendTextureObject to, 718 QSSGRenderTextureTargetType target = QSSGRenderTextureTargetType::Texture2D) = 0; 719 720 /** 721 * @brief Attach a texture object to the render target 722 * 723 * @param[in] rto Pointer to render target object 724 * @param[in] attachment Attachment point (e.g COLOR0, DEPTH) 725 * @param[in] to Pointer to texture object 726 * @param[in] level Texture mip level 727 * @param[in] layer Texture layer or slice 728 * 729 * @return no return. 730 */ 731 virtual void renderTargetAttach(QSSGRenderBackendRenderTargetObject rto, 732 QSSGRenderFrameBufferAttachment attachment, 733 QSSGRenderBackendTextureObject to, 734 qint32 level, 735 qint32 layer) = 0; 736 737 /** 738 * @brief Make a render target active 739 * 740 * @param[in] rto Pointer to render target object 741 * 742 * @return no return. 743 */ 744 virtual void setRenderTarget(QSSGRenderBackendRenderTargetObject rto) = 0; 745 746 /** 747 * @brief Check if a render target is ready for render 748 * 749 * @param[in] rto Pointer to render target object 750 * 751 * @return true if usable. 752 */ 753 virtual bool renderTargetIsValid(QSSGRenderBackendRenderTargetObject rto) = 0; 754 755 /** 756 * @brief Make a render target active for reading 757 * 758 * @param[in] rto Pointer to render target object 759 * 760 * @return no return. 761 */ 762 virtual void setReadTarget(QSSGRenderBackendRenderTargetObject rto) = 0; 763 764 /** 765 * @brief Set active buffers for drawing 766 * 767 * @param[in] rto Pointer to render target object 768 * @param[in] inDrawBufferSet Pointer to array of enabled render targets 769 * 770 * @return no return. 771 */ 772 virtual void setDrawBuffers(QSSGRenderBackendRenderTargetObject rto, QSSGDataView<qint32> inDrawBufferSet) = 0; 773 774 /** 775 * @brief Set active buffer for reading 776 * 777 * @param[in] rto Pointer to render target object 778 * @param[in] inReadFace Buffer to read from 779 * 780 * @return no return. 781 */ 782 virtual void setReadBuffer(QSSGRenderBackendRenderTargetObject rto, QSSGReadFace inReadFace) = 0; 783 784 /** 785 * @brief Copy framebuffer attachments. Source is set with SetReadTarget dest with 786 * SetRenderTarget 787 * 788 * @param[in] srcX0 Lower left X coord of source rectangle 789 * @param[in] srcY0 Lower left Y coord of source rectangle 790 * @param[in] srcX1 Upper right X coord of source rectangle 791 * @param[in] srcY1 Upper right Y coord of source rectangle 792 * @param[in] dstX0 Lower left X coord of dest rectangle 793 * @param[in] dstY0 Lower left Y coord of dest rectangle 794 * @param[in] dstX1 Upper right X coord of dest rectangle 795 * @param[in] dstY1 Upper right Y coord of dest rectangle 796 * @param[in] inDrawBufferSet pointer to array of enabled render targets 797 * @param[in] filter Copy filter method (NEAREST or LINEAR) 798 * 799 * @return no return. 800 */ 801 virtual void blitFramebuffer(qint32 srcX0, 802 qint32 srcY0, 803 qint32 srcX1, 804 qint32 srcY1, 805 qint32 dstX0, 806 qint32 dstY0, 807 qint32 dstX1, 808 qint32 dstY1, 809 QSSGRenderClearFlags flags, 810 QSSGRenderTextureMagnifyingOp filter) = 0; 811 812 /** 813 * @brief Copy framebuffer attachments to texture. Source is set with SetReadTarget dest with 814 * SetRenderTarget 815 * 816 * @param[in] srcX0 Lower left X coord of source rectangle 817 * @param[in] srcY0 Lower left Y coord of source rectangle 818 * @param[in] srcX1 Width source rectangle 819 * @param[in] srcY1 Height source rectangle 820 * @param[in] dstX0 Lower left X coord of dest rectangle 821 * @param[in] dstY0 Lower left Y coord of dest rectangle 822 * @param[in] flags Attachment to copy 823 * @param[in] texture The destination texture 824 * @param[in] target The texture target 825 * 826 * @return no return. 827 */ 828 virtual void copyFramebufferTexture(qint32 srcX0, 829 qint32 srcY0, 830 qint32 width, 831 qint32 height, 832 qint32 dstX0, 833 qint32 dstY0, 834 QSSGRenderBackendTextureObject texture, 835 QSSGRenderTextureTargetType target 836 = QSSGRenderTextureTargetType::Texture2D) = 0; 837 838 /** 839 * @brief create a render buffer object 840 * 841 * @param[in] storageFormat Format of the buffer 842 * @param[in] width Buffer with 843 * @param[in] height Buffer height 844 * 845 * @return The created render buffer object or nullptr if the creation failed. 846 */ 847 virtual QSSGRenderBackendRenderbufferObject createRenderbuffer(QSSGRenderRenderBufferFormat storageFormat, 848 qint32 width, 849 qint32 height) = 0; 850 851 /** 852 * @brief Release a single renderbuffer object 853 * 854 * @param[in] bo Pointer to renderbuffer object 855 * 856 * @return no return. 857 */ 858 virtual void releaseRenderbuffer(QSSGRenderBackendRenderbufferObject rbo) = 0; 859 860 /** 861 * @brief resize a render buffer object 862 * 863 * @param[in] storageFormat Format of the buffer 864 * @param[in] width Buffer with 865 * @param[in] height Buffer height 866 * 867 * @return True on success 868 */ 869 virtual bool resizeRenderbuffer(QSSGRenderBackendRenderbufferObject rbo, 870 QSSGRenderRenderBufferFormat storageFormat, 871 qint32 width, 872 qint32 height) = 0; 873 874 /** 875 * @brief create a texture object 876 * 877 * @return The created texture object or nullptr if the creation failed.. 878 */ 879 virtual QSSGRenderBackendTextureObject createTexture() = 0; 880 881 /** 882 * @brief set texture data for a 2D texture 883 * 884 * @param[in] to Pointer to texture object 885 * @param[in] target Texture target 2D, 3D 886 * @param[in] level Texture mip level 887 * @param[in] internalFormat format of the texture 888 * @param[in] width texture width 889 * @param[in] height texture height 890 * @param[in] border border 891 * @param[in] format format of provided pixel data 892 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 893 * application. 894 * 895 * @return No return 896 */ 897 virtual void setTextureData2D(QSSGRenderBackendTextureObject to, 898 QSSGRenderTextureTargetType target, 899 qint32 level, 900 QSSGRenderTextureFormat internalFormat, 901 qint32 width, 902 qint32 height, 903 qint32 border, 904 QSSGRenderTextureFormat format, 905 QSSGByteView hostData) = 0; 906 907 /** 908 * @brief set texture data for the face of a Cube map 909 * 910 * @param[in] to Pointer to texture object 911 * @param[in] target Texture target face 912 * @param[in] level Texture mip level 913 * @param[in] internalFormat format of the texture 914 * @param[in] width texture width 915 * @param[in] height texture height 916 * @param[in] border border 917 * @param[in] format format of provided pixel data 918 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 919 * application. 920 * 921 * @return No return 922 */ 923 virtual void setTextureDataCubeFace(QSSGRenderBackendTextureObject to, 924 QSSGRenderTextureTargetType target, 925 qint32 level, 926 QSSGRenderTextureFormat internalFormat, 927 qint32 width, 928 qint32 height, 929 qint32 border, 930 QSSGRenderTextureFormat format, 931 QSSGByteView hostData) = 0; 932 933 /** 934 * @brief create a storage for a 2D texture including mip levels 935 * Note that this makes texture immutable in size and format 936 * 937 * @param[in] to Pointer to texture object 938 * @param[in] target Texture target 2D, 3D 939 * @param[in] levels Texture mip level count 940 * @param[in] internalFormat format of the texture 941 * @param[in] width texture width 942 * @param[in] height texture height 943 * 944 * @return No return 945 */ 946 virtual void createTextureStorage2D(QSSGRenderBackendTextureObject to, 947 QSSGRenderTextureTargetType target, 948 qint32 levels, 949 QSSGRenderTextureFormat internalFormat, 950 qint32 width, 951 qint32 height) = 0; 952 953 /** 954 * @brief set texture sub data for a 2D texture 955 * 956 * @param[in] to Pointer to texture object 957 * @param[in] target Texture target 2D, 3D 958 * @param[in] level Texture mip level 959 * @param[in] xOffset Texture x offset 960 * @param[in] yOffset Texture y offset 961 * @param[in] width Texture width 962 * @param[in] height Texture height 963 * @param[in] border border 964 * @param[in] format format of texture 965 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 966 * application. 967 * 968 * @return No return 969 */ 970 virtual void setTextureSubData2D(QSSGRenderBackendTextureObject to, 971 QSSGRenderTextureTargetType target, 972 qint32 level, 973 qint32 xOffset, 974 qint32 yOffset, 975 qint32 width, 976 qint32 height, 977 QSSGRenderTextureFormat format, 978 QSSGByteView hostData) = 0; 979 980 /** 981 * @brief set compressed texture data for a 2D texture 982 * 983 * @param[in] to Pointer to texture object 984 * @param[in] target Texture target 2D, 3D 985 * @param[in] level Texture mip level 986 * @param[in] internalFormat format of the texture 987 * @param[in] width texture width 988 * @param[in] height texture height 989 * @param[in] border border 990 * @param[in] imageSize image size in bytes located at hostPtr 991 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 992 * application. 993 * 994 * @return No return 995 */ 996 virtual void setCompressedTextureData2D(QSSGRenderBackendTextureObject to, 997 QSSGRenderTextureTargetType target, 998 qint32 level, 999 QSSGRenderTextureFormat internalFormat, 1000 qint32 width, 1001 qint32 height, 1002 qint32 border, 1003 QSSGByteView hostData) = 0; 1004 1005 /** 1006 * @brief set compressed texture data for a Cubemap face 1007 * 1008 * @param[in] to Pointer to texture object 1009 * @param[in] target Texture target 2D, 3D 1010 * @param[in] level Texture mip level 1011 * @param[in] internalFormat format of the texture 1012 * @param[in] width texture width 1013 * @param[in] height texture height 1014 * @param[in] border border 1015 * @param[in] imageSize image size in bytes located at hostPtr 1016 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 1017 * application. 1018 * 1019 * @return No return 1020 */ 1021 virtual void setCompressedTextureDataCubeFace(QSSGRenderBackendTextureObject to, 1022 QSSGRenderTextureTargetType target, 1023 qint32 level, 1024 QSSGRenderTextureFormat internalFormat, 1025 qint32 width, 1026 qint32 height, 1027 qint32 border, 1028 QSSGByteView hostData) = 0; 1029 1030 /** 1031 * @brief set compressed texture sub data for a 2D texture 1032 * 1033 * @param[in] to Pointer to texture object 1034 * @param[in] target Texture target 2D, 3D 1035 * @param[in] level Texture mip level 1036 * @param[in] xOffset Texture x offset 1037 * @param[in] yOffset Texture y offset 1038 * @param[in] width texture width 1039 * @param[in] height texture height 1040 * @param[in] format format of provided pixel data 1041 * @param[in] imageSize image size in bytes located at hostPtr 1042 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 1043 * application. 1044 * 1045 * @return No return 1046 */ 1047 virtual void setCompressedTextureSubData2D(QSSGRenderBackendTextureObject to, 1048 QSSGRenderTextureTargetType target, 1049 qint32 level, 1050 qint32 xOffset, 1051 qint32 yOffset, 1052 qint32 width, 1053 qint32 height, 1054 QSSGRenderTextureFormat format, 1055 QSSGByteView hostData) = 0; 1056 1057 /** 1058 * @brief establish a multisampled 2D texture 1059 * 1060 * @param[in] to Pointer to texture object 1061 * @param[in] target Texture target 2D MS 1062 * @param[in] samples Textures sample count 1063 * @param[in] internalFormat Format of the texture 1064 * @param[in] width Texture width 1065 * @param[in] height Texture height 1066 * @param[in] bool Fixed sample locations 1067 * 1068 * @return No return 1069 */ 1070 virtual void setMultisampledTextureData2D(QSSGRenderBackendTextureObject to, 1071 QSSGRenderTextureTargetType target, 1072 qint32 samples, 1073 QSSGRenderTextureFormat internalFormat, 1074 qint32 width, 1075 qint32 height, 1076 bool fixedsamplelocations) = 0; 1077 1078 /** 1079 * @brief set texture data for a 3D texture or 2D texture array 1080 * 1081 * @param[in] to Pointer to texture object 1082 * @param[in] target Texture target 2D, 3D 1083 * @param[in] level Texture mip level 1084 * @param[in] internalFormat format of the texture 1085 * @param[in] width texture width 1086 * @param[in] height texture height 1087 * @param[in] depth texture depth or slice count 1088 * @param[in] border border 1089 * @param[in] format format of provided pixel data 1090 * @param[in] hostPtr A pointer to the buffer data that is allocated by the 1091 * application. 1092 * 1093 * @return No return 1094 */ 1095 virtual void setTextureData3D(QSSGRenderBackendTextureObject to, 1096 QSSGRenderTextureTargetType target, 1097 qint32 level, 1098 QSSGRenderTextureFormat internalFormat, 1099 qint32 width, 1100 qint32 height, 1101 qint32 depth, 1102 qint32 border, 1103 QSSGRenderTextureFormat format, 1104 QSSGByteView hostData) = 0; 1105 1106 /** 1107 * @brief generate mipmap levels 1108 * 1109 * @param[in] to Pointer to texture object 1110 * @param[in] target Texture target 2D,... 1111 * @param[in] hint How to generate mips (Nicest) 1112 * 1113 * @return No return 1114 */ 1115 virtual void generateMipMaps(QSSGRenderBackendTextureObject to, 1116 QSSGRenderTextureTargetType target, 1117 QSSGRenderHint genType) = 0; 1118 1119 /** 1120 * @brief bind a texture object 1121 * 1122 * @param[in] to Pointer to texture object 1123 * @param[in] target Where to bind this texture (e.g. 2D, 3D, ...) 1124 * @param[in] unit Which unit to bind this texture 1125 * 1126 * @return no return. 1127 */ 1128 virtual void bindTexture(QSSGRenderBackendTextureObject to, 1129 QSSGRenderTextureTargetType target, 1130 qint32 unit) = 0; 1131 1132 /** 1133 * @brief select active texture unit 1134 * 1135 * @param[in] unit Which unit to bind for texture 1136 * 1137 * @return no return. 1138 */ 1139 virtual void setActiveTexture(qint32 unit) = 0; 1140 1141 /** 1142 * @brief bind a image/texture object 1143 * 1144 * @param[in] to Pointer to texture object 1145 * @param[in] unit Which unit to bind this texture 1146 * @param[in] level Which level to bind 1147 * @param[in] layered Bind layered texture (cube map, array,... ) 1148 * @param[in] level Specify layer. Only valid of layered=false. 1149 * @param[in] access Access mode ( read, write, read-write ) 1150 * @param[in] format Texture format must be compatible with Image format 1151 * 1152 * @return no return. 1153 */ 1154 virtual void bindImageTexture(QSSGRenderBackendTextureObject to, 1155 quint32 unit, 1156 qint32 level, 1157 bool layered, 1158 qint32 layer, 1159 QSSGRenderImageAccessType accessFlags, 1160 QSSGRenderTextureFormat format) = 0; 1161 1162 /** 1163 * @brief Release a single texture object 1164 * 1165 * @param[in] to Pointer to buffer object 1166 * 1167 * @return no return. 1168 */ 1169 virtual void releaseTexture(QSSGRenderBackendTextureObject to) = 0; 1170 1171 /** 1172 * @brief query texture swizzle mode 1173 * This is mainly for luminance, alpha replacement with R8 formats 1174 * 1175 * @param[in] inFormat input texture format to check 1176 * 1177 * @return texture swizzle mode 1178 */ 1179 virtual QSSGRenderTextureSwizzleMode getTextureSwizzleMode(const QSSGRenderTextureFormat inFormat) const = 0; 1180 1181 /** 1182 * @ brief create a sampler 1183 * 1184 * @param[in] minFilter Texture min filter 1185 * @param[in] magFilter Texture mag filter 1186 * @param[in] wrapS Texture coord generation for S 1187 * @param[in] wrapT Texture coord generation for T 1188 * @param[in] wrapR Texture coord generation for R 1189 * @param[in] minLod Texture min level of detail 1190 * @param[in] maxLod Texture max level of detail 1191 * @param[in] lodBias Texture level of detail example 1192 * @param[in] compareMode Texture compare mode 1193 * @param[in] compareFunc Texture compare function 1194 * @param[in] anisoFilter Aniso filter value [1.0, 16.0] 1195 * @param[in] borderColor Texture border color float[4] 1196 * 1197 * @return The created sampler object or nullptr if the creation failed. 1198 */ 1199 virtual QSSGRenderBackendSamplerObject createSampler( 1200 QSSGRenderTextureMinifyingOp minFilter = QSSGRenderTextureMinifyingOp::Linear, 1201 QSSGRenderTextureMagnifyingOp magFilter = QSSGRenderTextureMagnifyingOp::Linear, 1202 QSSGRenderTextureCoordOp wrapS = QSSGRenderTextureCoordOp::ClampToEdge, 1203 QSSGRenderTextureCoordOp wrapT = QSSGRenderTextureCoordOp::ClampToEdge, 1204 QSSGRenderTextureCoordOp wrapR = QSSGRenderTextureCoordOp::ClampToEdge, 1205 qint32 minLod = -1000, 1206 qint32 maxLod = 1000, 1207 float lodBias = 0.0, 1208 QSSGRenderTextureCompareMode compareMode = QSSGRenderTextureCompareMode::NoCompare, 1209 QSSGRenderTextureCompareOp compareFunc = QSSGRenderTextureCompareOp::LessThanOrEqual, 1210 float anisotropy = 1.0, 1211 float *borderColor = nullptr) = 0; 1212 1213 /** 1214 * @ brief update a sampler 1215 * 1216 * @param[in] so Pointer to sampler object 1217 * @param[in] target Texture target 2D, 3D 1218 * @param[in] minFilter Texture min filter 1219 * @param[in] magFilter Texture mag filter 1220 * @param[in] wrapS Texture coord generation for S 1221 * @param[in] wrapT Texture coord generation for T 1222 * @param[in] wrapR Texture coord generation for R 1223 * @param[in] minLod Texture min level of detail 1224 * @param[in] maxLod Texture max level of detail 1225 * @param[in] lodBias Texture level of detail bias (unused) 1226 * @param[in] compareMode Texture compare mode 1227 * @param[in] compareFunc Texture compare function 1228 * @param[in] anisoFilter Aniso filter value [1.0, 16.0] 1229 * @param[in] borderColor Texture border color float[4] (unused) 1230 * 1231 * @return No return 1232 */ 1233 virtual void updateSampler(QSSGRenderBackendSamplerObject so, 1234 QSSGRenderTextureTargetType target, 1235 QSSGRenderTextureMinifyingOp minFilter = QSSGRenderTextureMinifyingOp::Linear, 1236 QSSGRenderTextureMagnifyingOp magFilter = QSSGRenderTextureMagnifyingOp::Linear, 1237 QSSGRenderTextureCoordOp wrapS = QSSGRenderTextureCoordOp::ClampToEdge, 1238 QSSGRenderTextureCoordOp wrapT = QSSGRenderTextureCoordOp::ClampToEdge, 1239 QSSGRenderTextureCoordOp wrapR = QSSGRenderTextureCoordOp::ClampToEdge, 1240 float minLod = -1000.0, 1241 float maxLod = 1000.0, 1242 float lodBias = 0.0, 1243 QSSGRenderTextureCompareMode compareMode = QSSGRenderTextureCompareMode::NoCompare, 1244 QSSGRenderTextureCompareOp compareFunc = QSSGRenderTextureCompareOp::LessThanOrEqual, 1245 float anisotropy = 1.0, 1246 float *borderColor = nullptr) = 0; 1247 1248 /** 1249 * @ brief Update a textures swizzle mode 1250 * 1251 * @param[in] so Pointer to texture object 1252 * @param[in] target Texture target 2D, 3D 1253 * @param[in] swizzleMode Texture swizzle mode 1254 * 1255 * @return No return 1256 */ 1257 virtual void updateTextureSwizzle(QSSGRenderBackendTextureObject to, 1258 QSSGRenderTextureTargetType target, 1259 QSSGRenderTextureSwizzleMode swizzleMode) = 0; 1260 1261 /** 1262 * @ brief Update state belonging to a texture object 1263 * 1264 * @param[in] so Pointer to texture object 1265 * @param[in] target Texture target 2D, 3D, Cube 1266 * @param[in] baseLevel Texture base level 1267 * @param[in] maxLevel Texture max level 1268 * 1269 * @return No return 1270 */ 1271 virtual void updateTextureObject(QSSGRenderBackendTextureObject to, 1272 QSSGRenderTextureTargetType target, 1273 qint32 baseLevel, 1274 qint32 maxLevel) = 0; 1275 1276 /** 1277 * @brief Release a single sampler object 1278 * 1279 * @param[in] so Pointer to sampler object 1280 * 1281 * @return no return. 1282 */ 1283 virtual void releaseSampler(QSSGRenderBackendSamplerObject so) = 0; 1284 1285 /** 1286 * @brief create a attribute layout object 1287 * 1288 * @param[in] attribs Array off vertex attributes. 1289 * 1290 * @return The created attribute layout object or nullptr if the creation failed. 1291 */ 1292 virtual QSSGRenderBackendAttribLayoutObject createAttribLayout(QSSGDataView<QSSGRenderVertexBufferEntry> attribs) = 0; 1293 1294 /** 1295 * @brief Release a attribute layoutr object 1296 * 1297 * @param[in] ao Pointer to attribute layout object 1298 * 1299 * @return no return. 1300 */ 1301 virtual void releaseAttribLayout(QSSGRenderBackendAttribLayoutObject ao) = 0; 1302 1303 /** 1304 * @brief create a input assembler object 1305 * 1306 * @param[in] attribLayout Pointer to QSSGRenderBackendAttribLayoutObject object 1307 * @param[in] buffers list of vertex buffers 1308 * @param[in] indexBuffer index buffer object 1309 * @param[in] strides list of strides of the buffer 1310 * @param[in] offsets list of offsets into the buffer 1311 * @param[in] patchVertexCount vertext count for a patch. Only valid for patch primitives 1312 * 1313 * @return The created input assembler object or nullptr if the creation failed. 1314 */ 1315 virtual QSSGRenderBackendInputAssemblerObject createInputAssembler(QSSGRenderBackendAttribLayoutObject attribLayout, 1316 QSSGDataView<QSSGRenderBackendBufferObject> buffers, 1317 const QSSGRenderBackendBufferObject indexBuffer, 1318 QSSGDataView<quint32> strides, 1319 QSSGDataView<quint32> offsets, 1320 quint32 patchVertexCount) = 0; 1321 1322 /** 1323 * @brief Release a input assembler object 1324 * 1325 * @param[in] iao Pointer to attribute layout object 1326 * 1327 * @return no return. 1328 */ 1329 virtual void releaseInputAssembler(QSSGRenderBackendInputAssemblerObject iao) = 0; 1330 1331 /** 1332 * @brief Set a input assembler object. 1333 * This setup the render engine vertex assmebly 1334 * 1335 * @param[in] iao Pointer to attribute layout object 1336 * @param[in] po Pointer program object 1337 * 1338 * @return false if it fails. 1339 */ 1340 virtual bool setInputAssembler(QSSGRenderBackendInputAssemblerObject iao, QSSGRenderBackendShaderProgramObject po) = 0; 1341 1342 /** 1343 * @brief Reset all the states cached in the backend 1344 * so as to ensure that backend commands to set necessary states are called. 1345 * This will be called every frame just before QtQuick3D rendering commands are called 1346 * because such states might have been changed outside of QtQuick3D. 1347 */ 1348 virtual void resetStates() = 0; 1349 1350 /** 1351 * @brief Set the per patch vertex count 1352 * 1353 * @param[in] iao Pointer to attribute layout object 1354 * @param[in] count Count of vertices per patch 1355 * 1356 * @return false if it fails. 1357 */ 1358 virtual void setPatchVertexCount(QSSGRenderBackendInputAssemblerObject iao, quint32 count) = 0; 1359 1360 /** 1361 * @brief create a vertex shader object 1362 * 1363 * @param[in] source Pointer to shader source 1364 * @param[in/out] errorMessage Pointer to copy the error message 1365 * @param[in] binary True if the source is actually a binary program 1366 * 1367 * @return The created vertex shader object or nullptr if the creation failed. 1368 */ 1369 virtual QSSGRenderBackendVertexShaderObject createVertexShader(QSSGByteView source, 1370 QByteArray &errorMessage, 1371 bool binary) = 0; 1372 1373 /** 1374 * @brief release a vertex shader object 1375 * 1376 * @param[in] vso Pointer to vertex shader object 1377 * 1378 * @return No Return. 1379 */ 1380 virtual void releaseVertexShader(QSSGRenderBackendVertexShaderObject vso) = 0; 1381 1382 /** 1383 * @brief create a fragment shader object 1384 * 1385 * @param[in] source Pointer to shader source 1386 * @param[in/out] errorMessage Pointer to copy the error message 1387 * @param[in] binary True if the source is actually a binary program 1388 * 1389 * @return The created vertex shader object or nullptr if the creation failed. 1390 */ 1391 virtual QSSGRenderBackendFragmentShaderObject createFragmentShader(QSSGByteView source, 1392 QByteArray &errorMessage, 1393 bool binary) = 0; 1394 1395 /** 1396 * @brief release a fragment shader object 1397 * 1398 * @param[in] vso Pointer to fragment shader object 1399 * 1400 * @return No Return. 1401 */ 1402 virtual void releaseFragmentShader(QSSGRenderBackendFragmentShaderObject fso) = 0; 1403 1404 /** 1405 * @brief create a tessellation control shader object 1406 * 1407 * @param[in] source Pointer to shader source 1408 * @param[in/out] errorMessage Pointer to copy the error message 1409 * @param[in] binary True if the source is actually a binary program 1410 * 1411 * @return The created tessellation control shader object or nullptr if the creation failed. 1412 */ 1413 virtual QSSGRenderBackendTessControlShaderObject createTessControlShader(QSSGByteView source, 1414 QByteArray &errorMessage, 1415 bool binary) = 0; 1416 1417 /** 1418 * @brief release a tessellation control shader object 1419 * 1420 * @param[in] tcso Pointer to tessellation control shader object 1421 * 1422 * @return No Return. 1423 */ 1424 virtual void releaseTessControlShader(QSSGRenderBackendTessControlShaderObject tcso) = 0; 1425 1426 /** 1427 * @brief create a tessellation evaluation shader object 1428 * 1429 * @param[in] source Pointer to shader source 1430 * @param[in/out] errorMessage Pointer to copy the error message 1431 * @param[in] binary True if the source is actually a binary program 1432 * 1433 * @return The created tessellation evaluation shader object or nullptr if the creation failed. 1434 */ 1435 virtual QSSGRenderBackendTessEvaluationShaderObject createTessEvaluationShader(QSSGByteView source, 1436 QByteArray &errorMessage, 1437 bool binary) = 0; 1438 1439 /** 1440 * @brief release a tessellation evaluation shader object 1441 * 1442 * @param[in] tcso Pointer to tessellation evaluation shader object 1443 * 1444 * @return No Return. 1445 */ 1446 virtual void releaseTessEvaluationShader(QSSGRenderBackendTessEvaluationShaderObject teso) = 0; 1447 1448 /** 1449 * @brief create a geometry shader object 1450 * 1451 * @param[in] source Pointer to shader source 1452 * @param[in/out] errorMessage Pointer to copy the error message 1453 * @param[in] binary True if the source is actually a binary program 1454 * 1455 * @return The created geometry shader object or nullptr if the creation failed. 1456 */ 1457 virtual QSSGRenderBackendGeometryShaderObject createGeometryShader(QSSGByteView source, 1458 QByteArray &errorMessage, 1459 bool binary) = 0; 1460 1461 /** 1462 * @brief release a geometry shader object 1463 * 1464 * @param[in] tcso Pointer to geometry shader object 1465 * 1466 * @return No Return. 1467 */ 1468 virtual void releaseGeometryShader(QSSGRenderBackendGeometryShaderObject gso) = 0; 1469 1470 /** 1471 * @brief create a compute shader object 1472 * 1473 * @param[in] source Pointer to shader source 1474 * @param[in/out] errorMessage Pointer to copy the error message 1475 * @param[in] binary True if the source is actually a binary program 1476 * 1477 * @return The created compute shader object or nullptr if the creation failed. 1478 */ 1479 virtual QSSGRenderBackendComputeShaderObject createComputeShader(QSSGByteView source, 1480 QByteArray &errorMessage, 1481 bool binary) = 0; 1482 1483 /** 1484 * @brief release a compute shader object 1485 * 1486 * @param[in] cso Pointer to compute shader object 1487 * 1488 * @return No Return. 1489 */ 1490 virtual void releaseComputeShader(QSSGRenderBackendComputeShaderObject cso) = 0; 1491 1492 /** 1493 * @brief attach a vertex shader object to a program object 1494 * 1495 * @param[in] po Pointer to program object 1496 * @param[in] vso Pointer to vertex shader object 1497 * 1498 * @return No Return. 1499 */ 1500 virtual void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendVertexShaderObject vso) = 0; 1501 1502 /** 1503 * @brief detach a vertex shader object to a program object 1504 * 1505 * @param[in] po Pointer to program object 1506 * @param[in] vso Pointer to vertex shader object 1507 * 1508 * @return No Return. 1509 */ 1510 virtual void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendVertexShaderObject vso) = 0; 1511 1512 /** 1513 * @brief attach a fragment shader object to a program object 1514 * 1515 * @param[in] po Pointer to program object 1516 * @param[in] fso Pointer to fragment shader object 1517 * 1518 * @return No Return. 1519 */ 1520 virtual void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendFragmentShaderObject fso) = 0; 1521 1522 /** 1523 * @brief detach a fragment shader object to a program object 1524 * 1525 * @param[in] po Pointer to program object 1526 * @param[in] fso Pointer to fragment shader object 1527 * 1528 * @return No Return. 1529 */ 1530 virtual void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendFragmentShaderObject fso) = 0; 1531 1532 /** 1533 * @brief attach a tessellation control shader object to a program object 1534 * 1535 * @param[in] po Pointer to program object 1536 * @param[in] tcso Pointer to tessellation control shader object 1537 * 1538 * @return No Return. 1539 */ 1540 virtual void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessControlShaderObject tcso) = 0; 1541 1542 /** 1543 * @brief detach a tessellation control shader object to a program object 1544 * 1545 * @param[in] po Pointer to program object 1546 * @param[in] tcso Pointer to tessellation control shader object 1547 * 1548 * @return No Return. 1549 */ 1550 virtual void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessControlShaderObject tcso) = 0; 1551 1552 /** 1553 * @brief attach a tessellation evaluation shader object to a program object 1554 * 1555 * @param[in] po Pointer to program object 1556 * @param[in] teso Pointer to tessellation evaluation shader object 1557 * 1558 * @return No Return. 1559 */ 1560 virtual void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessEvaluationShaderObject teso) = 0; 1561 1562 /** 1563 * @brief detach a tessellation evaluation shader object to a program object 1564 * 1565 * @param[in] po Pointer to program object 1566 * @param[in] teso Pointer to tessellation evaluation shader object 1567 * 1568 * @return No Return. 1569 */ 1570 virtual void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessEvaluationShaderObject teso) = 0; 1571 1572 /** 1573 * @brief attach a geometry shader object to a program object 1574 * 1575 * @param[in] po Pointer to program object 1576 * @param[in] teso Pointer to geometry shader object 1577 * 1578 * @return No Return. 1579 */ 1580 virtual void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendGeometryShaderObject gso) = 0; 1581 1582 /** 1583 * @brief detach a geometry shader object to a program object 1584 * 1585 * @param[in] po Pointer to program object 1586 * @param[in] teso Pointer to geometry shader object 1587 * 1588 * @return No Return. 1589 */ 1590 virtual void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendGeometryShaderObject gso) = 0; 1591 1592 /** 1593 * @brief attach a compute shader object to a program object 1594 * 1595 * @param[in] po Pointer to program object 1596 * @param[in] cso Pointer to compute shader object 1597 * 1598 * @return No Return. 1599 */ 1600 virtual void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendComputeShaderObject cso) = 0; 1601 1602 /** 1603 * @brief detach a compute shader object to a program object 1604 * 1605 * @param[in] po Pointer to program object 1606 * @param[in] cso Pointer to compute shader object 1607 * 1608 * @return No Return. 1609 */ 1610 virtual void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendComputeShaderObject cso) = 0; 1611 1612 /** 1613 * @brief create a shader program object 1614 * 1615 * @param[in] isSeparable Tell the backend that this program is separable 1616 * 1617 * @return The created shader program object or nullptr if the creation failed. 1618 */ 1619 virtual QSSGRenderBackendShaderProgramObject createShaderProgram(bool isSeparable) = 0; 1620 1621 /** 1622 * @brief release a shader program object 1623 * 1624 * @param[in] po Pointer to shader program object 1625 * 1626 * @return No Return. 1627 */ 1628 virtual void releaseShaderProgram(QSSGRenderBackendShaderProgramObject po) = 0; 1629 1630 /** 1631 * @brief link a shader program object 1632 * 1633 * @param[in] po Pointer to shader program object 1634 * @param[in/out] errorMessage Pointer to copy the error message 1635 * 1636 * @return True if program is successfully linked. 1637 */ 1638 virtual bool linkProgram(QSSGRenderBackendShaderProgramObject po, QByteArray &errorMessage) = 0; 1639 1640 /** 1641 * @brief link a binary shader program object 1642 * 1643 * @param[in] po Pointer to shader program object 1644 * @param[in/out] errorMessage Pointer to copy the error message 1645 * @param[in] format Binary format 1646 * @param[in] binary Binary data 1647 * 1648 * @return True if program is successfully linked. 1649 */ 1650 virtual bool linkProgram(QSSGRenderBackendShaderProgramObject po, 1651 QByteArray &errorMessage, 1652 quint32 format, const QByteArray &binary) = 0; 1653 1654 /** 1655 * @brief Get shader program binary 1656 * 1657 * @param[in] po Pointer to shader program object 1658 * @param[out] format The format of the program binary 1659 * @param[out] binary The program binary data 1660 * 1661 */ 1662 virtual void getProgramBinary(QSSGRenderBackendShaderProgramObject po, quint32 &format, 1663 QByteArray &binary) = 0; 1664 1665 /** 1666 * @brief Make a program current 1667 * 1668 * @param[in] po Pointer to shader program object 1669 * 1670 * @return No return 1671 */ 1672 virtual void setActiveProgram(QSSGRenderBackendShaderProgramObject po) = 0; 1673 1674 /** 1675 * @brief create a program pipeline object 1676 * 1677 * 1678 * @return The created program pipeline object or nullptr if the creation failed. 1679 */ 1680 virtual QSSGRenderBackendProgramPipeline createProgramPipeline() = 0; 1681 1682 /** 1683 * @brief release a program pipeline object 1684 * 1685 * @param[in] ppo Pointer to program pipeline object 1686 * 1687 * @return No Return. 1688 */ 1689 virtual void releaseProgramPipeline(QSSGRenderBackendProgramPipeline ppo) = 0; 1690 1691 /** 1692 * @brief Make a program pipeline current 1693 * 1694 * @param[in] ppo Pointer to program pipeline object 1695 * 1696 * @return No return 1697 */ 1698 virtual void setActiveProgramPipeline(QSSGRenderBackendProgramPipeline ppo) = 0; 1699 1700 /** 1701 * @brief Make a program stage active for this pipeline 1702 * 1703 * @param[in] ppo Pointer to program pipeline object 1704 * @param[in] flags Shader stage flags to which this po is bound to 1705 * @param[in] po Pointer to shader program object 1706 * 1707 * @return No return 1708 */ 1709 virtual void setProgramStages(QSSGRenderBackendProgramPipeline ppo, 1710 QSSGRenderShaderTypeFlags flags, 1711 QSSGRenderBackendShaderProgramObject po) = 0; 1712 1713 /** 1714 * @brief Runs a compute program 1715 * 1716 * @param[in] po Pointer to shader program object 1717 * @param[in] numGroupsX The number of work groups to be launched in the X 1718 * dimension 1719 * @param[in] numGroupsY The number of work groups to be launched in the Y 1720 * dimension 1721 * @param[in] numGroupsZ The number of work groups to be launched in the Z 1722 * dimension 1723 * 1724 * @return No return 1725 */ 1726 virtual void dispatchCompute(QSSGRenderBackendShaderProgramObject po, quint32 numGroupsX, quint32 numGroupsY, quint32 numGroupsZ) = 0; 1727 1728 /** 1729 * @brief Query constant count for a program object 1730 * 1731 * @param[in] po Pointer to shader program object 1732 * 1733 * @return Return active constant count 1734 */ 1735 virtual qint32 getConstantCount(QSSGRenderBackendShaderProgramObject po) = 0; 1736 1737 /** 1738 * @brief Query constant buffer count for a program object 1739 * 1740 * @param[in] po Pointer to shader program object 1741 * 1742 * @return Return active constant buffer count 1743 */ 1744 virtual qint32 getConstantBufferCount(QSSGRenderBackendShaderProgramObject po) = 0; 1745 1746 /** 1747 * @brief Query constant information by ID 1748 * 1749 * @param[in] po Pointer to shader program object 1750 * @param[in] id Constant ID 1751 * @param[in] bufSize Max char for nameBuf 1752 * @param[out] numElem Usually one unless for arrays 1753 * @param[out] type Constant data type (QVector4D, QVector3D,...) 1754 * @param[out] binding Unit binding point for samplers and images 1755 * @param[out] nameBuf Name of the constant 1756 * 1757 * @return Return current constant location or -1 if not found 1758 */ 1759 virtual qint32 getConstantInfoByID(QSSGRenderBackendShaderProgramObject po, 1760 quint32 id, 1761 quint32 bufSize, 1762 qint32 *numElem, 1763 QSSGRenderShaderDataType *type, 1764 qint32 *binding, 1765 char *nameBuf) = 0; 1766 1767 /** 1768 * @brief Query constant buffer information by ID 1769 * 1770 * @param[in] po Pointer to shader program object 1771 * @param[in] id Constant buffer ID 1772 * @param[in] nameBufSize Size of nameBuf 1773 * @param[out] paramCount Count ot parameter contained in the buffer 1774 * @param[out] bufferSize Data size of the constant buffer 1775 * @param[out] length Actual characters written 1776 * @param[out] nameBuf Receives the name of the buffer 1777 * 1778 * @return Return current constant buffer location or -1 if not found 1779 */ 1780 virtual qint32 getConstantBufferInfoByID(QSSGRenderBackendShaderProgramObject po, 1781 quint32 id, 1782 quint32 nameBufSize, 1783 qint32 *paramCount, 1784 qint32 *bufferSize, 1785 qint32 *length, 1786 char *nameBuf) = 0; 1787 1788 /** 1789 * @brief Query constant buffer param indices 1790 * 1791 * @param[in] po Pointer to shader program object 1792 * @param[in] id Constant buffer ID 1793 * @param[out] indices Receives the indices of the uniforms within the 1794 * constant buffer 1795 * 1796 * @return no return value 1797 */ 1798 virtual void getConstantBufferParamIndices(QSSGRenderBackendShaderProgramObject po, quint32 id, qint32 *indices) = 0; 1799 1800 /** 1801 * @brief Query constant buffer param info by indices 1802 * 1803 * @param[in] po Pointer to shader program object 1804 * @param[in] count Number of indices 1805 * @param[in] indices The indices of the uniforms within the constant 1806 * buffer 1807 * @param[out] type Array of param types ( float ,int, ...) 1808 * @param[out] size Array of param size 1809 * @param[out] offset Array of param offsets within the constant buffer 1810 * 1811 * @return no return value 1812 */ 1813 virtual void getConstantBufferParamInfoByIndices(QSSGRenderBackendShaderProgramObject po, 1814 quint32 count, 1815 quint32 *indices, 1816 QSSGRenderShaderDataType *type, 1817 qint32 *size, 1818 qint32 *offset) = 0; 1819 1820 /** 1821 * @brief Bind program constant block 1822 * 1823 * @param[in] po Pointer to shader program object 1824 * @param[in] blockIndex Constant block index returned by 1825 * GetConstantBufferInfoByID 1826 * @param[in] binding Block binding location which should be the same as index 1827 * in ProgramSetConstantBlock 1828 * 1829 * @return No return 1830 */ 1831 virtual void programSetConstantBlock(QSSGRenderBackendShaderProgramObject po, quint32 blockIndex, quint32 binding) = 0; 1832 1833 /** 1834 * @brief Bind constant buffer for usage in the current active shader program 1835 * 1836 * @param[in] index Constant ID 1837 * @param[in] bo Pointer to constant buffer object 1838 * 1839 * @return No return 1840 */ 1841 virtual void programSetConstantBuffer(quint32 index, QSSGRenderBackendBufferObject bo) = 0; 1842 1843 /** 1844 * @brief Query storage buffer count for a program object 1845 * 1846 * @param[in] po Pointer to shader program object 1847 * 1848 * @return Return active storage buffer count 1849 */ 1850 virtual qint32 getStorageBufferCount(QSSGRenderBackendShaderProgramObject po) = 0; 1851 1852 /** 1853 * @brief Query storage buffer information by ID 1854 * 1855 * @param[in] po Pointer to shader program object 1856 * @param[in] id Storage buffer ID 1857 * @param[in] nameBufSize Size of nameBuf 1858 * @param[out] paramCount Count of parameter contained in the buffer 1859 * @param[out] bufferSize Data size of the constant buffer 1860 * @param[out] length Actual characters written 1861 * @param[out] nameBuf Receives the name of the buffer 1862 * 1863 * @return Return current storage buffer binding or -1 if not found 1864 */ 1865 virtual qint32 getStorageBufferInfoByID(QSSGRenderBackendShaderProgramObject po, 1866 quint32 id, 1867 quint32 nameBufSize, 1868 qint32 *paramCount, 1869 qint32 *bufferSize, 1870 qint32 *length, 1871 char *nameBuf) = 0; 1872 1873 /** 1874 * @brief Bind a storage buffer for usage in the current active shader program 1875 * 1876 * @param[in] index Constant ID 1877 * @param[in] bo Pointer to storage buffer object 1878 * 1879 * @return No return 1880 */ 1881 virtual void programSetStorageBuffer(quint32 index, QSSGRenderBackendBufferObject bo) = 0; 1882 1883 /** 1884 * @brief Set constant value 1885 * 1886 * @param[in] po Pointer program object 1887 * @param[in] id Constant ID 1888 * @param[in] type Constant data type (QVector4D, QVector3D,...) 1889 * @param[in] count Element count 1890 * @param[in] value Pointer to constant value 1891 * @param[in] transpose Transpose a matrix 1892 * 1893 * @return No return 1894 */ 1895 virtual void setConstantValue(QSSGRenderBackendShaderProgramObject po, 1896 quint32 id, 1897 QSSGRenderShaderDataType type, 1898 qint32 count, 1899 const void *value, 1900 bool transpose = false) = 0; 1901 1902 /** 1903 * @brief Draw the current active vertex buffer 1904 * 1905 * @param[in] drawMode Draw mode (Triangles, ....) 1906 * @param[in] start Start vertex 1907 * @param[in] count Vertex count 1908 * 1909 * @return no return. 1910 */ 1911 virtual void draw(QSSGRenderDrawMode drawMode, quint32 start, quint32 count) = 0; 1912 1913 /** 1914 * @brief Draw the current active index buffer 1915 * 1916 * @param[in] drawMode Draw mode (Triangles, ....) 1917 * @param[in] count Index count 1918 * @param[in] type Index type (quint16, quint8) 1919 * @param[in] indices Pointer to index buffer. In the case of buffer objects 1920 * this is an offset into the active index buffer 1921 *object. 1922 * 1923 * @return no return. 1924 */ 1925 virtual void drawIndexed(QSSGRenderDrawMode drawMode, quint32 count, QSSGRenderComponentType type, const void *indices) = 0; 1926 1927 /** 1928 * @brief Read a pixel rectangle from render target (from bottom left) 1929 * 1930 * @param[in] rto Pointer to render target object 1931 * @param[in] x Windows X start coord 1932 * @param[in] y Windows Y start coord 1933 * @param[in] width Read width dim 1934 * @param[in] height Read height dim 1935 * @param[out] pixels Returned pixel data 1936 * 1937 * @return No return 1938 */ 1939 virtual void readPixel(QSSGRenderBackendRenderTargetObject rto, 1940 qint32 x, 1941 qint32 y, 1942 qint32 width, 1943 qint32 height, 1944 QSSGRenderReadPixelFormat inFormat, 1945 QSSGByteRef pixels) = 0; 1946 1947 virtual QSurfaceFormat format() const = 0; 1948 1949 protected: 1950 /// struct for what the backend supports 1951 typedef struct QSSGRenderBackendSupport 1952 { 1953 union { 1954 struct 1955 { 1956 bool bDXTImagesSupported : 1; ///< compressed images supported 1957 bool bAnistropySupported : 1; ///< anistropic filtering supported 1958 bool bTextureSwizzleSupported : 1; ///< texture swizzle supported 1959 bool bDepthStencilSupported : 1; ///< depth stencil textures are supported 1960 bool bFPRenderTargetsSupported : 1; ///< floating point render targets are 1961 /// supported 1962 bool bConstantBufferSupported : 1; ///< Constant (uniform) buffers are supported 1963 bool bMsTextureSupported : 1; ///< Multisample textures are esupported 1964 bool bFastBlitsSupported : 1; ///< The hardware supports fast memor blits 1965 bool bTessellationSupported : 1; ///< Hardware supports tessellation 1966 bool bComputeSupported : 1; ///< Hardware supports compute shader 1967 bool bGeometrySupported : 1; ///< Hardware supports geometry shader 1968 bool bTimerQuerySupported : 1; ///< Hardware supports timer queries 1969 bool bProgramInterfaceSupported : 1; ///< API supports program interface queries 1970 bool bStorageBufferSupported : 1; ///< Shader storage buffers are supported 1971 /// supported 1972 bool bShaderImageLoadStoreSupported : 1; ///< Shader image load / store 1973 /// operations are supported 1974 bool bProgramPipelineSupported : 1; ///< Driver supports separate programs 1975 bool bNVAdvancedBlendSupported : 1; ///< Advanced blend modes supported 1976 bool bNVBlendCoherenceSupported : 1; ///< Advanced blend done coherently 1977 /// supported 1978 bool bGPUShader5ExtensionSupported : 1; 1979 bool bKHRAdvancedBlendSupported : 1; ///< Advanced blend modes supported 1980 bool bKHRBlendCoherenceSupported : 1; ///< Advanced blend done coherently 1981 bool bVertexArrayObjectSupported : 1; 1982 bool bStandardDerivativesSupported : 1; 1983 bool bTextureLodSupported : 1; 1984 } bits; 1985 1986 quint32 u32Values; 1987 } caps; 1988 } QSSGRenderBackendSupportBits; 1989 1990 QSSGRenderBackendSupportBits m_backendSupport; ///< holds the backend support bits 1991 }; 1992 1993 QT_END_NAMESPACE 1994 1995 #endif 1996