예제 #1
0
GLuint QGLPixelBuffer::generateDynamicTexture() const
{
    Q_D(const QGLPixelBuffer);
    if (!d->fbo)
        return 0;

    if (d->fbo->format().samples() > 0
        && QOpenGLExtensions(QOpenGLContext::currentContext())
           .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit))
    {
        if (!d->blit_fbo)
            const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size);
    } else {
        return d->fbo->texture();
    }

    GLuint texture;
    QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();

    funcs->glGenTextures(1, &texture);
    funcs->glBindTexture(GL_TEXTURE_2D, texture);

    funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, d->req_size.width(), d->req_size.height(), 0,
                        GL_RGBA, GL_UNSIGNED_BYTE, 0);

    return texture;
}
/*!
    \fn bool QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()

    Returns \c true if the OpenGL \c{GL_EXT_framebuffer_blit} extension
    is present on this system; otherwise returns \c false.

    \sa blitFramebuffer()
*/
bool QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()
{
    return QOpenGLExtensions(QOpenGLContext::currentContext()).hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit);
}