| 1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DRender/qrendertargetoutput.h> |
| 6 | #include <Qt3DRender/private/uniform_p.h> |
| 7 | #include <graphicshelpergl2_p.h> |
| 8 | #include <Qt3DRender/private/attachmentpack_p.h> |
| 9 | #include <QOpenGLContext> |
| 10 | #include <QOpenGLVersionFunctionsFactory> |
| 11 | #include <QOpenGLBuffer> |
| 12 | #include <QOpenGLFunctions_2_0> |
| 13 | #include <QOpenGLExtraFunctions> |
| 14 | #include <QOpenGLShaderProgram> |
| 15 | #include <QOpenGLVertexArrayObject> |
| 16 | #include <QSurfaceFormat> |
| 17 | |
| 18 | #if !QT_CONFIG(opengles2) |
| 19 | |
| 20 | #define TEST_SHOULD_BE_PERFORMED 1 |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | using namespace Qt3DRender; |
| 25 | using namespace Qt3DRender::Render; |
| 26 | using namespace Qt3DRender::Render::OpenGL; |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | const QByteArray vertCode = QByteArrayLiteral( |
| 31 | "#version 120\n" \ |
| 32 | "attribute vec3 vertexPosition;\n" \ |
| 33 | "attribute vec2 vertexTexCoord;\n" \ |
| 34 | "varying vec2 texCoord;\n" \ |
| 35 | "void main()\n" \ |
| 36 | "{\n" \ |
| 37 | " texCoord = vertexTexCoord;\n" \ |
| 38 | " gl_Position = vec4(vertexPosition, 1.0);\n" \ |
| 39 | "}\n"); |
| 40 | |
| 41 | const QByteArray fragCodeUniformsFloat = QByteArrayLiteral( |
| 42 | "#version 120\n" \ |
| 43 | "uniform float multiplier;\n" \ |
| 44 | "uniform vec2 multiplierVec2;\n" \ |
| 45 | "uniform vec3 multiplierVec3;\n" \ |
| 46 | "uniform vec4 multiplierVec4;\n" \ |
| 47 | "void main()\n" \ |
| 48 | "{\n" \ |
| 49 | " vec4 randomMult = multiplierVec4 + vec4(multiplierVec3, 0.0) + vec4(multiplierVec2, 0.0, 0.0);\n" \ |
| 50 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * randomMult * multiplier;\n" \ |
| 51 | "}\n"); |
| 52 | |
| 53 | const QByteArray fragCodeUniformsInt = QByteArrayLiteral( |
| 54 | "#version 120\n" \ |
| 55 | "uniform int multiplier;\n" \ |
| 56 | "uniform ivec2 multiplierVec2;\n" \ |
| 57 | "uniform ivec3 multiplierVec3;\n" \ |
| 58 | "uniform ivec4 multiplierVec4;\n" \ |
| 59 | "void main()\n" \ |
| 60 | "{\n" \ |
| 61 | " ivec4 randomMult = multiplierVec4 + ivec4(multiplierVec3, 0) + ivec4(multiplierVec2, 0, 0);\n" \ |
| 62 | " gl_FragColor = ivec4(1, 0, 0, 1) * randomMult * multiplier;\n" \ |
| 63 | "}\n"); |
| 64 | |
| 65 | const QByteArray fragCodeUniformsFloatMatrices = QByteArrayLiteral( |
| 66 | "#version 120\n" \ |
| 67 | "uniform mat2 m2;\n" \ |
| 68 | "uniform mat2x3 m23;\n" \ |
| 69 | "uniform mat3x2 m32;\n" \ |
| 70 | "uniform mat2x4 m24;\n" \ |
| 71 | "uniform mat4x2 m42;\n" \ |
| 72 | "uniform mat3 m3;\n" \ |
| 73 | "uniform mat3x4 m34;\n" \ |
| 74 | "uniform mat4x3 m43;\n" \ |
| 75 | "uniform mat4 m4;\n" \ |
| 76 | "void main()\n" \ |
| 77 | "{\n" \ |
| 78 | " float lengthSum = m2[0][0] + m23[0][0] + m32[0][0] + m24[0][0] + m42[0][0] + m3[0][0] + m34[0][0] + m43[0][0] + m4[0][0];\n" \ |
| 79 | " gl_FragColor = vec4(1, 0, 0, 1) * lengthSum;\n" \ |
| 80 | "}\n"); |
| 81 | |
| 82 | |
| 83 | const QByteArray fragCodeSamplers = QByteArrayLiteral( |
| 84 | "#version 120\n" \ |
| 85 | "varying vec2 texCoord;\n" \ |
| 86 | "uniform sampler1D s1;\n" \ |
| 87 | "uniform sampler2D s2;\n" \ |
| 88 | "uniform sampler3D s3;\n" \ |
| 89 | "uniform samplerCube scube;\n" \ |
| 90 | "void main()\n" \ |
| 91 | "{\n" \ |
| 92 | " gl_FragColor = vec4(1, 0, 0, 1) *" \ |
| 93 | " texture1D(s1, texCoord.x) *" \ |
| 94 | " texture2D(s2, texCoord) *" \ |
| 95 | " texture3D(s3, vec3(texCoord, 0.0)) *" \ |
| 96 | " textureCube(scube, vec3(texCoord, 0));\n" \ |
| 97 | "}\n"); |
| 98 | |
| 99 | } // anonymous |
| 100 | |
| 101 | class tst_GraphicsHelperGL2 : public QObject |
| 102 | { |
| 103 | Q_OBJECT |
| 104 | private Q_SLOTS: |
| 105 | |
| 106 | void init() |
| 107 | { |
| 108 | m_window.reset(new QWindow); |
| 109 | m_window->setSurfaceType(QWindow::OpenGLSurface); |
| 110 | m_window->setGeometry(0, 0, 10, 10); |
| 111 | m_window->create(); |
| 112 | |
| 113 | QSurfaceFormat format; |
| 114 | format.setVersion(2, 0); |
| 115 | format.setProfile(QSurfaceFormat::NoProfile); |
| 116 | format.setDepthBufferSize(24); |
| 117 | format.setSamples(4); |
| 118 | format.setStencilBufferSize(8); |
| 119 | m_window->setFormat(format); |
| 120 | m_glContext.setFormat(format); |
| 121 | |
| 122 | if (!m_glContext.create()) { |
| 123 | qWarning() << "Failed to create OpenGL context"; |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | if (!m_glContext.makeCurrent(m_window.data())) { |
| 128 | qWarning() << "Failed to make OpenGL context current"; |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | if ((m_func = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_2_0>()) != nullptr) { |
| 133 | m_extraFunctions = m_glContext.extraFunctions(); |
| 134 | m_glHelper.initializeHelper(&m_glContext, m_func); |
| 135 | m_initializationSuccessful = true; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void cleanup() |
| 140 | { |
| 141 | m_glContext.doneCurrent(); |
| 142 | } |
| 143 | |
| 144 | void alphaTest() |
| 145 | { |
| 146 | if (!m_initializationSuccessful) |
| 147 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 148 | // Deprecated |
| 149 | } |
| 150 | |
| 151 | void bindBufferBase() |
| 152 | { |
| 153 | if (!m_initializationSuccessful) |
| 154 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 155 | |
| 156 | // Not supported by GL2 |
| 157 | } |
| 158 | |
| 159 | void bindFragDataLocation() |
| 160 | { |
| 161 | if (!m_initializationSuccessful) |
| 162 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 163 | // Not supported by GL2 |
| 164 | } |
| 165 | |
| 166 | void bindFrameBufferAttachment() |
| 167 | { |
| 168 | if (!m_initializationSuccessful) |
| 169 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 170 | |
| 171 | // GIVEN |
| 172 | GLuint fboId; |
| 173 | m_extraFunctions->glGenFramebuffers(1, &fboId); |
| 174 | |
| 175 | Attachment attachment; |
| 176 | attachment.m_point = QRenderTargetOutput::Color0; |
| 177 | |
| 178 | // THEN |
| 179 | QVERIFY(fboId != 0); |
| 180 | |
| 181 | // WHEN |
| 182 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboId); |
| 183 | |
| 184 | QOpenGLTexture texture(QOpenGLTexture::Target2D); |
| 185 | texture.setSize(512, 512); |
| 186 | texture.setFormat(QOpenGLTexture::RGBA32F); |
| 187 | texture.setMinificationFilter(QOpenGLTexture::Linear); |
| 188 | texture.setMagnificationFilter(QOpenGLTexture::Linear); |
| 189 | texture.setWrapMode(QOpenGLTexture::ClampToEdge); |
| 190 | if (!texture.create()) |
| 191 | qWarning() << "Texture creation failed"; |
| 192 | texture.allocateStorage(); |
| 193 | QVERIFY(texture.isStorageAllocated()); |
| 194 | GLint error = m_func->glGetError(); |
| 195 | QVERIFY(error == 0); |
| 196 | m_glHelper.bindFrameBufferAttachment(&texture, attachment); |
| 197 | |
| 198 | // THEN |
| 199 | GLenum status = m_extraFunctions->glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); |
| 200 | QVERIFY(status == GL_FRAMEBUFFER_COMPLETE); |
| 201 | |
| 202 | error = m_func->glGetError(); |
| 203 | QVERIFY(error == 0); |
| 204 | GLint textureAttachmentId = 0; |
| 205 | m_extraFunctions->glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, |
| 206 | GL_COLOR_ATTACHMENT0, |
| 207 | GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, |
| 208 | &textureAttachmentId); |
| 209 | QCOMPARE(GLuint(textureAttachmentId), texture.textureId()); |
| 210 | |
| 211 | // Restore state |
| 212 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 213 | m_extraFunctions->glDeleteFramebuffers(1, &fboId); |
| 214 | } |
| 215 | |
| 216 | void bindFrameBufferObject() |
| 217 | { |
| 218 | if (!m_initializationSuccessful) |
| 219 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 220 | |
| 221 | // GIVEN |
| 222 | GLuint fboId; |
| 223 | m_extraFunctions->glGenFramebuffers(1, &fboId); |
| 224 | |
| 225 | // THEN |
| 226 | QVERIFY(fboId != 0); |
| 227 | |
| 228 | // WHEN |
| 229 | m_glHelper.bindFrameBufferObject(fboId, GraphicsHelperInterface::FBODraw); |
| 230 | |
| 231 | // THEN |
| 232 | GLint error = m_func->glGetError(); |
| 233 | QVERIFY(error == 0); |
| 234 | GLint boundindFBOId = 0; |
| 235 | m_func->glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &boundindFBOId); |
| 236 | QVERIFY(GLuint(boundindFBOId) == fboId); |
| 237 | |
| 238 | // WHEN |
| 239 | m_glHelper.bindFrameBufferObject(fboId, GraphicsHelperInterface::FBORead); |
| 240 | |
| 241 | // THEN |
| 242 | error = m_func->glGetError(); |
| 243 | QVERIFY(error == 0); |
| 244 | boundindFBOId = 0; |
| 245 | m_func->glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &boundindFBOId); |
| 246 | QVERIFY(GLuint(boundindFBOId) == fboId); |
| 247 | |
| 248 | // WHEN |
| 249 | m_glHelper.bindFrameBufferObject(fboId, GraphicsHelperInterface::FBOReadAndDraw); |
| 250 | |
| 251 | // THEN |
| 252 | error = m_func->glGetError(); |
| 253 | QVERIFY(error == 0); |
| 254 | boundindFBOId = 0; |
| 255 | m_func->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundindFBOId); |
| 256 | QVERIFY(GLuint(boundindFBOId) == fboId); |
| 257 | |
| 258 | // Cleanup |
| 259 | m_extraFunctions->glDeleteFramebuffers(1, &fboId); |
| 260 | } |
| 261 | |
| 262 | void bindShaderStorageBlock() |
| 263 | { |
| 264 | if (!m_initializationSuccessful) |
| 265 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 266 | // Not supported by GL2 |
| 267 | } |
| 268 | |
| 269 | void bindUniformBlock() |
| 270 | { |
| 271 | if (!m_initializationSuccessful) |
| 272 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 273 | // Not supported by GL2 |
| 274 | } |
| 275 | |
| 276 | void blendEquation() |
| 277 | { |
| 278 | if (!m_initializationSuccessful) |
| 279 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 280 | |
| 281 | // GIVEN |
| 282 | GLint equation = 0; |
| 283 | m_func->glGetIntegerv(GL_BLEND_EQUATION_RGB, &equation); |
| 284 | QCOMPARE(equation, GL_FUNC_ADD); |
| 285 | |
| 286 | // WHEN |
| 287 | m_glHelper.blendEquation(GL_FUNC_REVERSE_SUBTRACT); |
| 288 | |
| 289 | // THEN |
| 290 | m_func->glGetIntegerv(GL_BLEND_EQUATION_RGB, &equation); |
| 291 | QCOMPARE(equation, GL_FUNC_REVERSE_SUBTRACT); |
| 292 | } |
| 293 | |
| 294 | void blendFunci() |
| 295 | { |
| 296 | if (!m_initializationSuccessful) |
| 297 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 298 | // Not supported by GL2 |
| 299 | } |
| 300 | |
| 301 | void blendFuncSeparatei() |
| 302 | { |
| 303 | if (!m_initializationSuccessful) |
| 304 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 305 | // Not supported by GL2 |
| 306 | } |
| 307 | |
| 308 | void boundFrameBufferObject() |
| 309 | { |
| 310 | if (!m_initializationSuccessful) |
| 311 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 312 | |
| 313 | // GIVEN |
| 314 | GLuint fboId; |
| 315 | m_extraFunctions->glGenFramebuffers(1, &fboId); |
| 316 | |
| 317 | // WHEN |
| 318 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboId); |
| 319 | |
| 320 | // THEN |
| 321 | GLint boundBuffer = 0; |
| 322 | m_func->glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &boundBuffer); |
| 323 | QCOMPARE(GLuint(boundBuffer), fboId); |
| 324 | |
| 325 | // THEN |
| 326 | QCOMPARE(m_glHelper.boundFrameBufferObject(), fboId); |
| 327 | |
| 328 | // Reset state |
| 329 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 330 | m_extraFunctions->glDeleteFramebuffers(1, &fboId); |
| 331 | } |
| 332 | |
| 333 | void checkFrameBufferComplete() |
| 334 | { |
| 335 | if (!m_initializationSuccessful) |
| 336 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 337 | |
| 338 | // GIVEN |
| 339 | GLuint fboId; |
| 340 | m_extraFunctions->glGenFramebuffers(1, &fboId); |
| 341 | |
| 342 | Attachment attachment; |
| 343 | attachment.m_point = QRenderTargetOutput::Color0; |
| 344 | |
| 345 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboId); |
| 346 | |
| 347 | QOpenGLTexture texture(QOpenGLTexture::Target2D); |
| 348 | texture.setSize(512, 512); |
| 349 | texture.setFormat(QOpenGLTexture::RGBA8U); |
| 350 | texture.setMinificationFilter(QOpenGLTexture::Linear); |
| 351 | texture.setMagnificationFilter(QOpenGLTexture::Linear); |
| 352 | texture.create(); |
| 353 | texture.allocateStorage(); |
| 354 | m_glHelper.bindFrameBufferAttachment(&texture, attachment); |
| 355 | |
| 356 | // THEN |
| 357 | GLenum status = m_extraFunctions->glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); |
| 358 | QVERIFY(status == GL_FRAMEBUFFER_COMPLETE); |
| 359 | |
| 360 | QVERIFY(m_glHelper.checkFrameBufferComplete()); |
| 361 | |
| 362 | // Restore |
| 363 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 364 | m_extraFunctions->glDeleteFramebuffers(1, &fboId); |
| 365 | } |
| 366 | |
| 367 | void clearBufferf() |
| 368 | { |
| 369 | if (!m_initializationSuccessful) |
| 370 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 371 | // Not supported by GL2 |
| 372 | } |
| 373 | |
| 374 | void createFrameBufferObject() |
| 375 | { |
| 376 | if (!m_initializationSuccessful) |
| 377 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 378 | |
| 379 | // WHEN |
| 380 | const GLuint fboId = m_glHelper.createFrameBufferObject(); |
| 381 | |
| 382 | // THEN |
| 383 | QVERIFY(fboId != 0); |
| 384 | |
| 385 | // Restore |
| 386 | m_extraFunctions->glDeleteFramebuffers(1, &fboId); |
| 387 | } |
| 388 | |
| 389 | void depthMask() |
| 390 | { |
| 391 | if (!m_initializationSuccessful) |
| 392 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 393 | |
| 394 | // GIVEN |
| 395 | GLboolean depthWritingEnabled = false; |
| 396 | m_func->glGetBooleanv(GL_DEPTH_WRITEMASK, &depthWritingEnabled); |
| 397 | |
| 398 | // THEN |
| 399 | QVERIFY(depthWritingEnabled); |
| 400 | |
| 401 | // WHEN |
| 402 | m_glHelper.depthMask(GL_FALSE); |
| 403 | |
| 404 | // THEN |
| 405 | m_func->glGetBooleanv(GL_DEPTH_WRITEMASK, &depthWritingEnabled); |
| 406 | QVERIFY(!depthWritingEnabled); |
| 407 | |
| 408 | // WHEN |
| 409 | m_glHelper.depthMask(GL_TRUE); |
| 410 | |
| 411 | // THEN |
| 412 | m_func->glGetBooleanv(GL_DEPTH_WRITEMASK, &depthWritingEnabled); |
| 413 | QVERIFY(depthWritingEnabled); |
| 414 | } |
| 415 | |
| 416 | void depthTest() |
| 417 | { |
| 418 | if (!m_initializationSuccessful) |
| 419 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 420 | |
| 421 | // GIVEN |
| 422 | m_func->glDisable(GL_DEPTH_TEST); |
| 423 | m_func->glDepthFunc(GL_LESS); |
| 424 | |
| 425 | // WHEN |
| 426 | m_glHelper.depthTest(GL_LEQUAL); |
| 427 | |
| 428 | // THEN |
| 429 | QVERIFY(m_func->glIsEnabled(GL_DEPTH_TEST)); |
| 430 | GLint depthMode = 0; |
| 431 | m_func->glGetIntegerv(GL_DEPTH_FUNC, &depthMode); |
| 432 | QCOMPARE(depthMode, GL_LEQUAL); |
| 433 | |
| 434 | // WHEN |
| 435 | m_glHelper.depthTest(GL_LESS); |
| 436 | QVERIFY(m_func->glIsEnabled(GL_DEPTH_TEST)); |
| 437 | m_func->glGetIntegerv(GL_DEPTH_FUNC, &depthMode); |
| 438 | QCOMPARE(depthMode, GL_LESS); |
| 439 | } |
| 440 | |
| 441 | void disableClipPlane() |
| 442 | { |
| 443 | if (!m_initializationSuccessful) |
| 444 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 445 | |
| 446 | // GIVEN |
| 447 | m_func->glEnable(GL_CLIP_DISTANCE0 + 5); |
| 448 | |
| 449 | // THEN |
| 450 | QVERIFY(m_func->glIsEnabled(GL_CLIP_DISTANCE0 + 5)); |
| 451 | |
| 452 | // WHEN |
| 453 | m_glHelper.disableClipPlane(5); |
| 454 | |
| 455 | // THEN |
| 456 | QVERIFY(!m_func->glIsEnabled(GL_CLIP_DISTANCE0 + 5)); |
| 457 | } |
| 458 | |
| 459 | void disablei() |
| 460 | { |
| 461 | if (!m_initializationSuccessful) |
| 462 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 463 | // Not supported by GL2 |
| 464 | } |
| 465 | |
| 466 | void disablePrimitiveRestart() |
| 467 | { |
| 468 | if (!m_initializationSuccessful) |
| 469 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 470 | // Not supported by GL2 |
| 471 | } |
| 472 | |
| 473 | void drawBuffers() |
| 474 | { |
| 475 | if (!m_initializationSuccessful) |
| 476 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 477 | |
| 478 | // GIVEN |
| 479 | GLuint fboId; |
| 480 | m_extraFunctions->glGenFramebuffers(1, &fboId); |
| 481 | |
| 482 | // THEN |
| 483 | QVERIFY(fboId != 0); |
| 484 | |
| 485 | // WHEN |
| 486 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboId); |
| 487 | QOpenGLTexture *textures[4]; |
| 488 | |
| 489 | // Create 4 attachments |
| 490 | for (int i = 0; i < 4; ++i) { |
| 491 | Attachment attachment; |
| 492 | attachment.m_point = static_cast<QRenderTargetOutput::AttachmentPoint>(i); |
| 493 | |
| 494 | QOpenGLTexture *texture = new QOpenGLTexture(QOpenGLTexture::Target2D); |
| 495 | textures[i] = texture; |
| 496 | texture->setSize(512, 512); |
| 497 | texture->setFormat(QOpenGLTexture::RGBA32F); |
| 498 | texture->setMinificationFilter(QOpenGLTexture::Linear); |
| 499 | texture->setMagnificationFilter(QOpenGLTexture::Linear); |
| 500 | texture->setWrapMode(QOpenGLTexture::ClampToEdge); |
| 501 | if (!texture->create()) |
| 502 | qWarning() << "Texture creation failed"; |
| 503 | texture->allocateStorage(); |
| 504 | QVERIFY(texture->isStorageAllocated()); |
| 505 | GLint error = m_func->glGetError(); |
| 506 | QVERIFY(error == 0); |
| 507 | m_glHelper.bindFrameBufferAttachment(texture, attachment); |
| 508 | } |
| 509 | // THEN |
| 510 | GLenum status = m_extraFunctions->glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); |
| 511 | QVERIFY(status == GL_FRAMEBUFFER_COMPLETE); |
| 512 | |
| 513 | // WHEN |
| 514 | GLenum bufferEnum = GL_COLOR_ATTACHMENT4; |
| 515 | m_func->glDrawBuffers(1, &bufferEnum); |
| 516 | |
| 517 | // THEN |
| 518 | GLint enumValue = -1; |
| 519 | m_func->glGetIntegerv(GL_DRAW_BUFFER0, &enumValue); |
| 520 | QCOMPARE(enumValue, GL_COLOR_ATTACHMENT4); |
| 521 | |
| 522 | // WHEN |
| 523 | GLenum newBufferEnum = GL_COLOR_ATTACHMENT0 + 2; |
| 524 | m_glHelper.drawBuffers(1, &newBufferEnum); |
| 525 | |
| 526 | // THEN |
| 527 | m_func->glGetIntegerv(GL_DRAW_BUFFER0, &enumValue); |
| 528 | QCOMPARE(enumValue, GL_COLOR_ATTACHMENT0 + 2); |
| 529 | |
| 530 | // WHEN |
| 531 | newBufferEnum = 0; |
| 532 | m_glHelper.drawBuffers(1, &newBufferEnum); |
| 533 | |
| 534 | // THEN |
| 535 | m_func->glGetIntegerv(GL_DRAW_BUFFER0, &enumValue); |
| 536 | QCOMPARE(enumValue, GL_NONE); |
| 537 | |
| 538 | // Restore |
| 539 | m_extraFunctions->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 540 | m_extraFunctions->glDeleteFramebuffers(1, &fboId); |
| 541 | for (int i = 0; i < 4; ++i) |
| 542 | delete textures[i]; |
| 543 | } |
| 544 | |
| 545 | void enableClipPlane() |
| 546 | { |
| 547 | if (!m_initializationSuccessful) |
| 548 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 549 | |
| 550 | // GIVEN |
| 551 | m_func->glDisable(GL_CLIP_DISTANCE0 + 4); |
| 552 | |
| 553 | // THEN |
| 554 | QVERIFY(!m_func->glIsEnabled(GL_CLIP_DISTANCE0 + 4)); |
| 555 | |
| 556 | // WHEN |
| 557 | m_glHelper.enableClipPlane(4); |
| 558 | |
| 559 | // THEN |
| 560 | QVERIFY(m_func->glIsEnabled(GL_CLIP_DISTANCE0 + 4)); |
| 561 | } |
| 562 | |
| 563 | void enablei() |
| 564 | { |
| 565 | if (!m_initializationSuccessful) |
| 566 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 567 | // Not supported by GL2 |
| 568 | } |
| 569 | |
| 570 | void enablePrimitiveRestart() |
| 571 | { |
| 572 | if (!m_initializationSuccessful) |
| 573 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 574 | // Not supported by GL2 |
| 575 | } |
| 576 | |
| 577 | void enableVertexAttribute() |
| 578 | { |
| 579 | if (!m_initializationSuccessful) |
| 580 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 581 | |
| 582 | // GIVEN |
| 583 | QOpenGLVertexArrayObject vao; |
| 584 | vao.create(); |
| 585 | QOpenGLVertexArrayObject::Binder binder(&vao); |
| 586 | |
| 587 | QOpenGLShaderProgram shaderProgram; |
| 588 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 589 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeSamplers); |
| 590 | QVERIFY(shaderProgram.link()); |
| 591 | shaderProgram.bind(); |
| 592 | |
| 593 | // WHEN |
| 594 | GLint positionLocation = m_func->glGetAttribLocation(shaderProgram.programId(), "vertexPosition"); |
| 595 | GLint texCoordLocation = m_func->glGetAttribLocation(shaderProgram.programId(), "vertexTexCoord"); |
| 596 | m_glHelper.enableVertexAttributeArray(positionLocation); |
| 597 | m_glHelper.enableVertexAttributeArray(texCoordLocation); |
| 598 | |
| 599 | // THEN |
| 600 | const GLint error = m_func->glGetError(); |
| 601 | QVERIFY(error == 0); |
| 602 | } |
| 603 | |
| 604 | void frontFace() |
| 605 | { |
| 606 | if (!m_initializationSuccessful) |
| 607 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 608 | |
| 609 | // GIVEN |
| 610 | m_func->glFrontFace(GL_CW); |
| 611 | |
| 612 | // THEN |
| 613 | GLint face = 0; |
| 614 | m_func->glGetIntegerv(GL_FRONT_FACE, &face); |
| 615 | QCOMPARE(face, GL_CW); |
| 616 | |
| 617 | // WHEN |
| 618 | m_glHelper.frontFace(GL_CCW); |
| 619 | |
| 620 | // THEN |
| 621 | m_func->glGetIntegerv(GL_FRONT_FACE, &face); |
| 622 | QCOMPARE(face, GL_CCW); |
| 623 | } |
| 624 | |
| 625 | void getRenderBufferDimensions() |
| 626 | { |
| 627 | if (!m_initializationSuccessful) |
| 628 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 629 | // Not supported by GL2 |
| 630 | } |
| 631 | |
| 632 | void getTextureDimensions() |
| 633 | { |
| 634 | if (!m_initializationSuccessful) |
| 635 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 636 | |
| 637 | // GIVEN |
| 638 | QOpenGLTexture texture(QOpenGLTexture::Target2D); |
| 639 | texture.setSize(512, 512); |
| 640 | texture.setFormat(QOpenGLTexture::RGBA8U); |
| 641 | texture.setMinificationFilter(QOpenGLTexture::Linear); |
| 642 | texture.setMagnificationFilter(QOpenGLTexture::Linear); |
| 643 | texture.create(); |
| 644 | texture.allocateStorage(); |
| 645 | |
| 646 | // WHEN |
| 647 | const QSize dimensions = m_glHelper.getTextureDimensions(texture.textureId(), GL_TEXTURE_2D); |
| 648 | |
| 649 | // THEN |
| 650 | QCOMPARE(dimensions, QSize(512, 512)); |
| 651 | } |
| 652 | |
| 653 | void pointSize() |
| 654 | { |
| 655 | if (!m_initializationSuccessful) |
| 656 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 657 | |
| 658 | // WHEN |
| 659 | m_glHelper.pointSize(false, 0.5f); |
| 660 | // THEN |
| 661 | GLfloat size = 0.0f; |
| 662 | m_func->glGetFloatv(GL_POINT_SIZE, &size); |
| 663 | QCOMPARE(size, 0.5f); |
| 664 | } |
| 665 | |
| 666 | void maxClipPlaneCount() |
| 667 | { |
| 668 | if (!m_initializationSuccessful) |
| 669 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 670 | |
| 671 | // GIVEN |
| 672 | GLint maxCount = -1; |
| 673 | m_func->glGetIntegerv(GL_MAX_CLIP_PLANES, &maxCount); |
| 674 | |
| 675 | // THEN |
| 676 | QCOMPARE(maxCount, m_glHelper.maxClipPlaneCount()); |
| 677 | } |
| 678 | |
| 679 | void programUniformBlock() |
| 680 | { |
| 681 | if (!m_initializationSuccessful) |
| 682 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 683 | |
| 684 | // Not supported by GL2 |
| 685 | } |
| 686 | |
| 687 | void programAttributesAndLocations() |
| 688 | { |
| 689 | if (!m_initializationSuccessful) |
| 690 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 691 | |
| 692 | // GIVEN |
| 693 | QOpenGLShaderProgram shaderProgram; |
| 694 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 695 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeSamplers); |
| 696 | QVERIFY(shaderProgram.link()); |
| 697 | |
| 698 | // WHEN |
| 699 | std::vector<ShaderAttribute> activeAttributes = m_glHelper.programAttributesAndLocations(shaderProgram.programId()); |
| 700 | |
| 701 | // THEN |
| 702 | QCOMPARE(activeAttributes.size(), 2U); |
| 703 | std::sort(activeAttributes.begin(), activeAttributes.end(), [] (const ShaderAttribute &a, const ShaderAttribute &b) { return a.m_name < b.m_name; }); |
| 704 | |
| 705 | const ShaderAttribute attribute1 = activeAttributes.at(0); |
| 706 | QCOMPARE(attribute1.m_name, QStringLiteral("vertexPosition")); |
| 707 | QCOMPARE(attribute1.m_size, 1); |
| 708 | QCOMPARE(attribute1.m_location, shaderProgram.attributeLocation("vertexPosition")); |
| 709 | QCOMPARE(attribute1.m_type, GLenum(GL_FLOAT_VEC3)); |
| 710 | |
| 711 | const ShaderAttribute attribute2 = activeAttributes.at(1); |
| 712 | QCOMPARE(attribute2.m_name, QStringLiteral("vertexTexCoord")); |
| 713 | QCOMPARE(attribute2.m_size, 1); |
| 714 | QCOMPARE(attribute2.m_location, shaderProgram.attributeLocation("vertexTexCoord")); |
| 715 | QCOMPARE(attribute2.m_type, GLenum(GL_FLOAT_VEC2)); |
| 716 | } |
| 717 | |
| 718 | void programUniformsAndLocations() |
| 719 | { |
| 720 | if (!m_initializationSuccessful) |
| 721 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 722 | |
| 723 | // GIVEN |
| 724 | QOpenGLShaderProgram shaderProgram; |
| 725 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 726 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloat); |
| 727 | QVERIFY(shaderProgram.link()); |
| 728 | |
| 729 | // WHEN |
| 730 | std::vector<ShaderUniform> activeUniforms = m_glHelper.programUniformsAndLocations(shaderProgram.programId()); |
| 731 | |
| 732 | // THEN |
| 733 | QCOMPARE(activeUniforms.size(), 4U); |
| 734 | std::sort(activeUniforms.begin(), activeUniforms.end(), [] (const ShaderUniform &a, const ShaderUniform &b) { return a.m_name < b.m_name; }); |
| 735 | |
| 736 | const ShaderUniform uniform1 = activeUniforms.at(0); |
| 737 | QCOMPARE(uniform1.m_location, shaderProgram.uniformLocation("multiplier")); |
| 738 | QCOMPARE(uniform1.m_offset, -1); |
| 739 | QCOMPARE(uniform1.m_blockIndex, -1); |
| 740 | QCOMPARE(uniform1.m_arrayStride, -1); |
| 741 | QCOMPARE(uniform1.m_matrixStride, -1); |
| 742 | QCOMPARE(uniform1.m_size, 1); |
| 743 | QCOMPARE(uniform1.m_type, GLenum(GL_FLOAT)); |
| 744 | QCOMPARE(uniform1.m_name, QStringLiteral("multiplier")); |
| 745 | |
| 746 | const ShaderUniform uniform2 = activeUniforms.at(1); |
| 747 | QCOMPARE(uniform2.m_location, shaderProgram.uniformLocation("multiplierVec2")); |
| 748 | QCOMPARE(uniform2.m_offset, -1); |
| 749 | QCOMPARE(uniform2.m_blockIndex, -1); |
| 750 | QCOMPARE(uniform2.m_arrayStride, -1); |
| 751 | QCOMPARE(uniform2.m_matrixStride, -1); |
| 752 | QCOMPARE(uniform2.m_size, 1); |
| 753 | QCOMPARE(uniform2.m_type, GLenum(GL_FLOAT_VEC2)); |
| 754 | QCOMPARE(uniform2.m_name, QStringLiteral("multiplierVec2")); |
| 755 | |
| 756 | const ShaderUniform uniform3 = activeUniforms.at(2); |
| 757 | QCOMPARE(uniform3.m_location, shaderProgram.uniformLocation("multiplierVec3")); |
| 758 | QCOMPARE(uniform3.m_offset, -1); |
| 759 | QCOMPARE(uniform3.m_blockIndex, -1); |
| 760 | QCOMPARE(uniform3.m_arrayStride, -1); |
| 761 | QCOMPARE(uniform3.m_matrixStride, -1); |
| 762 | QCOMPARE(uniform3.m_size, 1); |
| 763 | QCOMPARE(uniform3.m_type, GLenum(GL_FLOAT_VEC3)); |
| 764 | QCOMPARE(uniform3.m_name, QStringLiteral("multiplierVec3")); |
| 765 | |
| 766 | const ShaderUniform uniform4 = activeUniforms.at(3); |
| 767 | QCOMPARE(uniform4.m_location, shaderProgram.uniformLocation("multiplierVec4")); |
| 768 | QCOMPARE(uniform4.m_offset, -1); |
| 769 | QCOMPARE(uniform4.m_blockIndex, -1); |
| 770 | QCOMPARE(uniform4.m_arrayStride, -1); |
| 771 | QCOMPARE(uniform4.m_matrixStride, -1); |
| 772 | QCOMPARE(uniform4.m_size, 1); |
| 773 | QCOMPARE(uniform4.m_type, GLenum(GL_FLOAT_VEC4)); |
| 774 | QCOMPARE(uniform4.m_name, QStringLiteral("multiplierVec4")); |
| 775 | } |
| 776 | |
| 777 | void programShaderStorageBlock() |
| 778 | { |
| 779 | if (!m_initializationSuccessful) |
| 780 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 781 | // Not supported by GL2 |
| 782 | } |
| 783 | |
| 784 | void releaseFrameBufferObject() |
| 785 | { |
| 786 | if (!m_initializationSuccessful) |
| 787 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 788 | // GIVEN |
| 789 | GLuint fboId; |
| 790 | m_extraFunctions->glGenFramebuffers(1, &fboId); |
| 791 | |
| 792 | // THEN |
| 793 | QVERIFY(fboId != 0); |
| 794 | |
| 795 | // WHEN |
| 796 | m_glHelper.releaseFrameBufferObject(fboId); |
| 797 | |
| 798 | // THEN |
| 799 | QVERIFY(!m_extraFunctions->glIsFramebuffer(fboId)); |
| 800 | } |
| 801 | |
| 802 | void setMSAAEnabled() |
| 803 | { |
| 804 | if (!m_initializationSuccessful) |
| 805 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 806 | |
| 807 | // GIVEN |
| 808 | m_func->glDisable(GL_MULTISAMPLE); |
| 809 | |
| 810 | // THEN |
| 811 | QVERIFY(!m_func->glIsEnabled(GL_MULTISAMPLE)); |
| 812 | |
| 813 | // WHEN |
| 814 | m_glHelper.setMSAAEnabled(true); |
| 815 | |
| 816 | // THEN |
| 817 | QVERIFY(m_func->glIsEnabled(GL_MULTISAMPLE)); |
| 818 | |
| 819 | // WHEN |
| 820 | m_glHelper.setMSAAEnabled(false); |
| 821 | |
| 822 | // THEN |
| 823 | QVERIFY(!m_func->glIsEnabled(GL_MULTISAMPLE)); |
| 824 | } |
| 825 | |
| 826 | void setAlphaCoverageEnabled() |
| 827 | { |
| 828 | if (!m_initializationSuccessful) |
| 829 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 830 | |
| 831 | // GIVEN |
| 832 | m_func->glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); |
| 833 | |
| 834 | // THEN |
| 835 | QVERIFY(!m_func->glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE)); |
| 836 | |
| 837 | // WHEN |
| 838 | m_glHelper.setAlphaCoverageEnabled(true); |
| 839 | |
| 840 | // THEN |
| 841 | QVERIFY(m_func->glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE)); |
| 842 | |
| 843 | // WHEN |
| 844 | m_glHelper.setAlphaCoverageEnabled(false); |
| 845 | |
| 846 | // THEN |
| 847 | QVERIFY(!m_func->glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE)); |
| 848 | } |
| 849 | |
| 850 | void setClipPlane() |
| 851 | { |
| 852 | if (!m_initializationSuccessful) |
| 853 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 854 | |
| 855 | // Deprecated in 3.3 core |
| 856 | } |
| 857 | |
| 858 | void setSeamlessCubemap() |
| 859 | { |
| 860 | if (!m_initializationSuccessful) |
| 861 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 862 | // Not supported in GL2 |
| 863 | } |
| 864 | |
| 865 | void setVerticesPerPatch() |
| 866 | { |
| 867 | // Not supported in GL2 |
| 868 | } |
| 869 | |
| 870 | #define SUPPORTS_FEATURE(Feature, IsSupported) \ |
| 871 | QVERIFY(m_glHelper.supportsFeature(Feature) == IsSupported); |
| 872 | |
| 873 | void supportsFeature() |
| 874 | { |
| 875 | SUPPORTS_FEATURE(GraphicsHelperInterface::UniformBufferObject, false); |
| 876 | SUPPORTS_FEATURE(GraphicsHelperInterface::BindableFragmentOutputs, false); |
| 877 | SUPPORTS_FEATURE(GraphicsHelperInterface::PrimitiveRestart, false); |
| 878 | SUPPORTS_FEATURE(GraphicsHelperInterface::RenderBufferDimensionRetrieval, false); |
| 879 | SUPPORTS_FEATURE(GraphicsHelperInterface::TextureDimensionRetrieval, true); |
| 880 | SUPPORTS_FEATURE(GraphicsHelperInterface::UniformBufferObject, false); |
| 881 | SUPPORTS_FEATURE(GraphicsHelperInterface::ShaderStorageObject, false); |
| 882 | SUPPORTS_FEATURE(GraphicsHelperInterface::Compute, false); |
| 883 | SUPPORTS_FEATURE(GraphicsHelperInterface::DrawBuffersBlend, false); |
| 884 | SUPPORTS_FEATURE(GraphicsHelperInterface::Tessellation, false); |
| 885 | SUPPORTS_FEATURE(GraphicsHelperInterface::BlitFramebuffer, false); |
| 886 | SUPPORTS_FEATURE(GraphicsHelperInterface::IndirectDrawing, false); |
| 887 | SUPPORTS_FEATURE(GraphicsHelperInterface::MapBuffer, true); |
| 888 | SUPPORTS_FEATURE(GraphicsHelperInterface::Fences, false); |
| 889 | } |
| 890 | |
| 891 | |
| 892 | #define ADD_UNIFORM_ENTRY(FragShader, Name, Type, ComponentSize, ExpectedRawSize) \ |
| 893 | QTest::newRow(#FragShader"_"#Type) << FragShader << QStringLiteral(Name) << Type << ComponentSize << ExpectedRawSize; |
| 894 | |
| 895 | void uniformsByteSize_data() |
| 896 | { |
| 897 | QTest::addColumn<QByteArray>("fragShader"); |
| 898 | QTest::addColumn<QString>("name"); |
| 899 | QTest::addColumn<int>("type"); |
| 900 | QTest::addColumn<int>("componentSize"); |
| 901 | QTest::addColumn<int>("expectedByteSize"); |
| 902 | |
| 903 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloat, "multiplier", GL_FLOAT, 1, 4); |
| 904 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloat, "multiplierVec2", GL_FLOAT_VEC2, 1, 4 * 2); |
| 905 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloat, "multiplierVec3",GL_FLOAT_VEC3, 1, 4 * 3); |
| 906 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloat, "multiplierVec4", GL_FLOAT_VEC4, 1, 4 * 4); |
| 907 | |
| 908 | ADD_UNIFORM_ENTRY(fragCodeUniformsInt, "multiplier", GL_INT, 1, 4); |
| 909 | ADD_UNIFORM_ENTRY(fragCodeUniformsInt, "multiplierVec2", GL_INT_VEC2, 1, 4 * 2); |
| 910 | ADD_UNIFORM_ENTRY(fragCodeUniformsInt, "multiplierVec3", GL_INT_VEC3, 1, 4 * 3); |
| 911 | ADD_UNIFORM_ENTRY(fragCodeUniformsInt, "multiplierVec4", GL_INT_VEC4, 1, 4 * 4); |
| 912 | |
| 913 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m2", GL_FLOAT_MAT2, 1, 4 * 2 * 2); |
| 914 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m23", GL_FLOAT_MAT2x3, 1, 4 * 2 * 3); |
| 915 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m32", GL_FLOAT_MAT3x2, 1, 4 * 3 * 2); |
| 916 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m24", GL_FLOAT_MAT2x4, 1, 4 * 2 * 4); |
| 917 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m42", GL_FLOAT_MAT4x2, 1, 4 * 4 * 2); |
| 918 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m3", GL_FLOAT_MAT3, 1, 4 * 3 * 3); |
| 919 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m34", GL_FLOAT_MAT3x4, 1, 4 * 3 * 4); |
| 920 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m43", GL_FLOAT_MAT4x3, 1, 4 * 4 * 3); |
| 921 | ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m4", GL_FLOAT_MAT4, 1, 4 * 4 * 4); |
| 922 | |
| 923 | ADD_UNIFORM_ENTRY(fragCodeSamplers, "s1", GL_SAMPLER_1D, 1, 4); |
| 924 | ADD_UNIFORM_ENTRY(fragCodeSamplers, "s2", GL_SAMPLER_2D, 1, 4); |
| 925 | ADD_UNIFORM_ENTRY(fragCodeSamplers, "s3", GL_SAMPLER_3D, 1, 4); |
| 926 | ADD_UNIFORM_ENTRY(fragCodeSamplers, "scube", GL_SAMPLER_CUBE, 1, 4); |
| 927 | } |
| 928 | |
| 929 | void uniformsByteSize() |
| 930 | { |
| 931 | if (!m_initializationSuccessful) |
| 932 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 933 | |
| 934 | // GIVEN |
| 935 | QFETCH(QByteArray, fragShader); |
| 936 | QFETCH(QString, name); |
| 937 | QFETCH(int, type); |
| 938 | QFETCH(int, componentSize); |
| 939 | QFETCH(int, expectedByteSize); |
| 940 | |
| 941 | QOpenGLShaderProgram shaderProgram; |
| 942 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 943 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragShader); |
| 944 | QVERIFY(shaderProgram.link()); |
| 945 | |
| 946 | GLint location = shaderProgram.uniformLocation(name); |
| 947 | // WHEN |
| 948 | const std::vector<ShaderUniform> activeUniforms = m_glHelper.programUniformsAndLocations(shaderProgram.programId()); |
| 949 | ShaderUniform matchingUniform; |
| 950 | for (const ShaderUniform &u : activeUniforms) { |
| 951 | if (u.m_location == location) { |
| 952 | matchingUniform = u; |
| 953 | break; |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | // THEN |
| 958 | QCOMPARE(matchingUniform.m_location, location); |
| 959 | QCOMPARE(matchingUniform.m_type, GLuint(type)); |
| 960 | QCOMPARE(matchingUniform.m_size, componentSize); |
| 961 | |
| 962 | // WHEN |
| 963 | const int computedRawByteSize = m_glHelper.uniformByteSize(matchingUniform); |
| 964 | |
| 965 | // THEN |
| 966 | QCOMPARE(expectedByteSize, computedRawByteSize); |
| 967 | |
| 968 | // Restore |
| 969 | m_func->glUseProgram(0); |
| 970 | } |
| 971 | |
| 972 | void useProgram() |
| 973 | { |
| 974 | if (!m_initializationSuccessful) |
| 975 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 976 | |
| 977 | // GIVEN |
| 978 | QOpenGLShaderProgram shaderProgram; |
| 979 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 980 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloat); |
| 981 | |
| 982 | // THEN |
| 983 | QVERIFY(shaderProgram.link()); |
| 984 | |
| 985 | GLint currentProg = 0; |
| 986 | m_func->glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProg); |
| 987 | QVERIFY(currentProg == 0); |
| 988 | |
| 989 | // WHEN |
| 990 | m_glHelper.useProgram(shaderProgram.programId()); |
| 991 | |
| 992 | // THEN |
| 993 | m_func->glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProg); |
| 994 | QCOMPARE(GLuint(currentProg), shaderProgram.programId()); |
| 995 | |
| 996 | // WHEN |
| 997 | m_glHelper.useProgram(0); |
| 998 | |
| 999 | // THEN |
| 1000 | m_func->glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProg); |
| 1001 | QVERIFY(currentProg == 0); |
| 1002 | } |
| 1003 | |
| 1004 | void vertexAttribDivisor() |
| 1005 | { |
| 1006 | if (!m_initializationSuccessful) |
| 1007 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1008 | // Not available in 3.2 |
| 1009 | } |
| 1010 | |
| 1011 | void vertexAttributePointer() |
| 1012 | { |
| 1013 | if (!m_initializationSuccessful) |
| 1014 | QSKIP("Initialization failed, OpenGL 4.3 Core functions not supported"); |
| 1015 | |
| 1016 | // GIVEN |
| 1017 | QOpenGLVertexArrayObject vao; |
| 1018 | vao.create(); |
| 1019 | QOpenGLVertexArrayObject::Binder binder(&vao); |
| 1020 | |
| 1021 | QOpenGLShaderProgram shaderProgram; |
| 1022 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1023 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeSamplers); |
| 1024 | QVERIFY(shaderProgram.link()); |
| 1025 | |
| 1026 | GLint positionLocation = m_func->glGetAttribLocation(shaderProgram.programId(), "vertexPosition"); |
| 1027 | GLint texCoordLocation = m_func->glGetAttribLocation(shaderProgram.programId(), "vertexTexCoord"); |
| 1028 | |
| 1029 | const int vertexCount = 99; |
| 1030 | QOpenGLBuffer positionBuffer(QOpenGLBuffer::VertexBuffer); |
| 1031 | positionBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 1032 | positionBuffer.create(); |
| 1033 | positionBuffer.bind(); |
| 1034 | positionBuffer.allocate(vertexCount * sizeof(QVector3D)); |
| 1035 | |
| 1036 | QOpenGLBuffer texCoordBuffer(QOpenGLBuffer::VertexBuffer); |
| 1037 | texCoordBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 1038 | texCoordBuffer.create(); |
| 1039 | texCoordBuffer.allocate(vertexCount * sizeof(QVector2D)); |
| 1040 | |
| 1041 | // WHEN |
| 1042 | shaderProgram.bind(); |
| 1043 | positionBuffer.bind(); |
| 1044 | m_glHelper.enableVertexAttributeArray(positionLocation); |
| 1045 | m_glHelper.vertexAttributePointer(GL_FLOAT_VEC3, positionLocation, 3, GL_FLOAT, GL_TRUE, 0, 0); |
| 1046 | |
| 1047 | texCoordBuffer.bind(); |
| 1048 | m_glHelper.enableVertexAttributeArray(texCoordLocation); |
| 1049 | m_glHelper.vertexAttributePointer(GL_FLOAT_VEC2, texCoordLocation, 2, GL_FLOAT, GL_TRUE, 0, 0); |
| 1050 | |
| 1051 | // THEN |
| 1052 | const GLint error = m_func->glGetError(); |
| 1053 | QVERIFY(error == 0); |
| 1054 | } |
| 1055 | |
| 1056 | void glUniform1fv() |
| 1057 | { |
| 1058 | if (!m_initializationSuccessful) |
| 1059 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1060 | |
| 1061 | // GIVEN |
| 1062 | QOpenGLShaderProgram shaderProgram; |
| 1063 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1064 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloat); |
| 1065 | QVERIFY(shaderProgram.link()); |
| 1066 | |
| 1067 | // WHEN |
| 1068 | m_func->glUseProgram(shaderProgram.programId()); |
| 1069 | GLfloat value = 883.0f; |
| 1070 | const GLint location = shaderProgram.uniformLocation("multiplier"); |
| 1071 | m_glHelper.glUniform1fv(location, 1, &value); |
| 1072 | |
| 1073 | // THEN |
| 1074 | GLfloat setValue = 0.0f; |
| 1075 | m_func->glGetUniformfv(shaderProgram.programId(), location, &setValue); |
| 1076 | QCOMPARE(value, setValue); |
| 1077 | |
| 1078 | // Restore |
| 1079 | m_func->glUseProgram(0); |
| 1080 | } |
| 1081 | |
| 1082 | void glUniform2fv() |
| 1083 | { |
| 1084 | if (!m_initializationSuccessful) |
| 1085 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1086 | |
| 1087 | // GIVEN |
| 1088 | QOpenGLShaderProgram shaderProgram; |
| 1089 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1090 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloat); |
| 1091 | QVERIFY(shaderProgram.link()); |
| 1092 | |
| 1093 | // WHEN |
| 1094 | m_func->glUseProgram(shaderProgram.programId()); |
| 1095 | GLfloat values[2] = { 383.0f, 427.0f }; |
| 1096 | const GLint location = shaderProgram.uniformLocation("multiplierVec2"); |
| 1097 | m_glHelper.glUniform2fv(location, 1, values); |
| 1098 | |
| 1099 | // THEN |
| 1100 | GLfloat setValues[2] = { 0.0f, 0.0f }; |
| 1101 | m_func->glGetUniformfv(shaderProgram.programId(), location, setValues); |
| 1102 | for (int i = 0; i < 2; ++i) |
| 1103 | QCOMPARE(setValues[i], values[i]); |
| 1104 | |
| 1105 | // Restore |
| 1106 | m_func->glUseProgram(0); |
| 1107 | } |
| 1108 | |
| 1109 | void glUniform3fv() |
| 1110 | { |
| 1111 | if (!m_initializationSuccessful) |
| 1112 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1113 | |
| 1114 | // GIVEN |
| 1115 | QOpenGLShaderProgram shaderProgram; |
| 1116 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1117 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloat); |
| 1118 | QVERIFY(shaderProgram.link()); |
| 1119 | |
| 1120 | // WHEN |
| 1121 | m_func->glUseProgram(shaderProgram.programId()); |
| 1122 | GLfloat values[3] = { 572.0f, 1340.0f, 1584.0f }; |
| 1123 | const GLint location = shaderProgram.uniformLocation("multiplierVec3"); |
| 1124 | m_glHelper.glUniform3fv(location, 1, values); |
| 1125 | |
| 1126 | // THEN |
| 1127 | GLfloat setValues[3] = { 0.0f, 0.0f, 0.0f }; |
| 1128 | m_func->glGetUniformfv(shaderProgram.programId(), location, setValues); |
| 1129 | for (int i = 0; i < 3; ++i) |
| 1130 | QCOMPARE(setValues[i], values[i]); |
| 1131 | |
| 1132 | // Restore |
| 1133 | m_func->glUseProgram(0); |
| 1134 | } |
| 1135 | |
| 1136 | void glUniform4fv() |
| 1137 | { |
| 1138 | if (!m_initializationSuccessful) |
| 1139 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1140 | |
| 1141 | // GIVEN |
| 1142 | QOpenGLShaderProgram shaderProgram; |
| 1143 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1144 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloat); |
| 1145 | QVERIFY(shaderProgram.link()); |
| 1146 | |
| 1147 | // WHEN |
| 1148 | m_func->glUseProgram(shaderProgram.programId()); |
| 1149 | GLfloat values[4] = { 454.0f, 350.0f, 883.0f, 355.0f }; |
| 1150 | const GLint location = shaderProgram.uniformLocation("multiplierVec4"); |
| 1151 | m_glHelper.glUniform4fv(location, 1, values); |
| 1152 | |
| 1153 | // THEN |
| 1154 | GLfloat setValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 1155 | m_func->glGetUniformfv(shaderProgram.programId(), location, setValues); |
| 1156 | for (int i = 0; i < 4; ++i) |
| 1157 | QCOMPARE(setValues[i], values[i]); |
| 1158 | |
| 1159 | // Restore |
| 1160 | m_func->glUseProgram(0); |
| 1161 | } |
| 1162 | |
| 1163 | void glUniform1iv() |
| 1164 | { |
| 1165 | if (!m_initializationSuccessful) |
| 1166 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1167 | |
| 1168 | // GIVEN |
| 1169 | QOpenGLShaderProgram shaderProgram; |
| 1170 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1171 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsInt); |
| 1172 | QVERIFY(shaderProgram.link()); |
| 1173 | |
| 1174 | // WHEN |
| 1175 | m_func->glUseProgram(shaderProgram.programId()); |
| 1176 | GLint value = 883; |
| 1177 | const GLint location = shaderProgram.uniformLocation("multiplier"); |
| 1178 | m_glHelper.glUniform1iv(location, 1, &value); |
| 1179 | |
| 1180 | // THEN |
| 1181 | GLint setValue = 0; |
| 1182 | m_func->glGetUniformiv(shaderProgram.programId(), location, &setValue); |
| 1183 | QCOMPARE(value, setValue); |
| 1184 | |
| 1185 | // Restore |
| 1186 | m_func->glUseProgram(0); |
| 1187 | } |
| 1188 | |
| 1189 | void glUniform2iv() |
| 1190 | { |
| 1191 | if (!m_initializationSuccessful) |
| 1192 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1193 | |
| 1194 | // GIVEN |
| 1195 | QOpenGLShaderProgram shaderProgram; |
| 1196 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1197 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsInt); |
| 1198 | QVERIFY(shaderProgram.link()); |
| 1199 | |
| 1200 | // WHEN |
| 1201 | m_func->glUseProgram(shaderProgram.programId()); |
| 1202 | GLint values[2] = { 383, 427 }; |
| 1203 | const GLint location = shaderProgram.uniformLocation("multiplierVec2"); |
| 1204 | m_glHelper.glUniform2iv(location, 1, values); |
| 1205 | |
| 1206 | // THEN |
| 1207 | GLint setValues[2] = { 0, 0 }; |
| 1208 | m_func->glGetUniformiv(shaderProgram.programId(), location, setValues); |
| 1209 | for (int i = 0; i < 2; ++i) |
| 1210 | QCOMPARE(values[i], setValues[i]); |
| 1211 | |
| 1212 | // Restore |
| 1213 | m_func->glUseProgram(0); |
| 1214 | } |
| 1215 | |
| 1216 | void glUniform3iv() |
| 1217 | { |
| 1218 | if (!m_initializationSuccessful) |
| 1219 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1220 | |
| 1221 | // GIVEN |
| 1222 | QOpenGLShaderProgram shaderProgram; |
| 1223 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1224 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsInt); |
| 1225 | QVERIFY(shaderProgram.link()); |
| 1226 | |
| 1227 | // WHEN |
| 1228 | m_func->glUseProgram(shaderProgram.programId()); |
| 1229 | GLint values[3] = { 572, 1340, 1584 }; |
| 1230 | const GLint location = shaderProgram.uniformLocation("multiplierVec3"); |
| 1231 | m_glHelper.glUniform3iv(location, 1, values); |
| 1232 | |
| 1233 | // THEN |
| 1234 | GLint setValues[3] = { 0, 0, 0 }; |
| 1235 | m_func->glGetUniformiv(shaderProgram.programId(), location, setValues); |
| 1236 | for (int i = 0; i < 3; ++i) |
| 1237 | QCOMPARE(values[i], setValues[i]); |
| 1238 | |
| 1239 | // Restore |
| 1240 | m_func->glUseProgram(0); |
| 1241 | } |
| 1242 | |
| 1243 | void glUniform4iv() |
| 1244 | { |
| 1245 | if (!m_initializationSuccessful) |
| 1246 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1247 | |
| 1248 | // GIVEN |
| 1249 | QOpenGLShaderProgram shaderProgram; |
| 1250 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1251 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsInt); |
| 1252 | QVERIFY(shaderProgram.link()); |
| 1253 | |
| 1254 | // WHEN |
| 1255 | m_func->glUseProgram(shaderProgram.programId()); |
| 1256 | GLint values[4] = { 454, 350, 883, 355 }; |
| 1257 | const GLint location = shaderProgram.uniformLocation("multiplierVec4"); |
| 1258 | m_glHelper.glUniform4iv(location, 1, values); |
| 1259 | |
| 1260 | // THEN |
| 1261 | GLint setValues[4] = { 0, 0, 0, 0 }; |
| 1262 | m_func->glGetUniformiv(shaderProgram.programId(), location, setValues); |
| 1263 | for (int i = 0; i < 4; ++i) |
| 1264 | QCOMPARE(values[i], setValues[i]); |
| 1265 | |
| 1266 | // Restore |
| 1267 | m_func->glUseProgram(0); |
| 1268 | } |
| 1269 | |
| 1270 | void glUniform1uiv() |
| 1271 | { |
| 1272 | if (!m_initializationSuccessful) |
| 1273 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1274 | // Not supported by GL2 |
| 1275 | } |
| 1276 | |
| 1277 | void glUniform2uiv() |
| 1278 | { |
| 1279 | if (!m_initializationSuccessful) |
| 1280 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1281 | // Not supported by GL2 |
| 1282 | } |
| 1283 | |
| 1284 | void glUniform3uiv() |
| 1285 | { |
| 1286 | if (!m_initializationSuccessful) |
| 1287 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1288 | // Not supported by GL2 |
| 1289 | } |
| 1290 | |
| 1291 | void glUniform4uiv() |
| 1292 | { |
| 1293 | if (!m_initializationSuccessful) |
| 1294 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1295 | // Not supported by GL2 |
| 1296 | } |
| 1297 | |
| 1298 | void glUniformMatrix2fv() |
| 1299 | { |
| 1300 | if (!m_initializationSuccessful) |
| 1301 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1302 | |
| 1303 | // GIVEN |
| 1304 | QOpenGLShaderProgram shaderProgram; |
| 1305 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1306 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloatMatrices); |
| 1307 | QVERIFY(shaderProgram.link()); |
| 1308 | |
| 1309 | // WHEN |
| 1310 | m_func->glUseProgram(shaderProgram.programId()); |
| 1311 | GLfloat values[4] = { 454.0f, 350.0f, 883.0f, 355.0f }; |
| 1312 | const GLint location = shaderProgram.uniformLocation("m2"); |
| 1313 | m_glHelper.glUniformMatrix2fv(location, 1, values); |
| 1314 | |
| 1315 | // THEN |
| 1316 | GLfloat setValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 1317 | m_func->glGetUniformfv(shaderProgram.programId(), location, setValues); |
| 1318 | for (int i = 0; i < 4; ++i) |
| 1319 | QCOMPARE(values[i], setValues[i]); |
| 1320 | |
| 1321 | // Restore |
| 1322 | m_func->glUseProgram(0); |
| 1323 | } |
| 1324 | |
| 1325 | void glUniformMatrix3fv() |
| 1326 | { |
| 1327 | if (!m_initializationSuccessful) |
| 1328 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1329 | |
| 1330 | // GIVEN |
| 1331 | QOpenGLShaderProgram shaderProgram; |
| 1332 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1333 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloatMatrices); |
| 1334 | QVERIFY(shaderProgram.link()); |
| 1335 | |
| 1336 | // WHEN |
| 1337 | m_func->glUseProgram(shaderProgram.programId()); |
| 1338 | GLfloat values[9] = { 454.0f, 350.0f, 883.0f, 355.0f, 1340.0f, 1584.0f, 1200.0f, 427.0f, 396.0f }; |
| 1339 | const GLint location = shaderProgram.uniformLocation("m3"); |
| 1340 | m_glHelper.glUniformMatrix3fv(location, 1, values); |
| 1341 | |
| 1342 | // THEN |
| 1343 | GLfloat setValues[9] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; |
| 1344 | m_func->glGetUniformfv(shaderProgram.programId(), location, setValues); |
| 1345 | for (int i = 0; i < 9; ++i) |
| 1346 | QCOMPARE(values[i], setValues[i]); |
| 1347 | |
| 1348 | // Restore |
| 1349 | m_func->glUseProgram(0); |
| 1350 | } |
| 1351 | |
| 1352 | void glUniformMatrix4fv() |
| 1353 | { |
| 1354 | if (!m_initializationSuccessful) |
| 1355 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1356 | |
| 1357 | // GIVEN |
| 1358 | QOpenGLShaderProgram shaderProgram; |
| 1359 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Vertex, vertCode); |
| 1360 | shaderProgram.addShaderFromSourceCode(QOpenGLShader::Fragment, fragCodeUniformsFloatMatrices); |
| 1361 | QVERIFY(shaderProgram.link()); |
| 1362 | |
| 1363 | // WHEN |
| 1364 | m_func->glUseProgram(shaderProgram.programId()); |
| 1365 | GLfloat values[16] = { 454.0f, 350.0f, 883.0f, 355.0f, 1340.0f, 1584.0f, 1200.0f, 427.0f, 396.0f, 1603.0f, 55.0f, 5.7f, 383.0f, 6.2f, 5.3f, 327.0f }; |
| 1366 | const GLint location = shaderProgram.uniformLocation("m4"); |
| 1367 | m_glHelper.glUniformMatrix4fv(location, 1, values); |
| 1368 | |
| 1369 | // THEN |
| 1370 | GLfloat setValues[16] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; |
| 1371 | m_func->glGetUniformfv(shaderProgram.programId(), location, setValues); |
| 1372 | for (int i = 0; i < 16; ++i) |
| 1373 | QCOMPARE(values[i], setValues[i]); |
| 1374 | |
| 1375 | // Restore |
| 1376 | m_func->glUseProgram(0); |
| 1377 | } |
| 1378 | |
| 1379 | void glUniformMatrix2x3fv() |
| 1380 | { |
| 1381 | if (!m_initializationSuccessful) |
| 1382 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1383 | // Not supported by GL2 |
| 1384 | } |
| 1385 | |
| 1386 | void glUniformMatrix3x2fv() |
| 1387 | { |
| 1388 | if (!m_initializationSuccessful) |
| 1389 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1390 | // Not supported by GL2 |
| 1391 | } |
| 1392 | |
| 1393 | void glUniformMatrix2x4fv() |
| 1394 | { |
| 1395 | if (!m_initializationSuccessful) |
| 1396 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1397 | // Not supported by GL2 |
| 1398 | } |
| 1399 | |
| 1400 | void glUniformMatrix4x2fv() |
| 1401 | { |
| 1402 | if (!m_initializationSuccessful) |
| 1403 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1404 | // Not supported by GL2 |
| 1405 | } |
| 1406 | |
| 1407 | void glUniformMatrix3x4fv() |
| 1408 | { |
| 1409 | if (!m_initializationSuccessful) |
| 1410 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1411 | // Not supported by GL2 |
| 1412 | } |
| 1413 | |
| 1414 | void glUniformMatrix4x3fv() |
| 1415 | { |
| 1416 | if (!m_initializationSuccessful) |
| 1417 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1418 | // Not supported by GL2 |
| 1419 | } |
| 1420 | |
| 1421 | void blitFramebuffer() |
| 1422 | { |
| 1423 | if (!m_initializationSuccessful) |
| 1424 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1425 | // Not supported by GL2 |
| 1426 | } |
| 1427 | |
| 1428 | #define ADD_GL_TYPE_ENTRY(Type, Expected) \ |
| 1429 | QTest::newRow(#Type) << Type << Expected; |
| 1430 | |
| 1431 | void uniformTypeFromGLType_data() |
| 1432 | { |
| 1433 | QTest::addColumn<int>("glType"); |
| 1434 | QTest::addColumn<UniformType>("expected"); |
| 1435 | |
| 1436 | ADD_GL_TYPE_ENTRY(GL_FLOAT, UniformType::Float); |
| 1437 | ADD_GL_TYPE_ENTRY(GL_FLOAT_VEC2, UniformType::Vec2); |
| 1438 | ADD_GL_TYPE_ENTRY(GL_FLOAT_VEC3, UniformType::Vec3); |
| 1439 | ADD_GL_TYPE_ENTRY(GL_FLOAT_VEC3, UniformType::Vec3); |
| 1440 | ADD_GL_TYPE_ENTRY(GL_FLOAT_VEC2, UniformType::Vec2); |
| 1441 | ADD_GL_TYPE_ENTRY(GL_FLOAT_VEC3, UniformType::Vec3); |
| 1442 | ADD_GL_TYPE_ENTRY(GL_FLOAT_VEC3, UniformType::Vec3); |
| 1443 | ADD_GL_TYPE_ENTRY(GL_INT, UniformType::Int); |
| 1444 | ADD_GL_TYPE_ENTRY(GL_INT_VEC2, UniformType::IVec2); |
| 1445 | ADD_GL_TYPE_ENTRY(GL_INT_VEC3, UniformType::IVec3); |
| 1446 | ADD_GL_TYPE_ENTRY(GL_INT_VEC4, UniformType::IVec4); |
| 1447 | ADD_GL_TYPE_ENTRY(GL_BOOL, UniformType::Bool); |
| 1448 | ADD_GL_TYPE_ENTRY(GL_BOOL_VEC2, UniformType::BVec2); |
| 1449 | ADD_GL_TYPE_ENTRY(GL_BOOL_VEC3, UniformType::BVec3); |
| 1450 | ADD_GL_TYPE_ENTRY(GL_BOOL_VEC4, UniformType::BVec4); |
| 1451 | ADD_GL_TYPE_ENTRY(GL_FLOAT_MAT2, UniformType::Mat2); |
| 1452 | ADD_GL_TYPE_ENTRY(GL_FLOAT_MAT3, UniformType::Mat3); |
| 1453 | ADD_GL_TYPE_ENTRY(GL_FLOAT_MAT4, UniformType::Mat4); |
| 1454 | ADD_GL_TYPE_ENTRY(GL_SAMPLER_1D, UniformType::Sampler); |
| 1455 | ADD_GL_TYPE_ENTRY(GL_SAMPLER_1D_SHADOW, UniformType::Sampler); |
| 1456 | ADD_GL_TYPE_ENTRY(GL_SAMPLER_2D, UniformType::Sampler); |
| 1457 | ADD_GL_TYPE_ENTRY(GL_SAMPLER_2D_SHADOW, UniformType::Sampler); |
| 1458 | ADD_GL_TYPE_ENTRY(GL_SAMPLER_3D, UniformType::Sampler); |
| 1459 | ADD_GL_TYPE_ENTRY(GL_SAMPLER_CUBE, UniformType::Sampler); |
| 1460 | } |
| 1461 | |
| 1462 | void uniformTypeFromGLType() |
| 1463 | { |
| 1464 | // GIVEN |
| 1465 | QFETCH(int, glType); |
| 1466 | QFETCH(UniformType, expected); |
| 1467 | |
| 1468 | // WHEN |
| 1469 | UniformType computed = m_glHelper.uniformTypeFromGLType(glType); |
| 1470 | |
| 1471 | // THEN |
| 1472 | QCOMPARE(computed, expected); |
| 1473 | } |
| 1474 | |
| 1475 | void drawBuffer() |
| 1476 | { |
| 1477 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1478 | // Not supported by GL2 |
| 1479 | } |
| 1480 | |
| 1481 | void readBuffer() |
| 1482 | { |
| 1483 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1484 | // Not supported by GL2 |
| 1485 | } |
| 1486 | |
| 1487 | void fenceSync() |
| 1488 | { |
| 1489 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1490 | // Not supported by GL2 |
| 1491 | } |
| 1492 | |
| 1493 | void clientWaitSync() |
| 1494 | { |
| 1495 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1496 | // Not supported by GL2 |
| 1497 | } |
| 1498 | |
| 1499 | void waitSync() |
| 1500 | { |
| 1501 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1502 | // Not supported by GL2 |
| 1503 | } |
| 1504 | |
| 1505 | void wasSyncSignaled() |
| 1506 | { |
| 1507 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1508 | // Not supported by GL2 |
| 1509 | } |
| 1510 | |
| 1511 | void deleteSync() |
| 1512 | { |
| 1513 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1514 | // Not supported by GL2 |
| 1515 | } |
| 1516 | |
| 1517 | void rasterMode() |
| 1518 | { |
| 1519 | if (!m_initializationSuccessful) |
| 1520 | QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); |
| 1521 | |
| 1522 | m_func->glGetError(); |
| 1523 | |
| 1524 | // WHEN |
| 1525 | m_glHelper.rasterMode(GL_FRONT_AND_BACK, GL_LINE); |
| 1526 | |
| 1527 | // THEN |
| 1528 | const GLint error = m_func->glGetError(); |
| 1529 | QVERIFY(error == 0); |
| 1530 | GLint p; |
| 1531 | m_func->glGetIntegerv(GL_POLYGON_MODE, &p); |
| 1532 | QCOMPARE(p, GL_LINE); |
| 1533 | } |
| 1534 | |
| 1535 | private: |
| 1536 | QScopedPointer<QWindow> m_window; |
| 1537 | QOpenGLContext m_glContext; |
| 1538 | GraphicsHelperGL2 m_glHelper; |
| 1539 | QOpenGLFunctions_2_0 *m_func = nullptr; |
| 1540 | QOpenGLExtraFunctions *m_extraFunctions; |
| 1541 | bool m_initializationSuccessful = false; |
| 1542 | }; |
| 1543 | |
| 1544 | QT_END_NAMESPACE |
| 1545 | |
| 1546 | #endif |
| 1547 | |
| 1548 | int main(int argc, char *argv[]) |
| 1549 | { |
| 1550 | #ifdef TEST_SHOULD_BE_PERFORMED |
| 1551 | QGuiApplication app(argc, argv); |
| 1552 | app.setAttribute(Qt::AA_Use96Dpi, true); |
| 1553 | tst_GraphicsHelperGL2 tc; |
| 1554 | QTEST_SET_MAIN_SOURCE_PATH |
| 1555 | return QTest::qExec(&tc, argc, argv); |
| 1556 | #endif |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
| 1560 | #ifdef TEST_SHOULD_BE_PERFORMED |
| 1561 | #include "tst_graphicshelpergl2.moc" |
| 1562 | #endif |