コード例 #1
0
    void canExtractEmptyUniformDeclarationWhenNoUniform()
    {
        ShaderProgram shaderProgram;
        addShader(shaderProgram, Shader::FRAGMENT_SHADER, VALID_FRAGMENT_SHADER_SOURCE);
        QVERIFY(shaderProgram.link());

        UniformDeclarationVector uniformDeclarationVector;
        shaderProgram.extractActive(uniformDeclarationVector);

        QVERIFY(uniformDeclarationVector.empty());
    }
コード例 #2
0
    void canExtractArrayUniformDeclaration()
    {
        ShaderProgram shaderProgram;
        const char* source = \
                "uniform vec4 position[];"\
                "void main() {"\
                " gl_Position = position[0] + position[1] + position[3];"\
                "}";

        addShader(shaderProgram, Shader::VERTEX_SHADER, source);
        QVERIFY(shaderProgram.link());

        UniformDeclarationVector uniformDeclarationVector;
        shaderProgram.extractActive(uniformDeclarationVector);

        QCOMPARE(uniformDeclarationVector.size(), static_cast<size_t>(1));

        QCOMPARE(uniformDeclarationVector[0], UniformDeclaration(0, 4, GL_FLOAT_VEC4, "position[0]"));
    }
コード例 #3
0
    void canExtractMultipleUniformDeclaration()
    {
        ShaderProgram shaderProgram;
        const char* source = \
                "uniform vec4 position;"\
                "uniform mat4 mvp;"
                "void main() {"\
                " gl_Position = mvp * position;"\
                "}";

        addShader(shaderProgram, Shader::VERTEX_SHADER, source);
        QVERIFY(shaderProgram.link());

        UniformDeclarationVector uniformDeclarationVector;
        shaderProgram.extractActive(uniformDeclarationVector);

        QCOMPARE(uniformDeclarationVector.size(), static_cast<size_t>(2));

        for (unsigned int i = 0; i < uniformDeclarationVector.size(); ++i)
        {
            UniformDeclaration& uniformDeclaration = uniformDeclarationVector[i];
            QCOMPARE(uniformDeclaration.getIndex(), static_cast<GLuint>(i));
            if (uniformDeclaration.getName() == "position")
            {
                QCOMPARE(uniformDeclaration.getSize(), 1);
                QCOMPARE(uniformDeclaration.getType(), static_cast<GLenum>(GL_FLOAT_VEC4));
            }
            else if (uniformDeclaration.getName() == "mvp")
            {
                QCOMPARE(uniformDeclaration.getSize(), 1);
                QCOMPARE(uniformDeclaration.getType(), static_cast<GLenum>(GL_FLOAT_MAT4));
            }
            else
            {
                QFAIL("unexpected uniform");
            }
        }
    }
コード例 #4
0
    void canExtractStructArrayUniformDeclaration()
    {
        ShaderProgram shaderProgram;
        const char* source = \
                "struct MyStruct {"\
                " vec4 position1[2];"\
                " vec3 position2;"\
                "};"\
                "uniform MyStruct ms[2];"\
                "void main() {"\
                " gl_Position = ms[1].position1[1] + vec4(ms[1].position2, 0);"\
                "}";

        addShader(shaderProgram, Shader::VERTEX_SHADER, source);
        QVERIFY(shaderProgram.link());

        UniformDeclarationVector uniformDeclarationVector;
        shaderProgram.extractActive(uniformDeclarationVector);

        QCOMPARE(uniformDeclarationVector.size(), static_cast<size_t>(2));
        QCOMPARE(uniformDeclarationVector[0], UniformDeclaration(0, 2, GL_FLOAT_VEC4, "ms[1].position1[0]"));
        QCOMPARE(uniformDeclarationVector[1], UniformDeclaration(1, 1, GL_FLOAT_VEC3, "ms[1].position2"));
    }