| 45 | } |
| 46 | |
| 47 | void RunTestInOpenGLOffscreenEnvironment(char const * testName, testing::TestFunction const & fn) |
| 48 | { |
| 49 | std::vector<char> buf(strlen(testName) + 1); |
| 50 | strcpy(buf.data(), testName); |
| 51 | char * raw = buf.data(); |
| 52 | |
| 53 | int argc = 1; |
| 54 | QApplication app(argc, &raw); |
| 55 | |
| 56 | QSurfaceFormat fmt; |
| 57 | fmt.setAlphaBufferSize(8); |
| 58 | fmt.setBlueBufferSize(8); |
| 59 | fmt.setGreenBufferSize(8); |
| 60 | fmt.setRedBufferSize(8); |
| 61 | fmt.setStencilBufferSize(0); |
| 62 | fmt.setSamples(0); |
| 63 | fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer); |
| 64 | fmt.setSwapInterval(1); |
| 65 | fmt.setDepthBufferSize(16); |
| 66 | fmt.setProfile(QSurfaceFormat::CoreProfile); |
| 67 | fmt.setVersion(3, 2); |
| 68 | |
| 69 | auto surface = std::make_unique<QOffscreenSurface>(); |
| 70 | surface->setFormat(fmt); |
| 71 | surface->create(); |
| 72 | |
| 73 | auto context = std::make_unique<QOpenGLContext>(); |
| 74 | context->setFormat(fmt); |
| 75 | context->create(); |
| 76 | context->makeCurrent(surface.get()); |
| 77 | |
| 78 | if (fn) |
| 79 | fn(); |
| 80 | |
| 81 | context->doneCurrent(); |
| 82 | surface->destroy(); |
| 83 | |
| 84 | QTimer::singleShot(0, &app, SLOT(quit())); |
| 85 | app.exec(); |
| 86 | } |