src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test with a block containing an array of structs.
Test with a block containing an array of structs.
Test with a block containing an array of structs .
TEST_P(UniformBufferTest, BlockContainingArrayOfStructs)
{
    constexpr char kFS[] =
        "#version 300 es\n"
        "precision highp float;\n"
        "out vec4 my_FragColor;\n"
        "struct light_t {\n"
        "    vec4 intensity;\n"
        "};\n"
        "const int maxLights = 2;\n"
        "layout(std140) uniform lightData { light_t lights[maxLights]; };\n"
        "vec4 processLight(vec4 lighting, light_t light)\n"
        "{\n"
        "    return lighting + light.intensity;\n"
        "}\n"
        "void main()\n"
        "{\n"
        "    vec4 lighting = vec4(0, 0, 0, 1);\n"
        "    for (int n = 0; n < maxLights; n++)\n"
        "    {\n"
        "        lighting = processLight(lighting, lights[n]);\n"
        "    }\n"
        "    my_FragColor = lighting;\n"
        "}\n";
    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 kVectorElementCount = 4;
    const GLsizei kBytesPerElement    = 4;
    const GLsizei kDataSize           = kStructCount * kVectorElementCount * kBytesPerElement;
    std::vector<GLubyte> v(kDataSize, 0);
    float *vAsFloat = reinterpret_cast<float *>(v.data());
    vAsFloat[1]                       = 0.5f;
    vAsFloat[kVectorElementCount + 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 , BlockContainingArrayOfStructs ) { constexpr char kFS [ ] = " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS ) ; GLint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; const GLsizei kStructCount = 2 ; const GLsizei kVectorElementCount = 4 ; const GLsizei kBytesPerElement = 4 ; const GLsizei kDataSize = kStructCount * kVectorElementCount * kBytesPerElement ; std :: vector < GLubyte > v ( kDataSize , 0 ) ; float * vAsFloat = reinterpret_cast < float * > ( v . data ( ) ) ; vAsFloat [ 1 ] = 0.5f ; vAsFloat [ kVectorElementCount + 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.
Test with a block containing an array of structs .