本文整理汇总了C++中QSurfaceFormat::swapBehavior方法的典型用法代码示例。如果您正苦于以下问题:C++ QSurfaceFormat::swapBehavior方法的具体用法?C++ QSurfaceFormat::swapBehavior怎么用?C++ QSurfaceFormat::swapBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSurfaceFormat
的用法示例。
在下文中一共展示了QSurfaceFormat::swapBehavior方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: qPixelFormatFromSurfaceFormat
static PIXELFORMATDESCRIPTOR
qPixelFormatFromSurfaceFormat(const QSurfaceFormat &format,
const QWindowsOpenGLAdditionalFormat &additional)
{
PIXELFORMATDESCRIPTOR pfd;
initPixelFormatDescriptor(&pfd);
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.dwFlags = PFD_SUPPORT_OPENGL;
if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA)
pfd.dwFlags = PFD_SUPPORT_COMPOSITION;
const bool isPixmap = (additional.formatFlags & QWindowsGLRenderToPixmap) != 0;
pfd.dwFlags |= isPixmap ? PFD_DRAW_TO_BITMAP : PFD_DRAW_TO_WINDOW;
if (!(additional.formatFlags & QWindowsGLDirectRendering))
pfd.dwFlags |= PFD_GENERIC_FORMAT;
if (format.stereo())
pfd.dwFlags |= PFD_STEREO;
if (format.swapBehavior() == QSurfaceFormat::DoubleBuffer && !isPixmap)
pfd.dwFlags |= PFD_DOUBLEBUFFER;
pfd.cDepthBits =
format.depthBufferSize() >= 0 ? format.depthBufferSize() : 32;
pfd.cAlphaBits = format.alphaBufferSize() > 0 ? format.alphaBufferSize() : 8;
pfd.cStencilBits = format.stencilBufferSize() > 0 ? format.stencilBufferSize() : 8;
if (additional.formatFlags & QWindowsGLAccumBuffer)
pfd.cAccumRedBits = pfd.cAccumGreenBits = pfd.cAccumBlueBits = pfd.cAccumAlphaBits = 16;
return pfd;
}
示例3: 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 );
}
示例4: 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;
}
示例5: glXGetVisualFromFBConfig
XVisualInfo *qglx_findVisualInfo(Display *display, int screen, QSurfaceFormat *format)
{
Q_ASSERT(format);
XVisualInfo *visualInfo = 0;
GLXFBConfig config = qglx_findConfig(display,screen,*format);
if (config) {
visualInfo = glXGetVisualFromFBConfig(display, config);
*format = qglx_surfaceFormatFromGLXFBConfig(display, config);
}
// attempt to fall back to glXChooseVisual
bool reduced = true;
QSurfaceFormat reducedFormat = *format;
while (!visualInfo && reduced) {
QVarLengthArray<int, 13> attribs;
attribs.append(GLX_RGBA);
if (reducedFormat.redBufferSize() > 0) {
attribs.append(GLX_RED_SIZE);
attribs.append(reducedFormat.redBufferSize());
}
if (reducedFormat.greenBufferSize() > 0) {
attribs.append(GLX_GREEN_SIZE);
attribs.append(reducedFormat.greenBufferSize());
}
if (reducedFormat.blueBufferSize() > 0) {
attribs.append(GLX_BLUE_SIZE);
attribs.append(reducedFormat.blueBufferSize());
}
if (reducedFormat.stencilBufferSize() > 0) {
attribs.append(GLX_STENCIL_SIZE);
attribs.append(reducedFormat.stencilBufferSize());
}
if (reducedFormat.depthBufferSize() > 0) {
attribs.append(GLX_DEPTH_SIZE);
attribs.append(reducedFormat.depthBufferSize());
}
if (reducedFormat.swapBehavior() != QSurfaceFormat::SingleBuffer)
attribs.append(GLX_DOUBLEBUFFER);
attribs.append(XNone);
visualInfo = glXChooseVisual(display, screen, attribs.data());
if (visualInfo)
*format = reducedFormat;
reducedFormat = qglx_reduceSurfaceFormat(reducedFormat, &reduced);
}
return visualInfo;
}
示例6: choosePixelFormat
// Choose a suitable pixelformat using GDI WinAPI in case ARB
// functions cannot be found. First tries to find a suitable
// format using GDI function ChoosePixelFormat(). Since that
// does not handle overlay and direct-rendering requests, manually loop
// over the available formats to find the best one.
// Note: As of Windows 7, it seems direct-rendering is handled, so,
// the code might be obsolete?
static int choosePixelFormat(HDC hdc, const QSurfaceFormat &format,
const QWindowsOpenGLAdditionalFormat &additional,
PIXELFORMATDESCRIPTOR *obtainedPfd)
{
// 1) Try ChoosePixelFormat().
PIXELFORMATDESCRIPTOR requestedPfd = qPixelFormatFromSurfaceFormat(format, QWindowsGLDirectRendering);
initPixelFormatDescriptor(obtainedPfd);
int pixelFormat = ChoosePixelFormat(hdc, &requestedPfd);
if (pixelFormat >= 0) {
DescribePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd);
if (isAcceptableFormat(additional, *obtainedPfd))
return pixelFormat;
}
// 2) No matching format found, manual search loop.
const int pfiMax = DescribePixelFormat(hdc, 0, 0, NULL);
int bestScore = -1;
int bestPfi = -1;
const bool stereoRequested = format.stereo();
const bool accumBufferRequested = testFlag(additional.formatFlags, QWindowsGLAccumBuffer);
const bool doubleBufferRequested = format.swapBehavior() == QSurfaceFormat::DoubleBuffer;
const bool directRenderingRequested = testFlag(additional.formatFlags, QWindowsGLDirectRendering);
for (int pfi = 1; pfi <= pfiMax; pfi++) {
PIXELFORMATDESCRIPTOR checkPfd;
initPixelFormatDescriptor(&checkPfd);
DescribePixelFormat(hdc, pfi, sizeof(PIXELFORMATDESCRIPTOR), &checkPfd);
if (isAcceptableFormat(additional, checkPfd)) {
int score = checkPfd.cColorBits + checkPfd.cAlphaBits + checkPfd.cStencilBits;
if (accumBufferRequested)
score += checkPfd.cAccumBits;
if (doubleBufferRequested == testFlag(checkPfd.dwFlags, PFD_DOUBLEBUFFER))
score += 1000;
if (stereoRequested == testFlag(checkPfd.dwFlags, PFD_STEREO))
score += 2000;
if (directRenderingRequested == isDirectRendering(checkPfd))
score += 4000;
if (checkPfd.iPixelType == PFD_TYPE_RGBA)
score += 8000;
if (score > bestScore) {
bestScore = score;
bestPfi = pfi;
*obtainedPfd = checkPfd;
}
if (QWindowsContext::verboseGL)
qDebug() << __FUNCTION__ << " checking " << pfi << '/' << pfiMax
<< " score=" << score << " (best " << bestPfi << '/' << bestScore
<< ") " << checkPfd;
}
} // for
if (bestPfi > 0)
pixelFormat = bestPfi;
return pixelFormat;
}
示例7: spec
QVector<int> qglx_buildSpec(const QSurfaceFormat &format, int drawableBit)
{
QVector<int> spec(48);
int i = 0;
spec[i++] = GLX_LEVEL;
spec[i++] = 0;
spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = drawableBit;
spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_RGBA_BIT;
spec[i++] = GLX_RED_SIZE; spec[i++] = (format.redBufferSize() == -1) ? 1 : format.redBufferSize();
spec[i++] = GLX_GREEN_SIZE; spec[i++] = (format.greenBufferSize() == -1) ? 1 : format.greenBufferSize();
spec[i++] = GLX_BLUE_SIZE; spec[i++] = (format.blueBufferSize() == -1) ? 1 : format.blueBufferSize();
if (format.hasAlpha()) {
spec[i++] = GLX_ALPHA_SIZE; spec[i++] = format.alphaBufferSize();
}
spec[i++] = GLX_DOUBLEBUFFER; spec[i++] = format.swapBehavior() != QSurfaceFormat::SingleBuffer ? True : False;
spec[i++] = GLX_STEREO; spec[i++] = format.stereo() ? True : False;
if (format.depthBufferSize() > 0) {
spec[i++] = GLX_DEPTH_SIZE; spec[i++] = format.depthBufferSize();
}
if (format.stencilBufferSize() > 0) {
spec[i++] = GLX_STENCIL_SIZE; spec[i++] = (format.stencilBufferSize() == -1) ? 1 : format.stencilBufferSize();
}
if (format.samples() > 1) {
spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
spec[i++] = 1;
spec[i++] = GLX_SAMPLES_ARB;
spec[i++] = format.samples();
}
spec[i++] = XNone;
return spec;
}
示例8: displayString
//.........这里部分代码省略.........
if (value.userType() == qMetaTypeId<QPainterPath>()) {
const QPainterPath path = value.value<QPainterPath>();
if (path.isEmpty()) {
return QObject::tr("<empty>");
}
return QObject::tr("<%1 elements>").arg(path.elementCount());
}
if (value.userType() == qMetaTypeId<QMargins>()) {
const QMargins margins = value.value<QMargins>();
return QObject::tr("left: %1, top: %2, right: %3, bottom: %4")
.arg(margins.left()).arg(margins.top())
.arg(margins.right()).arg(margins.bottom());
}
if (value.canConvert<QObject*>()) {
return Util::displayString(value.value<QObject*>());
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
if (value.userType() == qMetaTypeId<QSet<QByteArray> >()) {
const QSet<QByteArray> set = value.value<QSet<QByteArray> >();
QStringList l;
foreach (const QByteArray &b, set)
l.push_back(QString::fromUtf8(b));
return l.join(", ");
}
if (value.userType() == qMetaTypeId<QSurfaceFormat>()) {
const QSurfaceFormat format = value.value<QSurfaceFormat>();
QString s;
switch (format.renderableType()) {
case QSurfaceFormat::DefaultRenderableType: s += "Default"; break;
case QSurfaceFormat::OpenGL: s += "OpenGL"; break;
case QSurfaceFormat::OpenGLES: s += "OpenGL ES"; break;
case QSurfaceFormat::OpenVG: s += "OpenVG"; break;
}
s += " (" + QString::number(format.majorVersion()) + "." + QString::number(format.minorVersion());
switch (format.profile()) {
case QSurfaceFormat::CoreProfile: s += " core"; break;
case QSurfaceFormat::CompatibilityProfile: s += " compat"; break;
case QSurfaceFormat::NoProfile: break;
}
s += ")";
s += " RGBA: " + QString::number(format.redBufferSize()) + "/" + QString::number(format.greenBufferSize())
+ "/" + QString::number(format.blueBufferSize()) + "/" + QString::number(format.alphaBufferSize());
s += " Depth: " + QString::number(format.depthBufferSize());
s += " Stencil: " + QString::number(format.stencilBufferSize());
s += " Buffer: ";
switch (format.swapBehavior()) {
case QSurfaceFormat::DefaultSwapBehavior: s += "default"; break;
case QSurfaceFormat::SingleBuffer: s += "single"; break;
case QSurfaceFormat::DoubleBuffer: s += "double"; break;
case QSurfaceFormat::TripleBuffer: s += "triple"; break;
default: s += "unknown";
}
return s;
}
if (value.userType() == qMetaTypeId<QSurface::SurfaceClass>()) {
const QSurface::SurfaceClass sc = value.value<QSurface::SurfaceClass>();
switch (sc) {
case QSurface::Window: return QObject::tr("Window");
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
case QSurface::Offscreen: return QObject::tr("Offscreen");
#endif
default: return QObject::tr("Unknown Surface Class");
}
}
if (value.userType() == qMetaTypeId<QSurface::SurfaceType>()) {
const QSurface::SurfaceType type = value.value<QSurface::SurfaceType>();
switch (type) {
case QSurface::RasterSurface: return QObject::tr("Raster");
case QSurface::OpenGLSurface: return QObject::tr("OpenGL");
default: return QObject::tr("Unknown Surface Type");
}
}
#endif
// enums
const QString enumStr = Util::enumToString(value);
if (!enumStr.isEmpty()) {
return enumStr;
}
// custom converters
const QHash<int, Converter<QString>*>::const_iterator it = s_variantHandlerRepository()->stringConverters.constFind(value.userType());
if (it != s_variantHandlerRepository()->stringConverters.constEnd()) {
return (*it.value())(value);
}
return value.toString();
}