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_GL_BASE_H 32 #define QSSG_RENDER_BACKEND_GL_BASE_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 /// @file QSSGrenderbackendglbase.h 46 /// NVRender OpenGL Core backend definition. 47 48 #include <QtQuick3DRender/private/qssgrenderbackend_p.h> 49 #include <QtQuick3DRender/private/qssgopenglutil_p.h> 50 #include <QtQuick3DRender/private/qssgrenderbackendshaderprogramgl_p.h> 51 52 #include <QtCore/QVector> 53 54 #include <QtGui/QSurfaceFormat> 55 #include <QtGui/QOpenGLFunctions> 56 57 QT_BEGIN_NAMESPACE 58 59 // Enable this to log opengl errors instead of an assert 60 //#define RENDER_BACKEND_LOG_GL_ERRORS 61 62 ///< forward declaration 63 class QSSGRenderBackendRasterizerStateGL; 64 class QSSGRenderBackendDepthStencilStateGL; 65 66 namespace QSSGGlExtStrings { 67 QByteArray exts3tc(); 68 QByteArray extsdxt(); 69 QByteArray extsAniso(); 70 QByteArray extsTexSwizzle(); 71 QByteArray extsFPRenderTarget(); 72 QByteArray extsTimerQuery(); 73 QByteArray extsGpuShader5(); 74 } 75 76 class QSSGRenderBackendGLBase : public QSSGRenderBackend 77 { 78 QSSGRenderBackendGLBase() = default; 79 80 public: 81 /// constructor 82 QSSGRenderBackendGLBase(const QSurfaceFormat &format); 83 /// destructor 84 ~QSSGRenderBackendGLBase() override; 85 86 public: 87 /// API Interface 88 QSSGRenderContextType getRenderContextType() const override; 89 bool isESCompatible() const; 90 91 QByteArray getShadingLanguageVersion() override; 92 /// get implementation depended values 93 qint32 getMaxCombinedTextureUnits() override; 94 bool getRenderBackendCap(QSSGRenderBackendCaps inCap) const override; 95 qint32 getDepthBits() const override; 96 qint32 getStencilBits() const override; 97 qint32 getMaxSamples() const override; 98 void getRenderBackendValue(QSSGRenderBackendQuery inQuery, qint32 *params) const override; 99 100 /// state get/set functions 101 void setRenderState(bool bEnable, const QSSGRenderState value) override; 102 bool getRenderState(const QSSGRenderState value) override; 103 virtual QSSGRenderBackendDepthStencilStateObject createDepthStencilState( 104 bool enableDepth, 105 bool depthMask, 106 QSSGRenderBoolOp depthFunc, 107 bool enableStencil, 108 QSSGRenderStencilFunction &stencilFuncFront, 109 QSSGRenderStencilFunction &stencilFuncBack, 110 QSSGRenderStencilOperation &depthStencilOpFront, 111 QSSGRenderStencilOperation &depthStencilOpBack) override; 112 virtual void releaseDepthStencilState(QSSGRenderBackendDepthStencilStateObject inDepthStencilState) override; 113 virtual QSSGRenderBackendRasterizerStateObject createRasterizerState(float depthBias, float depthScale) override; 114 void releaseRasterizerState(QSSGRenderBackendRasterizerStateObject rasterizerState) override; 115 virtual void setDepthStencilState(QSSGRenderBackendDepthStencilStateObject inDepthStencilState) override; 116 void setRasterizerState(QSSGRenderBackendRasterizerStateObject rasterizerState) override; 117 QSSGRenderBoolOp getDepthFunc() override; 118 void setDepthFunc(const QSSGRenderBoolOp func) override; 119 bool getDepthWrite() override; 120 void setDepthWrite(bool bEnable) override; 121 void setColorWrites(bool bRed, bool bGreen, bool bBlue, bool bAlpha) override; 122 void setMultisample(bool bEnable) override; 123 void getBlendFunc(QSSGRenderBlendFunctionArgument *pBlendFuncArg) override; 124 void setBlendFunc(const QSSGRenderBlendFunctionArgument &blendFuncArg) override; 125 void setBlendEquation(const QSSGRenderBlendEquationArgument &pBlendEquArg) override; 126 void setBlendBarrier(void) override; 127 QSSGCullFaceMode getCullFaceMode() override; 128 void setCullFaceMode(const QSSGCullFaceMode cullFaceMode) override; 129 void getScissorRect(QRect *pRect) override; 130 void setScissorRect(const QRect &rect) override; 131 void getViewportRect(QRect *pRect) override; 132 void setViewportRect(const QRect &rect) override; 133 134 void setClearColor(const QVector4D *pClearColor) override; 135 void clear(QSSGRenderClearFlags flags) override; 136 137 /// resource handling 138 QSSGRenderBackendBufferObject createBuffer(QSSGRenderBufferType bindFlags, 139 QSSGRenderBufferUsageType usage, 140 QSSGByteView hostData) override; 141 void bindBuffer(QSSGRenderBackendBufferObject bo, QSSGRenderBufferType bindFlags) override; 142 void releaseBuffer(QSSGRenderBackendBufferObject bo) override; 143 void updateBuffer(QSSGRenderBackendBufferObject bo, 144 QSSGRenderBufferType bindFlags, 145 QSSGRenderBufferUsageType usage, 146 QSSGByteView data) override; 147 void updateBufferRange(QSSGRenderBackendBufferObject bo, 148 QSSGRenderBufferType bindFlags, 149 size_t offset, 150 QSSGByteView data) override; 151 void *mapBuffer(QSSGRenderBackendBufferObject bo, 152 QSSGRenderBufferType bindFlags, 153 size_t offset, 154 size_t length, 155 QSSGRenderBufferAccessFlags accessFlags) override; 156 bool unmapBuffer(QSSGRenderBackendBufferObject bo, QSSGRenderBufferType bindFlags) override; 157 void setMemoryBarrier(QSSGRenderBufferBarrierFlags barriers) override; 158 159 QSSGRenderBackendQueryObject createQuery() override; 160 void releaseQuery(QSSGRenderBackendQueryObject qo) override; 161 void beginQuery(QSSGRenderBackendQueryObject qo, QSSGRenderQueryType type) override; 162 void endQuery(QSSGRenderBackendQueryObject qo, QSSGRenderQueryType type) override; 163 void getQueryResult(QSSGRenderBackendQueryObject qo, QSSGRenderQueryResultType resultType, quint32 *params) override; 164 void getQueryResult(QSSGRenderBackendQueryObject qo, QSSGRenderQueryResultType resultType, quint64 *params) override; 165 void setQueryTimer(QSSGRenderBackendQueryObject qo) override; 166 167 QSSGRenderBackendSyncObject createSync(QSSGRenderSyncType tpye, QSSGRenderSyncFlags syncFlags) override; 168 void releaseSync(QSSGRenderBackendSyncObject so) override; 169 void waitSync(QSSGRenderBackendSyncObject so, QSSGRenderCommandFlushFlags syncFlags, quint64 timeout) override; 170 171 QSSGRenderBackendRenderTargetObject createRenderTarget() override; 172 void releaseRenderTarget(QSSGRenderBackendRenderTargetObject rto) override; 173 174 void renderTargetAttach(QSSGRenderBackendRenderTargetObject rto, 175 QSSGRenderFrameBufferAttachment attachment, 176 QSSGRenderBackendRenderbufferObject rbo) override; 177 178 void renderTargetAttach(QSSGRenderBackendRenderTargetObject rto, 179 QSSGRenderFrameBufferAttachment attachment, 180 QSSGRenderBackendTextureObject to, 181 QSSGRenderTextureTargetType target = QSSGRenderTextureTargetType::Texture2D) override; 182 183 void renderTargetAttach(QSSGRenderBackendRenderTargetObject rto, 184 QSSGRenderFrameBufferAttachment attachment, 185 QSSGRenderBackendTextureObject to, 186 qint32 level, 187 qint32 layer) override; 188 189 void setRenderTarget(QSSGRenderBackendRenderTargetObject rto) override; 190 bool renderTargetIsValid(QSSGRenderBackendRenderTargetObject rto) override; 191 192 QSSGRenderBackendRenderbufferObject createRenderbuffer(QSSGRenderRenderBufferFormat storageFormat, 193 qint32 width, 194 qint32 height) override; 195 void releaseRenderbuffer(QSSGRenderBackendRenderbufferObject rbo) override; 196 bool resizeRenderbuffer(QSSGRenderBackendRenderbufferObject rbo, 197 QSSGRenderRenderBufferFormat storageFormat, 198 qint32 width, 199 qint32 height) override; 200 201 QSSGRenderBackendTextureObject createTexture() override; 202 void bindTexture(QSSGRenderBackendTextureObject to, QSSGRenderTextureTargetType target, qint32 unit) override; 203 void setActiveTexture(qint32 unit) override; 204 void bindImageTexture(QSSGRenderBackendTextureObject to, 205 quint32 unit, 206 qint32 level, 207 bool layered, 208 qint32 layer, 209 QSSGRenderImageAccessType access, 210 QSSGRenderTextureFormat format) override; 211 void releaseTexture(QSSGRenderBackendTextureObject to) override; 212 void setTextureData2D(QSSGRenderBackendTextureObject to, 213 QSSGRenderTextureTargetType target, 214 qint32 level, 215 QSSGRenderTextureFormat internalFormat, 216 qint32 width, 217 qint32 height, 218 qint32 border, 219 QSSGRenderTextureFormat format, 220 QSSGByteView hostData) override; 221 void setTextureDataCubeFace(QSSGRenderBackendTextureObject to, 222 QSSGRenderTextureTargetType target, 223 qint32 level, 224 QSSGRenderTextureFormat internalFormat, 225 qint32 width, 226 qint32 height, 227 qint32 border, 228 QSSGRenderTextureFormat format, 229 QSSGByteView hostData) override; 230 void createTextureStorage2D(QSSGRenderBackendTextureObject to, 231 QSSGRenderTextureTargetType target, 232 qint32 levels, 233 QSSGRenderTextureFormat internalFormat, 234 qint32 width, 235 qint32 height) override; 236 void setTextureSubData2D(QSSGRenderBackendTextureObject to, 237 QSSGRenderTextureTargetType target, 238 qint32 level, 239 qint32 xOffset, 240 qint32 yOffset, 241 qint32 width, 242 qint32 height, 243 QSSGRenderTextureFormat format, 244 QSSGByteView hostData) override; 245 void setCompressedTextureData2D(QSSGRenderBackendTextureObject to, 246 QSSGRenderTextureTargetType target, 247 qint32 level, 248 QSSGRenderTextureFormat internalFormat, 249 qint32 width, 250 qint32 height, 251 qint32 border, 252 QSSGByteView hostData) override; 253 void setCompressedTextureDataCubeFace(QSSGRenderBackendTextureObject to, 254 QSSGRenderTextureTargetType target, 255 qint32 level, 256 QSSGRenderTextureFormat internalFormat, 257 qint32 width, 258 qint32 height, 259 qint32 border, 260 QSSGByteView hostData) override; 261 void setCompressedTextureSubData2D(QSSGRenderBackendTextureObject to, 262 QSSGRenderTextureTargetType target, 263 qint32 level, 264 qint32 xOffset, 265 qint32 yOffset, 266 qint32 width, 267 qint32 height, 268 QSSGRenderTextureFormat format, 269 QSSGByteView hostData) override; 270 void setMultisampledTextureData2D(QSSGRenderBackendTextureObject to, 271 QSSGRenderTextureTargetType target, 272 qint32 samples, 273 QSSGRenderTextureFormat internalFormat, 274 qint32 width, 275 qint32 height, 276 bool fixedsamplelocations) override = 0; 277 278 void setTextureData3D(QSSGRenderBackendTextureObject to, 279 QSSGRenderTextureTargetType target, 280 qint32 level, 281 QSSGRenderTextureFormat internalFormat, 282 qint32 width, 283 qint32 height, 284 qint32 depth, 285 qint32 border, 286 QSSGRenderTextureFormat format, 287 QSSGByteView hostData) override; 288 289 void generateMipMaps(QSSGRenderBackendTextureObject to, 290 QSSGRenderTextureTargetType target, 291 QSSGRenderHint genType) override; 292 293 virtual QSSGRenderTextureSwizzleMode getTextureSwizzleMode(const QSSGRenderTextureFormat inFormat) const override; 294 295 QSSGRenderBackendSamplerObject createSampler( 296 QSSGRenderTextureMinifyingOp minFilter = QSSGRenderTextureMinifyingOp::Linear, 297 QSSGRenderTextureMagnifyingOp magFilter = QSSGRenderTextureMagnifyingOp::Linear, 298 QSSGRenderTextureCoordOp wrapS = QSSGRenderTextureCoordOp::ClampToEdge, 299 QSSGRenderTextureCoordOp wrapT = QSSGRenderTextureCoordOp::ClampToEdge, 300 QSSGRenderTextureCoordOp wrapR = QSSGRenderTextureCoordOp::ClampToEdge, 301 qint32 minLod = -1000, 302 qint32 maxLod = 1000, 303 float lodBias = 0.0, 304 QSSGRenderTextureCompareMode compareMode = QSSGRenderTextureCompareMode::NoCompare, 305 QSSGRenderTextureCompareOp compareFunc = QSSGRenderTextureCompareOp::LessThanOrEqual, 306 float anisotropy = 1.0, 307 float *borderColor = nullptr) override; 308 309 void updateSampler(QSSGRenderBackendSamplerObject so, 310 QSSGRenderTextureTargetType target, 311 QSSGRenderTextureMinifyingOp minFilter = QSSGRenderTextureMinifyingOp::Linear, 312 QSSGRenderTextureMagnifyingOp magFilter = QSSGRenderTextureMagnifyingOp::Linear, 313 QSSGRenderTextureCoordOp wrapS = QSSGRenderTextureCoordOp::ClampToEdge, 314 QSSGRenderTextureCoordOp wrapT = QSSGRenderTextureCoordOp::ClampToEdge, 315 QSSGRenderTextureCoordOp wrapR = QSSGRenderTextureCoordOp::ClampToEdge, 316 float minLod = -1000.0, 317 float maxLod = 1000.0, 318 float lodBias = 0.0, 319 QSSGRenderTextureCompareMode compareMode = QSSGRenderTextureCompareMode::NoCompare, 320 QSSGRenderTextureCompareOp compareFunc = QSSGRenderTextureCompareOp::LessThanOrEqual, 321 float anisotropy = 1.0, 322 float *borderColor = nullptr) override; 323 324 void updateTextureObject(QSSGRenderBackendTextureObject to, 325 QSSGRenderTextureTargetType target, 326 qint32 baseLevel, 327 qint32 maxLevel) override; 328 329 void updateTextureSwizzle(QSSGRenderBackendTextureObject to, 330 QSSGRenderTextureTargetType target, 331 QSSGRenderTextureSwizzleMode swizzleMode) override; 332 333 void releaseSampler(QSSGRenderBackendSamplerObject so) override; 334 335 virtual QSSGRenderBackendAttribLayoutObject createAttribLayout(QSSGDataView<QSSGRenderVertexBufferEntry> attribs) override; 336 void releaseAttribLayout(QSSGRenderBackendAttribLayoutObject ao) override; 337 338 virtual QSSGRenderBackendInputAssemblerObject createInputAssembler(QSSGRenderBackendAttribLayoutObject attribLayout, 339 QSSGDataView<QSSGRenderBackendBufferObject> buffers, 340 const QSSGRenderBackendBufferObject indexBuffer, 341 QSSGDataView<quint32> strides, 342 QSSGDataView<quint32> offsets, 343 quint32 patchVertexCount) override; 344 void releaseInputAssembler(QSSGRenderBackendInputAssemblerObject iao) override; 345 346 bool setInputAssembler(QSSGRenderBackendInputAssemblerObject iao, QSSGRenderBackendShaderProgramObject po) override = 0; 347 void resetStates() override; setPatchVertexCount(QSSGRenderBackendInputAssemblerObject,quint32)348 void setPatchVertexCount(QSSGRenderBackendInputAssemblerObject, quint32) override { Q_ASSERT(false); } 349 350 // shader 351 virtual QSSGRenderBackendVertexShaderObject createVertexShader(QSSGByteView source, 352 QByteArray &errorMessage, 353 bool binary) override; 354 virtual QSSGRenderBackendFragmentShaderObject createFragmentShader(QSSGByteView source, 355 QByteArray &errorMessage, 356 bool binary) override; 357 virtual QSSGRenderBackendTessControlShaderObject createTessControlShader(QSSGByteView source, 358 QByteArray &errorMessage, 359 bool binary) override; 360 virtual QSSGRenderBackendTessEvaluationShaderObject createTessEvaluationShader(QSSGByteView source, 361 QByteArray &errorMessage, 362 bool binary) override; 363 virtual QSSGRenderBackendGeometryShaderObject createGeometryShader(QSSGByteView source, 364 QByteArray &errorMessage, 365 bool binary) override; 366 virtual QSSGRenderBackendComputeShaderObject createComputeShader(QSSGByteView source, 367 QByteArray &errorMessage, 368 bool binary) override; 369 void releaseVertexShader(QSSGRenderBackendVertexShaderObject vso) override; 370 void releaseFragmentShader(QSSGRenderBackendFragmentShaderObject fso) override; 371 void releaseTessControlShader(QSSGRenderBackendTessControlShaderObject tcso) override; 372 void releaseTessEvaluationShader(QSSGRenderBackendTessEvaluationShaderObject teso) override; 373 void releaseGeometryShader(QSSGRenderBackendGeometryShaderObject gso) override; 374 void releaseComputeShader(QSSGRenderBackendComputeShaderObject cso) override; 375 void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendVertexShaderObject vso) override; 376 void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendFragmentShaderObject fso) override; 377 void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessControlShaderObject tcso) override; 378 void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessEvaluationShaderObject teso) override; 379 void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendGeometryShaderObject gso) override; 380 void attachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendComputeShaderObject cso) override; 381 void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendVertexShaderObject vso) override; 382 void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendFragmentShaderObject fso) override; 383 void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessControlShaderObject tcso) override; 384 void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendTessEvaluationShaderObject teso) override; 385 void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendGeometryShaderObject gso) override; 386 void detachShader(QSSGRenderBackendShaderProgramObject po, QSSGRenderBackendComputeShaderObject cso) override; 387 QSSGRenderBackendShaderProgramObject createShaderProgram(bool isSeparable) override; 388 void releaseShaderProgram(QSSGRenderBackendShaderProgramObject po) override; 389 bool linkProgram(QSSGRenderBackendShaderProgramObject po, QByteArray &errorMessage) override; 390 bool linkProgram(QSSGRenderBackendShaderProgramObject po, QByteArray &errorMessage, 391 quint32 format, const QByteArray &binary) override; 392 void getProgramBinary(QSSGRenderBackendShaderProgramObject po, quint32 &format, QByteArray &binary) override; 393 void setActiveProgram(QSSGRenderBackendShaderProgramObject po) override; 394 void dispatchCompute(QSSGRenderBackendShaderProgramObject po, quint32 numGroupsX, quint32 numGroupsY, quint32 numGroupsZ) override; 395 QSSGRenderBackendProgramPipeline createProgramPipeline() override; 396 void releaseProgramPipeline(QSSGRenderBackendProgramPipeline po) override; 397 void setActiveProgramPipeline(QSSGRenderBackendProgramPipeline po) override; 398 void setProgramStages(QSSGRenderBackendProgramPipeline ppo, 399 QSSGRenderShaderTypeFlags flags, 400 QSSGRenderBackendShaderProgramObject po) override; 401 402 // uniforms 403 qint32 getConstantCount(QSSGRenderBackendShaderProgramObject po) override; 404 qint32 getConstantInfoByID(QSSGRenderBackendShaderProgramObject po, 405 quint32 id, 406 quint32 bufSize, 407 qint32 *numElem, 408 QSSGRenderShaderDataType *type, 409 qint32 *binding, 410 char *nameBuf) override; 411 void setConstantValue(QSSGRenderBackendShaderProgramObject po, 412 quint32 id, 413 QSSGRenderShaderDataType type, 414 qint32 count, 415 const void *value, 416 bool transpose) override; 417 418 // uniform buffers 419 qint32 getConstantBufferCount(QSSGRenderBackendShaderProgramObject po) override; 420 qint32 getConstantBufferInfoByID(QSSGRenderBackendShaderProgramObject po, 421 quint32 id, 422 quint32 nameBufSize, 423 qint32 *paramCount, 424 qint32 *bufferSize, 425 qint32 *length, 426 char *nameBuf) override; 427 void getConstantBufferParamIndices(QSSGRenderBackendShaderProgramObject po, quint32 id, qint32 *indices) override; 428 void getConstantBufferParamInfoByIndices(QSSGRenderBackendShaderProgramObject po, 429 quint32 count, 430 quint32 *indices, 431 QSSGRenderShaderDataType *type, 432 qint32 *size, 433 qint32 *offset) override; 434 void programSetConstantBlock(QSSGRenderBackendShaderProgramObject po, quint32 blockIndex, quint32 binding) override; 435 void programSetConstantBuffer(quint32 index, QSSGRenderBackendBufferObject bo) override; 436 437 // storage buffers 438 qint32 getStorageBufferCount(QSSGRenderBackendShaderProgramObject po) override; 439 qint32 getStorageBufferInfoByID(QSSGRenderBackendShaderProgramObject po, 440 quint32 id, 441 quint32 nameBufSize, 442 qint32 *paramCount, 443 qint32 *bufferSize, 444 qint32 *length, 445 char *nameBuf) override; 446 void programSetStorageBuffer(quint32 index, QSSGRenderBackendBufferObject bo) override; 447 448 /// draw calls 449 void draw(QSSGRenderDrawMode drawMode, quint32 start, quint32 count) override; 450 void drawIndexed(QSSGRenderDrawMode drawMode, quint32 count, QSSGRenderComponentType type, const void *indices) override; 451 452 // read calls 453 void readPixel(QSSGRenderBackendRenderTargetObject rto, 454 qint32 x, 455 qint32 y, 456 qint32 width, 457 qint32 height, 458 QSSGRenderReadPixelFormat inFormat, 459 QSSGByteRef pixels) override; 460 format()461 QSurfaceFormat format() const override { return m_format; } 462 463 private: 464 const char *getShadingLanguageVersionString(); 465 const char *getVersionString(); 466 const char *getVendorString(); 467 const char *getRendererString(); 468 void getAttributes(QSSGRenderBackendShaderProgramGL *pProgram); 469 470 protected: 471 const char *getExtensionString(); // Used to resolve caps in the different backends 472 473 private: 474 static const qint32 ACTIVATED_TEXTURE_UNIT_UNKNOWN = -1; 475 476 protected: 477 virtual bool compileSource(GLuint shaderID, QSSGByteView source, QByteArray &errorMessage, bool binary); 478 virtual void setAndInspectHardwareCaps(); 479 480 GLConversion m_conversion; ///< Class for conversion from base type to GL types 481 QList<QByteArray> m_extensions; ///< contains the OpenGL extension string 482 qint32 m_maxAttribCount; ///< Maximum attributes which can be used 483 qint32 m_usedAttribCount; ///< Number of attributes which have possibly been used 484 qint32 m_activatedTextureUnit = ACTIVATED_TEXTURE_UNIT_UNKNOWN; ///< Activated Texture Unit 485 QVector<GLenum> m_drawBuffersArray; ///< Contains the drawbuffer enums 486 QSurfaceFormat m_format; 487 488 QSSGRenderBackendRasterizerStateGL *m_currentRasterizerState = nullptr; ///< this holds the current rasterizer state 489 QSSGRenderBackendDepthStencilStateGL *m_currentDepthStencilState = nullptr; ///< this holds the current depth stencil state 490 491 #ifdef RENDER_BACKEND_LOG_GL_ERRORS checkGLError(const char * function,const char * file,const unsigned int line)492 void checkGLError(const char *function, const char *file, const unsigned int line) const 493 { 494 GLenum error = m_glFunctions->glGetError(); 495 if (error != GL_NO_ERROR) { 496 qCCritical(RENDER_GL_ERROR) << GLConversion::processGLError(error) << " " << function << " " << file << " " << line; 497 } 498 } 499 #else checkGLError()500 void checkGLError() const 501 { 502 #ifdef QT_DEBUG 503 const GLenum error = m_glFunctions->glGetError(); 504 if (error != GL_NO_ERROR) 505 qCCritical(RENDER_GL_ERROR, "GL Error: %s", GLConversion::processGLError(error)); 506 #endif 507 } 508 #endif 509 QOpenGLFunctions *m_glFunctions = nullptr; 510 QOpenGLExtraFunctions *m_glExtraFunctions = nullptr; 511 }; 512 513 QT_END_NAMESPACE 514 515 #endif 516