src/third_party/angle/src/tests/gl_tests/UniformBufferTest.cpp
// Test uniform block bindings specified by layout in shader work properly.
Test uniform block bindings specified by layout in shader work properly.
Test uniform block bindings specified by layout in shader work properly .
TEST_P(UniformBufferTest31, UniformBufferBindings)
{
    constexpr char kVS[] =
        "#version 310 es\n"
        "in vec4 position;\n"
        "void main()\n"
        "{\n"
        "    gl_Position = position;\n"
        "}";
    constexpr char kFS[] =
        "#version 310 es\n"
        "precision highp float;\n"
        "layout(binding = 2) uniform uni {\n"
        "    vec4 color;\n"
        "};\n"
        "out vec4 fragColor;\n"
        "void main()\n"
        "{"
        "    fragColor = color;\n"
        "}";
    ANGLE_GL_PROGRAM(program, kVS, kFS);
    GLuint uniformBufferIndex = glGetUniformBlockIndex(program, "uni");
    ASSERT_NE(GL_INVALID_INDEX, uniformBufferIndex);
    GLBuffer uniformBuffer;
    int px = getWindowWidth() / 2;
    int py = getWindowHeight() / 2;
    ASSERT_GL_NO_ERROR();
    GLuint vec4Size = 4 * sizeof(float);
    std::vector<char> v(vec4Size);
    float *first = reinterpret_cast<float *>(v.data());
    first[0] = 10.f / 255.f;
    first[1] = 20.f / 255.f;
    first[2] = 30.f / 255.f;
    first[3] = 40.f / 255.f;
    glBindBuffer(GL_UNIFORM_BUFFER, uniformBuffer.get());
    glBufferData(GL_UNIFORM_BUFFER, vec4Size, v.data(), GL_STATIC_DRAW);
    EXPECT_GL_NO_ERROR();
    glBindBufferBase(GL_UNIFORM_BUFFER, 2, uniformBuffer.get());
    drawQuad(program, "position", 0.5f);
    EXPECT_GL_NO_ERROR();
    EXPECT_PIXEL_EQ(px, py, 10, 20, 30, 40);
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    EXPECT_PIXEL_EQ(px, py, 0, 0, 0, 0);
    glUniformBlockBinding(program, uniformBufferIndex, 5);
    glBindBufferBase(GL_UNIFORM_BUFFER, 5, uniformBuffer.get());
    drawQuad(program, "position", 0.5f);
    EXPECT_GL_NO_ERROR();
    EXPECT_PIXEL_EQ(px, py, 10, 20, 30, 40);
}
TEST_P ( UniformBufferTest31 , UniformBufferBindings ) { constexpr char kVS [ ] = " \n " " \n " " \n " " \n " " \n " " " ; constexpr char kFS [ ] = " \n " " \n " " \n " " \n " " \n " " \n " " \n " " " " \n " " " ; ANGLE_GL_PROGRAM ( program , kVS , kFS ) ; GLuint uniformBufferIndex = glGetUniformBlockIndex ( program , " " ) ; ASSERT_NE ( GL_INVALID_INDEX , uniformBufferIndex ) ; GLBuffer uniformBuffer ; int px = getWindowWidth ( ) / 2 ; int py = getWindowHeight ( ) / 2 ; ASSERT_GL_NO_ERROR ( ) ; GLuint vec4Size = 4 * sizeof ( float ) ; std :: vector < char > v ( vec4Size ) ; float * first = reinterpret_cast < float * > ( v . data ( ) ) ; first [ 0 ] = 10.f / 255.f ; first [ 1 ] = 20.f / 255.f ; first [ 2 ] = 30.f / 255.f ; first [ 3 ] = 40.f / 255.f ; glBindBuffer ( GL_UNIFORM_BUFFER , uniformBuffer . get ( ) ) ; glBufferData ( GL_UNIFORM_BUFFER , vec4Size , v . data ( ) , GL_STATIC_DRAW ) ; EXPECT_GL_NO_ERROR ( ) ; glBindBufferBase ( GL_UNIFORM_BUFFER , 2 , uniformBuffer . get ( ) ) ; drawQuad ( program , " " , 0.5f ) ; EXPECT_GL_NO_ERROR ( ) ; EXPECT_PIXEL_EQ ( px , py , 10 , 20 , 30 , 40 ) ; glClearColor ( 0.0 , 0.0 , 0.0 , 0.0 ) ; glClear ( GL_COLOR_BUFFER_BIT ) ; EXPECT_PIXEL_EQ ( px , py , 0 , 0 , 0 , 0 ) ; glUniformBlockBinding ( program , uniformBufferIndex , 5 ) ; glBindBufferBase ( GL_UNIFORM_BUFFER , 5 , uniformBuffer . get ( ) ) ; drawQuad ( program , " " , 0.5f ) ; EXPECT_GL_NO_ERROR ( ) ; EXPECT_PIXEL_EQ ( px , py , 10 , 20 , 30 , 40 ) ; }
Test uniform block bindings specified by layout in shader work properly.
Test uniform block bindings specified by layout in shader work properly .
// Let's create a buffer which contains one vec4. // Clear the framebuffer // Try to bind the buffer to another binding point