src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test uniform block whose member is vec2 type.
Test uniform block whose member is vec2 type.
Test uniform block whose member is vec2 type .
TEST_P(UniformBlockWithOneLargeArrayMemberTest, MemberTypeIsVec2)
{
    std::ostringstream stream;
    generateArraySizeAndDivisorsDeclaration(stream, false, false, false);
    const std::string &kFS =
        "#version 300 es\n"
        "precision highp float;\n" +
        stream.str() +
        "out vec4 my_FragColor;\n"
        "layout(std140) uniform buffer { vec2 s[arraySize]; };\n"
        "void main()\n"
        "{\n"
        "    uvec2 coord = uvec2(floor(gl_FragCoord.xy));\n"
        "    uint index = (coord.x +  coord.y * 128u) / divisor;\n"
        "    my_FragColor = vec4(s[index], s[index].x, 1.0);\n"
        "}\n";
    GLint blockSize;
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS.c_str());
    GLint uniformBufferIndex = glGetUniformBlockIndex(program, "buffer");
    glGetActiveUniformBlockiv(program, uniformBufferIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &blockSize);
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, blockSize, nullptr, GL_STATIC_DRAW);
    glBindBufferBase(GL_UNIFORM_BUFFER, 0, mUniformBuffer);
    glUniformBlockBinding(program, uniformBufferIndex, 0);
    const GLuint arraySize  = getArraySize();
    const GLuint floatCount = arraySize * kFloatPerVector;
    std::vector<GLfloat> floatData(floatCount, 0.0f);
    setArrayValues(floatData, 0, arraySize, 4, 0, 1, 2, 1.0f, 0.0f, 0.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::magenta, GLColor::magenta, GLColor::magenta, GLColor::magenta);
    setArrayValues(floatData, 0, arraySize, 4, 0, 1, 2, 0.0f, 1.0f, 0.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::green, GLColor::green, GLColor::green, GLColor::green);
    setArrayValues(floatData, arraySize / 4, arraySize / 2, 4, 0, 1, 2, 1.0f, 0.0f, 0.0f, 0.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::green, GLColor::magenta, GLColor::green, GLColor::green);
}
TEST_P ( UniformBlockWithOneLargeArrayMemberTest , MemberTypeIsVec2 ) { std :: ostringstream stream ; generateArraySizeAndDivisorsDeclaration ( stream , false , false , false ) ; const std :: string & kFS = " \n " " \n " + stream . str ( ) + " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " ; GLint blockSize ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS . c_str ( ) ) ; GLint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; glGetActiveUniformBlockiv ( program , uniformBufferIndex , GL_UNIFORM_BLOCK_DATA_SIZE , & blockSize ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; glBufferData ( GL_UNIFORM_BUFFER , blockSize , nullptr , GL_STATIC_DRAW ) ; glBindBufferBase ( GL_UNIFORM_BUFFER , 0 , mUniformBuffer ) ; glUniformBlockBinding ( program , uniformBufferIndex , 0 ) ; const GLuint arraySize = getArraySize ( ) ; const GLuint floatCount = arraySize * kFloatPerVector ; std :: vector < GLfloat > floatData ( floatCount , 0.0f ) ; setArrayValues ( floatData , 0 , arraySize , 4 , 0 , 1 , 2 , 1.0f , 0.0f , 0.0f , 0.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: magenta , GLColor :: magenta , GLColor :: magenta , GLColor :: magenta ) ; setArrayValues ( floatData , 0 , arraySize , 4 , 0 , 1 , 2 , 0.0f , 1.0f , 0.0f , 0.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: green , GLColor :: green , GLColor :: green , GLColor :: green ) ; setArrayValues ( floatData , arraySize / 4 , arraySize / 2 , 4 , 0 , 1 , 2 , 1.0f , 0.0f , 0.0f , 0.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: green , GLColor :: magenta , GLColor :: green , GLColor :: green ) ; }
Test uniform block whose member is vec2 type.
Test uniform block whose member is vec2 type .