src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test with a block containing an array of structs containing arrays.
Test with a block containing an array of structs containing arrays.
Test with a block containing an array of structs containing arrays .
TEST_P(UniformBufferTest, BlockContainingArrayOfStructsContainingArrays)
{
    constexpr char kFS[] =
        R"(#version 300 es
        precision highp float;
        out vec4 my_FragColor;
        struct light_t
        {
            vec4 intensity[3];
        };
        const int maxLights = 2;
        layout(std140) uniform lightData { light_t lights[maxLights]; };
        vec4 processLight(vec4 lighting, light_t light)
        {
            return lighting + light.intensity[1];
        }
        void main()
        {
            vec4 lighting = vec4(0, 0, 0, 1);
            lighting = processLight(lighting, lights[0]);
            lighting = processLight(lighting, lights[1]);
            my_FragColor = lighting;
        })";
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
    GLint uniformBufferIndex = glGetUniformBlockIndex(program, "lightData");
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    const GLsizei kStructCount       = 2;
    const GLsizei kVectorsPerStruct  = 3;
    const GLsizei kElementsPerVector = 4;
    const GLsizei kBytesPerElement   = 4;
    const GLsizei kDataSize =
        kStructCount * kVectorsPerStruct * kElementsPerVector * kBytesPerElement;
    std::vector<GLubyte> v(kDataSize, 0);
    float *vAsFloat = reinterpret_cast<float *>(v.data());
    vAsFloat[kElementsPerVector + 1]                                          = 0.5f;
    vAsFloat[kVectorsPerStruct * kElementsPerVector + kElementsPerVector + 1] = 0.5f;
    glBufferData(GL_UNIFORM_BUFFER, kDataSize, v.data(), GL_STATIC_DRAW);
    glBindBufferBase(GL_UNIFORM_BUFFER, 0, mUniformBuffer);
    glUniformBlockBinding(program, uniformBufferIndex, 0);
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
TEST_P ( UniformBufferTest , BlockContainingArrayOfStructsContainingArrays ) { constexpr char kFS [ ] = R" ( #version 300 es
        precision highp float;
        out vec4 my_FragColor;
        struct light_t
        {
            vec4 intensity[3];
        };
        const int maxLights = 2;
        layout(std140) uniform lightData { light_t lights[maxLights]; };
        vec4 processLight(vec4 lighting, light_t light)
        {
            return lighting + light.intensity[1];
        }
        void main()
        {
            vec4 lighting = vec4(0, 0, 0, 1);
            lighting = processLight(lighting, lights[0]);
            lighting = processLight(lighting, lights[1]);
            my_FragColor = lighting;
        } ) " ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS ) ; GLint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; const GLsizei kStructCount = 2 ; const GLsizei kVectorsPerStruct = 3 ; const GLsizei kElementsPerVector = 4 ; const GLsizei kBytesPerElement = 4 ; const GLsizei kDataSize = kStructCount * kVectorsPerStruct * kElementsPerVector * kBytesPerElement ; std :: vector < GLubyte > v ( kDataSize , 0 ) ; float * vAsFloat = reinterpret_cast < float * > ( v . data ( ) ) ; vAsFloat [ kElementsPerVector + 1 ] = 0.5f ; vAsFloat [ kVectorsPerStruct * kElementsPerVector + kElementsPerVector + 1 ] = 0.5f ; glBufferData ( GL_UNIFORM_BUFFER , kDataSize , v . data ( ) , GL_STATIC_DRAW ) ; glBindBufferBase ( GL_UNIFORM_BUFFER , 0 , mUniformBuffer ) ; glUniformBlockBinding ( program , uniformBufferIndex , 0 ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , GLColor :: green ) ; }
Test with a block containing an array of structs containing arrays.
Test with a block containing an array of structs containing arrays .