void CustomWindow::vsyncChangedHandler( bool vsync ) { QSurfaceFormat fmt = format(); // Grab OpenGL context surface format if it's ready to go, it's more filled out than the window one // It can be unitialized on startup before so check that it exists before using it if( openglContext() ) { fmt = openglContext()->format(); } #if defined( Q_OS_WIN ) fmt.setSwapBehavior( vsync ? QSurfaceFormat::SingleBuffer : QSurfaceFormat::DoubleBuffer ); #elif defined( Q_OS_MACX ) // Leave it alone, OS X happily accepts single buffering #endif fmt.setSwapInterval( vsync ? 1 : 0 ); // Window must be reset to apply the changes resetPlatformWindow( fmt ); emit doubleBufferedChanged( fmt.swapBehavior() == QSurfaceFormat::DoubleBuffer ); }
void KisOpenGL::initialize() { #ifdef HAVE_OPENGL dbgUI << "OpenGL: initializing"; KisConfig cfg; QSurfaceFormat format; format.setProfile(QSurfaceFormat::CompatibilityProfile); format.setOptions(QSurfaceFormat::DeprecatedFunctions); format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setVersion(3, 2); // if (cfg.disableDoubleBuffering()) { if (false) { format.setSwapBehavior(QSurfaceFormat::SingleBuffer); } else { format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); } format.setSwapInterval(0); // Disable vertical refresh syncing QSurfaceFormat::setDefaultFormat(format); #endif }
CustomWindow::CustomWindow( QWindow *parent ) : QQuickWindow( parent ) { connect( this, &CustomWindow::vsyncChanged, this, &CustomWindow::vsyncChangedHandler ); // Reinitalize the scene graph when the OpenGL context gets destroyed // Needed because only when the context gets recreated is the format read setPersistentOpenGLContext( false ); setPersistentSceneGraph( false ); // Grab window surface format as the OpenGL context will not be created yet QSurfaceFormat fmt = format(); #if defined( Q_OS_WIN ) // Set buffering mode // Testing shows that on Windows, vsync stays on (swapBuffers() blocks) while single buffered // even when the swap interval is 0 and even while fullscreen! So, we have to turn on double buffering if we // want vsync to actually be off, but turn on single buffering while vsynced to avoid unnecessary additional latency fmt.setSwapBehavior( vsync ? QSurfaceFormat::SingleBuffer : QSurfaceFormat::DoubleBuffer ); emit doubleBufferedChanged( fmt.swapBehavior() == QSurfaceFormat::DoubleBuffer ); #elif defined( Q_OS_MACX ) fmt.setSwapBehavior( QSurfaceFormat::SingleBuffer ); emit doubleBufferedChanged( fmt.swapBehavior() == QSurfaceFormat::DoubleBuffer ); // For proper OS X fullscreen setFlags( flags() | Qt::WindowFullscreenButtonHint ); #endif // Enforce the default value for vsync fmt.setSwapInterval( vsync ? 1 : 0 ); setFormat( fmt ); }
SsvepBciScreen::SsvepBciScreen(QSharedPointer<SsvepBci> pSsvepBci, QSharedPointer<SsvepBciSetupStimulusWidget> pSsvepBciSetupStimulusWidget, QOpenGLWidget *parent) : m_pSsvepBci(pSsvepBci) , m_pSsvepBciSetupStimulusWidget(pSsvepBciSetupStimulusWidget) , m_pScreenKeyboard(QSharedPointer<ScreenKeyboard>(new ScreenKeyboard(m_pSsvepBci, m_pSsvepBciSetupStimulusWidget, QSharedPointer<SsvepBciScreen>(this)))) , m_dXPosCross(0.5) , m_dYPosCross(0.5) , m_dStep(0.01) , m_bUseScreenKeyboard(false) , m_qPainter(this) , m_qCrossColor(Qt::red) , m_bClearScreen(true) { Q_UNUSED(parent); // register Meta Type qRegisterMetaType<MyQList>("MyQList"); //set format of the QOpenGLWidget (enable vsync and setup buffers) QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setSwapInterval(1); setFormat(format); // set update behaviour to preserved-swap-buffer setUpdateBehavior(UpdateBehavior::PartialUpdate); // connect classResult and frequency list signal of SsvepBci class to setClassResult slot connect(m_pSsvepBci.data(), &SsvepBci::classificationResult, this, &SsvepBciScreen::setClassResults); connect(m_pSsvepBci.data(), &SsvepBci::getFrequencyLabels, this, &SsvepBciScreen::updateFrequencyList); // initialize freqList m_lFreqList << 6.66 << 7.5 << 8.57 << 10 << 12; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); Q_INIT_RESOURCE(ARehab_vTerapeuta); QSurfaceFormat format; format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); format.setRenderableType(QSurfaceFormat::OpenGL); format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setSamples(4); format.setSwapInterval(0); //Disable VSync QSurfaceFormat::setDefaultFormat(format); ARehabGUIDesigner::ARehabMainWindow w; QFile styleFile(":/styles/main.qss"); styleFile.open(QFile::ReadOnly); app.setStyleSheet(QLatin1String(styleFile.readAll())); styleFile.close(); w.show(); return (app.exec()); }
ContextPoolContext::ContextPoolContext(QOpenGLContext* share_context, bool reserved) : reserved(reserved), count(0), surface(NULL), context(NULL) { QSurfaceFormat format; format.setMajorVersion(3); format.setMinorVersion(2); format.setSwapInterval(0); format.setSwapBehavior(QSurfaceFormat::SingleBuffer); format.setRenderableType(QSurfaceFormat::OpenGL); format.setProfile(QSurfaceFormat::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); surface = new QOffscreenSurface(); surface->setFormat(format); surface->create(); if (!surface->isValid()) { throw; } context = new QOpenGLContext(); context->setShareContext(share_context); context->setFormat(surface->requestedFormat()); if (!context->create()) { throw; } context->makeCurrent(surface); gl = context->versionFunctions<QOpenGLFunctions_3_2_Core>(); if (gl == nullptr || !gl->initializeOpenGLFunctions()) { throw; } indirect = new QOpenGLExtension_ARB_multi_draw_indirect(); if (!indirect->initializeOpenGLFunctions()) { throw; } vab = new QOpenGLExtension_ARB_vertex_attrib_binding(); if (!vab->initializeOpenGLFunctions()) { throw; } sso = new QOpenGLExtension_ARB_separate_shader_objects(); if (!sso->initializeOpenGLFunctions()) { throw; } tex = new QOpenGLExtension_ARB_texture_buffer_object(); if (!tex->initializeOpenGLFunctions()) { throw; } buffer = (QOpenGLExtension_ARB_buffer_storage)context->getProcAddress("glBufferStorage"); debug = new QOpenGLExtension_ARB_debug_output(); if (!debug->initializeOpenGLFunctions()) { throw; } debug->glDebugMessageCallbackARB(debug_callback, nullptr); debug->glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_FALSE); debug->glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, 0, GL_TRUE); context->doneCurrent(); context->moveToThread(nullptr); }
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat) { QSurfaceFormat format; EGLint redSize = 0; EGLint greenSize = 0; EGLint blueSize = 0; EGLint alphaSize = 0; EGLint depthSize = 0; EGLint stencilSize = 0; EGLint sampleCount = 0; EGLint renderableType = 0; eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType); if (referenceFormat.renderableType() == QSurfaceFormat::OpenVG && (renderableType & EGL_OPENVG_BIT)) format.setRenderableType(QSurfaceFormat::OpenVG); #ifdef EGL_VERSION_1_4 else if (referenceFormat.renderableType() == QSurfaceFormat::OpenGL && (renderableType & EGL_OPENGL_BIT)) format.setRenderableType(QSurfaceFormat::OpenGL); else if (referenceFormat.renderableType() == QSurfaceFormat::DefaultRenderableType #ifndef QT_NO_OPENGL && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL #endif && (renderableType & EGL_OPENGL_BIT)) format.setRenderableType(QSurfaceFormat::OpenGL); #endif else format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRedBufferSize(redSize); format.setGreenBufferSize(greenSize); format.setBlueBufferSize(blueSize); format.setAlphaBufferSize(alphaSize); format.setDepthBufferSize(depthSize); format.setStencilBufferSize(stencilSize); format.setSamples(sampleCount); format.setStereo(false); // EGL doesn't support stereo buffers format.setSwapInterval(referenceFormat.swapInterval()); // Clear the EGL error state because some of the above may // have errored out because the attribute is not applicable // to the surface type. Such errors don't matter. eglGetError(); return format; }
GLView::GLView(int textureWidth, int textureHeight, std::function<void(GLView *)> initCallback) : QOpenGLWidget(), _textureWidth(textureWidth), _textureHeight(textureHeight) { #if __APPLE__ QSurfaceFormat glFormat; glFormat.setVersion( 3, 3 ); glFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); glFormat.setSwapBehavior(QSurfaceFormat::SwapBehavior::SingleBuffer); glFormat.setSwapInterval(0); setFormat(glFormat); #endif _initCallback = initCallback; }
void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3, TestFunction const & fn) { std::vector<char> buf(strlen(testName) + 1); strcpy(buf.data(), testName); char * raw = buf.data(); int argc = 1; QApplication app(argc, &raw); QSurfaceFormat fmt; fmt.setAlphaBufferSize(8); fmt.setBlueBufferSize(8); fmt.setGreenBufferSize(8); fmt.setRedBufferSize(8); fmt.setStencilBufferSize(0); fmt.setSamples(0); fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer); fmt.setSwapInterval(1); fmt.setDepthBufferSize(16); if (apiOpenGLES3) { fmt.setProfile(QSurfaceFormat::CoreProfile); fmt.setVersion(3, 2); } else { fmt.setProfile(QSurfaceFormat::CompatibilityProfile); fmt.setVersion(2, 1); } auto surface = std::make_unique<QOffscreenSurface>(); surface->setFormat(fmt); surface->create(); auto context = std::make_unique<QOpenGLContext>(); context->setFormat(fmt); context->create(); context->makeCurrent(surface.get()); if (fn) fn(apiOpenGLES3); context->doneCurrent(); surface->destroy(); QTimer::singleShot(0, &app, SLOT(quit())); app.exec(); }
QTestWindow() { setSurfaceType(QSurface::OpenGLSurface); QSurfaceFormat format; // Qt Quick may need a depth and stencil buffer. Always make sure these are available. format.setDepthBufferSize(16); format.setStencilBufferSize(8); format.setVersion(4, 3); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); format.setSwapInterval(0); setFormat(format); _qGlContext.setFormat(format); _qGlContext.create(); show(); makeCurrent(); setupDebugLogger(this); gpu::Context::init<gpu::GLBackend>(); _context = std::make_shared<gpu::Context>(); auto shader = makeShader(unlit_vert, unlit_frag, gpu::Shader::BindingSet{}); auto state = std::make_shared<gpu::State>(); state->setMultisampleEnable(true); state->setDepthTest(gpu::State::DepthTest { true }); _pipeline = gpu::Pipeline::create(shader, state); // Clear screen gpu::Batch batch; batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, 0.0, 0.5, 1.0 }); _context->render(batch); DependencyManager::set<GeometryCache>(); DependencyManager::set<DeferredLightingEffect>(); resize(QSize(800, 600)); _time.start(); }
void KisOpenGL::setDefaultFormat() { QSurfaceFormat format; #ifdef Q_OS_MAC // format.setProfile(QSurfaceFormat::CoreProfile); // format.setOptions(QSurfaceFormat::DeprecatedFunctions); format.setVersion(2, 1); #else format.setProfile(QSurfaceFormat::CompatibilityProfile); format.setOptions(QSurfaceFormat::DeprecatedFunctions); format.setVersion(3, 0); #endif format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); KisConfig cfg; if (cfg.disableVSync()) { format.setSwapInterval(0); // Disable vertical refresh syncing } QSurfaceFormat::setDefaultFormat(format); }
void OpenGLWindow::Init() { // OpenGL //auto surface = new QOffscreenSurface(); //surface->setFormat(format); //surface->create(); //setSwapInterval QSurfaceFormat format; format.setVersion(4, 0); format.setSwapInterval(0); format.setProfile(QSurfaceFormat::CoreProfile); setFormat(format); auto glfwCTX = glfwGetWGLContext(Engine::Window->window); auto window = glfwGetWin32Window(Engine::Window->window); auto newNative = new QWGLNativeContext(glfwCTX, window); QOpenGLContext* qtctx = new QOpenGLContext(); //qtctx->setFormat(format); qtctx->setNativeHandle(QVariant::fromValue<QWGLNativeContext>(*newNative)); bool created = qtctx->create(); bool value = qtctx->makeCurrent(this); // Test auto nativeHandle = qtctx->nativeHandle(); auto windowsNative = nativeHandle.value<QWGLNativeContext>(); // Share context qtGLContext = new QOpenGLContext(this); //qtGLContext->setFormat(format); qtGLContext->setShareContext(qtctx); bool success = qtGLContext->create(); nativeHandle = qtGLContext->nativeHandle(); windowsNative = nativeHandle.value<QWGLNativeContext>(); bool sharing = qtGLContext->areSharing(qtctx, qtGLContext); bool sharing2 = qtGLContext->shareContext(); }
window::window(init_fn_type const& init_fn, step_fn_type const& step_fn, draw_fn_type const& draw_fn, fini_fn_type const& fini_fn) : m_context(nullptr) , m_gl_logger(nullptr) , m_initialised(false) , m_finished(false) , m_init_fn(init_fn) , m_step_fn(step_fn) , m_draw_fn(draw_fn) , m_fini_fn(fini_fn) { QSurfaceFormat format; // format.setDepthBufferSize(16); format.setDepthBufferSize( 24 ); format.setMajorVersion(4U); format.setMinorVersion(2U); format.setProfile(QSurfaceFormat::CoreProfile); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setOption(QSurfaceFormat::DebugContext); format.setSwapInterval(0); format.setSamples(0); m_context = new QOpenGLContext(this); m_context->setFormat(format); m_context->create(); setSurfaceType(QWindow::OpenGLSurface); setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); //setGeometry(QRect(10, 10, 640, 480)); setFormat(format); create(); }
QtWaylandMotorcarCompositor *QtWaylandMotorcarCompositor::create(int argc, char** argv, motorcar::Scene *scene) { // Enable the following to have touch events generated from mouse events. // Very handy for testing touch event delivery without a real touch device. // QGuiApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); QGuiApplication *app = new QGuiApplication(argc, argv); QScreen *screen = NULL; //screen = QGuiApplication::primaryScreen(); screen = QGuiApplication::screens().back(); QRect screenGeometry = screen->geometry(); QSurfaceFormat format; // std::cout << "color buffer size: " << format.redBufferSize() << std::endl; // format.setRedBufferSize(8); // format.setGreenBufferSize(8); // format.setBlueBufferSize(8); // format.setAlphaBufferSize(8); format.setDepthBufferSize(8); format.setStencilBufferSize(8); format.setSwapInterval(1); format.setStencilBufferSize(8); QRect geom = screenGeometry; // if (QCoreApplication::arguments().contains(QLatin1String("-nofullscreen"))) // geom = QRect(screenGeometry.width() / 4, screenGeometry.height() / 4, // screenGeometry.width() / 2, screenGeometry.height() / 2); QOpenGLWindow *window = new QOpenGLWindow(format, geom); return new QtWaylandMotorcarCompositor(window, app, scene); }
void Game::createRenderer(bool forceNoVSync) { // Create the main window / renderer int hRes, vRes; bool fullScreen = false; m_settings.loadResolution(hRes, vRes, fullScreen); if (!hRes || !vRes) { hRes = QGuiApplication::primaryScreen()->geometry().width(); vRes = QGuiApplication::primaryScreen()->geometry().height(); } adjustSceneSize(hRes, vRes); MCLogger().info() << "Resolution: " << hRes << " " << vRes << " " << fullScreen; MCLogger().info() << "Creating the renderer.."; QSurfaceFormat format; #ifdef __MC_GL30__ format.setVersion(3, 0); format.setProfile(QSurfaceFormat::CoreProfile); #elif defined(__MC_GLES__) format.setVersion(1, 0); #else format.setVersion(2, 1); #endif format.setSamples(0); // Supported only in Qt 5.3+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) if (forceNoVSync) { format.setSwapInterval(0); } else { format.setSwapInterval(Settings::instance().loadVSync()); } #else Q_UNUSED(forceNoVSync); #endif m_renderer = new Renderer(hRes, vRes, fullScreen, m_world.renderer().glScene()); m_renderer->setFormat(format); if (fullScreen) { m_renderer->showFullScreen(); } else { m_renderer->show(); } m_renderer->setEventHandler(*m_eventHandler); connect(m_renderer, &Renderer::initialized, this, &Game::init); connect(m_stateMachine, &StateMachine::renderingEnabled, m_renderer, &Renderer::setEnabled); }