src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test uniform block with row major qualifier whose member is matrix type.
Test uniform block with row major qualifier whose member is matrix type.
Test uniform block with row major qualifier whose member is matrix type .
TEST_P(UniformBlockWithOneLargeArrayMemberTest, MemberTypeIsMatrixAndRowMajorQualifier)
{
    ANGLE_SKIP_TEST_IF((IsOSX() && IsOpenGL()) || IsAndroid() || (IsAMD() && IsOpenGL()) ||
                       (IsLinux() && IsIntel() && IsOpenGL()));
    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"
        "layout(std140, row_major) uniform buffer { mat4 s[arraySize]; };\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 = s[index_x][index_y];\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 * kVectorPerMat * kFloatPerVector;
    std::vector<GLfloat> floatData(floatCount, 0.0f);
    setArrayValues(floatData, 0, arraySize, 16, 0, 2, 4, 0.0f, 0.0f, 0.0f, 0.0f, 8, 2, 4, 1.0f,
                   1.0f, 1.0f, 1.0f);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, floatCount * sizeof(GLfloat), floatData.data());
    drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f);
    checkResults(GLColor::blue, GLColor::blue, GLColor::blue, GLColor::blue);
    setArrayValues(floatData, 0, arraySize, 16, 4, 1, 4, 1.0f, 1.0f, 1.0f, 1.0f, 8, 1, 4, 0.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::green, GLColor::green, GLColor::green);
    setArrayValues(floatData, arraySize / 4, arraySize / 2, 16, 0, 1, 4, 1.0f, 1.0f, 1.0f, 1.0f, 4,
                   1, 4, 0.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::red, GLColor::green, GLColor::green);
}
TEST_P ( UniformBlockWithOneLargeArrayMemberTest , MemberTypeIsMatrixAndRowMajorQualifier ) { ANGLE_SKIP_TEST_IF ( ( IsOSX ( ) && IsOpenGL ( ) ) || IsAndroid ( ) || ( IsAMD ( ) && IsOpenGL ( ) ) || ( IsLinux ( ) && IsIntel ( ) && IsOpenGL ( ) ) ) ; 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 " ; 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 * kVectorPerMat * kFloatPerVector ; std :: vector < GLfloat > floatData ( floatCount , 0.0f ) ; setArrayValues ( floatData , 0 , arraySize , 16 , 0 , 2 , 4 , 0.0f , 0.0f , 0.0f , 0.0f , 8 , 2 , 4 , 1.0f , 1.0f , 1.0f , 1.0f ) ; glBufferSubData ( GL_UNIFORM_BUFFER , 0 , floatCount * sizeof ( GLfloat ) , floatData . data ( ) ) ; drawQuad ( program . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; checkResults ( GLColor :: blue , GLColor :: blue , GLColor :: blue , GLColor :: blue ) ; setArrayValues ( floatData , 0 , arraySize , 16 , 4 , 1 , 4 , 1.0f , 1.0f , 1.0f , 1.0f , 8 , 1 , 4 , 0.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 :: green , GLColor :: green , GLColor :: green ) ; setArrayValues ( floatData , arraySize / 4 , arraySize / 2 , 16 , 0 , 1 , 4 , 1.0f , 1.0f , 1.0f , 1.0f , 4 , 1 , 4 , 0.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 :: red , GLColor :: green , GLColor :: green ) ; }
Test uniform block with row major qualifier whose member is matrix type.
Test uniform block with row major qualifier whose member is matrix type .
// http://anglebug.com/3837 , http://anglebug.com/2273