本文整理汇总了C++中QOpenGLContext::format方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLContext::format方法的具体用法?C++ QOpenGLContext::format怎么用?C++ QOpenGLContext::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLContext
的用法示例。
在下文中一共展示了QOpenGLContext::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: onInitializeGL
void OpenGLRendererBase::onInitializeGL()
{
DPTR_D(OpenGLRendererBase);
//makeCurrent();
QOpenGLContext *ctx = const_cast<QOpenGLContext*>(QOpenGLContext::currentContext()); //qt4 returns const
d.glv.setOpenGLContext(ctx);
//const QByteArray extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
bool hasGLSL = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
qDebug("OpenGL version: %d.%d hasGLSL: %d", ctx->format().majorVersion(), ctx->format().minorVersion(), hasGLSL);
initializeOpenGLFunctions();
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
}
示例3: 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);
}
示例4: q_supportsElementIndexUint
static bool q_supportsElementIndexUint(QSGRendererInterface::GraphicsApi api)
{
static bool elementIndexUint = true;
#if QT_CONFIG(opengl)
if (api == QSGRendererInterface::OpenGL) {
static bool elementIndexUintChecked = false;
if (!elementIndexUintChecked) {
elementIndexUintChecked = true;
QOpenGLContext *context = QOpenGLContext::currentContext();
QScopedPointer<QOpenGLContext> dummyContext;
QScopedPointer<QOffscreenSurface> dummySurface;
bool ok = true;
if (!context) {
dummyContext.reset(new QOpenGLContext);
dummyContext->create();
context = dummyContext.data();
dummySurface.reset(new QOffscreenSurface);
dummySurface->setFormat(context->format());
dummySurface->create();
ok = context->makeCurrent(dummySurface.data());
}
if (ok) {
elementIndexUint = static_cast<QOpenGLExtensions *>(context->functions())->hasOpenGLExtension(
QOpenGLExtensions::ElementIndexUint);
}
}
}
#else
Q_UNUSED(api);
#endif
return elementIndexUint;
}
示例5: 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 {
示例6: ba
QOpenGLExtensionMatcher::QOpenGLExtensionMatcher()
{
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QOpenGLFunctions *funcs = ctx->functions();
const char *extensionStr = 0;
if (ctx->isOpenGLES() || ctx->format().majorVersion() < 3)
extensionStr = reinterpret_cast<const char *>(funcs->glGetString(GL_EXTENSIONS));
if (extensionStr) {
QByteArray ba(extensionStr);
QList<QByteArray> extensions = ba.split(' ');
m_extensions = extensions.toSet();
} else {
#ifdef QT_OPENGL_3
// clear error state
while (funcs->glGetError()) {}
if (ctx) {
qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress("glGetStringi");
if (!glGetStringi)
return;
GLint numExtensions;
funcs->glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
for (int i = 0; i < numExtensions; ++i) {
const char *str = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
m_extensions.insert(str);
}
}
#endif // QT_OPENGL_3
}
}
示例7: 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;
}
示例8: initializeGL
void MapWidget::initializeGL()
{
initializeOpenGLFunctions();
QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION))));
QOpenGLContext *ctx = QOpenGLContext::currentContext();
Q_UNUSED(ctx);
lg = new QOpenGLDebugLogger(context());
lg->initialize();
lg->startLogging(QOpenGLDebugLogger::SynchronousLogging);
lg->enableMessages();
connect(lg, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, SLOT(glLog(QOpenGLDebugMessage)));
qDebug() << "Driver Version String:" << versionString;
qDebug() << "Current Context:" << ctx->format();
//glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &gpuTotalMemory);
//qDebug() << "total" << gpuTotalMemory;
m_renderer = new Renderer();
m_renderer->createStaticResources();
//m_painterOverlay = new PainterOverlay();
}
示例9: contextProfile
QSurfaceFormat::OpenGLContextProfile QSGShaderSourceBuilder::contextProfile() const
{
QOpenGLContext *context = QOpenGLContext::currentContext();
QSurfaceFormat::OpenGLContextProfile profile = QSurfaceFormat::NoProfile;
Q_ASSERT(context);
profile = context->format().profile();
return profile;
}
示例10: checkVersion
static bool checkVersion(QOpenGLContext &context, QSurfaceFormat &format)
{
QSurfaceFormat currSurface = context.format();
QPair<int,int> currVersion = currSurface.version();
QPair<int,int> reqVersion = format.version();
if (currVersion.first > reqVersion.first)
return true;
return (currVersion.first == reqVersion.first && currVersion.second >= reqVersion.second);
}
示例11: initialize
void OpenGLRenderPrivate::initialize()
{
initializeOpenGLFunctions();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
for (int i = 0; i < 5; ++i){
const char *fShaderCode = nullptr;
switch (i){
case 0:
case 1:
fShaderCode = fShaderI420;
break;
case 2:
fShaderCode = fShaderNV12;
break;
case 3:
fShaderCode = fShaderNV21;
break;
case 4:
fShaderCode = fShaderBGRP;
break;
}
QOpenGLShaderProgram &p = program[i];
p.addShaderFromSourceCode(QOpenGLShader::Vertex, vShaderCode);
p.addShaderFromSourceCode(QOpenGLShader::Fragment, fShaderCode);
p.bindAttributeLocation("VtxCoord", 0);
p.bindAttributeLocation("TexCoord", 1);
p.bind();
switch (i){
case 0:
p.setUniformValue("SamplerY", 0);
p.setUniformValue("SamplerU", 1);
p.setUniformValue("SamplerV", 2);
break;
case 1:
p.setUniformValue("SamplerY", 0);
p.setUniformValue("SamplerV", 1);
p.setUniformValue("SamplerU", 2);
break;
case 2:
case 3:
p.setUniformValue("SamplerY", 0);
p.setUniformValue("SamplerA", 1);
break;
case 4:
p.setUniformValue("SamplerP", 0);
break;
}
}
tex[0] = 0; tex[1] = 0;
tex[2] = 1; tex[3] = 0;
tex[4] = 0; tex[5] = 1;
tex[6] = 1; tex[7] = 1;
QOpenGLContext *c = QOpenGLContext::currentContext();
timer.setInterval(c->format().swapInterval() / (double)c->screen()->refreshRate());
}
示例12: create
bool QOpenGLTextureBlitter::create()
{
QOpenGLContext *currentContext = QOpenGLContext::currentContext();
if (!currentContext)
return false;
Q_D(QOpenGLTextureBlitter);
d->vao->create();
d->vao->bind();
if (d->program)
return true;
d->program.reset(new QOpenGLShaderProgram());
QSurfaceFormat format = currentContext->format();
if (format.profile() == QSurfaceFormat::CoreProfile && format.version() >= qMakePair(3,2)) {
d->program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader150);
d->program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader150);
} else {
d->program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader);
d->program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader);
}
d->program->link();
if (!d->program->isLinked()) {
qWarning() << Q_FUNC_INFO << "Could not link shader program:\n" << d->program->log();
return false;
}
d->program->bind();
d->vertexBuffer.create();
d->vertexBuffer.bind();
d->vertexBuffer.allocate(vertex_buffer_data, sizeof(vertex_buffer_data));
d->vertexBuffer.release();
d->textureBuffer.create();
d->textureBuffer.bind();
d->textureBuffer.allocate(texture_buffer_data, sizeof(texture_buffer_data));
d->textureBuffer.release();
d->vertexCoordAttribPos = d->program->attributeLocation("vertexCoord");
d->vertexTransformUniformPos = d->program->uniformLocation("vertexTransform");
d->textureCoordAttribPos = d->program->attributeLocation("textureCoord");
d->textureTransformUniformPos = d->program->uniformLocation("textureTransform");
d->swizzleUniformPos = d->program->uniformLocation("swizzle");
d->program->setUniformValue(d->swizzleUniformPos,false);
d->vao->release();
return true;
}
示例13: onInitializeGL
void OpenGLRendererBase::onInitializeGL()
{
DPTR_D(OpenGLRendererBase);
//makeCurrent();
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
initializeOpenGLFunctions();
#endif
QOpenGLContext *ctx = const_cast<QOpenGLContext*>(QOpenGLContext::currentContext()); //qt4 returns const
d.glv.setOpenGLContext(ctx);
//const QByteArray extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
bool hasGLSL = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
qDebug("OpenGL version: %d.%d hasGLSL: %d", ctx->format().majorVersion(), ctx->format().minorVersion(), hasGLSL);
static bool sInfo = true;
if (sInfo) {
sInfo = false;
qDebug("GL_VERSION: %s", DYGL(glGetString(GL_VERSION)));
qDebug("GL_VENDOR: %s", DYGL(glGetString(GL_VENDOR)));
qDebug("GL_RENDERER: %s", DYGL(glGetString(GL_RENDERER)));
qDebug("GL_SHADING_LANGUAGE_VERSION: %s", DYGL(glGetString(GL_SHADING_LANGUAGE_VERSION)));
}
}
示例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: 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.
}
}