Source/ThirdParty/ANGLE/src/tests/gl_tests/UniformBufferTest.cpp
// Test a uniform block where an individual matrix field is set as row-major whereas the whole block
// is set as column-major.
Test a uniform block where an individual matrix field is set as row-major whereas the whole block
is set as column-major.
Test a uniform block where an individual matrix field is set as row - major whereas the whole block is set as column - major .
TEST_P(UniformBufferTest, Std140UniformBlockWithPerMemberRowMajorQualifier)
{
    ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL() && !IsOSX());
    constexpr char kFS[] =
        R"(#version 300 es
        precision highp float;
        out vec4 my_FragColor;
        layout(std140, column_major) uniform matrixBuffer
        {
            layout(row_major) mat2 m;
        } buffer;
        void main()
        {
            // Vector constructor accesses elements in column-major order.
            my_FragColor = vec4(buffer.m);
        })";
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
    GLint uniformBufferIndex = glGetUniformBlockIndex(program, "matrixBuffer");
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    const GLsizei kElementsPerMatrix = 8;  
    const GLsizei kBytesPerElement   = 4;
    const GLsizei kDataSize          = kElementsPerMatrix * kBytesPerElement;
    std::vector<GLubyte> v(kDataSize, 0);
    float *vAsFloat = reinterpret_cast<float *>(v.data());
    vAsFloat[0u] = 1.0f;
    vAsFloat[1u] = 128.0f / 255.0f;
    vAsFloat[4u] = 64.0f / 255.0f;
    vAsFloat[5u] = 32.0f / 255.0f;
    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);
    ASSERT_GL_NO_ERROR();
    EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 64, 128, 32), 5);
}
TEST_P ( UniformBufferTest , Std140UniformBlockWithPerMemberRowMajorQualifier ) { ANGLE_SKIP_TEST_IF ( IsAMD ( ) && IsOpenGL ( ) && ! IsOSX ( ) ) ; constexpr char kFS [ ] = R" ( #version 300 es

        precision highp float;
        out vec4 my_FragColor;

        layout(std140, column_major) uniform matrixBuffer
        {
            layout(row_major) mat2 m;
        } buffer;

        void main()
        {
            // Vector constructor accesses elements in column-major order.
            my_FragColor = vec4(buffer.m);
        } ) " ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS ) ; GLint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; const GLsizei kElementsPerMatrix = 8 ; const GLsizei kBytesPerElement = 4 ; const GLsizei kDataSize = kElementsPerMatrix * kBytesPerElement ; std :: vector < GLubyte > v ( kDataSize , 0 ) ; float * vAsFloat = reinterpret_cast < float * > ( v . data ( ) ) ; vAsFloat [ 0u ] = 1.0f ; vAsFloat [ 1u ] = 128.0f / 255.0f ; vAsFloat [ 4u ] = 64.0f / 255.0f ; vAsFloat [ 5u ] = 32.0f / 255.0f ; 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 ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_PIXEL_COLOR_NEAR ( 0 , 0 , GLColor ( 255 , 64 , 128 , 32 ) , 5 ) ; }
Test a uniform block where an individual matrix field is set as row-major whereas the whole block
is set as column-major.
Test a uniform block where an individual matrix field is set as row - major whereas the whole block is set as column - major .
// AMD OpenGL driver doesn't seem to apply the row-major qualifier right. // http://anglebug.com/2273 // Each mat2 row gets padded into a vec4.