src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test that uniform block instance with nested structs that contain vec3s inside is handled
// correctly. This is meant to test that HLSL structure padding to implement std140 layout works
// together with uniform blocks.
Test that uniform block instance with nested structs that contain vec3s inside is handled
correctly. This is meant to test that HLSL structure padding to implement std140 layout works
together with uniform blocks.
Test that uniform block instance with nested structs that contain vec3s inside is handled correctly . This is meant to test that HLSL structure padding to implement std140 layout works together with uniform blocks .
TEST_P(UniformBufferTest, Std140UniformBlockInstanceWithNestedStructsContainingVec3s)
{
    ANGLE_SKIP_TEST_IF(IsAndroid() && !IsNVIDIA());
    constexpr char kFS[] =
        R"(#version 300 es
        precision highp float;
        out vec4 my_FragColor;
        struct Sinner {
          vec3 v;
        };
        struct S {
            Sinner s1;
            Sinner s2;
        };
        layout(std140) uniform structBuffer { S s; } buffer;
        void accessStruct(S s)
        {
            my_FragColor = vec4(s.s1.v.xy, s.s2.v.xy);
        }
        void main()
        {
            accessStruct(buffer.s);
        })";
    ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
    GLint uniformBufferIndex = glGetUniformBlockIndex(program, "structBuffer");
    glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer);
    const GLsizei kVectorsPerBlock         = 2;
    const GLsizei kElementsPerPaddedVector = 4;
    const GLsizei kBytesPerElement         = 4;
    const GLsizei kDataSize = kVectorsPerBlock * kElementsPerPaddedVector * kBytesPerElement;
    std::vector<GLubyte> v(kDataSize, 0);
    float *vAsFloat = reinterpret_cast<float *>(v.data());
    vAsFloat[1u]      = 1.0f;
    vAsFloat[4u + 1u] = 1.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);
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
TEST_P ( UniformBufferTest , Std140UniformBlockInstanceWithNestedStructsContainingVec3s ) { ANGLE_SKIP_TEST_IF ( IsAndroid ( ) && ! IsNVIDIA ( ) ) ; constexpr char kFS [ ] = R" ( #version 300 es

        precision highp float;
        out vec4 my_FragColor;

        struct Sinner {
          vec3 v;
        };

        struct S {
            Sinner s1;
            Sinner s2;
        };

        layout(std140) uniform structBuffer { S s; } buffer;

        void accessStruct(S s)
        {
            my_FragColor = vec4(s.s1.v.xy, s.s2.v.xy);
        }

        void main()
        {
            accessStruct(buffer.s);
        } ) " ; ANGLE_GL_PROGRAM ( program , essl3_shaders :: vs :: Simple ( ) , kFS ) ; GLint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; glBindBuffer ( GL_UNIFORM_BUFFER , mUniformBuffer ) ; const GLsizei kVectorsPerBlock = 2 ; const GLsizei kElementsPerPaddedVector = 4 ; const GLsizei kBytesPerElement = 4 ; const GLsizei kDataSize = kVectorsPerBlock * kElementsPerPaddedVector * kBytesPerElement ; std :: vector < GLubyte > v ( kDataSize , 0 ) ; float * vAsFloat = reinterpret_cast < float * > ( v . data ( ) ) ; vAsFloat [ 1u ] = 1.0f ; vAsFloat [ 4u + 1u ] = 1.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 ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , GLColor :: green ) ; }
Test that uniform block instance with nested structs that contain vec3s inside is handled
correctly.
Test that uniform block instance with nested structs that contain vec3s inside is handled correctly .
// Got incorrect test result on non-NVIDIA Android - the alpha channel was not set correctly // from the second vector, possibly the platform doesn't implement std140 packing right? // http://anglebug.com/2217 // Set second value in each vec3.