예제 #1
0
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);
}
예제 #2
0
Window::Window()
  : QOpenGLWidget()
{
  QSurfaceFormat format;
  format.setSamples(8);
  format.setStencilBufferSize(8);
  setFormat(format);
  printf("Version Major:%d minor:%d \n",format.version().first, format.version().second);
  datachanged = colorchanged = true;
}
예제 #3
0
void tst_QSurfaceFormat::versionCheck()
{
    QFETCH( int, formatMajor );
    QFETCH( int, formatMinor );
    QFETCH( int, compareMajor );
    QFETCH( int, compareMinor );
    QFETCH( bool, expected );

    QSurfaceFormat format;
    format.setMinorVersion(formatMinor);
    format.setMajorVersion(formatMajor);

    QCOMPARE(format.version() >= qMakePair(compareMajor, compareMinor), expected);

    format.setVersion(formatMajor, formatMinor);
    QCOMPARE(format.version() >= qMakePair(compareMajor, compareMinor), expected);
}
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;
}
예제 #5
0
QtOpenGLWindowBase::QtOpenGLWindowBase(const QSurfaceFormat & format)
: m_context(new QOpenGLContext)
, m_initialized(false)
, m_updatePending(false)
{
    QSurfaceFormat f(format);
    f.setRenderableType(QSurfaceFormat::OpenGL);

    setSurfaceType(OpenGLSurface);
    create();

    if (f.version().first < 3)
    {
        m_context->setFormat(f);
        if (!m_context->create()) {
            qDebug() << "Could not create intermediate OpenGL context.";
            QApplication::quit();
        } else {
            QSurfaceFormat intermediateFormat = m_context->format();
            qDebug().nospace() << "Created intermediate OpenGL context " << intermediateFormat.version().first << "." << intermediateFormat.version().second;

            if ((intermediateFormat.version().first == 3 && intermediateFormat.version().second == 0) || intermediateFormat.version().first < 3)
            {
                f.setMajorVersion(3);
                f.setMinorVersion(2);
                f.setProfile(QSurfaceFormat::CoreProfile);
            }
        }
    }

    m_context->setFormat(f);
    if (!m_context->create()) {
        qDebug() << "Could not create OpenGL context.";
        QApplication::quit();
    } else {
        qDebug().nospace() << "Created OpenGL context " << m_context->format().version().first << "." << m_context->format().version().second;
    }
}
예제 #6
0
void NcRenderingLayer::init(NcMapView *view)
{
    // shaders
	QSurfaceFormat glf = QSurfaceFormat::defaultFormat();
	qDebug()<<"Glversion ="<<glf.version();
    this->shader = new QOpenGLShaderProgram();
    this->shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":shaders/simple.vert");
    this->shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":shaders/color.frag");
    this->shader->link();

	this->rect_shader =  new QOpenGLShaderProgram();
    this->rect_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":shaders/simple.vert");
    this->rect_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":shaders/rect_color.frag");
    this->rect_shader->link();
    glGenVertexArrays(1, &this->vao);
    glGenBuffers(1, &this->vbo);
    glGenBuffers(1, &this->colorbuffer);

//    QPointF origin = QPointF(0,0);//view->getOrigin();
//    QPointF wTopRight  = view->cam()->geo2world(view->getGeoBounds().bottomLeft()) - origin;
//    QPointF wBottomRight = view->cam()->geo2world(view->getGeoBounds().bottomRight()) - origin;
//    QPointF wTopLeft     = view->cam()->geo2world(view->getGeoBounds().topLeft()) - origin;
//    QPointF wBottomLeft  = view->cam()->geo2world(view->getGeoBounds().topRight()) - origin;
//    QPointF wTopLeft  = QVector3DD(253522375.1, 432502876, -9.968698493).toPointF() - origin;
//    QPointF wBottomLeft = QVector3DD(253522375.1, 432234063.2, -9.968698493).toPointF() - origin;
//    QPointF wTopRight     = QVector3DD(253880792.2, 432502876, -9.968698493).toPointF() - origin;
//    QPointF wBottomRight  = QVector3DD(253880792.2, 432234063.2, -9.968698493).toPointF() - origin;

//    qDebug() << wBottomLeft << wBottomRight << wTopLeft << wTopRight;
    float z = 0;
    float points[] = {
//        wBottomLeft.x(),-wBottomLeft.y(), z,
//        0, 0, z,
//        wBottomRight.x(),-wBottomRight.y(),  z,
//        wTopRight.x(), -wTopRight.y(),  z,
//        wBottomLeft.x(),-wBottomLeft.y(), z,
//        wTopRight.x(), -wTopRight.y(),  z,
//        wTopLeft.x(), -wTopLeft.y(), z
//        0.0f,1.0f, z,
//        1.0f,1.0f, z,
//        1.0f,0.0f, z,
//        0.0f,1.0f, z,
//        1.0f,0.0f, z,
//        0.0f,0.0f, z
        0.0, 0.0, 0.0,
        1.0, 0.0, 0.0,
        0.0, 1.0, 0.0,
        1.0, 0.0, 0.0,
        1.0, 1.0, 0.0,
        0.0, 1.0, 0.0
    };

    float colors[] = {
        1,0,0,
        0,0,1,
        1,0,0,
        1,0,0,
        1,0,1,
        1,0,0
    };

    glBindBuffer(GL_ARRAY_BUFFER, this->vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindBuffer(GL_ARRAY_BUFFER, this->colorbuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    // texture
    createTexImage2D(view->getWidth(), view->getHeight(), GL_R32F, GL_RED, GL_FLOAT, &this->tex, (void*)view->getData().data());

//	this->rectangle(0.2,0.2,0.5,0.5);
}