本文整理汇总了C++中QSurfaceFormat::majorVersion方法的典型用法代码示例。如果您正苦于以下问题:C++ QSurfaceFormat::majorVersion方法的具体用法?C++ QSurfaceFormat::majorVersion怎么用?C++ QSurfaceFormat::majorVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSurfaceFormat
的用法示例。
在下文中一共展示了QSurfaceFormat::majorVersion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createContext
static HGLRC createContext(const QOpenGLStaticContext &staticContext,
HDC hdc,
const QSurfaceFormat &format,
const QWindowsOpenGLAdditionalFormat &,
HGLRC shared = 0)
{
enum { attribSize = 11 };
if (!staticContext.hasExtensions())
return 0;
int attributes[attribSize];
int attribIndex = 0;
qFill(attributes, attributes + attribSize, int(0));
const int requestedVersion = (format.majorVersion() << 8) + format.minorVersion();
if (requestedVersion > 0x0101) {
attributes[attribIndex++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
attributes[attribIndex++] = format.majorVersion();
attributes[attribIndex++] = WGL_CONTEXT_MINOR_VERSION_ARB;
attributes[attribIndex++] = format.minorVersion();
}
if (requestedVersion >= 0x0300) {
attributes[attribIndex++] = WGL_CONTEXT_FLAGS_ARB;
attributes[attribIndex] = 0;
if (format.testOption(QSurfaceFormat::DeprecatedFunctions))
attributes[attribIndex] |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
if (format.testOption(QSurfaceFormat::DebugContext))
attributes[attribIndex++] |= WGL_CONTEXT_DEBUG_BIT_ARB;
attribIndex++;
}
if (requestedVersion >= 0x0302) {
switch (format.profile()) {
case QSurfaceFormat::NoProfile:
break;
case QSurfaceFormat::CoreProfile:
attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attributes[attribIndex++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
break;
case QSurfaceFormat::CompatibilityProfile:
attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attributes[attribIndex++] = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
break;
}
}
if (QWindowsContext::verboseGL)
qDebug("%s: Creating context version %d.%d with %d attributes",
__FUNCTION__, format.majorVersion(), format.minorVersion(), attribIndex / 2);
const HGLRC result =
staticContext.wglCreateContextAttribsARB(hdc, shared, attributes);
if (!result)
qErrnoWarning("%s: wglCreateContextAttribsARB() failed.", __FUNCTION__);
return result;
}
示例2: context
void GLWidget277::debugContextVersion() {
QOpenGLContext *ctx = context();
QSurfaceFormat form = format();
QSurfaceFormat ctxform = ctx->format();
QSurfaceFormat::OpenGLContextProfile prof = ctxform.profile();
const char *profile =
prof == QSurfaceFormat::CoreProfile ? "Core" :
prof == QSurfaceFormat::CompatibilityProfile ? "Compatibility" :
"None";
int ctxmajor = ctxform.majorVersion();
int ctxminor = ctxform.minorVersion();
bool valid = ctx->isValid();
int formmajor = form.majorVersion();
int formminor = form.minorVersion();
const char *vendor = glGS(GL_VENDOR);
const char *renderer = glGS(GL_RENDERER);
const char *version = glGS(GL_VERSION);
const char *s_glsl = glGS(GL_SHADING_LANGUAGE_VERSION);
printf("Widget version: %d.%d\n", ctxmajor, ctxminor);
printf("Context valid: %s\n", valid ? "yes" : "NO");
printf("Format version: %d.%d\n", formmajor, formminor);
printf("Profile: %s\n", profile);
printf(" Vendor: %s\n", vendor);
printf(" Renderer: %s\n", renderer);
printf(" Version: %s\n", version);
printf(" GLSL: %s\n", s_glsl);
QString glsl = s_glsl;
if (ctxmajor < 3 || glsl.startsWith("1.10") || glsl.startsWith("1.20")) {
printf("ERROR: "
"Unable to get an OpenGL 3.x context with GLSL 1.30 or newer. "
"If your hardware should support it, update your drivers. "
"If you have switchable graphics, make sure that you are using the discrete GPU.\n");
QApplication::exit();
} else if ((ctxmajor == 3 && ctxminor < 2) || glsl.startsWith("1.30") || glsl.startsWith("1.40")) {
printf("WARNING: "
"Unable to get an OpenGL 3.2 context with GLSL 1.50. "
"If your hardware should support it, update your drivers. "
"If you have switchable graphics, make sure that you are using the discrete GPU. "
"If you cannot get 3.2 support, it is possible to port this project....");
// Note: doing this requires at least the following actions:
// * Change the header and base class in glwidget277.h to 3.0/3.1 instead of 3.2 Core.
// * Change the shaders to require GLSL 1.30 or 1.40.
}
}
示例3: printFormat
void Widget::printFormat(const QSurfaceFormat &format)
{
m_output->append(tr("OpenGL version: %1.%2").arg(format.majorVersion()).arg(format.minorVersion()));
for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i)
if (profiles[i].profile == format.profile()) {
m_output->append(tr("Profile: %1").arg(QString::fromLatin1(profiles[i].str)));
break;
}
QString opts;
for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i)
if (format.testOption(options[i].option))
opts += QString::fromLatin1(options[i].str) + QLatin1Char(' ');
m_output->append(tr("Options: %1").arg(opts));
for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i)
if (renderables[i].renderable == format.renderableType()) {
m_output->append(tr("Renderable type: %1").arg(QString::fromLatin1(renderables[i].str)));
break;
}
m_output->append(tr("Depth buffer size: %1").arg(QString::number(format.depthBufferSize())));
m_output->append(tr("Stencil buffer size: %1").arg(QString::number(format.stencilBufferSize())));
m_output->append(tr("Samples: %1").arg(QString::number(format.samples())));
m_output->append(tr("Red buffer size: %1").arg(QString::number(format.redBufferSize())));
m_output->append(tr("Green buffer size: %1").arg(QString::number(format.greenBufferSize())));
m_output->append(tr("Blue buffer size: %1").arg(QString::number(format.blueBufferSize())));
m_output->append(tr("Alpha buffer size: %1").arg(QString::number(format.alphaBufferSize())));
m_output->append(tr("Swap interval: %1").arg(QString::number(format.swapInterval())));
}
示例4: fromSurfaceFormat
QT_BEGIN_NAMESPACE
/*!
Returns an OpenGL format for the window format specified by \a format.
*/
QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format)
{
QGLFormat retFormat;
if (format.alphaBufferSize() >= 0)
retFormat.setAlphaBufferSize(format.alphaBufferSize());
if (format.blueBufferSize() >= 0)
retFormat.setBlueBufferSize(format.blueBufferSize());
if (format.greenBufferSize() >= 0)
retFormat.setGreenBufferSize(format.greenBufferSize());
if (format.redBufferSize() >= 0)
retFormat.setRedBufferSize(format.redBufferSize());
if (format.depthBufferSize() >= 0)
retFormat.setDepthBufferSize(format.depthBufferSize());
if (format.samples() > 1) {
retFormat.setSampleBuffers(true);
retFormat.setSamples(format.samples());
}
if (format.stencilBufferSize() > 0) {
retFormat.setStencil(true);
retFormat.setStencilBufferSize(format.stencilBufferSize());
}
retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer);
retFormat.setStereo(format.stereo());
retFormat.setVersion(format.majorVersion(), format.minorVersion());
retFormat.setProfile(static_cast<QGLFormat::OpenGLContextProfile>(format.profile()));
return retFormat;
}
示例5: main
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
// create an OpenGL format specifier
QSurfaceFormat format;
// set the number of samples for multisampling
// will need to enable glEnable(GL_MULTISAMPLE); once we have a context
format.setSamples(4);
#if defined( __APPLE__)
// at present mac osx Mountain Lion only supports GL3.2
// the new mavericks will have GL 4.x so can change
format.setMajorVersion(4);
format.setMinorVersion(1);
#else
// with luck we have the latest GL version so set to this
format.setMajorVersion(4);
format.setMinorVersion(3);
#endif
// now we are going to set to CoreProfile OpenGL so we can't use and old Immediate mode GL
format.setProfile(QSurfaceFormat::CoreProfile);
// now set the depth buffer to 24 bits
format.setDepthBufferSize(24);
// now we are going to create our scene window
NGLScene window;
// and set the OpenGL format
window.setFormat(format);
// we can now query the version to see if it worked
std::cout<<"Profile is "<<format.majorVersion()<<" "<<format.minorVersion()<<"\n";
// set the window size
// and finally show
window.show();
window.resize(1024, 720);
return app.exec();
}
示例6: openGLPaintDevice
void tst_QOpenGL::openGLPaintDevice()
{
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
QSKIP("QTBUG-22617");
#endif
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext ctx;
QVERIFY(ctx.create());
QSurfaceFormat format = ctx.format();
if (format.majorVersion() < 2)
QSKIP("This test requires at least OpenGL 2.0");
QVERIFY(ctx.makeCurrent(surface.data()));
const QSize size(128, 128);
QImage image(size, QImage::Format_RGB32);
QPainter p(&image);
p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red);
p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green);
p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue);
p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white);
p.end();
QOpenGLFramebufferObject fbo(size);
QVERIFY(fbo.bind());
QOpenGLPaintDevice device(size);
QVERIFY(p.begin(&device));
p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red);
p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green);
p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue);
p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white);
p.end();
QImage actual = fbo.toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(image.size(), actual.size());
QCOMPARE(image, actual);
QVERIFY(p.begin(&device));
p.fillRect(0, 0, image.width(), image.height(), Qt::black);
p.drawImage(0, 0, image);
p.end();
actual = fbo.toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(image.size(), actual.size());
QCOMPARE(image, actual);
QVERIFY(p.begin(&device));
p.fillRect(0, 0, image.width(), image.height(), Qt::black);
p.fillRect(0, 0, image.width(), image.height(), QBrush(image));
p.end();
actual = fbo.toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(image.size(), actual.size());
QCOMPARE(image, actual);
}
示例7: main
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
// create an OpenGL format specifier
QSurfaceFormat format;
// set the number of samples for multisampling
// will need to enable glEnable(GL_MULTISAMPLE); once we have a context
format.setSamples(4);
format.setMajorVersion(3);
format.setMinorVersion(2);
// now we are going to set to Compat Profile OpenGL so we can use and old Immediate mode GL
format.setProfile(QSurfaceFormat::CompatibilityProfile);
// now set the depth buffer to 24 bits
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
// now we are going to create our scene window
OpenGLWindow window;
// we can now query the version to see if it worked
std::cout<<"Profile is "<<format.majorVersion()<<" "<<format.minorVersion()<<"\n";
// set the window size
window.resize(1024, 720);
// and finally show
window.show();
return app.exec();
}
示例8: qMakePair
bool QOpenGLFunctions_ES2::isContextCompatible(QOpenGLContext *context)
{
Q_ASSERT(context);
QSurfaceFormat f = context->format();
const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion());
if (v < qMakePair(2, 0))
return false;
if (f.renderableType() != QSurfaceFormat::OpenGLES)
return false;
return true;
}
示例9: debugFormatVersion
void debugFormatVersion() {
QSurfaceFormat form = QSurfaceFormat::defaultFormat();
QSurfaceFormat::OpenGLContextProfile prof = form.profile();
const char *profile =
prof == QSurfaceFormat::CoreProfile ? "Core" :
prof == QSurfaceFormat::CompatibilityProfile ? "Compatibility" :
"None";
printf("Requested format:\n");
printf(" Version: %d.%d\n", form.majorVersion(), form.minorVersion());
printf(" Profile: %s\n", profile);
}
示例10: qMakePair
bool QOpenGLFunctions_4_1_Compatibility::isContextCompatible(QOpenGLContext *context)
{
Q_ASSERT(context);
QSurfaceFormat f = context->format();
const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion());
if (v < qMakePair(4, 1))
return false;
if (f.profile() == QSurfaceFormat::CoreProfile)
return false;
return true;
}
示例11: initializeContext
int KisOpenGL::initializeContext(QOpenGLContext* s) {
#ifdef HAVE_OPENGL
KisConfig cfg;
dbgUI << "OpenGL: Opening new context";
// Double check we were given the version we requested
QSurfaceFormat format = s->format();
glVersion = 100 * format.majorVersion() + format.minorVersion();
if (!SharedSurface) {
SharedSurface = new QOffscreenSurface();
SharedSurface->setFormat(format);
SharedSurface->create();
}
if (!SharedContext) {
SharedContext = new QOpenGLContext;
SharedContext->setFormat(format);
SharedContext->setShareContext(s);
SharedContext->create();
SharedContext->makeCurrent(SharedSurface);
}
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
QFile log(QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/krita-opengl.txt");
log.open(QFile::WriteOnly);
QString vendor((const char*)f->glGetString(GL_VENDOR));
log.write(vendor.toLatin1());
log.write(", ");
QString renderer((const char*)f->glGetString(GL_RENDERER));
log.write(renderer.toLatin1());
log.write(", ");
QString version((const char*)f->glGetString(GL_VERSION));
log.write(version.toLatin1());
// Check if we have a bugged driver that needs fence workaround
bool isOnX11 = false;
#ifdef HAVE_X11
isOnX11 = true;
#endif
if ((isOnX11 && renderer.startsWith("AMD")) || cfg.forceOpenGLFenceWorkaround()) {
NeedsFenceWorkaround = true;
}
#else
Q_UNUSED(s);
NeedsFenceWorkaround = false;
#endif
return glVersion;
}
示例12: QPlatformOpenGLContext
QWaylandBrcmGLContext::QWaylandBrcmGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformOpenGLContext *share)
: QPlatformOpenGLContext()
, m_eglDisplay(eglDisplay)
, m_config(q_configFromGLFormat(m_eglDisplay, brcmFixFormat(format), true))
, m_format(q_glFormatFromConfig(m_eglDisplay, m_config))
{
EGLContext shareEGLContext = share ? static_cast<QWaylandBrcmGLContext *>(share)->eglContext() : EGL_NO_CONTEXT;
eglBindAPI(EGL_OPENGL_ES_API);
QVector<EGLint> eglContextAttrs;
eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
eglContextAttrs.append(format.majorVersion() == 1 ? 1 : 2);
eglContextAttrs.append(EGL_NONE);
m_context = eglCreateContext(m_eglDisplay, m_config, shareEGLContext, eglContextAttrs.constData());
}
示例13: testProperties
void tst_QQuickOpenGLInfo::testProperties()
{
QQuickView view;
view.setSource(testFileUrl("basic.qml"));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QSignalSpy spy(&view, SIGNAL(sceneGraphInitialized()));
spy.wait();
QVERIFY(view.openglContext());
QSurfaceFormat format = view.openglContext()->format();
QObject* obj = view.rootObject();
QVERIFY(obj);
QCOMPARE(obj->property("majorVersion").toInt(), format.majorVersion());
QCOMPARE(obj->property("minorVersion").toInt(), format.minorVersion());
QCOMPARE(obj->property("profile").toInt(), static_cast<int>(format.profile()));
QCOMPARE(obj->property("renderableType").toInt(), static_cast<int>(format.renderableType()));
}
示例14: doRendering
void HsQMLCanvasBackEnd::doRendering()
{
if (!mGL) {
mGL = mWindow->openglContext();
QObject::connect(
mGL, SIGNAL(aboutToBeDestroyed()), this, SLOT(doCleanup()));
HsQMLGLCanvasType ctype;
QSurfaceFormat format = mGL->format();
switch (format.renderableType()) {
case QSurfaceFormat::OpenGL: ctype = HSQML_GL_DESKTOP; break;
case QSurfaceFormat::OpenGLES: ctype = HSQML_GL_ES; break;
default: setStatus(HsQMLCanvas::BadConfig); return;
}
mGLViewportFn = reinterpret_cast<GLViewportFn>(
mGL->getProcAddress("glViewport"));
mGLClearColorFn = reinterpret_cast<GLClearColorFn>(
mGL->getProcAddress("glClearColor"));
mGLClearFn = reinterpret_cast<GLClearFn>(
mGL->getProcAddress("glClear"));
if (!mGLViewportFn || !mGLClearColorFn || !mGLClearFn) {
setStatus(HsQMLCanvas::BadProcs);
return;
}
mGLCallbacks->mSetupCb(
ctype, format.majorVersion(), format.minorVersion());
}
// Reset OpenGL state before rendering
#if QT_VERSION >= 0x050200
mWindow->resetOpenGLState();
#else
#warning Resetting OpenGL state requires Qt 5.2 or later
#endif
// Clear window if painting below the scenegraph
if (mWinInfo.needsBelowClear()) {
QColor bg = mWindow->color();
mGLClearColorFn(bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF());
mGLClearFn(GL_COLOR_BUFFER_BIT);
}
// Setup prior to paint callback
QMatrix4x4 matrix;
bool inlineMode = HsQMLCanvas::Inline == mDisplayMode;
if (inlineMode) {
if (!mFBO->bind()) {
setStatus(HsQMLCanvas::BadBind);
return;
}
mGLViewportFn(0, 0, qCeil(mCanvasWidth), qCeil(mCanvasHeight));
// Clear FBO to transparent
mGLClearColorFn(0, 0, 0, 0);
mGLClearFn(GL_COLOR_BUFFER_BIT);
}
else {
// Calculate matrix for non-inline display modes
QMatrix4x4 smatrix;
QSGNode* node = mTransformNode;
while (node) {
if (QSGNode::TransformNodeType == node->type()) {
QSGTransformNode* tnode = static_cast<QSGTransformNode*>(node);
smatrix = tnode->matrix() * smatrix;
}
node = node->parent();
}
matrix.translate(-1, 1);
matrix.scale(2.0f/mWindow->width(), -2.0f/mWindow->height());
matrix *= smatrix;
matrix.scale(mItemWidth/2.0f, mItemHeight/2.0f);
matrix.translate(1, 1);
mGLViewportFn(0, 0, mWindow->width(), mWindow->height());
}
setStatus(HsQMLCanvas::Okay);
mGLCallbacks->mPaintCb(matrix.data(), mItemWidth, mItemHeight);
if (inlineMode) {
mFBO->release();
}
}
示例15: init
void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share)
{
m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig);
// m_format now has the renderableType() resolved (it cannot be Default anymore)
// but does not yet contain version, profile, options.
m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
QVector<EGLint> contextAttrs;
contextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
contextAttrs.append(format.majorVersion());
const bool hasKHRCreateContext = q_hasEglExtension(m_eglDisplay, "EGL_KHR_create_context");
if (hasKHRCreateContext) {
contextAttrs.append(EGL_CONTEXT_MINOR_VERSION_KHR);
contextAttrs.append(format.minorVersion());
int flags = 0;
// The debug bit is supported both for OpenGL and OpenGL ES.
if (format.testOption(QSurfaceFormat::DebugContext))
flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
// The fwdcompat bit is only for OpenGL 3.0+.
if (m_format.renderableType() == QSurfaceFormat::OpenGL
&& format.majorVersion() >= 3
&& !format.testOption(QSurfaceFormat::DeprecatedFunctions))
flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
if (flags) {
contextAttrs.append(EGL_CONTEXT_FLAGS_KHR);
contextAttrs.append(flags);
}
// Profiles are OpenGL only and mandatory in 3.2+. The value is silently ignored for < 3.2.
if (m_format.renderableType() == QSurfaceFormat::OpenGL) {
contextAttrs.append(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR);
contextAttrs.append(format.profile() == QSurfaceFormat::CoreProfile
? EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
: EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR);
}
}
contextAttrs.append(EGL_NONE);
switch (m_format.renderableType()) {
case QSurfaceFormat::OpenVG:
m_api = EGL_OPENVG_API;
break;
#ifdef EGL_VERSION_1_4
case QSurfaceFormat::OpenGL:
m_api = EGL_OPENGL_API;
break;
#endif // EGL_VERSION_1_4
default:
m_api = EGL_OPENGL_ES_API;
break;
}
eglBindAPI(m_api);
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, m_shareContext, contextAttrs.constData());
if (m_eglContext == EGL_NO_CONTEXT && m_shareContext != EGL_NO_CONTEXT) {
m_shareContext = 0;
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, 0, contextAttrs.constData());
}
if (m_eglContext == EGL_NO_CONTEXT) {
qWarning("QEGLPlatformContext: Failed to create context: %x", eglGetError());
return;
}
static const bool printConfig = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEBUG");
if (printConfig) {
qDebug() << "Created context for format" << format << "with config:";
q_printEglConfig(m_eglDisplay, m_eglConfig);
}
// Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize().
}