Пример #1
0
bool isBipartite(int G[][V], int src)
{
    int colorMatrix[V], color, temp, u;

    initColorMatrix(colorMatrix, V);

    struct Queue* queue = createQueue(V);

    color = 1;
    colorMatrix[src] = color;
    enQueue(queue, src);

    while (!isEmpty(queue))
    {
        temp = deQueue(queue);
        // assign alternate color to its neighbor
        color = 1 - colorMatrix[temp];

    	for (u = 0; u < V; ++u)
        {
        	// an edge exists and destination not colored
        	if (G[temp][u] && colorMatrix[u] == -1)
	        {
		        colorMatrix[u] = color;
                enQueue(queue, u);
	        }

            else if (G[temp][u] && colorMatrix[u] == colorMatrix[temp])
                return false;
        }
    }

    return true;
}
Пример #2
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;
}
Пример #3
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;
}