src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
TEST_P(UniformBlockWithOneLargeArrayMemberTest, MemberTypeIsStructAndInstancedArray)
{
    std::ostringstream stream;
    generateArraySizeAndDivisorsDeclaration(stream, false, true, false);
    const std::string &kFS =
        "#version 300 es\n"
        "precision highp float;\n" +
        stream.str() +
        "out vec4 my_FragColor;\n"
        "struct S { mat4 color;};\n"
        "layout(std140) uniform buffer { S s[arraySize]; } instance[2];\n"
        "void main()\n"
        "{\n"
        "    uvec2 coord = uvec2(floor(gl_FragCoord.xy));\n"
        "    uint index = coord.x +  coord.y * 128u;\n"
        "    uint index_x = index / divisor1;\n"
        "    uint index_y = (index % divisor1) / divisor2;\n"
        "    my_FragColor = instance[0].s[index_x].color[index_y] + "
        "instance[1].s[index_x].color[index_y];\n"
        "}\n";

    GLint blockSize0, blockSize1;
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS.c_str());
    GLint uniformBufferIndex0 = glGetUniformBlockIndex(program, "buffer[0]");
    GLint uniformBufferIndex1 = glGetUniformBlockIndex(program, "buffer[1]");
    glGetActiveUniformBlockiv(program, uniformBufferIndex0, GL_UNIFORM_BLOCK_DATA_SIZE,
                              &blockSize0);
    glGetActiveUniformBlockiv(program, uniformBufferIndex1, GL_UNIFORM_BLOCK_DATA_SIZE,
                              &blockSize1);

    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, blockSize0, nullptr, GL_STATIC_DRAW);

    glBindBufferBase(GL_UNIFORM_BUFFER, 0, mUniformBuffer);
    glUniformBlockBinding(program, uniformBufferIndex0, 0);

    const GLuint arraySize  = getArraySize();
    const GLuint floatCount = arraySize * kVectorPerMat * kFloatPerVector;
    std::vector<GLfloat> floatData0(floatCount, 0.0f);
    std::vector<GLfloat> floatData1(floatCount, 0.0f);

    setArrayValues(floatData0, 0, arraySize, 16, 0, 4, 4, 0.0f, 0.0f, 1.0f, 1.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData0.data());

    GLBuffer uniformBuffer1;
    glBindBuffer(GL_UNIFORM_BUFFER, uniformBuffer1);
    glBufferData(GL_UNIFORM_BUFFER, blockSize1, nullptr, GL_STATIC_DRAW);

    glBindBufferBase(GL_UNIFORM_BUFFER, 1, uniformBuffer1);
    glUniformBlockBinding(program, uniformBufferIndex0, 1);

    setArrayValues(floatData1, 0, arraySize, 16, 0, 4, 4, 0.0f, 1.0f, 0.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData1.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::cyan, GLColor::cyan, GLColor::cyan, GLColor::cyan);

    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    setArrayValues(floatData0, 0, arraySize, 16, 0, 4, 4, 1.0f, 0.0f, 0.0f, 1.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData0.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::yellow, GLColor::yellow, GLColor::yellow, GLColor::yellow);

    glBindBuffer(GL_UNIFORM_BUFFER, uniformBuffer1);
    setArrayValues(floatData1, arraySize / 4, arraySize / 2, 16, 0, 4, 4, 0.0f, 0.0f, 1.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData1.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::yellow, GLColor::magenta, GLColor::yellow, GLColor::yellow);
}
// Test instanced uniform block array whose member is structure type, which contains a mat4 member.
Test instanced uniform block array whose member is structure type, which contains a mat4 member.
Test instanced uniform block array whose member is structure type which contains a mat4 member .
TEST_P(UniformBlockWithOneLargeArrayMemberTest, MemberTypeIsStructAndInstancedArray)
{
    std::ostringstream stream;
    generateArraySizeAndDivisorsDeclaration(stream, false, true, false);
    const std::string &kFS =
        "#version 300 es\n"
        "precision highp float;\n" +
        stream.str() +
        "out vec4 my_FragColor;\n"
        "struct S { mat4 color;};\n"
        "layout(std140) uniform buffer { S s[arraySize]; } instance[2];\n"
        "void main()\n"
        "{\n"
        "    uvec2 coord = uvec2(floor(gl_FragCoord.xy));\n"
        "    uint index = coord.x +  coord.y * 128u;\n"
        "    uint index_x = index / divisor1;\n"
        "    uint index_y = (index % divisor1) / divisor2;\n"
        "    my_FragColor = instance[0].s[index_x].color[index_y] + "
        "instance[1].s[index_x].color[index_y];\n"
        "}\n";
    GLint blockSize0, blockSize1;
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS.c_str());
    GLint uniformBufferIndex0 = glGetUniformBlockIndex(program, "buffer[0]");
    GLint uniformBufferIndex1 = glGetUniformBlockIndex(program, "buffer[1]");
    glGetActiveUniformBlockiv(program, uniformBufferIndex0, GL_UNIFORM_BLOCK_DATA_SIZE,
                              &blockSize0);
    glGetActiveUniformBlockiv(program, uniformBufferIndex1, GL_UNIFORM_BLOCK_DATA_SIZE,
                              &blockSize1);
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, blockSize0, nullptr, GL_STATIC_DRAW);
    glBindBufferBase(GL_UNIFORM_BUFFER, 0, mUniformBuffer);
    glUniformBlockBinding(program, uniformBufferIndex0, 0);
    const GLuint arraySize  = getArraySize();
    const GLuint floatCount = arraySize * kVectorPerMat * kFloatPerVector;
    std::vector<GLfloat> floatData0(floatCount, 0.0f);
    std::vector<GLfloat> floatData1(floatCount, 0.0f);
    setArrayValues(floatData0, 0, arraySize, 16, 0, 4, 4, 0.0f, 0.0f, 1.0f, 1.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData0.data());
    GLBuffer uniformBuffer1;
    glBindBuffer(GL_UNIFORM_BUFFER, uniformBuffer1);
    glBufferData(GL_UNIFORM_BUFFER, blockSize1, nullptr, GL_STATIC_DRAW);
    glBindBufferBase(GL_UNIFORM_BUFFER, 1, uniformBuffer1);
    glUniformBlockBinding(program, uniformBufferIndex0, 1);
    setArrayValues(floatData1, 0, arraySize, 16, 0, 4, 4, 0.0f, 1.0f, 0.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData1.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::cyan, GLColor::cyan, GLColor::cyan, GLColor::cyan);
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    setArrayValues(floatData0, 0, arraySize, 16, 0, 4, 4, 1.0f, 0.0f, 0.0f, 1.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData0.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::yellow, GLColor::yellow, GLColor::yellow, GLColor::yellow);
    glBindBuffer(GL_UNIFORM_BUFFER, uniformBuffer1);
    setArrayValues(floatData1, arraySize / 4, arraySize / 2, 16, 0, 4, 4, 0.0f, 0.0f, 1.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData1.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::yellow, GLColor::magenta, GLColor::yellow, GLColor::yellow);
}
TEST_P ( UniformBlockWithOneLargeArrayMemberTest , MemberTypeIsStructAndInstancedArray ) { std :: ostringstream stream ; generateArraySizeAndDivisorsDeclaration ( stream , false , true , false ) ; const std :: string & kFS = " \n " " \n " + stream . str ( ) + " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " " " \n " " \n " ; GLint blockSize0 , blockSize1 ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS . c_str ( ) ) ; GLint uniformBufferIndex0 = glGetUniformBlockIndex ( program , " " ) ; GLint uniformBufferIndex1 = glGetUniformBlockIndex ( program , " " ) ; glGetActiveUniformBlockiv ( program , uniformBufferIndex0 , GL_UNIFORM_BLOCK_DATA_SIZE , & blockSize0 ) ; glGetActiveUniformBlockiv ( program , uniformBufferIndex1 , GL_UNIFORM_BLOCK_DATA_SIZE , & blockSize1 ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; glBufferData ( GL_UNIFORM_BUFFER , blockSize0 , nullptr , GL_STATIC_DRAW ) ; glBindBufferBase ( GL_UNIFORM_BUFFER , 0 , mUniformBuffer ) ; glUniformBlockBinding ( program , uniformBufferIndex0 , 0 ) ; const GLuint arraySize = getArraySize ( ) ; const GLuint floatCount = arraySize * kVectorPerMat * kFloatPerVector ; std :: vector < GLfloat > floatData0 ( floatCount , 0.0f ) ; std :: vector < GLfloat > floatData1 ( floatCount , 0.0f ) ; setArrayValues ( floatData0 , 0 , arraySize , 16 , 0 , 4 , 4 , 0.0f , 0.0f , 1.0f , 1.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData0 . data ( ) ) ; GLBuffer uniformBuffer1 ; glBindBuffer ( GL_UNIFORM_BUFFER , uniformBuffer1 ) ; glBufferData ( GL_UNIFORM_BUFFER , blockSize1 , nullptr , GL_STATIC_DRAW ) ; glBindBufferBase ( GL_UNIFORM_BUFFER , 1 , uniformBuffer1 ) ; glUniformBlockBinding ( program , uniformBufferIndex0 , 1 ) ; setArrayValues ( floatData1 , 0 , arraySize , 16 , 0 , 4 , 4 , 0.0f , 1.0f , 0.0f , 0.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData1 . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: cyan , GLColor :: cyan , GLColor :: cyan , GLColor :: cyan ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; setArrayValues ( floatData0 , 0 , arraySize , 16 , 0 , 4 , 4 , 1.0f , 0.0f , 0.0f , 1.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData0 . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: yellow , GLColor :: yellow , GLColor :: yellow , GLColor :: yellow ) ; glBindBuffer ( GL_UNIFORM_BUFFER , uniformBuffer1 ) ; setArrayValues ( floatData1 , arraySize / 4 , arraySize / 2 , 16 , 0 , 4 , 4 , 0.0f , 0.0f , 1.0f , 0.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData1 . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: yellow , GLColor :: magenta , GLColor :: yellow , GLColor :: yellow ) ; }
Test instanced uniform block array whose member is structure type, which contains a mat4 member.
Test instanced uniform block array whose member is structure type which contains a mat4 member .