示例#1
0
void GlslPainter::init()
{
    _context = const_cast<QGLContext *>(QGLContext::currentContext());
    Q_ASSERT(_context);
    _context->makeCurrent();

    if (!_program)
        _program = new QGLShaderProgram(_context);

    const char *vertexProgram =
            "attribute highp vec4 targetVertex;\n"
            "attribute highp vec2 textureCoordinates;\n"
            "uniform highp mat4 positionMatrix;\n"
            "varying highp vec2 textureCoord;\n"
            "void main(void)\n"
            "{\n"
            "    gl_Position = positionMatrix * targetVertex;\n"
            "    textureCoord = textureCoordinates;\n"
            "}\n";

    static const char *vertexShader =
            "uniform sampler2D texY;\n"
            "uniform sampler2D texU;\n"
            "uniform sampler2D texV;\n"
            "uniform mediump mat4 colorMatrix;\n"
            "varying highp vec2 textureCoord;\n"
            "uniform lowp float opacity;"
            "void main(void)\n"
            "{\n"
            "    highp vec4 color = vec4(\n"
            "           texture2D(texY, textureCoord.st).r,\n"
            "           texture2D(texV, textureCoord.st).r,\n" // !!!! mind the swp
            "           texture2D(texU, textureCoord.st).r,\n"
            "           1.0);\n"
            "    gl_FragColor = colorMatrix * color * opacity;\n"
            "}\n";

    initYv12();
    initColorMatrix();

    if (!_program->addShaderFromSourceCode(QGLShader::Vertex, vertexProgram))
        qFatal("couldnt add vertex shader");
    else if (!_program->addShaderFromSourceCode(QGLShader::Fragment, vertexShader))
        qFatal("couldnt add fragment shader");
    else if (!_program->link())
        qFatal("couldnt link shader");

    glGenTextures(_textureCount, _textureIds);

    _inited = true;
}
示例#2
0
void GlslPainter::init()
{
    m_context = const_cast<QGLContext *>(QGLContext::currentContext());
    Q_ASSERT(m_context);
    m_context->makeCurrent();

    if (!m_program)
        m_program = new QGLShaderProgram(m_context);

    const char *vertexProgram =
            "attribute highp vec4 targetVertex;\n"
            "attribute highp vec2 textureCoordinates;\n"
            "uniform highp mat4 positionMatrix;\n"
            "varying highp vec2 textureCoord;\n"
            "void main(void)\n"
            "{\n"
            "    gl_Position = positionMatrix * targetVertex;\n"
            "    textureCoord = textureCoordinates;\n"
            "}\n";

    const char *program = 0;
    switch (m_frame->format) {
    case VideoFrame::Format_RGB32://////////////////////////////////////// RGB32
        initRgb32();
        program = s_phonon_rgb32Shader;
        break;
    case VideoFrame::Format_YV12: ///////////////////////////////////////// YV12
        initYv12();
        program = s_phonon_yv12Shader;
        break;
    default: /////////////////////////////////////////////////////////// Default
        qDebug() << "format: " << m_frame->format;
        Q_ASSERT(false);
    }
    Q_ASSERT(program);
    initColorMatrix();

    if (!m_program->addShaderFromSourceCode(QGLShader::Vertex, vertexProgram))
        qFatal("couldnt add vertex shader");
    else if (!m_program->addShaderFromSourceCode(QGLShader::Fragment, program))
        qFatal("couldnt add fragment shader");
    else if (!m_program->link())
        qFatal("couldnt link shader");

    glGenTextures(m_textureCount, m_textureIds);

    m_inited = true;
}