本文整理汇总了C++中QWindow::setSurfaceType方法的典型用法代码示例。如果您正苦于以下问题:C++ QWindow::setSurfaceType方法的具体用法?C++ QWindow::setSurfaceType怎么用?C++ QWindow::setSurfaceType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWindow
的用法示例。
在下文中一共展示了QWindow::setSurfaceType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static QSurface *createSurface(int surfaceClass)
{
if (surfaceClass == int(QSurface::Window)) {
QWindow *window = new QWindow;
window->setSurfaceType(QWindow::OpenGLSurface);
window->setGeometry(0, 0, 10, 10);
window->create();
return window;
} else if (surfaceClass == int(QSurface::Offscreen)) {
// Create a window and get the format from that. For example, if an EGL
// implementation provides 565 and 888 configs for PBUFFER_BIT but only
// 888 for WINDOW_BIT, we may end up with a pbuffer surface that is
// incompatible with the context since it could choose the 565 while the
// window and the context uses a config with 888.
static QSurfaceFormat format;
if (format.redBufferSize() == -1) {
QWindow *window = new QWindow;
window->setSurfaceType(QWindow::OpenGLSurface);
window->setGeometry(0, 0, 10, 10);
window->create();
format = window->format();
delete window;
}
QOffscreenSurface *offscreenSurface = new QOffscreenSurface;
offscreenSurface->setFormat(format);
offscreenSurface->create();
return offscreenSurface;
}
return 0;
}
示例2: 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 {
示例3: 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;
}
示例4: 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);
}
示例5: aboutToBeDestroyed
void tst_QOpenGL::aboutToBeDestroyed()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 128, 128);
window.create();
QOpenGLContext *context = new QOpenGLContext;
QSignalSpy spy(context, SIGNAL(aboutToBeDestroyed()));
context->create();
context->makeCurrent(&window);
QCOMPARE(spy.size(), 0);
delete context;
QCOMPARE(spy.size(), 1);
}
示例6: 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());
}
示例7: 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;
}
示例8: if
static QSurface *createSurface(int surfaceClass)
{
if (surfaceClass == int(QSurface::Window)) {
QWindow *window = new QWindow;
window->setSurfaceType(QWindow::OpenGLSurface);
window->setGeometry(0, 0, 10, 10);
window->create();
return window;
} else if (surfaceClass == int(QSurface::Offscreen)) {
QOffscreenSurface *offscreenSurface = new QOffscreenSurface;
offscreenSurface->create();
return offscreenSurface;
}
return 0;
}
示例9: fbo
void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero()
{
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
QSKIP("QTBUG-22617");
#endif
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 128, 128);
window.create();
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(&window);
if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
QSKIP("QOpenGLFramebufferObject not supported on this platform");
QOpenGLFramebufferObject fbo(128, 128);
fbo.bind();
QOpenGLPaintDevice device(128, 128);
// QTBUG-15621 is only a problem when qreal is double, but do the test anyway.
qreal delta = sizeof(qreal) == sizeof(float) ? 1e-4 : 1e-8;
QVERIFY(128 != 128 + delta);
QPainterPath path;
path.moveTo(16 + delta, 16);
path.moveTo(16, 16);
path.lineTo(16 + delta, 16); // Short lines to check for division by zero.
path.lineTo(112 - delta, 16);
path.lineTo(112, 16);
path.quadTo(112, 16, 112, 16 + delta);
path.quadTo(112, 64, 112, 112 - delta);
path.quadTo(112, 112, 112, 112);
path.cubicTo(112, 112, 112, 112, 112 - delta, 112);
path.cubicTo(80, 112, 48, 112, 16 + delta, 112);
path.cubicTo(16 + delta, 112, 16 + delta, 112, 16, 112);
path.closeSubpath();
QPen pen(Qt::red, 28, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
QPainter p(&device);
p.fillRect(QRect(0, 0, 128, 128), Qt::blue);
p.strokePath(path, pen);
p.end();
QImage image = fbo.toImage().convertToFormat(QImage::Format_RGB32);
const QRgb red = 0xffff0000;
const QRgb blue = 0xff0000ff;
QCOMPARE(image.pixel(8, 8), red);
QCOMPARE(image.pixel(119, 8), red);
QCOMPARE(image.pixel(8, 119), red);
QCOMPARE(image.pixel(119, 119), red);
QCOMPARE(image.pixel(0, 0), blue);
QCOMPARE(image.pixel(127, 0), blue);
QCOMPARE(image.pixel(0, 127), blue);
QCOMPARE(image.pixel(127, 127), blue);
QCOMPARE(image.pixel(32, 32), blue);
QCOMPARE(image.pixel(95, 32), blue);
QCOMPARE(image.pixel(32, 95), blue);
QCOMPARE(image.pixel(95, 95), blue);
}
示例10: memset
bool OculusWin32DisplayPlugin::start() {
{
ovrInitParams initParams; memset(&initParams, 0, sizeof(initParams));
#ifdef DEBUG
initParams.Flags |= ovrInit_Debug;
#endif
ovrResult result = ovr_Initialize(&initParams);
Q_ASSERT(OVR_SUCCESS(result));
result = ovr_Create(&_hmd, &_luid);
_hmdDesc = ovr_GetHmdDesc(_hmd);
for_each_eye([&](ovrEyeType eye) {
_eyeFovs[eye] = _hmdDesc.DefaultEyeFov[eye];
_eyeProjections[eye] = toGlm(ovrMatrix4f_Projection(_eyeFovs[eye],
0.01f, 100.0f, ovrProjection_RightHanded));
ovrEyeRenderDesc erd = ovr_GetRenderDesc(_hmd, eye, _eyeFovs[eye]);
_eyeOffsets[eye] = erd.HmdToEyeViewOffset;
});
_eyeTextureSize = ovr_GetFovTextureSize(_hmd, ovrEye_Left, _eyeFovs[ovrEye_Left], 1.0f);
_renderTargetSize = { _eyeTextureSize.w * 2, _eyeTextureSize.h };
ovr_ConfigureTracking(_hmd,
ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection,
ovrTrackingCap_Orientation);
}
Q_ASSERT(!_window);
Q_ASSERT(_shareContext);
_window = new QWindow;
_window->setSurfaceType(QSurface::OpenGLSurface);
_window->setFormat(getDesiredSurfaceFormat());
_context = new QOpenGLContext;
_context->setFormat(getDesiredSurfaceFormat());
_context->setShareContext(_shareContext);
_context->create();
_window->show();
_window->setGeometry(QRect(100, -800, 1280, 720));
bool result = _context->makeCurrent(_window);
#if defined(Q_OS_WIN)
if (wglewGetExtension("WGL_EXT_swap_control")) {
wglSwapIntervalEXT(0);
int swapInterval = wglGetSwapIntervalEXT();
qDebug("V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF"));
}
#elif defined(Q_OS_LINUX)
#else
qCDebug(interfaceapp, "V-Sync is FORCED ON on this system\n");
#endif
Q_ASSERT(result);
{
// The geometry and shader for rendering the 2D UI surface when needed
_program = oria::loadProgram(
Resource::SHADERS_TEXTURED_VS,
Resource::SHADERS_TEXTURED_FS);
_quad = oria::loadPlane(_program, 1.0f);
glClearColor(0, 1, 1, 1);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_mirrorFbo = new MirrorFramebufferWrapper(_hmd);
_sceneSwapFbo = new SwapFramebufferWrapper(_hmd);
_sceneSwapFbo->Init(toGlm(_renderTargetSize));
_uiSwapFbo = new SwapFramebufferWrapper(_hmd);
_uiSwapFbo->Init(_uiSize);
_mirrorFbo->Init(uvec2(100, 100));
_context->doneCurrent();
}
_sceneLayer.ColorTexture[0] = _sceneSwapFbo->color;
_sceneLayer.ColorTexture[1] = nullptr;
_sceneLayer.Viewport[0].Pos = { 0, 0 };
_sceneLayer.Viewport[0].Size = _eyeTextureSize;
_sceneLayer.Viewport[1].Pos = { _eyeTextureSize.w, 0 };
_sceneLayer.Viewport[1].Size = _eyeTextureSize;
_sceneLayer.Header.Type = ovrLayerType_EyeFov;
_sceneLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft;
for_each_eye([&](ovrEyeType eye) {
_eyeViewports[eye] = _sceneLayer.Viewport[eye];
_sceneLayer.Fov[eye] = _eyeFovs[eye];
});
_uiLayer.ColorTexture = _uiSwapFbo->color;
_uiLayer.Header.Type = ovrLayerType_QuadInWorld;
_uiLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft;
_uiLayer.QuadPoseCenter.Orientation = { 0, 0, 0, 1 };
_uiLayer.QuadPoseCenter.Position = { 0, 0, -1 };
_uiLayer.QuadSize = { aspect(_uiSize), 1.0f };
_uiLayer.Viewport = { { 0, 0 }, { (int)_uiSize.x, (int)_uiSize.y } };
_timer.start(0);
//.........这里部分代码省略.........
示例11: main
//.........这里部分代码省略.........
switch (type) {
case WidgetType:
{
OnScreenWidget<QWidget> *qWidget =
new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
activeWidget = qWidget;
break;
}
case ImageWidgetType:
{
OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
activeWidget = qWidget;
break;
}
#ifndef QT_NO_OPENGL
case OpenGLBufferType:
{
QWindow win;
win.setSurfaceType(QSurface::OpenGLSurface);
win.create();
QOpenGLFramebufferObjectFormat fmt;
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
fmt.setSamples(4);
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(&win);
QOpenGLFramebufferObject fbo(width, height, fmt);
fbo.bind();
QOpenGLPaintDevice pdev(width, height);
QPainter pt(&pdev);
pcmd.setPainter(&pt);
pcmd.setFilePath(fileinfo.absolutePath());
pcmd.runCommands();
pt.end();
QImage image = fbo.toImage();
QLabel *label = createLabel();
label->setPixmap(QPixmap::fromImage(image));
label->resize(label->sizeHint());
label->show();
activeWidget = label;
break;
}
case OpenGLType:
{
OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>(files.at(j));
qGLWidget->setVerboseMode(verboseMode);
qGLWidget->setType(type);
qGLWidget->setCheckersBackground(checkers_background);