Example #1
0
void GLWidgetRendererPrivate::upload(const QRect &roi)
{
    updateTexturesIfNeeded();
    for (int i = 0; i < video_frame.planeCount(); ++i) {
        uploadPlane(i, internal_format[i], data_format[i], roi);
    }
}
Example #2
0
void GLWidgetRendererPrivate::upload(const QRect &roi)
{
    const VideoFormat &fmt = video_frame.format();
    bool update_textures = false;
    if (fmt != video_format) {
        update_textures = true;
        qDebug("pixel format changed: %s => %s", qPrintable(video_format.name()), qPrintable(fmt.name()));
        if (!prepareShaderProgram(fmt)) {
            qWarning("shader program create error...");
            return;
        } else {
            qDebug("shader program created!!!");
        }
    }
    // effective size may change even if plane size not changed
    if (update_textures || video_frame.size() != plane0Size) { //
        update_textures = true;
        //qDebug("---------------------update texture: %dx%d, %s", video_frame.width(), video_frame.height(), video_frame.format().name().toUtf8().constData());
        texture_size.resize(fmt.planeCount());
        effective_tex_width.resize(fmt.planeCount());
        for (int i = 0; i < fmt.planeCount(); ++i) {
            qDebug("plane linesize %d: padded = %d, effective = %d", i, video_frame.bytesPerLine(i), video_frame.effectiveBytesPerLine(i));
            qDebug("plane width %d: effective = %d", video_frame.planeWidth(i), video_frame.effectivePlaneWidth(i));
            qDebug("planeHeight %d = %d", i, video_frame.planeHeight(i));
            // we have to consider size of opengl format. set bytesPerLine here and change to width later
            texture_size[i] = QSize(video_frame.bytesPerLine(i), video_frame.planeHeight(i));
            effective_tex_width[i] = video_frame.effectiveBytesPerLine(i); //store bytes here, modify as width later
            // TODO: ratio count the GL_UNPACK_ALIGN?
            effective_tex_width_ratio = qMin((qreal)1.0, (qreal)video_frame.effectiveBytesPerLine(i)/(qreal)video_frame.bytesPerLine(i));
        }
        qDebug("effective_tex_width_ratio=%f", effective_tex_width_ratio);
        plane0Size = video_frame.size();
    }
    if (update_textures) {
        initTextures(fmt);
    }

    for (int i = 0; i < video_frame.planeCount(); ++i) {
        uploadPlane(i, internal_format[i], data_format[i], roi);
    }
}