| 1 | // Copyright (C) 2015 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 "graphicshelpergl3_3_p.h" |
| 5 | |
| 6 | #if !QT_CONFIG(opengles2) |
| 7 | #include <QOpenGLFunctions_3_3_Core> |
| 8 | #include <private/attachmentpack_p.h> |
| 9 | #include <logging_p.h> |
| 10 | #include <qgraphicsutils_p.h> |
| 11 | |
| 12 | # ifndef QT_OPENGL_3_2 |
| 13 | # define GL_PATCH_VERTICES 36466 |
| 14 | # define GL_ACTIVE_RESOURCES 0x92F5 |
| 15 | # define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 |
| 16 | # define GL_BUFFER_BINDING 0x9302 |
| 17 | # define GL_BUFFER_DATA_SIZE 0x9303 |
| 18 | # define GL_NUM_ACTIVE_VARIABLES 0x9304 |
| 19 | # define GL_SHADER_STORAGE_BLOCK 0x92E6 |
| 20 | # define GL_UNIFORM 0x92E1 |
| 21 | # define GL_UNIFORM_BLOCK 0x92E2 |
| 22 | # define GL_UNIFORM_BLOCK_INDEX 0x8A3A |
| 23 | # define GL_UNIFORM_OFFSET 0x8A3B |
| 24 | # define GL_UNIFORM_ARRAY_STRIDE 0x8A3C |
| 25 | # define GL_UNIFORM_MATRIX_STRIDE 0x8A3D |
| 26 | # define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 |
| 27 | # define GL_UNIFORM_BLOCK_BINDING 0x8A3F |
| 28 | # define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 |
| 29 | # endif |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | namespace Qt3DRender { |
| 34 | namespace Render { |
| 35 | namespace OpenGL { |
| 36 | |
| 37 | GraphicsHelperGL3_3::GraphicsHelperGL3_3() |
| 38 | : m_funcs(nullptr) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | GraphicsHelperGL3_3::~GraphicsHelperGL3_3() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void GraphicsHelperGL3_3::initializeHelper(QOpenGLContext *context, |
| 47 | QAbstractOpenGLFunctions *functions) |
| 48 | { |
| 49 | Q_UNUSED(context); |
| 50 | m_funcs = static_cast<QOpenGLFunctions_3_3_Core*>(functions); |
| 51 | const bool ok = m_funcs->initializeOpenGLFunctions(); |
| 52 | Q_ASSERT(ok); |
| 53 | Q_UNUSED(ok); |
| 54 | } |
| 55 | |
| 56 | void GraphicsHelperGL3_3::drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, |
| 57 | GLsizei primitiveCount, |
| 58 | GLint indexType, |
| 59 | void *indices, |
| 60 | GLsizei instances, |
| 61 | GLint baseVertex, |
| 62 | GLint baseInstance) |
| 63 | { |
| 64 | if (baseInstance != 0) |
| 65 | qWarning() << "glDrawElementsInstancedBaseVertexBaseInstance is not supported with OpenGL 3.3" ; |
| 66 | |
| 67 | // glDrawElements OpenGL 3.1 or greater |
| 68 | m_funcs->glDrawElementsInstancedBaseVertex(mode: primitiveType, |
| 69 | count: primitiveCount, |
| 70 | type: indexType, |
| 71 | indices, |
| 72 | instancecount: instances, |
| 73 | basevertex: baseVertex); |
| 74 | } |
| 75 | |
| 76 | void GraphicsHelperGL3_3::drawArraysInstanced(GLenum primitiveType, |
| 77 | GLint first, |
| 78 | GLsizei count, |
| 79 | GLsizei instances) |
| 80 | { |
| 81 | // glDrawArraysInstanced OpenGL 3.1 or greater |
| 82 | m_funcs->glDrawArraysInstanced(mode: primitiveType, |
| 83 | first, |
| 84 | count, |
| 85 | instancecount: instances); |
| 86 | } |
| 87 | |
| 88 | void GraphicsHelperGL3_3::drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) |
| 89 | { |
| 90 | if (baseInstance != 0) |
| 91 | qWarning() << "glDrawArraysInstancedBaseInstance is not supported with OpenGL 3" ; |
| 92 | m_funcs->glDrawArraysInstanced(mode: primitiveType, |
| 93 | first, |
| 94 | count, |
| 95 | instancecount: instances); |
| 96 | } |
| 97 | |
| 98 | void GraphicsHelperGL3_3::drawElements(GLenum primitiveType, |
| 99 | GLsizei primitiveCount, |
| 100 | GLint indexType, |
| 101 | void *indices, |
| 102 | GLint baseVertex) |
| 103 | { |
| 104 | m_funcs->glDrawElementsBaseVertex(mode: primitiveType, |
| 105 | count: primitiveCount, |
| 106 | type: indexType, |
| 107 | indices, |
| 108 | basevertex: baseVertex); |
| 109 | } |
| 110 | |
| 111 | void GraphicsHelperGL3_3::drawElementsIndirect(GLenum, GLenum, void *) |
| 112 | { |
| 113 | qWarning() << "Indirect Drawing is not supported with OpenGL 3" ; |
| 114 | } |
| 115 | |
| 116 | void GraphicsHelperGL3_3::drawArrays(GLenum primitiveType, |
| 117 | GLint first, |
| 118 | GLsizei count) |
| 119 | { |
| 120 | m_funcs->glDrawArrays(mode: primitiveType, |
| 121 | first, |
| 122 | count); |
| 123 | } |
| 124 | |
| 125 | void GraphicsHelperGL3_3::drawArraysIndirect(GLenum , void *) |
| 126 | { |
| 127 | qWarning() << "Indirect Drawing is not supported with OpenGL 3" ; |
| 128 | } |
| 129 | |
| 130 | void GraphicsHelperGL3_3::setVerticesPerPatch(GLint verticesPerPatch) |
| 131 | { |
| 132 | Q_UNUSED(verticesPerPatch); |
| 133 | qWarning() << "Tessellation not supported" ; |
| 134 | } |
| 135 | |
| 136 | void GraphicsHelperGL3_3::useProgram(GLuint programId) |
| 137 | { |
| 138 | m_funcs->glUseProgram(program: programId); |
| 139 | } |
| 140 | |
| 141 | std::vector<ShaderUniform> GraphicsHelperGL3_3::programUniformsAndLocations(GLuint programId) |
| 142 | { |
| 143 | std::vector<ShaderUniform> uniforms; |
| 144 | |
| 145 | GLint nbrActiveUniforms = 0; |
| 146 | m_funcs->glGetProgramiv(program: programId, GL_ACTIVE_UNIFORMS, params: &nbrActiveUniforms); |
| 147 | uniforms.reserve(n: nbrActiveUniforms); |
| 148 | char uniformName[256]; |
| 149 | for (GLint i = 0; i < nbrActiveUniforms; i++) { |
| 150 | ShaderUniform uniform; |
| 151 | GLsizei uniformNameLength = 0; |
| 152 | // Size is 1 for scalar and more for struct or arrays |
| 153 | // Type is the GL Type |
| 154 | m_funcs->glGetActiveUniform(program: programId, index: i, bufSize: sizeof(uniformName) - 1, length: &uniformNameLength, |
| 155 | size: &uniform.m_size, type: &uniform.m_type, name: uniformName); |
| 156 | uniformName[sizeof(uniformName) - 1] = '\0'; |
| 157 | uniform.m_location = m_funcs->glGetUniformLocation(program: programId, name: uniformName); |
| 158 | uniform.m_name = QString::fromUtf8(utf8: uniformName, size: uniformNameLength); |
| 159 | // Work around for uniform array names that aren't returned with [0] by some drivers |
| 160 | if (uniform.m_size > 1 && !uniform.m_name.endsWith(s: QLatin1String("[0]" ))) |
| 161 | uniform.m_name.append(s: QLatin1String("[0]" )); |
| 162 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_BLOCK_INDEX, params: &uniform.m_blockIndex); |
| 163 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_OFFSET, params: &uniform.m_offset); |
| 164 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_ARRAY_STRIDE, params: &uniform.m_arrayStride); |
| 165 | m_funcs->glGetActiveUniformsiv(program: programId, uniformCount: 1, uniformIndices: (GLuint*)&i, GL_UNIFORM_MATRIX_STRIDE, params: &uniform.m_matrixStride); |
| 166 | uniform.m_rawByteSize = uniformByteSize(description: uniform); |
| 167 | uniforms.push_back(x: uniform); |
| 168 | qCDebug(Rendering) << uniform.m_name << "size" << uniform.m_size |
| 169 | << " offset" << uniform.m_offset |
| 170 | << " rawSize" << uniform.m_rawByteSize; |
| 171 | } |
| 172 | |
| 173 | return uniforms; |
| 174 | } |
| 175 | |
| 176 | std::vector<ShaderAttribute> GraphicsHelperGL3_3::programAttributesAndLocations(GLuint programId) |
| 177 | { |
| 178 | std::vector<ShaderAttribute> attributes; |
| 179 | GLint nbrActiveAttributes = 0; |
| 180 | m_funcs->glGetProgramiv(program: programId, GL_ACTIVE_ATTRIBUTES, params: &nbrActiveAttributes); |
| 181 | attributes.reserve(n: nbrActiveAttributes); |
| 182 | char attributeName[256]; |
| 183 | for (GLint i = 0; i < nbrActiveAttributes; i++) { |
| 184 | ShaderAttribute attribute; |
| 185 | GLsizei attributeNameLength = 0; |
| 186 | // Size is 1 for scalar and more for struct or arrays |
| 187 | // Type is the GL Type |
| 188 | m_funcs->glGetActiveAttrib(program: programId, index: i, bufSize: sizeof(attributeName) - 1, length: &attributeNameLength, |
| 189 | size: &attribute.m_size, type: &attribute.m_type, name: attributeName); |
| 190 | attributeName[sizeof(attributeName) - 1] = '\0'; |
| 191 | attribute.m_location = m_funcs->glGetAttribLocation(program: programId, name: attributeName); |
| 192 | attribute.m_name = QString::fromUtf8(utf8: attributeName, size: attributeNameLength); |
| 193 | attributes.push_back(x: attribute); |
| 194 | } |
| 195 | return attributes; |
| 196 | } |
| 197 | |
| 198 | std::vector<ShaderUniformBlock> GraphicsHelperGL3_3::programUniformBlocks(GLuint programId) |
| 199 | { |
| 200 | std::vector<ShaderUniformBlock> blocks; |
| 201 | GLint nbrActiveUniformsBlocks = 0; |
| 202 | m_funcs->glGetProgramiv(program: programId, GL_ACTIVE_UNIFORM_BLOCKS, params: &nbrActiveUniformsBlocks); |
| 203 | blocks.reserve(n: nbrActiveUniformsBlocks); |
| 204 | for (GLint i = 0; i < nbrActiveUniformsBlocks; i++) { |
| 205 | QByteArray uniformBlockName(256, '\0'); |
| 206 | GLsizei length = 0; |
| 207 | ShaderUniformBlock uniformBlock; |
| 208 | m_funcs->glGetActiveUniformBlockName(program: programId, uniformBlockIndex: i, bufSize: 256, length: &length, uniformBlockName: uniformBlockName.data()); |
| 209 | uniformBlock.m_name = QString::fromUtf8(ba: uniformBlockName.left(n: length)); |
| 210 | uniformBlock.m_index = i; |
| 211 | m_funcs->glGetActiveUniformBlockiv(program: programId, uniformBlockIndex: i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, params: &uniformBlock.m_activeUniformsCount); |
| 212 | m_funcs->glGetActiveUniformBlockiv(program: programId, uniformBlockIndex: i, GL_UNIFORM_BLOCK_BINDING, params: &uniformBlock.m_binding); |
| 213 | m_funcs->glGetActiveUniformBlockiv(program: programId, uniformBlockIndex: i, GL_UNIFORM_BLOCK_DATA_SIZE, params: &uniformBlock.m_size); |
| 214 | blocks.push_back(x: uniformBlock); |
| 215 | } |
| 216 | return blocks; |
| 217 | } |
| 218 | |
| 219 | std::vector<ShaderStorageBlock> GraphicsHelperGL3_3::programShaderStorageBlocks(GLuint programId) |
| 220 | { |
| 221 | Q_UNUSED(programId); |
| 222 | qWarning() << "SSBO are not supported by OpenGL 3.3 (since OpenGL 4.3)" ; |
| 223 | return {}; |
| 224 | } |
| 225 | |
| 226 | void GraphicsHelperGL3_3::vertexAttribDivisor(GLuint index, GLuint divisor) |
| 227 | { |
| 228 | m_funcs->glVertexAttribDivisor(index, divisor); |
| 229 | } |
| 230 | |
| 231 | void GraphicsHelperGL3_3::vertexAttributePointer(GLenum shaderDataType, |
| 232 | GLuint index, |
| 233 | GLint size, |
| 234 | GLenum type, |
| 235 | GLboolean normalized, |
| 236 | GLsizei stride, |
| 237 | const GLvoid *pointer) |
| 238 | { |
| 239 | switch (shaderDataType) { |
| 240 | case GL_FLOAT: |
| 241 | case GL_FLOAT_VEC2: |
| 242 | case GL_FLOAT_VEC3: |
| 243 | case GL_FLOAT_VEC4: |
| 244 | case GL_FLOAT_MAT2: |
| 245 | case GL_FLOAT_MAT2x3: |
| 246 | case GL_FLOAT_MAT2x4: |
| 247 | case GL_FLOAT_MAT3: |
| 248 | case GL_FLOAT_MAT3x2: |
| 249 | case GL_FLOAT_MAT3x4: |
| 250 | case GL_FLOAT_MAT4x2: |
| 251 | case GL_FLOAT_MAT4x3: |
| 252 | case GL_FLOAT_MAT4: |
| 253 | m_funcs->glVertexAttribPointer(index, size, type, normalized, stride, pointer); |
| 254 | break; |
| 255 | |
| 256 | case GL_INT: |
| 257 | case GL_INT_VEC2: |
| 258 | case GL_INT_VEC3: |
| 259 | case GL_INT_VEC4: |
| 260 | case GL_UNSIGNED_INT: |
| 261 | case GL_UNSIGNED_INT_VEC2: |
| 262 | case GL_UNSIGNED_INT_VEC3: |
| 263 | case GL_UNSIGNED_INT_VEC4: |
| 264 | m_funcs->glVertexAttribIPointer(index, size, type, stride, pointer); |
| 265 | break; |
| 266 | |
| 267 | default: |
| 268 | qCWarning(Rendering) << "vertexAttribPointer: Unhandled type" ; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | void GraphicsHelperGL3_3::readBuffer(GLenum mode) |
| 273 | { |
| 274 | m_funcs->glReadBuffer(mode); |
| 275 | } |
| 276 | |
| 277 | void GraphicsHelperGL3_3::drawBuffer(GLenum mode) |
| 278 | { |
| 279 | m_funcs->glDrawBuffer(mode); |
| 280 | } |
| 281 | |
| 282 | void *GraphicsHelperGL3_3::fenceSync() |
| 283 | { |
| 284 | return m_funcs->glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, flags: 0); |
| 285 | } |
| 286 | |
| 287 | void GraphicsHelperGL3_3::clientWaitSync(void *sync, GLuint64 nanoSecTimeout) |
| 288 | { |
| 289 | m_funcs->glClientWaitSync(sync: static_cast<GLsync>(sync), GL_SYNC_FLUSH_COMMANDS_BIT, timeout: nanoSecTimeout); |
| 290 | } |
| 291 | |
| 292 | void GraphicsHelperGL3_3::waitSync(void *sync) |
| 293 | { |
| 294 | m_funcs->glWaitSync(sync: static_cast<GLsync>(sync), flags: 0, GL_TIMEOUT_IGNORED); |
| 295 | } |
| 296 | |
| 297 | bool GraphicsHelperGL3_3::wasSyncSignaled(void *sync) |
| 298 | { |
| 299 | GLint v; |
| 300 | m_funcs->glGetSynciv(sync: static_cast<GLsync>(sync), |
| 301 | GL_SYNC_STATUS, |
| 302 | bufSize: sizeof(v), |
| 303 | length: nullptr, |
| 304 | values: &v); |
| 305 | return v == GL_SIGNALED; |
| 306 | } |
| 307 | |
| 308 | void GraphicsHelperGL3_3::deleteSync(void *sync) |
| 309 | { |
| 310 | m_funcs->glDeleteSync(sync: static_cast<GLsync>(sync)); |
| 311 | } |
| 312 | |
| 313 | void GraphicsHelperGL3_3::rasterMode(GLenum faceMode, GLenum rasterMode) |
| 314 | { |
| 315 | m_funcs->glPolygonMode(face: faceMode, mode: rasterMode); |
| 316 | } |
| 317 | |
| 318 | void GraphicsHelperGL3_3::blendEquation(GLenum mode) |
| 319 | { |
| 320 | m_funcs->glBlendEquation(mode); |
| 321 | } |
| 322 | |
| 323 | void GraphicsHelperGL3_3::blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) |
| 324 | { |
| 325 | Q_UNUSED(buf); |
| 326 | Q_UNUSED(sfactor); |
| 327 | Q_UNUSED(dfactor); |
| 328 | |
| 329 | qWarning() << "glBlendFunci() not supported by OpenGL 3.3 (since OpenGL 4.0)" ; |
| 330 | } |
| 331 | |
| 332 | void GraphicsHelperGL3_3::blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) |
| 333 | { |
| 334 | Q_UNUSED(buf); |
| 335 | Q_UNUSED(sRGB); |
| 336 | Q_UNUSED(dRGB); |
| 337 | Q_UNUSED(sAlpha); |
| 338 | Q_UNUSED(dAlpha); |
| 339 | |
| 340 | qWarning() << "glBlendFuncSeparatei() not supported by OpenGL 3.3 (since OpenGL 4.0)" ; |
| 341 | } |
| 342 | |
| 343 | void GraphicsHelperGL3_3::alphaTest(GLenum, GLenum) |
| 344 | { |
| 345 | qCWarning(Rendering) << "AlphaTest not available with OpenGL 3.2 core" ; |
| 346 | } |
| 347 | |
| 348 | void GraphicsHelperGL3_3::depthTest(GLenum mode) |
| 349 | { |
| 350 | m_funcs->glEnable(GL_DEPTH_TEST); |
| 351 | m_funcs->glDepthFunc(func: mode); |
| 352 | } |
| 353 | |
| 354 | void GraphicsHelperGL3_3::depthMask(GLenum mode) |
| 355 | { |
| 356 | m_funcs->glDepthMask(flag: mode); |
| 357 | } |
| 358 | |
| 359 | void GraphicsHelperGL3_3::depthRange(GLdouble nearValue, GLdouble farValue) |
| 360 | { |
| 361 | m_funcs->glDepthRange(nearVal: nearValue, farVal: farValue); |
| 362 | } |
| 363 | |
| 364 | void GraphicsHelperGL3_3::frontFace(GLenum mode) |
| 365 | { |
| 366 | m_funcs->glFrontFace(mode); |
| 367 | |
| 368 | } |
| 369 | |
| 370 | void GraphicsHelperGL3_3::setMSAAEnabled(bool enabled) |
| 371 | { |
| 372 | enabled ? m_funcs->glEnable(GL_MULTISAMPLE) |
| 373 | : m_funcs->glDisable(GL_MULTISAMPLE); |
| 374 | } |
| 375 | |
| 376 | void GraphicsHelperGL3_3::setAlphaCoverageEnabled(bool enabled) |
| 377 | { |
| 378 | enabled ? m_funcs->glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 379 | : m_funcs->glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); |
| 380 | } |
| 381 | |
| 382 | GLuint GraphicsHelperGL3_3::createFrameBufferObject() |
| 383 | { |
| 384 | GLuint id; |
| 385 | m_funcs->glGenFramebuffers(n: 1, framebuffers: &id); |
| 386 | return id; |
| 387 | } |
| 388 | |
| 389 | void GraphicsHelperGL3_3::releaseFrameBufferObject(GLuint frameBufferId) |
| 390 | { |
| 391 | m_funcs->glDeleteFramebuffers(n: 1, framebuffers: &frameBufferId); |
| 392 | } |
| 393 | |
| 394 | void GraphicsHelperGL3_3::bindFrameBufferObject(GLuint frameBufferId, FBOBindMode mode) |
| 395 | { |
| 396 | switch (mode) { |
| 397 | case FBODraw: |
| 398 | m_funcs->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer: frameBufferId); |
| 399 | return; |
| 400 | case FBORead: |
| 401 | m_funcs->glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer: frameBufferId); |
| 402 | return; |
| 403 | case FBOReadAndDraw: |
| 404 | default: |
| 405 | m_funcs->glBindFramebuffer(GL_FRAMEBUFFER, framebuffer: frameBufferId); |
| 406 | return; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | GLuint GraphicsHelperGL3_3::boundFrameBufferObject() |
| 411 | { |
| 412 | GLint id = 0; |
| 413 | m_funcs->glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, params: &id); |
| 414 | return id; |
| 415 | } |
| 416 | |
| 417 | bool GraphicsHelperGL3_3::checkFrameBufferComplete() |
| 418 | { |
| 419 | return (m_funcs->glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); |
| 420 | } |
| 421 | |
| 422 | bool GraphicsHelperGL3_3::frameBufferNeedsRenderBuffer(const Attachment &attachment) |
| 423 | { |
| 424 | Q_UNUSED(attachment); |
| 425 | return false; |
| 426 | } |
| 427 | |
| 428 | void GraphicsHelperGL3_3::bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment) |
| 429 | { |
| 430 | GLenum attr = GL_DEPTH_STENCIL_ATTACHMENT; |
| 431 | |
| 432 | if (attachment.m_point <= QRenderTargetOutput::Color15) |
| 433 | attr = GL_COLOR_ATTACHMENT0 + attachment.m_point; |
| 434 | else if (attachment.m_point == QRenderTargetOutput::Depth) |
| 435 | attr = GL_DEPTH_ATTACHMENT; |
| 436 | else if (attachment.m_point == QRenderTargetOutput::Stencil) |
| 437 | attr = GL_STENCIL_ATTACHMENT; |
| 438 | |
| 439 | texture->bind(); |
| 440 | QOpenGLTexture::Target target = texture->target(); |
| 441 | if (target == QOpenGLTexture::Target1DArray || target == QOpenGLTexture::Target2DArray || |
| 442 | target == QOpenGLTexture::Target2DMultisampleArray || target == QOpenGLTexture::Target3D) |
| 443 | m_funcs->glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel, layer: attachment.m_layer); |
| 444 | else if (target == QOpenGLTexture::TargetCubeMapArray && attachment.m_face != QAbstractTexture::AllFaces) |
| 445 | m_funcs->glFramebufferTextureLayer( GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel, layer: attachment.m_layer * 6 + (attachment.m_face - QAbstractTexture::CubeMapPositiveX)); |
| 446 | else if (target == QOpenGLTexture::TargetCubeMap && attachment.m_face != QAbstractTexture::AllFaces) |
| 447 | m_funcs->glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment: attr, textarget: attachment.m_face, texture: texture->textureId(), level: attachment.m_mipLevel); |
| 448 | else |
| 449 | m_funcs->glFramebufferTexture(GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel); |
| 450 | texture->release(); |
| 451 | } |
| 452 | |
| 453 | void GraphicsHelperGL3_3::bindFrameBufferAttachment(RenderBuffer *renderBuffer, const Attachment &attachment) |
| 454 | { |
| 455 | Q_UNUSED(renderBuffer); |
| 456 | Q_UNUSED(attachment); |
| 457 | Q_UNREACHABLE(); |
| 458 | } |
| 459 | |
| 460 | bool GraphicsHelperGL3_3::supportsFeature(GraphicsHelperInterface::Feature feature) const |
| 461 | { |
| 462 | switch (feature) { |
| 463 | case MRT: |
| 464 | case UniformBufferObject: |
| 465 | case PrimitiveRestart: |
| 466 | case RenderBufferDimensionRetrieval: |
| 467 | case TextureDimensionRetrieval: |
| 468 | case BindableFragmentOutputs: |
| 469 | case BlitFramebuffer: |
| 470 | case Fences: |
| 471 | return true; |
| 472 | default: |
| 473 | return false; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | void GraphicsHelperGL3_3::drawBuffers(GLsizei n, const GLenum *bufs) |
| 478 | { |
| 479 | m_funcs->glDrawBuffers(n, bufs); |
| 480 | } |
| 481 | |
| 482 | void GraphicsHelperGL3_3::bindFragDataLocation(GLuint shader, const QHash<QString, int> &outputs) |
| 483 | { |
| 484 | for (auto it = outputs.begin(), end = outputs.end(); it != end; ++it) |
| 485 | m_funcs->glBindFragDataLocation(program: shader, color: it.value(), name: it.key().toStdString().c_str()); |
| 486 | } |
| 487 | |
| 488 | void GraphicsHelperGL3_3::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 489 | { |
| 490 | m_funcs->glUniformBlockBinding(program: programId, uniformBlockIndex, uniformBlockBinding); |
| 491 | } |
| 492 | |
| 493 | void GraphicsHelperGL3_3::bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) |
| 494 | { |
| 495 | Q_UNUSED(programId); |
| 496 | Q_UNUSED(shaderStorageBlockIndex); |
| 497 | Q_UNUSED(shaderStorageBlockBinding); |
| 498 | qWarning() << "SSBO are not supported by OpenGL 3.3 (since OpenGL 4.3)" ; |
| 499 | } |
| 500 | |
| 501 | void GraphicsHelperGL3_3::bindImageTexture(GLuint imageUnit, GLuint texture, |
| 502 | GLint mipLevel, GLboolean layered, |
| 503 | GLint layer, GLenum access, GLenum format) |
| 504 | { |
| 505 | Q_UNUSED(imageUnit); |
| 506 | Q_UNUSED(texture); |
| 507 | Q_UNUSED(mipLevel); |
| 508 | Q_UNUSED(layered); |
| 509 | Q_UNUSED(layer); |
| 510 | Q_UNUSED(access); |
| 511 | Q_UNUSED(format); |
| 512 | qWarning() << "Shader Images are not supported by OpenGL 3.3 (since OpenGL 4.2)" ; |
| 513 | } |
| 514 | |
| 515 | void GraphicsHelperGL3_3::bindBufferBase(GLenum target, GLuint index, GLuint buffer) |
| 516 | { |
| 517 | m_funcs->glBindBufferBase(target, index, buffer); |
| 518 | } |
| 519 | |
| 520 | void GraphicsHelperGL3_3::buildUniformBuffer(const QVariant &v, const ShaderUniform &description, QByteArray &buffer) |
| 521 | { |
| 522 | char *bufferData = buffer.data(); |
| 523 | |
| 524 | switch (description.m_type) { |
| 525 | |
| 526 | case GL_FLOAT: { |
| 527 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 1); |
| 528 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
| 529 | break; |
| 530 | } |
| 531 | |
| 532 | case GL_FLOAT_VEC2: { |
| 533 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 2); |
| 534 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | case GL_FLOAT_VEC3: { |
| 539 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 3); |
| 540 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | case GL_FLOAT_VEC4: { |
| 545 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 4); |
| 546 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
| 547 | break; |
| 548 | } |
| 549 | |
| 550 | case GL_FLOAT_MAT2: { |
| 551 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 4); |
| 552 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 2, rows: 2); |
| 553 | break; |
| 554 | } |
| 555 | |
| 556 | case GL_FLOAT_MAT2x3: { |
| 557 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 6); |
| 558 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 2, rows: 3); |
| 559 | break; |
| 560 | } |
| 561 | |
| 562 | case GL_FLOAT_MAT2x4: { |
| 563 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 8); |
| 564 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 2, rows: 4); |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | case GL_FLOAT_MAT3: { |
| 569 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 9); |
| 570 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 3, rows: 3); |
| 571 | break; |
| 572 | } |
| 573 | |
| 574 | case GL_FLOAT_MAT3x2: { |
| 575 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 6); |
| 576 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 3, rows: 2); |
| 577 | break; |
| 578 | } |
| 579 | |
| 580 | case GL_FLOAT_MAT3x4: { |
| 581 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 12); |
| 582 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 3, rows: 4); |
| 583 | break; |
| 584 | } |
| 585 | |
| 586 | case GL_FLOAT_MAT4: { |
| 587 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 16); |
| 588 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 4, rows: 4); |
| 589 | break; |
| 590 | } |
| 591 | |
| 592 | case GL_FLOAT_MAT4x2: { |
| 593 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 8); |
| 594 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 4, rows: 2); |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | case GL_FLOAT_MAT4x3: { |
| 599 | const GLfloat *data = QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, count: description.m_size, tupleSize: 12); |
| 600 | QGraphicsUtils::fillDataMatrixArray(buffer: bufferData, data, description, cols: 4, rows: 3); |
| 601 | break; |
| 602 | } |
| 603 | |
| 604 | case GL_INT: { |
| 605 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 1); |
| 606 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | case GL_INT_VEC2: { |
| 611 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 2); |
| 612 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
| 613 | break; |
| 614 | } |
| 615 | |
| 616 | case GL_INT_VEC3: { |
| 617 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 3); |
| 618 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
| 619 | break; |
| 620 | } |
| 621 | |
| 622 | case GL_INT_VEC4: { |
| 623 | const GLint *data = QGraphicsUtils::valueArrayFromVariant<GLint>(v, count: description.m_size, tupleSize: 4); |
| 624 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | case GL_UNSIGNED_INT: { |
| 629 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 1); |
| 630 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
| 631 | break; |
| 632 | } |
| 633 | |
| 634 | case GL_UNSIGNED_INT_VEC2: { |
| 635 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 2); |
| 636 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
| 637 | break; |
| 638 | } |
| 639 | |
| 640 | case GL_UNSIGNED_INT_VEC3: { |
| 641 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 3); |
| 642 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | case GL_UNSIGNED_INT_VEC4: { |
| 647 | const GLuint *data = QGraphicsUtils::valueArrayFromVariant<GLuint>(v, count: description.m_size, tupleSize: 4); |
| 648 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
| 649 | break; |
| 650 | } |
| 651 | |
| 652 | case GL_BOOL: { |
| 653 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 1); |
| 654 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 1); |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | case GL_BOOL_VEC2: { |
| 659 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 2); |
| 660 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 2); |
| 661 | break; |
| 662 | } |
| 663 | |
| 664 | case GL_BOOL_VEC3: { |
| 665 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 3); |
| 666 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 3); |
| 667 | break; |
| 668 | } |
| 669 | |
| 670 | case GL_BOOL_VEC4: { |
| 671 | const GLboolean *data = QGraphicsUtils::valueArrayFromVariant<GLboolean>(v, count: description.m_size, tupleSize: 4); |
| 672 | QGraphicsUtils::fillDataArray(buffer: bufferData, data, description, tupleSize: 4); |
| 673 | break; |
| 674 | } |
| 675 | |
| 676 | case GL_SAMPLER_1D: |
| 677 | case GL_SAMPLER_2D: |
| 678 | case GL_SAMPLER_3D: |
| 679 | case GL_SAMPLER_CUBE: |
| 680 | case GL_SAMPLER_BUFFER: |
| 681 | case GL_SAMPLER_2D_RECT: |
| 682 | case GL_INT_SAMPLER_1D: |
| 683 | case GL_INT_SAMPLER_2D: |
| 684 | case GL_INT_SAMPLER_3D: |
| 685 | case GL_INT_SAMPLER_CUBE: |
| 686 | case GL_INT_SAMPLER_BUFFER: |
| 687 | case GL_INT_SAMPLER_2D_RECT: |
| 688 | case GL_UNSIGNED_INT_SAMPLER_1D: |
| 689 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 690 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 691 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 692 | case GL_UNSIGNED_INT_SAMPLER_BUFFER: |
| 693 | case GL_UNSIGNED_INT_SAMPLER_2D_RECT: |
| 694 | case GL_SAMPLER_1D_SHADOW: |
| 695 | case GL_SAMPLER_2D_SHADOW: |
| 696 | case GL_SAMPLER_CUBE_SHADOW: |
| 697 | case GL_SAMPLER_1D_ARRAY: |
| 698 | case GL_SAMPLER_2D_ARRAY: |
| 699 | case GL_INT_SAMPLER_1D_ARRAY: |
| 700 | case GL_INT_SAMPLER_2D_ARRAY: |
| 701 | case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: |
| 702 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
| 703 | case GL_SAMPLER_1D_ARRAY_SHADOW: |
| 704 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 705 | case GL_SAMPLER_2D_RECT_SHADOW: |
| 706 | case GL_SAMPLER_2D_MULTISAMPLE: |
| 707 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
| 708 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
| 709 | case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 710 | case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 711 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: { |
| 712 | Q_ASSERT(description.m_size == 1); |
| 713 | int value = v.toInt(); |
| 714 | QGraphicsUtils::fillDataArray<GLint>(buffer: bufferData, data: &value, description, tupleSize: 1); |
| 715 | break; |
| 716 | } |
| 717 | |
| 718 | default: |
| 719 | qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | uint GraphicsHelperGL3_3::uniformByteSize(const ShaderUniform &description) |
| 725 | { |
| 726 | uint rawByteSize = 0; |
| 727 | int arrayStride = qMax(a: description.m_arrayStride, b: 0); |
| 728 | int matrixStride = qMax(a: description.m_matrixStride, b: 0); |
| 729 | |
| 730 | switch (description.m_type) { |
| 731 | |
| 732 | case GL_FLOAT_VEC2: |
| 733 | case GL_INT_VEC2: |
| 734 | case GL_UNSIGNED_INT_VEC2: |
| 735 | rawByteSize = 8; |
| 736 | break; |
| 737 | |
| 738 | case GL_FLOAT_VEC3: |
| 739 | case GL_INT_VEC3: |
| 740 | case GL_UNSIGNED_INT_VEC3: |
| 741 | rawByteSize = 12; |
| 742 | break; |
| 743 | |
| 744 | case GL_FLOAT_VEC4: |
| 745 | case GL_INT_VEC4: |
| 746 | case GL_UNSIGNED_INT_VEC4: |
| 747 | rawByteSize = 16; |
| 748 | break; |
| 749 | |
| 750 | case GL_FLOAT_MAT2: |
| 751 | rawByteSize = matrixStride ? 2 * matrixStride : 16; |
| 752 | break; |
| 753 | |
| 754 | case GL_FLOAT_MAT2x4: |
| 755 | rawByteSize = matrixStride ? 2 * matrixStride : 32; |
| 756 | break; |
| 757 | |
| 758 | case GL_FLOAT_MAT4x2: |
| 759 | rawByteSize = matrixStride ? 4 * matrixStride : 32; |
| 760 | break; |
| 761 | |
| 762 | case GL_FLOAT_MAT3: |
| 763 | rawByteSize = matrixStride ? 3 * matrixStride : 36; |
| 764 | break; |
| 765 | |
| 766 | case GL_FLOAT_MAT2x3: |
| 767 | rawByteSize = matrixStride ? 2 * matrixStride : 24; |
| 768 | break; |
| 769 | |
| 770 | case GL_FLOAT_MAT3x2: |
| 771 | rawByteSize = matrixStride ? 3 * matrixStride : 24; |
| 772 | break; |
| 773 | |
| 774 | case GL_FLOAT_MAT4: |
| 775 | rawByteSize = matrixStride ? 4 * matrixStride : 64; |
| 776 | break; |
| 777 | |
| 778 | case GL_FLOAT_MAT4x3: |
| 779 | rawByteSize = matrixStride ? 4 * matrixStride : 48; |
| 780 | break; |
| 781 | |
| 782 | case GL_FLOAT_MAT3x4: |
| 783 | rawByteSize = matrixStride ? 3 * matrixStride : 48; |
| 784 | break; |
| 785 | |
| 786 | case GL_BOOL: |
| 787 | rawByteSize = 1; |
| 788 | break; |
| 789 | |
| 790 | case GL_BOOL_VEC2: |
| 791 | rawByteSize = 2; |
| 792 | break; |
| 793 | |
| 794 | case GL_BOOL_VEC3: |
| 795 | rawByteSize = 3; |
| 796 | break; |
| 797 | |
| 798 | case GL_BOOL_VEC4: |
| 799 | rawByteSize = 4; |
| 800 | break; |
| 801 | |
| 802 | case GL_INT: |
| 803 | case GL_FLOAT: |
| 804 | case GL_UNSIGNED_INT: |
| 805 | case GL_SAMPLER_1D: |
| 806 | case GL_SAMPLER_2D: |
| 807 | case GL_SAMPLER_3D: |
| 808 | case GL_SAMPLER_CUBE: |
| 809 | case GL_SAMPLER_BUFFER: |
| 810 | case GL_SAMPLER_2D_RECT: |
| 811 | case GL_INT_SAMPLER_1D: |
| 812 | case GL_INT_SAMPLER_2D: |
| 813 | case GL_INT_SAMPLER_3D: |
| 814 | case GL_INT_SAMPLER_CUBE: |
| 815 | case GL_INT_SAMPLER_BUFFER: |
| 816 | case GL_INT_SAMPLER_2D_RECT: |
| 817 | case GL_UNSIGNED_INT_SAMPLER_1D: |
| 818 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 819 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 820 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 821 | case GL_UNSIGNED_INT_SAMPLER_BUFFER: |
| 822 | case GL_UNSIGNED_INT_SAMPLER_2D_RECT: |
| 823 | case GL_SAMPLER_1D_SHADOW: |
| 824 | case GL_SAMPLER_2D_SHADOW: |
| 825 | case GL_SAMPLER_CUBE_SHADOW: |
| 826 | case GL_SAMPLER_1D_ARRAY: |
| 827 | case GL_SAMPLER_2D_ARRAY: |
| 828 | case GL_INT_SAMPLER_1D_ARRAY: |
| 829 | case GL_INT_SAMPLER_2D_ARRAY: |
| 830 | case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: |
| 831 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
| 832 | case GL_SAMPLER_1D_ARRAY_SHADOW: |
| 833 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 834 | case GL_SAMPLER_2D_RECT_SHADOW: |
| 835 | case GL_SAMPLER_2D_MULTISAMPLE: |
| 836 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
| 837 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
| 838 | case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 839 | case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 840 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 841 | rawByteSize = 4; |
| 842 | break; |
| 843 | } |
| 844 | |
| 845 | return arrayStride ? rawByteSize * arrayStride : rawByteSize; |
| 846 | } |
| 847 | |
| 848 | void GraphicsHelperGL3_3::enableClipPlane(int clipPlane) |
| 849 | { |
| 850 | m_funcs->glEnable(GL_CLIP_DISTANCE0 + clipPlane); |
| 851 | } |
| 852 | |
| 853 | void GraphicsHelperGL3_3::disableClipPlane(int clipPlane) |
| 854 | { |
| 855 | m_funcs->glDisable(GL_CLIP_DISTANCE0 + clipPlane); |
| 856 | } |
| 857 | |
| 858 | void GraphicsHelperGL3_3::setClipPlane(int clipPlane, const QVector3D &normal, float distance) |
| 859 | { |
| 860 | // deprecated |
| 861 | Q_UNUSED(clipPlane); |
| 862 | Q_UNUSED(normal); |
| 863 | Q_UNUSED(distance); |
| 864 | } |
| 865 | |
| 866 | GLint GraphicsHelperGL3_3::maxClipPlaneCount() |
| 867 | { |
| 868 | GLint max = 0; |
| 869 | m_funcs->glGetIntegerv(GL_MAX_CLIP_DISTANCES, params: &max); |
| 870 | return max; |
| 871 | } |
| 872 | |
| 873 | void GraphicsHelperGL3_3::memoryBarrier(QMemoryBarrier::Operations barriers) |
| 874 | { |
| 875 | Q_UNUSED(barriers); |
| 876 | qWarning() << "memory barrier is not supported by OpenGL 3.3 (since 4.3)" ; |
| 877 | } |
| 878 | |
| 879 | void GraphicsHelperGL3_3::enablePrimitiveRestart(int primitiveRestartIndex) |
| 880 | { |
| 881 | m_funcs->glPrimitiveRestartIndex(index: primitiveRestartIndex); |
| 882 | m_funcs->glEnable(GL_PRIMITIVE_RESTART); |
| 883 | } |
| 884 | |
| 885 | void GraphicsHelperGL3_3::enableVertexAttributeArray(int location) |
| 886 | { |
| 887 | m_funcs->glEnableVertexAttribArray(index: location); |
| 888 | } |
| 889 | |
| 890 | void GraphicsHelperGL3_3::disablePrimitiveRestart() |
| 891 | { |
| 892 | m_funcs->glDisable(GL_PRIMITIVE_RESTART); |
| 893 | } |
| 894 | |
| 895 | void GraphicsHelperGL3_3::clearBufferf(GLint drawbuffer, const QVector4D &values) |
| 896 | { |
| 897 | GLfloat vec[4] = {values[0], values[1], values[2], values[3]}; |
| 898 | m_funcs->glClearBufferfv(GL_COLOR, drawbuffer, value: vec); |
| 899 | } |
| 900 | |
| 901 | void GraphicsHelperGL3_3::pointSize(bool programmable, GLfloat value) |
| 902 | { |
| 903 | if (programmable) { |
| 904 | m_funcs->glEnable(GL_PROGRAM_POINT_SIZE); |
| 905 | } else { |
| 906 | m_funcs->glDisable(GL_PROGRAM_POINT_SIZE); |
| 907 | m_funcs->glPointSize(size: value); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | void GraphicsHelperGL3_3::enablei(GLenum cap, GLuint index) |
| 912 | { |
| 913 | m_funcs->glEnablei(target: cap, index); |
| 914 | } |
| 915 | |
| 916 | void GraphicsHelperGL3_3::disablei(GLenum cap, GLuint index) |
| 917 | { |
| 918 | m_funcs->glDisablei(target: cap, index); |
| 919 | } |
| 920 | |
| 921 | void GraphicsHelperGL3_3::setSeamlessCubemap(bool enable) |
| 922 | { |
| 923 | if (enable) |
| 924 | m_funcs->glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); |
| 925 | else |
| 926 | m_funcs->glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); |
| 927 | } |
| 928 | |
| 929 | QSize GraphicsHelperGL3_3::getRenderBufferDimensions(GLuint renderBufferId) |
| 930 | { |
| 931 | GLint width = 0; |
| 932 | GLint height = 0; |
| 933 | |
| 934 | m_funcs->glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer: renderBufferId); |
| 935 | m_funcs->glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, params: &width); |
| 936 | m_funcs->glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, params: &height); |
| 937 | m_funcs->glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer: 0); |
| 938 | |
| 939 | return QSize(width, height); |
| 940 | } |
| 941 | |
| 942 | QSize GraphicsHelperGL3_3::getTextureDimensions(GLuint textureId, GLenum target, uint level) |
| 943 | { |
| 944 | GLint width = 0; |
| 945 | GLint height = 0; |
| 946 | |
| 947 | m_funcs->glBindTexture(target, texture: textureId); |
| 948 | m_funcs->glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, params: &width); |
| 949 | m_funcs->glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, params: &height); |
| 950 | m_funcs->glBindTexture(target, texture: 0); |
| 951 | |
| 952 | return QSize(width, height); |
| 953 | } |
| 954 | |
| 955 | void GraphicsHelperGL3_3::dispatchCompute(GLuint wx, GLuint wy, GLuint wz) |
| 956 | { |
| 957 | Q_UNUSED(wx); |
| 958 | Q_UNUSED(wy); |
| 959 | Q_UNUSED(wz); |
| 960 | qWarning() << "Compute Shaders are not supported by OpenGL 3.3 (since OpenGL 4.3)" ; |
| 961 | } |
| 962 | |
| 963 | char *GraphicsHelperGL3_3::mapBuffer(GLenum target, GLsizeiptr size) |
| 964 | { |
| 965 | return static_cast<char*>(m_funcs->glMapBufferRange(target, offset: 0, length: size, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)); |
| 966 | } |
| 967 | |
| 968 | GLboolean GraphicsHelperGL3_3::unmapBuffer(GLenum target) |
| 969 | { |
| 970 | return m_funcs->glUnmapBuffer(target); |
| 971 | } |
| 972 | |
| 973 | void GraphicsHelperGL3_3::glUniform1fv(GLint location, GLsizei count, const GLfloat *values) |
| 974 | { |
| 975 | m_funcs->glUniform1fv(location, count, value: values); |
| 976 | } |
| 977 | |
| 978 | void GraphicsHelperGL3_3::glUniform2fv(GLint location, GLsizei count, const GLfloat *values) |
| 979 | { |
| 980 | m_funcs->glUniform2fv(location, count, value: values); |
| 981 | } |
| 982 | |
| 983 | void GraphicsHelperGL3_3::glUniform3fv(GLint location, GLsizei count, const GLfloat *values) |
| 984 | { |
| 985 | m_funcs->glUniform3fv(location, count, value: values); |
| 986 | } |
| 987 | |
| 988 | void GraphicsHelperGL3_3::glUniform4fv(GLint location, GLsizei count, const GLfloat *values) |
| 989 | { |
| 990 | m_funcs->glUniform4fv(location, count, value: values); |
| 991 | } |
| 992 | |
| 993 | void GraphicsHelperGL3_3::glUniform1iv(GLint location, GLsizei count, const GLint *values) |
| 994 | { |
| 995 | m_funcs->glUniform1iv(location, count, value: values); |
| 996 | } |
| 997 | |
| 998 | void GraphicsHelperGL3_3::glUniform2iv(GLint location, GLsizei count, const GLint *values) |
| 999 | { |
| 1000 | m_funcs->glUniform2iv(location, count, value: values); |
| 1001 | } |
| 1002 | |
| 1003 | void GraphicsHelperGL3_3::glUniform3iv(GLint location, GLsizei count, const GLint *values) |
| 1004 | { |
| 1005 | m_funcs->glUniform3iv(location, count, value: values); |
| 1006 | } |
| 1007 | |
| 1008 | void GraphicsHelperGL3_3::glUniform4iv(GLint location, GLsizei count, const GLint *values) |
| 1009 | { |
| 1010 | m_funcs->glUniform4iv(location, count, value: values); |
| 1011 | } |
| 1012 | |
| 1013 | void GraphicsHelperGL3_3::glUniform1uiv(GLint location, GLsizei count, const GLuint *values) |
| 1014 | { |
| 1015 | m_funcs->glUniform1uiv(location, count, value: values); |
| 1016 | } |
| 1017 | |
| 1018 | void GraphicsHelperGL3_3::glUniform2uiv(GLint location, GLsizei count, const GLuint *values) |
| 1019 | { |
| 1020 | m_funcs->glUniform2uiv(location, count, value: values); |
| 1021 | } |
| 1022 | |
| 1023 | void GraphicsHelperGL3_3::glUniform3uiv(GLint location, GLsizei count, const GLuint *values) |
| 1024 | { |
| 1025 | m_funcs->glUniform3uiv(location, count, value: values); |
| 1026 | } |
| 1027 | |
| 1028 | void GraphicsHelperGL3_3::glUniform4uiv(GLint location, GLsizei count, const GLuint *values) |
| 1029 | { |
| 1030 | m_funcs->glUniform4uiv(location, count, value: values); |
| 1031 | } |
| 1032 | |
| 1033 | void GraphicsHelperGL3_3::glUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *values) |
| 1034 | { |
| 1035 | m_funcs->glUniformMatrix2fv(location, count, transpose: false, value: values); |
| 1036 | } |
| 1037 | |
| 1038 | void GraphicsHelperGL3_3::glUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *values) |
| 1039 | { |
| 1040 | m_funcs->glUniformMatrix3fv(location, count, transpose: false, value: values); |
| 1041 | } |
| 1042 | |
| 1043 | void GraphicsHelperGL3_3::glUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *values) |
| 1044 | { |
| 1045 | m_funcs->glUniformMatrix4fv(location, count, transpose: false, value: values); |
| 1046 | } |
| 1047 | |
| 1048 | void GraphicsHelperGL3_3::glUniformMatrix2x3fv(GLint location, GLsizei count, const GLfloat *values) |
| 1049 | { |
| 1050 | m_funcs->glUniformMatrix2x3fv(location, count, transpose: false, value: values); |
| 1051 | } |
| 1052 | |
| 1053 | void GraphicsHelperGL3_3::glUniformMatrix3x2fv(GLint location, GLsizei count, const GLfloat *values) |
| 1054 | { |
| 1055 | m_funcs->glUniformMatrix3x2fv(location, count, transpose: false, value: values); |
| 1056 | } |
| 1057 | |
| 1058 | void GraphicsHelperGL3_3::glUniformMatrix2x4fv(GLint location, GLsizei count, const GLfloat *values) |
| 1059 | { |
| 1060 | m_funcs->glUniformMatrix2x4fv(location, count, transpose: false, value: values); |
| 1061 | } |
| 1062 | |
| 1063 | void GraphicsHelperGL3_3::glUniformMatrix4x2fv(GLint location, GLsizei count, const GLfloat *values) |
| 1064 | { |
| 1065 | m_funcs->glUniformMatrix4x2fv(location, count, transpose: false, value: values); |
| 1066 | } |
| 1067 | |
| 1068 | void GraphicsHelperGL3_3::glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *values) |
| 1069 | { |
| 1070 | m_funcs->glUniformMatrix3x4fv(location, count, transpose: false, value: values); |
| 1071 | } |
| 1072 | |
| 1073 | void GraphicsHelperGL3_3::glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *values) |
| 1074 | { |
| 1075 | m_funcs->glUniformMatrix4x3fv(location, count, transpose: false, value: values); |
| 1076 | } |
| 1077 | |
| 1078 | UniformType GraphicsHelperGL3_3::uniformTypeFromGLType(GLenum type) |
| 1079 | { |
| 1080 | switch (type) { |
| 1081 | case GL_FLOAT: |
| 1082 | return UniformType::Float; |
| 1083 | case GL_FLOAT_VEC2: |
| 1084 | return UniformType::Vec2; |
| 1085 | case GL_FLOAT_VEC3: |
| 1086 | return UniformType::Vec3; |
| 1087 | case GL_FLOAT_VEC4: |
| 1088 | return UniformType::Vec4; |
| 1089 | case GL_FLOAT_MAT2: |
| 1090 | return UniformType::Mat2; |
| 1091 | case GL_FLOAT_MAT3: |
| 1092 | return UniformType::Mat3; |
| 1093 | case GL_FLOAT_MAT4: |
| 1094 | return UniformType::Mat4; |
| 1095 | case GL_FLOAT_MAT2x3: |
| 1096 | return UniformType::Mat2x3; |
| 1097 | case GL_FLOAT_MAT3x2: |
| 1098 | return UniformType::Mat3x2; |
| 1099 | case GL_FLOAT_MAT2x4: |
| 1100 | return UniformType::Mat2x4; |
| 1101 | case GL_FLOAT_MAT4x2: |
| 1102 | return UniformType::Mat4x2; |
| 1103 | case GL_FLOAT_MAT3x4: |
| 1104 | return UniformType::Mat3x4; |
| 1105 | case GL_FLOAT_MAT4x3: |
| 1106 | return UniformType::Mat4x3; |
| 1107 | case GL_INT: |
| 1108 | return UniformType::Int; |
| 1109 | case GL_INT_VEC2: |
| 1110 | return UniformType::IVec2; |
| 1111 | case GL_INT_VEC3: |
| 1112 | return UniformType::IVec3; |
| 1113 | case GL_INT_VEC4: |
| 1114 | return UniformType::IVec4; |
| 1115 | case GL_UNSIGNED_INT: |
| 1116 | return UniformType::UInt; |
| 1117 | case GL_UNSIGNED_INT_VEC2: |
| 1118 | return UniformType::UIVec2; |
| 1119 | case GL_UNSIGNED_INT_VEC3: |
| 1120 | return UniformType::UIVec3; |
| 1121 | case GL_UNSIGNED_INT_VEC4: |
| 1122 | return UniformType::UIVec4; |
| 1123 | case GL_BOOL: |
| 1124 | return UniformType::Bool; |
| 1125 | case GL_BOOL_VEC2: |
| 1126 | return UniformType::BVec2; |
| 1127 | case GL_BOOL_VEC3: |
| 1128 | return UniformType::BVec3; |
| 1129 | case GL_BOOL_VEC4: |
| 1130 | return UniformType::BVec4; |
| 1131 | |
| 1132 | case GL_SAMPLER_BUFFER: |
| 1133 | case GL_SAMPLER_1D: |
| 1134 | case GL_SAMPLER_1D_SHADOW: |
| 1135 | case GL_SAMPLER_1D_ARRAY: |
| 1136 | case GL_SAMPLER_2D: |
| 1137 | case GL_SAMPLER_2D_RECT: |
| 1138 | case GL_SAMPLER_2D_SHADOW: |
| 1139 | case GL_SAMPLER_2D_RECT_SHADOW: |
| 1140 | case GL_SAMPLER_CUBE: |
| 1141 | case GL_SAMPLER_CUBE_SHADOW: |
| 1142 | case GL_SAMPLER_2D_ARRAY: |
| 1143 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 1144 | case GL_SAMPLER_2D_MULTISAMPLE: |
| 1145 | case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 1146 | case GL_SAMPLER_3D: |
| 1147 | case GL_INT_SAMPLER_BUFFER: |
| 1148 | case GL_INT_SAMPLER_1D: |
| 1149 | case GL_INT_SAMPLER_2D: |
| 1150 | case GL_INT_SAMPLER_3D: |
| 1151 | case GL_INT_SAMPLER_CUBE: |
| 1152 | case GL_INT_SAMPLER_1D_ARRAY: |
| 1153 | case GL_INT_SAMPLER_2D_ARRAY: |
| 1154 | case GL_INT_SAMPLER_2D_MULTISAMPLE: |
| 1155 | case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 1156 | case GL_UNSIGNED_INT_SAMPLER_BUFFER: |
| 1157 | case GL_UNSIGNED_INT_SAMPLER_1D: |
| 1158 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 1159 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 1160 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 1161 | case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: |
| 1162 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
| 1163 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: |
| 1164 | case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: |
| 1165 | return UniformType::Sampler; |
| 1166 | default: |
| 1167 | Q_UNREACHABLE_RETURN(UniformType::Float); |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | void GraphicsHelperGL3_3::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) |
| 1172 | { |
| 1173 | m_funcs->glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 1174 | } |
| 1175 | |
| 1176 | } // namespace OpenGL |
| 1177 | } // namespace Render |
| 1178 | } // namespace Qt3DRender |
| 1179 | |
| 1180 | QT_END_NAMESPACE |
| 1181 | |
| 1182 | #endif // !QT_OPENGL_ES_2 |
| 1183 | |