本文整理汇总了C++中QSurfaceFormat::setSwapBehavior方法的典型用法代码示例。如果您正苦于以下问题:C++ QSurfaceFormat::setSwapBehavior方法的具体用法?C++ QSurfaceFormat::setSwapBehavior怎么用?C++ QSurfaceFormat::setSwapBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSurfaceFormat
的用法示例。
在下文中一共展示了QSurfaceFormat::setSwapBehavior方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doubleBufferedChanged
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 );
}
示例2: initialize
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
}
示例3: init
void ccApplication::init()
{
//See http://doc.qt.io/qt-5/qopenglwidget.html#opengl-function-calls-headers-and-qopenglfunctions
/** Calling QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance is mandatory
on some platforms (for example, OS X) when an OpenGL core profile context is requested. This is to
ensure that resource sharing between contexts stays functional as all internal contexts are created
using the correct version and profile.
**/
{
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setSwapBehavior( QSurfaceFormat::DoubleBuffer );
format.setStencilBufferSize( 0 );
#ifdef CC_GL_WINDOW_USE_QWINDOW
format.setStereo( true );
#endif
#ifdef Q_OS_MAC
format.setVersion( 2, 1 ); // must be 2.1 - see ccGLWindow::functions()
format.setProfile( QSurfaceFormat::CoreProfile );
#endif
#ifdef QT_DEBUG
format.setOption( QSurfaceFormat::DebugContext, true );
#endif
QSurfaceFormat::setDefaultFormat( format );
}
// The 'AA_ShareOpenGLContexts' attribute must be defined BEFORE the creation of the Q(Gui)Application
// DGM: this is mandatory to enable exclusive full screen for ccGLWidget (at least on Windows)
QCoreApplication::setAttribute( Qt::AA_ShareOpenGLContexts );
}
示例4: QMenu
OpenGLWidget::OpenGLWidget(MainWindow* mainWindow)
: QOpenGLWidget{mainWindow}
, m_axisLegendScene{mainWindow->app()}
, m_width{0}
, m_height{0}
, m_currentLocation{}
, m_previousLocation{}
{
this->setFocusPolicy(Qt::StrongFocus);
m_contextMenu = new QMenu(this);
QMenu* createMenu = m_contextMenu->addMenu("Create");
createMenu->addAction(tr("Box"), this, SLOT(createBox()));
createMenu->addAction(tr("Cylinder"), this, SLOT(createCylinder()));
createMenu->addAction(tr("Cone"), this, SLOT(createCone()));
createMenu->addAction(tr("Sphere"), this, SLOT(createSphere()));
m_contextMenu->addAction(tr("Import Mesh"), this, SLOT(importMesh()));
QSurfaceFormat format = this->format();
format.setVersion(kOpenGLMajorVersion, kOpenGLMinorVersion);
format.setProfile(QSurfaceFormat::CoreProfile);
format.setDepthBufferSize(32);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
LOG(INFO) << fmt::format("Setting format with OpenGL version {}.{}", kOpenGLMajorVersion, kOpenGLMinorVersion);
this->setFormat(format);
}
示例5: vsyncChangedHandler
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 );
}
示例6: qSurfaceFormatFromPixelFormat
static QSurfaceFormat
qSurfaceFormatFromPixelFormat(const PIXELFORMATDESCRIPTOR &pfd,
QWindowsOpenGLAdditionalFormat *additionalIn = 0)
{
QSurfaceFormat format;
if (pfd.dwFlags & PFD_DOUBLEBUFFER)
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
format.setDepthBufferSize(pfd.cDepthBits);
if (pfd.iPixelType == PFD_TYPE_RGBA)
format.setAlphaBufferSize(pfd.cAlphaBits);
format.setRedBufferSize(pfd.cRedBits);
format.setGreenBufferSize(pfd.cGreenBits);
format.setBlueBufferSize(pfd.cBlueBits);
format.setStencilBufferSize(pfd.cStencilBits);
format.setStereo(pfd.dwFlags & PFD_STEREO);
if (additionalIn) {
QWindowsOpenGLAdditionalFormat additional;
if (isDirectRendering(pfd))
additional.formatFlags |= QWindowsGLDirectRendering;
if (hasGLOverlay(pfd))
additional.formatFlags |= QWindowsGLOverlay;
if (pfd.cAccumRedBits)
additional.formatFlags |= QWindowsGLAccumBuffer;
if (testFlag(pfd.dwFlags, PFD_DRAW_TO_BITMAP)) {
additional.formatFlags |= QWindowsGLRenderToPixmap;
additional.pixmapDepth = pfd.cColorBits;
}
*additionalIn = additional;
}
return format;
}
示例7: qglx_reduceSurfaceFormat
QSurfaceFormat qglx_reduceSurfaceFormat(const QSurfaceFormat &format, bool *reduced)
{
QSurfaceFormat retFormat = format;
*reduced = true;
if (retFormat.redBufferSize() > 1) {
retFormat.setRedBufferSize(1);
} else if (retFormat.greenBufferSize() > 1) {
retFormat.setGreenBufferSize(1);
} else if (retFormat.blueBufferSize() > 1) {
retFormat.setBlueBufferSize(1);
} else if (retFormat.samples() > 1) {
retFormat.setSamples(qMin(retFormat.samples() / 2, 16));
} else if (retFormat.stereo()) {
retFormat.setStereo(false);
}else if (retFormat.stencilBufferSize() > 0) {
retFormat.setStencilBufferSize(0);
}else if (retFormat.hasAlpha()) {
retFormat.setAlphaBufferSize(0);
}else if (retFormat.depthBufferSize() > 0) {
retFormat.setDepthBufferSize(0);
}else if (retFormat.swapBehavior() != QSurfaceFormat::SingleBuffer) {
retFormat.setSwapBehavior(QSurfaceFormat::SingleBuffer);
}else{
*reduced = false;
}
return retFormat;
}
示例8: reserved
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);
}
示例9: defaultSurfaceFormat
QSurfaceFormat QSGContext::defaultSurfaceFormat() const
{
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
if (QQuickWindow::hasDefaultAlphaBuffer())
format.setAlphaBufferSize(8);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
return format;
}
示例10: QOpenGLWidget
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;
}
示例11: RunTestInOpenGLOffscreenEnvironment
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();
}
示例12: QWindow
OpenGLWindow::OpenGLWindow( QWindow *parent )
: QWindow( parent ), d( new Private(this) )
{
setSurfaceType( QWindow::OpenGLSurface );
QSurfaceFormat format;
//format.setDepthBufferSize( 24 );
//format.setSamples( 4 );
//format.setMajorVersion( 3 );
//format.setMinorVersion( 3 );
format.setSwapBehavior( QSurfaceFormat::DoubleBuffer );
format.setRenderableType( QSurfaceFormat::OpenGL );
format.setProfile( QSurfaceFormat::CompatibilityProfile );
setFormat( format );
create();
d->thread = OpenGLRenderThread::instance();
d->renderId = d->thread->registerSurface( this );
d->thread->update( d->renderId );
}
示例13: setDefaultFormat
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);
}
示例14: QOpenGLContext
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();
}
示例15: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSurfaceFormat format;
format.setMajorVersion(4);
format.setMinorVersion(1);
format.setProfile(QSurfaceFormat::CoreProfile);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
format.setSamples(2);
format.setDepthBufferSize(24);
format.setRedBufferSize(8);
format.setGreenBufferSize(8);
format.setBlueBufferSize(8);
format.setAlphaBufferSize(0);
format.setStencilBufferSize(8);
QSurfaceFormat::setDefaultFormat(format);
DemoGLWindow window;
window.show();
return a.exec();
}