本文整理汇总了C++中QOpenGLContext::create方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLContext::create方法的具体用法?C++ QOpenGLContext::create怎么用?C++ QOpenGLContext::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLContext
的用法示例。
在下文中一共展示了QOpenGLContext::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
QGuiApplication app(argc, argv);
Q_UNUSED(app);
QSurfaceFormat format;
format.setMajorVersion(3);
format.setMinorVersion(0);
QOpenGLContext context;
context.setFormat(format);
context.create();
if (!context.isValid()) return 1;
qDebug() << QString::fromLatin1("Context created.");
QOffscreenSurface surface;
surface.setFormat(format);
surface.create();
if(!surface.isValid()) return 2;
qDebug() << QString::fromLatin1("Surface created.");
context.makeCurrent(&surface);
return RUN_ALL_TESTS();
}
示例2: sizeLessWindow
// Verify that QOpenGLContext works with QWindows that do
// not have an explicit size set.
void tst_QOpenGL::sizeLessWindow()
{
// top-level window
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
QOpenGLContext context;
QVERIFY(context.create());
window.show();
QVERIFY(context.makeCurrent(&window));
QVERIFY(QOpenGLContext::currentContext());
}
QVERIFY(!QOpenGLContext::currentContext());
// child window
{
QWindow parent;
QWindow window(&parent);
window.setSurfaceType(QWindow::OpenGLSurface);
QOpenGLContext context;
QVERIFY(context.create());
parent.show();
window.show();
QVERIFY(context.makeCurrent(&window));
QVERIFY(QOpenGLContext::currentContext());
}
QVERIFY(!QOpenGLContext::currentContext());
}
示例3: initializeHardware
void XCompositeGLXClientBufferIntegration::initializeHardware(QtWayland::Display *)
{
qDebug() << "Initializing GLX integration";
QPlatformNativeInterface *nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface();
if (nativeInterface) {
mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWindow("Display",m_compositor->window()));
if (!mDisplay)
qFatal("could not retireve Display from platform integration");
} else {
qFatal("Platform integration doesn't have native interface");
}
mScreen = XDefaultScreen(mDisplay);
mHandler = new XCompositeHandler(m_compositor->handle(), mDisplay);
QOpenGLContext *glContext = new QOpenGLContext();
glContext->create();
m_glxBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glContext->getProcAddress("glXBindTexImageEXT"));
if (!m_glxBindTexImageEXT) {
qDebug() << "Did not find glxBindTexImageExt, everything will FAIL!";
}
m_glxReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glContext->getProcAddress("glXReleaseTexImageEXT"));
if (!m_glxReleaseTexImageEXT) {
qDebug() << "Did not find glxReleaseTexImageExt";
}
delete glContext;
}
示例4: getMaxTextureSize
int getMaxTextureSize()
{
int maxSize = 0;
// Create a temp context - required if this is called from another thread
QOpenGLContext ctx;
if ( !ctx.create() )
{
// TODO handle the error
qDebug() << "No OpenGL context could be created, this is clearly bad...";
exit(-1);
}
// rather than using a QWindow - which actually dosen't seem to work in this case either!
QOffscreenSurface surface;
surface.setFormat( ctx.format() );
surface.create();
ctx.makeCurrent(&surface);
// Now the call works
QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glEnable(GL_TEXTURE_2D);
glFuncs.glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
return maxSize;
}
示例5: fboSimpleRendering
void tst_QOpenGL::fboSimpleRendering()
{
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(surface.data());
if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("QOpenGLFramebufferObject not supported on this platform");
// No multisample with combined depth/stencil attachment:
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment);
QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat);
fbo->bind();
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFinish();
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QImage reference(fb.size(), QImage::Format_RGB32);
reference.fill(0xffff0000);
QFUZZY_COMPARE_IMAGES(fb, reference);
delete fbo;
}
示例6: fboHandleNulledAfterContextDestroyed
void tst_QOpenGL::fboHandleNulledAfterContextDestroyed()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
QOpenGLFramebufferObject *fbo = 0;
{
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(&window);
if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("QOpenGLFramebufferObject not supported on this platform");
fbo = new QOpenGLFramebufferObject(128, 128);
QVERIFY(fbo->handle() != 0);
}
QCOMPARE(fbo->handle(), 0U);
}
示例7: 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);
}
示例8: initialize
void KisOpenGL::initialize()
{
if (initialized) return;
setDefaultFormat();
// we need a QSurface active to get our GL functions from the context
QWindow surface;
surface.setSurfaceType( QSurface::OpenGLSurface );
surface.create();
QOpenGLContext context;
context.create();
context.makeCurrent( &surface );
QOpenGLFunctions *funcs = context.functions();
funcs->initializeOpenGLFunctions();
qDebug() << "OpenGL Info";
qDebug() << " Vendor: " << reinterpret_cast<const char *>(funcs->glGetString(GL_VENDOR));
qDebug() << " Renderer: " << reinterpret_cast<const char *>(funcs->glGetString(GL_RENDERER));
qDebug() << " Version: " << reinterpret_cast<const char *>(funcs->glGetString(GL_VERSION));
qDebug() << " Shading language: " << reinterpret_cast<const char *>(funcs->glGetString(GL_SHADING_LANGUAGE_VERSION));
qDebug() << " Requested format: " << QSurfaceFormat::defaultFormat();
qDebug() << " Current format: " << context.format();
glMajorVersion = context.format().majorVersion();
glMinorVersion = context.format().minorVersion();
supportsDeprecatedFunctions = (context.format().options() & QSurfaceFormat::DeprecatedFunctions);
initialized = true;
}
示例9: sharedResourceCleanup
void tst_QOpenGL::sharedResourceCleanup()
{
QFETCH(int, surfaceClass);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext *ctx = new QOpenGLContext;
ctx->create();
ctx->makeCurrent(surface.data());
SharedResourceTracker tracker;
SharedResource *resource = new SharedResource(&tracker);
resource->free();
QCOMPARE(tracker.invalidateResourceCalls, 0);
QCOMPARE(tracker.freeResourceCalls, 1);
QCOMPARE(tracker.destructorCalls, 1);
tracker.reset();
resource = new SharedResource(&tracker);
QOpenGLContext *ctx2 = new QOpenGLContext;
ctx2->setShareContext(ctx);
ctx2->create();
delete ctx;
resource->free();
// no current context, freeResource() delayed
QCOMPARE(tracker.invalidateResourceCalls, 0);
QCOMPARE(tracker.freeResourceCalls, 0);
QCOMPARE(tracker.destructorCalls, 0);
ctx2->makeCurrent(surface.data());
// freeResource() should now have been called
QCOMPARE(tracker.invalidateResourceCalls, 0);
QCOMPARE(tracker.freeResourceCalls, 1);
QCOMPARE(tracker.destructorCalls, 1);
tracker.reset();
resource = new SharedResource(&tracker);
// this should cause invalidateResource() to be called
delete ctx2;
QCOMPARE(tracker.invalidateResourceCalls, 1);
QCOMPARE(tracker.freeResourceCalls, 0);
QCOMPARE(tracker.destructorCalls, 0);
// should have no effect other than destroying the resource,
// as it has already been invalidated
resource->free();
QCOMPARE(tracker.invalidateResourceCalls, 1);
QCOMPARE(tracker.freeResourceCalls, 0);
QCOMPARE(tracker.destructorCalls, 1);
}
示例10: dumpGlInfo
void dumpGlInfo(QTextStream &str, bool listExtensions)
{
QOpenGLContext context;
if (context.create()) {
# ifdef QT_OPENGL_DYNAMIC
str << "Dynamic GL ";
# endif
switch (context.openGLModuleType()) {
case QOpenGLContext::LibGL:
str << "LibGL";
break;
case QOpenGLContext::LibGLES:
str << "LibGLES";
break;
}
QWindow window;
window.setSurfaceType(QSurface::OpenGLSurface);
window.create();
context.makeCurrent(&window);
QOpenGLFunctions functions(&context);
str << " Vendor: " << reinterpret_cast<const char *>(functions.glGetString(GL_VENDOR))
<< "\nRenderer: " << reinterpret_cast<const char *>(functions.glGetString(GL_RENDERER))
<< "\nVersion: " << reinterpret_cast<const char *>(functions.glGetString(GL_VERSION))
<< "\nShading language: " << reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION))
<< "\nFormat: " << context.format();
if (listExtensions) {
QList<QByteArray> extensionList = context.extensions().toList();
std::sort(extensionList.begin(), extensionList.end());
str << " \nFound " << extensionList.size() << " extensions:\n";
foreach (const QByteArray &extension, extensionList)
str << " " << extension << '\n';
}
} else {
示例11: testGLInternal
bool OpenGL2Common::testGL()
{
QOpenGLContext glCtx;
if ((isOK = glCtx.create()))
{
QOffscreenSurface offscreenSurface;
offscreenSurface.create();
if ((isOK = glCtx.makeCurrent(&offscreenSurface)))
testGLInternal();
}
return isOK;
}
示例12: create
void QEglFSWindow::create()
{
if (m_flags.testFlag(Created))
return;
QEGLPlatformWindow::create();
m_flags = Created;
if (window()->type() == Qt::Desktop)
return;
// Stop if there is already a window backed by a native window and surface. Additional
// raster windows will not have their own native window, surface and context. Instead,
// they will be composited onto the root window's surface.
QEglFSScreen *screen = this->screen();
if (screen->primarySurface() != EGL_NO_SURFACE) {
if (isRaster() && screen->compositingWindow())
return;
#if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)
// We can have either a single OpenGL window or multiple raster windows.
// Other combinations cannot work.
qFatal("EGLFS: OpenGL windows cannot be mixed with others.");
#endif
return;
}
m_flags |= HasNativeWindow;
setGeometry(QRect()); // will become fullscreen
QWindowSystemInterface::handleExposeEvent(window(), geometry());
EGLDisplay display = static_cast<QEglFSScreen *>(screen)->display();
QSurfaceFormat platformFormat = QEglFSHooks::hooks()->surfaceFormatFor(window()->requestedFormat());
m_config = QEglFSIntegration::chooseConfig(display, platformFormat);
m_format = q_glFormatFromConfig(display, m_config, platformFormat);
resetSurface();
screen->setPrimarySurface(m_surface);
if (isRaster()) {
QOpenGLContext *context = new QOpenGLContext(QGuiApplication::instance());
context->setFormat(window()->requestedFormat());
context->setScreen(window()->screen());
if (!context->create())
qFatal("EGLFS: Failed to create compositing context");
screen->setRootContext(context);
screen->setRootWindow(this);
}
}
示例13: getFirstSupported
static QSurfaceFormat* getFirstSupported(std::vector<QSurfaceFormat> &formats)
{
QOpenGLContext context;
for (QSurfaceFormat &format : formats)
{
context.setFormat(format);
if (context.create())
{
if (checkVersion(context, format)) return &format;
}
}
return NULL;
}
示例14: openGlContext
QString openGlContext()
{
QString result;
QTextStream str(&result);
QOpenGLContext context;
if (context.create()) {
# ifdef QT_OPENGL_DYNAMIC
str << "Dynamic GL ";
# endif
switch (context.openGLModuleType()) {
case QOpenGLContext::LibGL:
str << "LibGL";
break;
case QOpenGLContext::LibGLES:
str << "LibGLES";
break;
}
QWindow window;
if (QGuiApplication::platformName() == QLatin1String("greenisland"))
window.setFlags(Qt::Desktop);
window.setSurfaceType(QSurface::OpenGLSurface);
//window.setScreen(QGuiApplication::primaryScreen());
window.create();
if (context.makeCurrent(&window)) {
QOpenGLFunctions functions(&context);
str << " Vendor: " << reinterpret_cast<const char *>(functions.glGetString(GL_VENDOR))
<< "\nRenderer: " << reinterpret_cast<const char *>(functions.glGetString(GL_RENDERER))
<< "\nVersion: " << reinterpret_cast<const char *>(functions.glGetString(GL_VERSION))
<< "\nGLSL version: " << reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION))
<< "\nFormat: " << context.format();
QList<QByteArray> extensionList = context.extensions().toList();
std::sort(extensionList.begin(), extensionList.end());
QByteArray extensions = extensionList.join(' ');
str << " \nFound " << extensionList.size() << " extensions:\n";
str << wordWrap(extensions, 78);
context.doneCurrent();
}
window.destroy();
} else {
str << "Unable to create an Open GL context.\n";
}
return result;
}
示例15: initGl
void TestWindow::initGl() {
_glContext.setFormat(format());
if (!_glContext.create() || !_glContext.makeCurrent(this)) {
qFatal("Unable to intialize Window GL context");
}
gl::initModuleGl();
_glf.initializeOpenGLFunctions();
_glf.glGenFramebuffers(1, &_fbo);
if (!_sharedContext.create(&_glContext) || !_sharedContext.makeCurrent()) {
qFatal("Unable to intialize Shared GL context");
}
hifi::qml::OffscreenSurface::setSharedContext(_sharedContext.getContext());
_discardLamdba = hifi::qml::OffscreenSurface::getDiscardLambda();
}