| // | |
| // Copyright 2015 The ANGLE Project Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| // | |
| // ReadPixelsTest: | |
| // Tests calls related to glReadPixels. | |
| // | |
| #include "common/span.h" | |
| #include "test_utils/ANGLETest.h" | |
| #include <algorithm> | |
| #include <array> | |
| #include "test_utils/gl_raii.h" | |
| #include "util/random_utils.h" | |
| using namespace angle; | |
| namespace | |
| { | |
| class ReadPixelsTest : public ANGLETest<> | |
| { | |
| protected: | |
| ReadPixelsTest() | |
| { | |
| setWindowWidth(32); | |
| setWindowHeight(32); | |
| setConfigRedBits(8); | |
| setConfigGreenBits(8); | |
| setConfigBlueBits(8); | |
| setConfigAlphaBits(8); | |
| } | |
| }; | |
| // Test out of bounds framebuffer reads. | |
| TEST_P(ReadPixelsTest, OutOfBounds) | |
| { | |
| // TODO: re-enable once root cause of http://anglebug.com/42260408 is fixed | |
| ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| GLsizei pixelsWidth = 32; | |
| GLsizei pixelsHeight = 32; | |
| GLint offset = 16; | |
| std::vector<GLColor> pixels((pixelsWidth + offset) * (pixelsHeight + offset)); | |
| glReadPixels(-offset, -offset, pixelsWidth + offset, pixelsHeight + offset, GL_RGBA, | |
| GL_UNSIGNED_BYTE, &pixels[0]); | |
| EXPECT_GL_NO_ERROR(); | |
| // Expect that all pixels which fell within the framebuffer are red | |
| for (int y = pixelsHeight / 2; y < pixelsHeight; y++) | |
| { | |
| for (int x = pixelsWidth / 2; x < pixelsWidth; x++) | |
| { | |
| EXPECT_EQ(GLColor::red, pixels[y * (pixelsWidth + offset) + x]); | |
| } | |
| } | |
| } | |
| // Test readPixels with a large texture to verify no overflow in pitch calculations. | |
| TEST_P(ReadPixelsTest, LargeTexture) | |
| { | |
| // Need ES3 for RGBA32F | |
| ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); | |
| GLint maxTextureSize; | |
| glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); | |
| ANGLE_SKIP_TEST_IF(maxTextureSize < 16384); | |
| GLTexture tex; | |
| glBindTexture(GL_TEXTURE_2D, tex); | |
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 16384, 8193, 0, GL_RGBA, GL_FLOAT, nullptr); | |
| GLenum err = glGetError(); | |
| ANGLE_SKIP_TEST_IF(err == GL_OUT_OF_MEMORY || err == GL_INVALID_OPERATION); | |
| EXPECT_GL_NO_ERROR(); | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); | |
| EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| // Clear the row at 8192 to a specific color. | |
| glEnable(GL_SCISSOR_TEST); | |
| glScissor(0, 8192, 16384, 1); | |
| glClearColor(0.5f, 0.5f, 0.5f, 0.5f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glDisable(GL_SCISSOR_TEST); | |
| ANGLE_SKIP_TEST_IF(glGetError() == GL_OUT_OF_MEMORY); | |
| EXPECT_GL_NO_ERROR(); | |
| // Call gl.readPixels(0, 8192, 16384, 1, gl.RGBA, gl.FLOAT, outputBuffer). | |
| std::vector<float> data(16384 * 4); | |
| glReadPixels(0, 8192, 16384, 1, GL_RGBA, GL_FLOAT, data.data()); | |
| ANGLE_SKIP_TEST_IF(glGetError() == GL_OUT_OF_MEMORY); | |
| EXPECT_GL_NO_ERROR(); | |
| for (size_t i = 0; i < 16384 * 4; ++i) | |
| { | |
| EXPECT_EQ(0.5f, data[i]); | |
| } | |
| } | |
| class ReadPixelsPBONVTest : public ReadPixelsTest | |
| { | |
| protected: | |
| ReadPixelsPBONVTest() : mPBO(0), mTexture(0), mFBO(0) {} | |
| void testSetUp() override | |
| { | |
| glGenBuffers(1, &mPBO); | |
| glGenFramebuffers(1, &mFBO); | |
| reset(4 * getWindowWidth() * getWindowHeight(), 4, 4); | |
| } | |
| virtual void reset(GLuint bufferSize, GLuint fboWidth, GLuint fboHeight) | |
| { | |
| ANGLE_SKIP_TEST_IF(!hasPBOExts()); | |
| mPBOBufferSize = bufferSize; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, mPBOBufferSize, nullptr, GL_STATIC_DRAW); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glDeleteTextures(1, &mTexture); | |
| glGenTextures(1, &mTexture); | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, fboWidth, fboHeight); | |
| mFBOWidth = fboWidth; | |
| mFBOHeight = fboHeight; | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| void testTearDown() override | |
| { | |
| glDeleteBuffers(1, &mPBO); | |
| glDeleteTextures(1, &mTexture); | |
| glDeleteFramebuffers(1, &mFBO); | |
| } | |
| bool hasPBOExts() const | |
| { | |
| return IsGLExtensionEnabled("GL_NV_pixel_buffer_object") && | |
| IsGLExtensionEnabled("GL_EXT_texture_storage"); | |
| } | |
| GLuint mPBO = 0; | |
| GLuint mTexture = 0; | |
| GLuint mFBO = 0; | |
| GLuint mFBOWidth = 0; | |
| GLuint mFBOHeight = 0; | |
| GLuint mPBOBufferSize = 0; | |
| }; | |
| // Test basic usage of PBOs. | |
| TEST_P(ReadPixelsPBONVTest, Basic) | |
| { | |
| ANGLE_SKIP_TEST_IF(!hasPBOExts() || !IsGLExtensionEnabled("GL_EXT_map_buffer_range") || | |
| !IsGLExtensionEnabled("GL_OES_mapbuffer")); | |
| // http://anglebug.com/42263593 | |
| ANGLE_SKIP_TEST_IF(IsWindows() && IsDesktopOpenGL()); | |
| // http://anglebug.com/42263926 | |
| ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL()); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| // Clear last pixel to green | |
| glScissor(15, 15, 1, 1); | |
| glEnable(GL_SCISSOR_TEST); | |
| glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| auto dataColor = | |
| MapBufferRangeEXT<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, mPBOBufferSize, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::red, dataColor[0]); | |
| EXPECT_EQ(GLColor::red, dataColor[16 * 16 - 2]); | |
| EXPECT_EQ(GLColor::green, dataColor[16 * 16 - 1]); | |
| glUnmapBufferOES(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test that calling SubData preserves PBO data. | |
| TEST_P(ReadPixelsPBONVTest, SubDataPreservesContents) | |
| { | |
| ANGLE_SKIP_TEST_IF(!hasPBOExts() || !IsGLExtensionEnabled("GL_EXT_map_buffer_range") || | |
| !IsGLExtensionEnabled("GL_OES_mapbuffer")); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| unsigned char data[4] = {1, 2, 3, 4}; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 0, 4, data); | |
| auto dataColor = MapBufferRangeEXT<const GLColor>(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor(1, 2, 3, 4), dataColor[0]); | |
| EXPECT_EQ(GLColor::red, dataColor[1]); | |
| glUnmapBufferOES(GL_ARRAY_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test that calling ReadPixels with GL_DYNAMIC_DRAW buffer works | |
| TEST_P(ReadPixelsPBONVTest, DynamicPBO) | |
| { | |
| ANGLE_SKIP_TEST_IF(!hasPBOExts() || !IsGLExtensionEnabled("GL_EXT_map_buffer_range") || | |
| !IsGLExtensionEnabled("GL_OES_mapbuffer")); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, 4 * getWindowWidth() * getWindowHeight(), nullptr, | |
| GL_DYNAMIC_DRAW); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| unsigned char data[4] = {1, 2, 3, 4}; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 0, 4, data); | |
| auto dataColor = MapBufferRangeEXT<const GLColor>(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor(1, 2, 3, 4), dataColor[0]); | |
| EXPECT_EQ(GLColor::red, dataColor[1]); | |
| glUnmapBufferOES(GL_ARRAY_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| TEST_P(ReadPixelsPBONVTest, ReadFromFBO) | |
| { | |
| ANGLE_SKIP_TEST_IF(!hasPBOExts() || !IsGLExtensionEnabled("GL_EXT_map_buffer_range") || | |
| !IsGLExtensionEnabled("GL_OES_mapbuffer")); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glViewport(0, 0, mFBOWidth, mFBOHeight); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| // Clear last pixel to green | |
| glScissor(mFBOWidth - 1, mFBOHeight - 1, 1, 1); | |
| glEnable(GL_SCISSOR_TEST); | |
| glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, mFBOWidth, mFBOHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| auto dataColor = MapBufferRangeEXT<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, | |
| 4 * mFBOWidth * mFBOHeight, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::red, dataColor[0]); | |
| EXPECT_EQ(GLColor::red, dataColor[mFBOWidth * mFBOHeight - 2]); | |
| EXPECT_EQ(GLColor::green, dataColor[mFBOWidth * mFBOHeight - 1]); | |
| glUnmapBufferOES(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test calling ReadPixels with a non-zero "data" param into a PBO | |
| TEST_P(ReadPixelsPBONVTest, ReadFromFBOWithDataOffset) | |
| { | |
| ANGLE_SKIP_TEST_IF(!hasPBOExts() || !IsGLExtensionEnabled("GL_EXT_map_buffer_range") || | |
| !IsGLExtensionEnabled("GL_OES_mapbuffer")); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glViewport(0, 0, mFBOWidth, mFBOHeight); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| // Clear first pixel to green | |
| glScissor(0, 0, 1, 1); | |
| glEnable(GL_SCISSOR_TEST); | |
| glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| // Read (height - 1) rows offset by width * 4. | |
| glReadPixels(0, 0, mFBOWidth, mFBOHeight - 1, GL_RGBA, GL_UNSIGNED_BYTE, | |
| reinterpret_cast<void *>(mFBOWidth * static_cast<uintptr_t>(4))); | |
| auto dataColor = MapBufferRangeEXT<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, | |
| 4 * mFBOWidth * mFBOHeight, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::green, dataColor[mFBOWidth]); | |
| EXPECT_EQ(GLColor::red, dataColor[mFBOWidth + 1]); | |
| EXPECT_EQ(GLColor::red, dataColor[mFBOWidth * mFBOHeight - 1]); | |
| glUnmapBufferOES(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| class ReadPixelsPBOTest : public ReadPixelsPBONVTest | |
| { | |
| protected: | |
| ReadPixelsPBOTest() : ReadPixelsPBONVTest() {} | |
| void testSetUp() override | |
| { | |
| glGenBuffers(1, &mPBO); | |
| glGenFramebuffers(1, &mFBO); | |
| reset(4 * getWindowWidth() * getWindowHeight(), 4, 1); | |
| } | |
| void reset(GLuint bufferSize, GLuint fboWidth, GLuint fboHeight) override | |
| { | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glDeleteTextures(1, &mTexture); | |
| glGenTextures(1, &mTexture); | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, fboWidth, fboHeight); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| mFBOWidth = fboWidth; | |
| mFBOHeight = fboHeight; | |
| mPBOBufferSize = bufferSize; | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| }; | |
| // Test basic usage of PBOs. | |
| TEST_P(ReadPixelsPBOTest, Basic) | |
| { | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| auto dataColor = MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::red, dataColor[0]); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test that RGB565 readback produces identical results with and without a PBO. | |
| TEST_P(ReadPixelsPBOTest, RGB565MatchesClientMemory) | |
| { | |
| GLRenderbuffer renderbuffer; | |
| glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); | |
| glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 1, 1); | |
| GLFramebuffer framebuffer; | |
| glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| glDisable(GL_DITHER); | |
| glClearColor(107.0f / 255.0f, 1.0f, 132.0f / 255.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| const GLColor *mappedColor = static_cast<const GLColor *>( | |
| glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, sizeof(GLColor), GL_MAP_READ_BIT)); | |
| ASSERT_NE(nullptr, mappedColor); | |
| const GLColor pboResult = *mappedColor; | |
| EXPECT_GL_TRUE(glUnmapBuffer(GL_PIXEL_PACK_BUFFER)); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| GLColor clientResult; | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &clientResult); | |
| ASSERT_GL_NO_ERROR(); | |
| EXPECT_EQ(clientResult, pboResult); | |
| } | |
| // Test that PBO readback is synchronized with color attachment writes in SharedPresent layout. | |
| TEST_P(ReadPixelsPBOTest, SharedPresentPBOReadback) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsVulkan()); | |
| ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(getEGLWindow()->getDisplay(), | |
| "EGL_KHR_mutable_render_buffer")); | |
| setMutableRenderBuffer(true); | |
| recreateTestFixture(); | |
| ASSERT_FALSE(HasFatalFailure()); | |
| ANGLE_SKIP_TEST_IF(IsSkipped()); | |
| ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor()); | |
| const GLint colorLocation = glGetUniformLocation(program, essl1_shaders::ColorUniform()); | |
| ASSERT_NE(-1, colorLocation); | |
| EGLWindow *window = getEGLWindow(); | |
| ASSERT_EGL_TRUE(eglSurfaceAttrib(window->getDisplay(), window->getSurface(), EGL_RENDER_BUFFER, | |
| EGL_SINGLE_BUFFER)); | |
| glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| if (!eglSwapBuffers(window->getDisplay(), window->getSurface())) | |
| { | |
| ASSERT_EGL_ERROR(EGL_BAD_MATCH); | |
| ASSERT_EGL_TRUE(eglSurfaceAttrib(window->getDisplay(), window->getSurface(), | |
| EGL_RENDER_BUFFER, EGL_BACK_BUFFER)); | |
| GTEST_SKIP() << "Shared present mode is not supported by this surface."; | |
| } | |
| EGLint renderBuffer = EGL_BACK_BUFFER; | |
| ASSERT_EGL_TRUE(eglQueryContext(window->getDisplay(), window->getContext(), EGL_RENDER_BUFFER, | |
| &renderBuffer)); | |
| ASSERT_EQ(EGL_SINGLE_BUFFER, renderBuffer); | |
| const GLsizei width = getWindowWidth(); | |
| const GLsizei height = getWindowHeight(); | |
| const size_t pixelCount = width * height; | |
| const size_t dataSize = pixelCount * sizeof(GLColor); | |
| glUseProgram(program); | |
| // Change colors so stale image contents cannot accidentally match the current draw. | |
| for (const GLColor &color : {GLColor::green, GLColor::red, GLColor::blue}) | |
| { | |
| const angle::Vector4 normalizedColor = color.toNormalizedVector(); | |
| glUniform4f(colorLocation, normalizedColor.x(), normalizedColor.y(), normalizedColor.z(), | |
| normalizedColor.w()); | |
| // A draw, unlike a deferred clear, requires color attachment writes before compute reads. | |
| drawQuad(program, essl1_shaders::PositionAttrib(), 0.0f); | |
| // Keep default pack row order so framebuffer Y inversion requires compute readback. | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| const GLColor *pixels = static_cast<const GLColor *>( | |
| glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, dataSize, GL_MAP_READ_BIT)); | |
| ASSERT_NE(nullptr, pixels); | |
| // SAFETY: pixels maps dataSize bytes, which contains pixelCount GLColor elements. | |
| // The range is checked before the buffer is unmapped. | |
| EXPECT_TRUE(ANGLE_UNSAFE_BUFFERS( | |
| std::all_of(pixels, pixels + pixelCount, | |
| [&color](const GLColor &pixel) { return pixel == color; }))) | |
| << "Expected PBO color: " << color; | |
| EXPECT_GL_TRUE(glUnmapBuffer(GL_PIXEL_PACK_BUFFER)); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| } | |
| // Test copy to snorm | |
| TEST_P(ReadPixelsPBOTest, Snorm) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| constexpr GLsizei kSize = 6; | |
| GLRenderbuffer rbo; | |
| glBindRenderbuffer(GL_RENDERBUFFER, rbo); | |
| glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_SNORM, kSize, kSize); | |
| ASSERT_GL_NO_ERROR(); | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| glEnable(GL_SCISSOR_TEST); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glScissor(0, 0, kSize / 2, kSize / 2); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | |
| glScissor(kSize / 2, 0, kSize / 2, kSize / 2); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glClearColor(0.0f, 0.0f, 1.0f, 1.0f); | |
| glScissor(0, kSize / 2, kSize / 2, kSize / 2); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glClearColor(1.0f, 1.0f, 0.0f, 1.0f); | |
| glScissor(kSize / 2, kSize / 2, kSize / 2, kSize / 2); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glDisable(GL_SCISSOR_TEST); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_BYTE, 0); | |
| std::vector<GLColor> result(kSize * kSize); | |
| Span(result).copy_from( | |
| MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, kSize * kSize * 4, GL_MAP_READ_BIT)); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| auto verify = [&](Span<const GLColor, 4> expect) { | |
| for (size_t i = 0; i < kSize; ++i) | |
| { | |
| for (size_t j = 0; j < kSize; ++j) | |
| { | |
| uint32_t index = (i < kSize / 2 ? 0 : 1) << 1 | (j < kSize / 2 ? 0 : 1); | |
| EXPECT_EQ(result[i * kSize + j], expect[index]) << i << " " << j; | |
| } | |
| } | |
| }; | |
| // The image should have the following colors | |
| // | |
| // +---+---+ | |
| // | R | G | | |
| // +---+---+ | |
| // | B | Y | | |
| // +---+---+ | |
| // | |
| const GLColor kColors[4] = { | |
| GLColor(127, 0, 0, 127), | |
| GLColor(0, 127, 0, 127), | |
| GLColor(0, 0, 127, 127), | |
| GLColor(127, 127, 0, 127), | |
| }; | |
| verify(kColors); | |
| // Test again, but this time with reverse order | |
| if (EnsureGLExtensionEnabled("GL_ANGLE_pack_reverse_row_order")) | |
| { | |
| glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE); | |
| glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_BYTE, 0); | |
| Span(result).copy_from(MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, | |
| kSize * kSize * 4, GL_MAP_READ_BIT)); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| const GLColor kReversedColors[4] = { | |
| GLColor(0, 0, 127, 127), | |
| GLColor(127, 127, 0, 127), | |
| GLColor(127, 0, 0, 127), | |
| GLColor(0, 127, 0, 127), | |
| }; | |
| verify(kReversedColors); | |
| } | |
| } | |
| // Test read pixel to PBO of an sRGB unorm renderbuffer | |
| TEST_P(ReadPixelsPBOTest, SrgbUnorm) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_ANGLE_pack_reverse_row_order")); | |
| constexpr GLsizei kSize = 1; | |
| constexpr angle::GLColor clearColor(64, 0, 0, 255); | |
| constexpr angle::GLColor encodedToSrgbColor(136, 0, 0, 255); | |
| GLRenderbuffer rbo; | |
| glBindRenderbuffer(GL_RENDERBUFFER, rbo); | |
| glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8_ALPHA8, kSize, kSize); | |
| ASSERT_GL_NO_ERROR(); | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| glClearColor(clearColor[0] / 255.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE); | |
| glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| const GLColor result = MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, kSize * kSize * 4, | |
| GL_MAP_READ_BIT)[0]; | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_NEAR(result[0], encodedToSrgbColor[0], 1); | |
| } | |
| // Test an error is generated when the PBO is too small. | |
| TEST_P(ReadPixelsPBOTest, PBOTooSmall) | |
| { | |
| reset(4 * 16 * 16 - 1, 16, 16); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| // Test an error is generated when the PBO is mapped. | |
| TEST_P(ReadPixelsPBOTest, PBOMapped) | |
| { | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| // Test that binding a PBO to ARRAY_BUFFER works as expected. | |
| TEST_P(ReadPixelsPBOTest, ArrayBufferTarget) | |
| { | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| auto dataColor = MapBufferRange<const GLColor>(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::red, dataColor[0]); | |
| glUnmapBuffer(GL_ARRAY_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test that using a PBO does not overwrite existing data. | |
| TEST_P(ReadPixelsPBOTest, ExistingDataPreserved) | |
| { | |
| // Clear backbuffer to red | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| // Read 16x16 region from red backbuffer to PBO | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| // Clear backbuffer to green | |
| glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| // Read 16x16 region from green backbuffer to PBO at offset 16 | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<void *>(16)); | |
| auto dataColor = MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, 17 * sizeof(GLColor), | |
| GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| // Test pixel 0 is red (existing data) | |
| EXPECT_EQ(GLColor::red, dataColor[0]); | |
| // Test pixel 16 is green (new data) | |
| EXPECT_EQ(GLColor::green, dataColor[16]); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test that calling SubData preserves PBO data. | |
| TEST_P(ReadPixelsPBOTest, SubDataPreservesContents) | |
| { | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| unsigned char data[4] = {1, 2, 3, 4}; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 0, 4, data); | |
| auto dataColor = MapBufferRange<const GLColor>(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor(1, 2, 3, 4), dataColor[0]); | |
| glUnmapBuffer(GL_ARRAY_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Same as the prior test, but with an offset. | |
| TEST_P(ReadPixelsPBOTest, SubDataOffsetPreservesContents) | |
| { | |
| // anglebug.com/42260410 | |
| ANGLE_SKIP_TEST_IF(IsNexus5X() && IsAdreno() && IsOpenGLES()); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| unsigned char data[4] = {1, 2, 3, 4}; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 16, 4, data); | |
| auto dataColor = MapBufferRange<const GLColor>(GL_ARRAY_BUFFER, 0, 32, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::red, dataColor[0]); | |
| EXPECT_EQ(GLColor(1, 2, 3, 4), dataColor[4]); | |
| glUnmapBuffer(GL_ARRAY_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test that uploading data to buffer that's in use then writing to it as PBO works. | |
| TEST_P(ReadPixelsPBOTest, UseAsUBOThenUpdateThenReadFromFBO) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glViewport(0, 0, mFBOWidth, mFBOHeight); | |
| const std::array<GLColor, 4> kInitialData = {GLColor::red, GLColor::red, GLColor::red, | |
| GLColor::red}; | |
| const std::array<GLColor, 4> kUpdateData = {GLColor::white, GLColor::white, GLColor::white, | |
| GLColor::white}; | |
| GLBuffer buffer; | |
| glBindBuffer(GL_UNIFORM_BUFFER, buffer); | |
| glBufferData(GL_UNIFORM_BUFFER, sizeof(kInitialData), kInitialData.data(), GL_DYNAMIC_COPY); | |
| glBindBufferBase(GL_UNIFORM_BUFFER, 0, buffer); | |
| EXPECT_GL_NO_ERROR(); | |
| constexpr char kVerifyUBO[] = R"(#version 300 es | |
| precision mediump float; | |
| uniform block { | |
| uvec4 data; | |
| } ubo; | |
| out vec4 colorOut; | |
| void main() | |
| { | |
| if (all(equal(ubo.data, uvec4(0xFF0000FFu)))) | |
| colorOut = vec4(0, 1.0, 0, 1.0); | |
| else | |
| colorOut = vec4(1.0, 0, 0, 1.0); | |
| })"; | |
| ANGLE_GL_PROGRAM(verifyUbo, essl3_shaders::vs::Simple(), kVerifyUBO); | |
| drawQuad(verifyUbo, essl3_shaders::PositionAttrib(), 0.5); | |
| EXPECT_GL_NO_ERROR(); | |
| // Update buffer data | |
| glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(kInitialData), kUpdateData.data()); | |
| EXPECT_GL_NO_ERROR(); | |
| // Clear first pixel to blue | |
| glClearColor(0.0f, 0.0f, 1.0f, 1.0f); | |
| glScissor(0, 0, 1, 1); | |
| glEnable(GL_SCISSOR_TEST); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer); | |
| // Read the framebuffer pixels | |
| glReadPixels(0, 0, mFBOWidth, mFBOHeight, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| auto dataColor = MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, sizeof(kInitialData), | |
| GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor::blue, dataColor[0]); | |
| EXPECT_EQ(GLColor::green, dataColor[1]); | |
| EXPECT_EQ(GLColor::green, dataColor[2]); | |
| EXPECT_EQ(GLColor::green, dataColor[3]); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); | |
| EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::green); | |
| EXPECT_PIXEL_COLOR_EQ(2, 0, GLColor::green); | |
| EXPECT_PIXEL_COLOR_EQ(3, 0, GLColor::green); | |
| } | |
| // Test PBO readback with row length smaller than area width. | |
| TEST_P(ReadPixelsPBOTest, SmallRowLength) | |
| { | |
| constexpr int kSize = 2; | |
| reset(kSize * kSize * 4, kSize, kSize); | |
| std::vector<GLColor> texData(kSize * kSize); | |
| texData[0] = GLColor::red; | |
| texData[1] = GLColor::green; | |
| texData[2] = GLColor::blue; | |
| texData[3] = GLColor::white; | |
| glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, | |
| texData.data()); | |
| ASSERT_GL_NO_ERROR(); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| std::vector<GLColor> bufData(kSize * kSize, GLColor::black); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, mPBOBufferSize, bufData.data(), GL_STATIC_DRAW); | |
| glPixelStorei(GL_PACK_ROW_LENGTH, 1); | |
| glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| ASSERT_GL_NO_ERROR(); | |
| auto dataColor = | |
| MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, mPBOBufferSize, GL_MAP_READ_BIT); | |
| ASSERT_FALSE(dataColor.empty()); | |
| ASSERT_GL_NO_ERROR(); | |
| // TODO(anglebug.com/354005999) | |
| // Metal compute path may produce flaky results | |
| // Suppressed until a fallback is implemented | |
| if (!IsMetal()) | |
| { | |
| EXPECT_EQ(dataColor[0], GLColor::red); | |
| EXPECT_EQ(dataColor[1], GLColor::blue); | |
| EXPECT_EQ(dataColor[2], GLColor::white); | |
| EXPECT_EQ(dataColor[3], GLColor::black); | |
| } | |
| ASSERT_TRUE(glUnmapBuffer(GL_PIXEL_PACK_BUFFER)); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| // Test that readPixels with a large PACK_ROW_LENGTH into a PBO does not overflow int32 stride | |
| // calculation. Ported from crbug.com/528175330 / crbug.com/529867799. | |
| TEST_P(ReadPixelsPBOTest, PackLargeRowLength) | |
| { | |
| reset(16, 8, 8); | |
| const GLColor kExpectedColor(65, 128, 192, 255); | |
| constexpr GLint kLargeRowLength = 0x7fffffc; | |
| constexpr GLsizeiptr kByteOffsetToVerify = 0x1ffffff0; | |
| constexpr GLsizeiptr kBufferSize = kByteOffsetToVerify + 256; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, kBufferSize, nullptr, GL_STREAM_READ); | |
| ANGLE_SKIP_TEST_IF(glGetError() == GL_OUT_OF_MEMORY); | |
| ASSERT_GL_NO_ERROR(); | |
| glClearColor(kExpectedColor.R / 255.0f, kExpectedColor.G / 255.0f, kExpectedColor.B / 255.0f, | |
| kExpectedColor.A / 255.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glPixelStorei(GL_PACK_ROW_LENGTH, kLargeRowLength); | |
| glPixelStorei(GL_PACK_ALIGNMENT, 4); | |
| glReadPixels(0, 0, 1, 2, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| EXPECT_GL_NO_ERROR(); | |
| auto dataColor = | |
| MapBufferRange<const GLColor>(GL_PIXEL_PACK_BUFFER, 0, kBufferSize, GL_MAP_READ_BIT); | |
| ASSERT_FALSE(dataColor.empty()); | |
| GLColor actualColorRow0; | |
| GLColor actualColorRow1; | |
| // Check row 0 pixel (at byte offset 0) | |
| actualColorRow0 = dataColor[0]; | |
| // Check row 1 pixel (at byte offset kByteOffsetToVerify) | |
| constexpr size_t kRow1OffsetInPixels = kByteOffsetToVerify / sizeof(GLColor); | |
| actualColorRow1 = dataColor[kRow1OffsetInPixels]; | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_EQ(kExpectedColor, actualColorRow0); | |
| EXPECT_EQ(kExpectedColor, actualColorRow1); | |
| } | |
| // A readPixels with GL_PACK_ROW_LENGTH padding whose packed data exactly fills the bound pixel pack | |
| // buffer writes only each row's pixel bytes; the padding bytes between rows keep the buffer's | |
| // previous contents (ES 3.2 section 16.1.6 only specifies writing the elements of each pixel). | |
| // Exercises packLastRowSeparatelyWhenFillingPackBuffer on the GL backends. | |
| TEST_P(ReadPixelsPBOTest, RowPaddedReadIntoExactlySizedBufferPreservesContents) | |
| { | |
| constexpr GLint kReadWidth = 1; | |
| constexpr GLint kReadHeight = 4; | |
| constexpr GLint kRowLength = 8; | |
| constexpr size_t kPixelBytes = 4; | |
| constexpr size_t kRowPitchBytes = kRowLength * kPixelBytes; | |
| constexpr size_t kBufferSize = kRowPitchBytes * (kReadHeight - 1) + kPixelBytes; | |
| constexpr uint8_t kDonorByte = 0xB7; | |
| const GLColor kClearColor = GLColor::red; | |
| reset(kBufferSize, 4, 4); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| glClearColor(kClearColor.R / 255.0f, kClearColor.G / 255.0f, kClearColor.B / 255.0f, | |
| kClearColor.A / 255.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| std::vector<uint8_t> donor(kBufferSize, kDonorByte); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, kBufferSize, donor.data(), GL_STREAM_READ); | |
| ASSERT_GL_NO_ERROR(); | |
| // Leave a read pending on the buffer first; on affected drivers the padding loss reproduces | |
| // when the buffer has pending work. | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| glPixelStorei(GL_PACK_ROW_LENGTH, kRowLength); | |
| glReadPixels(0, 0, kReadWidth, kReadHeight, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| EXPECT_GL_NO_ERROR(); | |
| const angle::Span<const uint8_t> bytes = MapBufferRange<const uint8_t>( | |
| GL_PIXEL_PACK_BUFFER, /*offset=*/0, kBufferSize, GL_MAP_READ_BIT); | |
| ASSERT_EQ(kBufferSize, bytes.size()); | |
| ASSERT_GL_NO_ERROR(); | |
| const std::array<uint8_t, kPixelBytes> kExpectedPixel = {kClearColor.R, kClearColor.G, | |
| kClearColor.B, kClearColor.A}; | |
| for (size_t i = 0; i < kBufferSize; ++i) | |
| { | |
| const size_t byteInRow = i % kRowPitchBytes; | |
| if (byteInRow < kPixelBytes) | |
| { | |
| // Rows start at offsets 0, 32, 64, and 96; each holds one pixel. | |
| EXPECT_EQ(kExpectedPixel[byteInRow], bytes[i]) << "offset " << i; | |
| } | |
| else | |
| { | |
| // Padding bytes must keep the buffer's previous contents. | |
| EXPECT_EQ(kDonorByte, bytes[i]) << "offset " << i; | |
| } | |
| } | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // A single-row readPixels whose GL_PACK_ALIGNMENT padding makes the aligned row exactly fill | |
| // the bound pixel pack buffer writes only the pixel bytes; the trailing bytes keep the | |
| // buffer's previous contents. | |
| TEST_P(ReadPixelsPBOTest, AlignmentPaddedSingleRowIntoExactlySizedBufferPreservesContents) | |
| { | |
| constexpr size_t kPixelBytes = 4; | |
| constexpr size_t kBufferSize = 8; // One RGBA pixel aligned up to GL_PACK_ALIGNMENT 8. | |
| constexpr uint8_t kDonorByte = 0xB7; | |
| const GLColor kClearColor = GLColor::red; | |
| reset(kBufferSize, 2, 2); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| glClearColor(kClearColor.R / 255.0f, kClearColor.G / 255.0f, kClearColor.B / 255.0f, | |
| kClearColor.A / 255.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| std::vector<uint8_t> donor(kBufferSize, kDonorByte); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, kBufferSize, donor.data(), GL_STREAM_READ); | |
| ASSERT_GL_NO_ERROR(); | |
| // Leave a read pending on the buffer first; on affected drivers the padding loss reproduces | |
| // when the buffer has pending work. With the default GL_PACK_ALIGNMENT of 4 it writes only | |
| // the first 4 bytes. | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| glPixelStorei(GL_PACK_ALIGNMENT, 8); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| EXPECT_GL_NO_ERROR(); | |
| const angle::Span<const uint8_t> bytes = MapBufferRange<const uint8_t>( | |
| GL_PIXEL_PACK_BUFFER, /*offset=*/0, kBufferSize, GL_MAP_READ_BIT); | |
| ASSERT_EQ(kBufferSize, bytes.size()); | |
| ASSERT_GL_NO_ERROR(); | |
| const std::array<uint8_t, kPixelBytes> kExpectedPixel = {kClearColor.R, kClearColor.G, | |
| kClearColor.B, kClearColor.A}; | |
| for (size_t i = 0; i < kPixelBytes; ++i) | |
| { | |
| EXPECT_EQ(kExpectedPixel[i], bytes[i]) << "offset " << i; | |
| } | |
| for (size_t i = kPixelBytes; i < kBufferSize; ++i) | |
| { | |
| EXPECT_EQ(kDonorByte, bytes[i]) << "offset " << i; | |
| } | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // A multi-row readPixels whose last row has GL_PACK_ALIGNMENT padding into a pixel pack buffer | |
| // that ends at the spec's end byte succeeds, writes each row's pixels, and keeps the padding | |
| // between rows. Mirrors a case of WebGL 2 conformance2/reading/read-pixels-pack-parameters.html. | |
| TEST_P(ReadPixelsPBOTest, AlignmentPaddedRowsIntoSpecSizedBuffer) | |
| { | |
| constexpr GLint kReadHeight = 2; | |
| constexpr size_t kPixelBytes = 4; | |
| constexpr size_t kRowPitchBytes = 8; // One RGBA pixel aligned up to GL_PACK_ALIGNMENT 8. | |
| constexpr size_t kBufferSize = kRowPitchBytes * (kReadHeight - 1) + kPixelBytes; | |
| constexpr uint8_t kDonorByte = 0xB7; | |
| const GLColor kClearColor = GLColor::red; | |
| reset(kBufferSize, 2, 2); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| glClearColor(kClearColor.R / 255.0f, kClearColor.G / 255.0f, kClearColor.B / 255.0f, | |
| kClearColor.A / 255.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| std::vector<uint8_t> donor(kBufferSize, kDonorByte); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, kBufferSize, donor.data(), GL_STREAM_READ); | |
| ASSERT_GL_NO_ERROR(); | |
| glPixelStorei(GL_PACK_ALIGNMENT, 8); | |
| glReadPixels(0, 0, 1, kReadHeight, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| EXPECT_GL_NO_ERROR(); | |
| const angle::Span<const uint8_t> bytes = MapBufferRange<const uint8_t>( | |
| GL_PIXEL_PACK_BUFFER, /*offset=*/0, kBufferSize, GL_MAP_READ_BIT); | |
| ASSERT_EQ(kBufferSize, bytes.size()); | |
| ASSERT_GL_NO_ERROR(); | |
| const std::array<uint8_t, kPixelBytes> kExpectedPixel = {kClearColor.R, kClearColor.G, | |
| kClearColor.B, kClearColor.A}; | |
| for (size_t i = 0; i < kBufferSize; ++i) | |
| { | |
| const size_t byteInRow = i % kRowPitchBytes; | |
| if (byteInRow < kPixelBytes) | |
| { | |
| EXPECT_EQ(kExpectedPixel[byteInRow], bytes[i]) << "offset " << i; | |
| } | |
| else | |
| { | |
| EXPECT_EQ(kDonorByte, bytes[i]) << "offset " << i; | |
| } | |
| } | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Same as above for a read that starts below the framebuffer, with GL_PACK_ROW_LENGTH equal to | |
| // the width. Only the rows inside the framebuffer are checked. Mirrors a case of WebGL 2 | |
| // conformance2/reading/read-pixels-pack-parameters.html. Reads at a non-zero pack buffer offset; | |
| // see anglebug.com/584647615. | |
| TEST_P(ReadPixelsPBOTest, ClippedAlignmentPaddedRowsIntoSpecSizedBuffer) | |
| { | |
| constexpr GLint kReadWidth = 3; | |
| constexpr GLint kReadHeight = 3; | |
| constexpr size_t kPixelBytes = 4; | |
| constexpr size_t kRowBytes = kReadWidth * kPixelBytes; | |
| constexpr size_t kRowPitchBytes = 16; // Three RGBA pixels aligned up to GL_PACK_ALIGNMENT 8. | |
| constexpr size_t kReadOffset = 4; | |
| constexpr size_t kBufferSize = kReadOffset + kRowPitchBytes * (kReadHeight - 1) + kRowBytes; | |
| constexpr uint8_t kDonorByte = 0xB7; | |
| const GLColor kClearColor = GLColor::red; | |
| reset(kBufferSize, 4, 4); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| glClearColor(kClearColor.R / 255.0f, kClearColor.G / 255.0f, kClearColor.B / 255.0f, | |
| kClearColor.A / 255.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| std::vector<uint8_t> donor(kBufferSize, kDonorByte); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, kBufferSize, donor.data(), GL_STREAM_READ); | |
| ASSERT_GL_NO_ERROR(); | |
| glPixelStorei(GL_PACK_ALIGNMENT, 8); | |
| glPixelStorei(GL_PACK_ROW_LENGTH, kReadWidth); | |
| glReadPixels(0, -1, kReadWidth, kReadHeight, GL_RGBA, GL_UNSIGNED_BYTE, | |
| reinterpret_cast<void *>(kReadOffset)); | |
| EXPECT_GL_NO_ERROR(); | |
| const angle::Span<const uint8_t> bytes = MapBufferRange<const uint8_t>( | |
| GL_PIXEL_PACK_BUFFER, /*offset=*/0, kBufferSize, GL_MAP_READ_BIT); | |
| ASSERT_EQ(kBufferSize, bytes.size()); | |
| ASSERT_GL_NO_ERROR(); | |
| const std::array<uint8_t, kPixelBytes> kExpectedPixel = {kClearColor.R, kClearColor.G, | |
| kClearColor.B, kClearColor.A}; | |
| // Bytes before the read offset are untouched. Row 0 of the destination is below the | |
| // framebuffer and is not checked; rows 1 and 2 are inside it. | |
| for (size_t i = 0; i < kReadOffset; ++i) | |
| { | |
| EXPECT_EQ(kDonorByte, bytes[i]) << "offset " << i; | |
| } | |
| for (size_t i = kReadOffset + kRowPitchBytes; i < kBufferSize; ++i) | |
| { | |
| const size_t byteInRow = (i - kReadOffset) % kRowPitchBytes; | |
| if (byteInRow < kRowBytes) | |
| { | |
| EXPECT_EQ(kExpectedPixel[byteInRow % kPixelBytes], bytes[i]) << "offset " << i; | |
| } | |
| else | |
| { | |
| EXPECT_EQ(kDonorByte, bytes[i]) << "offset " << i; | |
| } | |
| } | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| class ReadPixelsPBODrawTest : public ReadPixelsPBOTest | |
| { | |
| protected: | |
| ReadPixelsPBODrawTest() : mProgram(0), mPositionVBO(0) {} | |
| void testSetUp() override | |
| { | |
| ReadPixelsPBOTest::testSetUp(); | |
| constexpr char kVS[] = | |
| "attribute vec4 aTest; attribute vec2 aPosition; varying vec4 vTest;\n" | |
| "void main()\n" | |
| "{\n" | |
| " vTest = aTest;\n" | |
| " gl_Position = vec4(aPosition, 0.0, 1.0);\n" | |
| " gl_PointSize = 1.0;\n" | |
| "}"; | |
| constexpr char kFS[] = | |
| "precision mediump float; varying vec4 vTest;\n" | |
| "void main()\n" | |
| "{\n" | |
| " gl_FragColor = vTest;\n" | |
| "}"; | |
| mProgram = CompileProgram(kVS, kFS); | |
| ASSERT_NE(0u, mProgram); | |
| glGenBuffers(1, &mPositionVBO); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPositionVBO); | |
| glBufferData(GL_ARRAY_BUFFER, 128, nullptr, GL_DYNAMIC_DRAW); | |
| glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| } | |
| void testTearDown() override | |
| { | |
| glDeleteProgram(mProgram); | |
| glDeleteBuffers(1, &mPositionVBO); | |
| ReadPixelsPBOTest::testTearDown(); | |
| } | |
| GLuint mProgram; | |
| GLuint mPositionVBO; | |
| }; | |
| // Test that we can draw with PBO data. | |
| TEST_P(ReadPixelsPBODrawTest, DrawWithPBO) | |
| { | |
| GLColor color(1, 2, 3, 4); | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindFramebuffer(GL_READ_FRAMEBUFFER, mFBO); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| EXPECT_GL_NO_ERROR(); | |
| float positionData[] = {0.5f, 0.5f}; | |
| glUseProgram(mProgram); | |
| glViewport(0, 0, 1, 1); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPositionVBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 0, 1 * 2 * 4, positionData); | |
| EXPECT_GL_NO_ERROR(); | |
| GLint positionLocation = glGetAttribLocation(mProgram, "aPosition"); | |
| EXPECT_NE(-1, positionLocation); | |
| GLint testLocation = glGetAttribLocation(mProgram, "aTest"); | |
| EXPECT_NE(-1, testLocation); | |
| glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); | |
| glEnableVertexAttribArray(positionLocation); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| glVertexAttribPointer(testLocation, 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0); | |
| glEnableVertexAttribArray(testLocation); | |
| EXPECT_GL_NO_ERROR(); | |
| glDrawArrays(GL_POINTS, 0, 1); | |
| EXPECT_GL_NO_ERROR(); | |
| color = GLColor(0, 0, 0, 0); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor(1, 2, 3, 4), color); | |
| } | |
| // Test that we can correctly update a buffer bound to the vertex stage with PBO. | |
| TEST_P(ReadPixelsPBODrawTest, UpdateVertexArrayWithPixelPack) | |
| { | |
| glUseProgram(mProgram); | |
| glViewport(0, 0, 1, 1); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| ASSERT_GL_NO_ERROR(); | |
| // First draw with pre-defined data. | |
| std::array<float, 2> positionData = {0.5f, 0.5f}; | |
| glBindBuffer(GL_ARRAY_BUFFER, mPositionVBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 0, positionData.size() * sizeof(positionData[0]), | |
| positionData.data()); | |
| ASSERT_GL_NO_ERROR(); | |
| GLint positionLocation = glGetAttribLocation(mProgram, "aPosition"); | |
| EXPECT_NE(-1, positionLocation); | |
| GLint testLocation = glGetAttribLocation(mProgram, "aTest"); | |
| EXPECT_NE(-1, testLocation); | |
| glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); | |
| glEnableVertexAttribArray(positionLocation); | |
| ASSERT_GL_NO_ERROR(); | |
| glBindBuffer(GL_ARRAY_BUFFER, mPBO); | |
| glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLColor), &GLColor::red); | |
| glVertexAttribPointer(testLocation, 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0); | |
| glEnableVertexAttribArray(testLocation); | |
| ASSERT_GL_NO_ERROR(); | |
| glDrawArrays(GL_POINTS, 0, 1); | |
| ASSERT_GL_NO_ERROR(); | |
| // Update the buffer bound to the VAO with a PBO. | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); | |
| ASSERT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| ASSERT_GL_NO_ERROR(); | |
| // Draw again and verify the VAO has the updated data. | |
| glDrawArrays(GL_POINTS, 0, 1); | |
| EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); | |
| } | |
| class ReadPixelsTextureNorm16PBOTest : public ReadPixelsTest | |
| { | |
| protected: | |
| void testSetUp() override | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glBindTexture(GL_TEXTURE_2D, mTex); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| template <typename T> | |
| void test(GLenum format, GLenum internalFormat, GLenum readFormat) | |
| { | |
| const bool isSigned = std::is_same<T, GLshort>::value; | |
| const GLenum type = isSigned ? GL_SHORT : GL_UNSIGNED_SHORT; | |
| T data[4] = {}; | |
| data[0] = isSigned ? -32767 : 32767; | |
| data[1] = isSigned ? -16383 : 16383; | |
| data[2] = isSigned ? -8191 : 8191; | |
| data[3] = isSigned ? -4095 : 4095; | |
| glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, data); | |
| ASSERT_GL_NO_ERROR(); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| bool supportedCombination = true; | |
| if (readFormat != GL_RGBA) | |
| { | |
| GLenum implementationFormat, implementationType; | |
| glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, | |
| reinterpret_cast<GLint *>(&implementationFormat)); | |
| glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, | |
| reinterpret_cast<GLint *>(&implementationType)); | |
| ASSERT_GL_NO_ERROR(); | |
| supportedCombination = implementationFormat == readFormat && implementationType == type; | |
| } | |
| glBufferData(GL_PIXEL_PACK_BUFFER, 12, nullptr, GL_STATIC_COPY); | |
| ASSERT_GL_NO_ERROR(); | |
| // Use non-zero offset for better code coverage | |
| constexpr GLint offset = 4; | |
| glReadPixels(0, 0, 1, 1, readFormat, type, reinterpret_cast<void *>(offset)); | |
| if (supportedCombination) | |
| { | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| else | |
| { | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| ANGLE_SKIP_TEST_IF(!supportedCombination); | |
| } | |
| auto dataRead = MapBufferRange<const T>(GL_PIXEL_PACK_BUFFER, offset, 8, GL_MAP_READ_BIT); | |
| ASSERT_GL_NO_ERROR(); | |
| EXPECT_EQ(dataRead[0], data[0]); | |
| if (readFormat == GL_RGBA || readFormat == GL_RG) | |
| { | |
| EXPECT_EQ(dataRead[1], format != GL_RED ? data[1] : 0); | |
| } | |
| if (readFormat == GL_RGBA) | |
| { | |
| EXPECT_EQ(dataRead[2], format == GL_RGBA ? data[2] : 0); | |
| EXPECT_EQ(dataRead[3], format == GL_RGBA ? data[3] : (isSigned ? 32767 : 65535)); | |
| } | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| } | |
| void testUnsigned(GLenum format, GLenum internalFormat, GLenum readFormat) | |
| { | |
| ASSERT(internalFormat == GL_RGBA16_EXT || internalFormat == GL_RG16_EXT || | |
| internalFormat == GL_R16_EXT); | |
| test<GLushort>(format, internalFormat, readFormat); | |
| } | |
| void testSigned(GLenum format, GLenum internalFormat, GLenum readFormat) | |
| { | |
| ASSERT(internalFormat == GL_RGBA16_SNORM_EXT || internalFormat == GL_RG16_SNORM_EXT || | |
| internalFormat == GL_R16_SNORM_EXT); | |
| test<GLshort>(format, internalFormat, readFormat); | |
| } | |
| GLFramebuffer mFBO; | |
| GLTexture mTex; | |
| GLBuffer mPBO; | |
| }; | |
| // Test PBO RGBA readback for RGBA16 color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, RGBA16_RGBA) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testUnsigned(GL_RGBA, GL_RGBA16_EXT, GL_RGBA); | |
| } | |
| // Test PBO RGBA readback for RG16 color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, RG16_RGBA) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testUnsigned(GL_RG, GL_RG16_EXT, GL_RGBA); | |
| } | |
| // Test PBO RG readback for RG16 color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, RG16_RG) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testUnsigned(GL_RG, GL_RG16_EXT, GL_RG); | |
| } | |
| // Test PBO RGBA readback for R16 color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, R16_RGBA) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testUnsigned(GL_RED, GL_R16_EXT, GL_RGBA); | |
| } | |
| // Test PBO RED readback for R16 color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, R16_RED) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testUnsigned(GL_RED, GL_R16_EXT, GL_RED); | |
| } | |
| // Test PBO RGBA readback for RGBA16_SNORM color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, RGBA16_SNORM_RGBA) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testSigned(GL_RGBA, GL_RGBA16_SNORM_EXT, GL_RGBA); | |
| } | |
| // Test PBO RGBA readback for RG16_SNORM color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, RG16_SNORM_RGBA) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testSigned(GL_RG, GL_RG16_SNORM_EXT, GL_RGBA); | |
| } | |
| // Test PBO RG readback for RG16_SNORM color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, RG16_SNORM_RG) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testSigned(GL_RG, GL_RG16_SNORM_EXT, GL_RG); | |
| } | |
| // Test PBO RGBA readback for R16_SNORM color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, R16_SNORM_RGBA) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testSigned(GL_RED, GL_R16_SNORM_EXT, GL_RGBA); | |
| } | |
| // Test PBO RED readback for R16_SNORM color buffer. | |
| TEST_P(ReadPixelsTextureNorm16PBOTest, R16_SNORM_RED) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testSigned(GL_RED, GL_R16_SNORM_EXT, GL_RED); | |
| } | |
| class ReadPixelsMultisampleTest : public ReadPixelsTest | |
| { | |
| protected: | |
| ReadPixelsMultisampleTest() : mFBO(0), mRBO(0), mPBO(0) | |
| { | |
| setSamples(4); | |
| setMultisampleEnabled(true); | |
| } | |
| void testSetUp() override | |
| { | |
| glGenFramebuffers(1, &mFBO); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glGenRenderbuffers(1, &mRBO); | |
| glBindRenderbuffer(GL_RENDERBUFFER, mRBO); | |
| glGenBuffers(1, &mPBO); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, 4 * getWindowWidth() * getWindowHeight(), nullptr, | |
| GL_STATIC_DRAW); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| void testTearDown() override | |
| { | |
| glDeleteFramebuffers(1, &mFBO); | |
| glDeleteRenderbuffers(1, &mRBO); | |
| glDeleteBuffers(1, &mPBO); | |
| } | |
| GLuint mFBO; | |
| GLuint mRBO; | |
| GLuint mPBO; | |
| }; | |
| // Test ReadPixels from a multisampled framebuffer. | |
| TEST_P(ReadPixelsMultisampleTest, BasicClear) | |
| { | |
| if (getClientMajorVersion() < 3 && !IsGLExtensionEnabled("GL_ANGLE_framebuffer_multisample")) | |
| { | |
| std::cout | |
| << "Test skipped because ES3 or GL_ANGLE_framebuffer_multisample is not available." | |
| << std::endl; | |
| return; | |
| } | |
| if (IsGLExtensionEnabled("GL_ANGLE_framebuffer_multisample")) | |
| { | |
| glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, GL_RGBA8, 4, 4); | |
| } | |
| else | |
| { | |
| glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_RGBA8, 4, 4); | |
| } | |
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mRBO); | |
| ASSERT_GL_NO_ERROR(); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| EXPECT_GL_NO_ERROR(); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA8, GL_UNSIGNED_BYTE, nullptr); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| // Test ReadPixels from a multisampled swapchain. | |
| TEST_P(ReadPixelsMultisampleTest, DefaultFramebuffer) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::red); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // Test ReadPixels from a multisampled swapchain into a PBO. | |
| TEST_P(ReadPixelsMultisampleTest, DefaultFramebufferPBO) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| const int w = getWindowWidth(); | |
| const int h = getWindowHeight(); | |
| glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| EXPECT_GL_NO_ERROR(); | |
| const std::vector<angle::GLColor> expectedColor(w * h, GLColor::red); | |
| std::vector<angle::GLColor> actualColor(w * h); | |
| auto mapped = MapBufferRange<const angle::GLColor>( | |
| GL_PIXEL_PACK_BUFFER, 0, sizeof(angle::GLColor) * w * h, GL_MAP_READ_BIT); | |
| ASSERT_FALSE(mapped.empty()); | |
| Span(actualColor).copy_from(mapped); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_EQ(expectedColor, actualColor); | |
| } | |
| class ReadPixelsTextureTest : public ANGLETest<> | |
| { | |
| public: | |
| ReadPixelsTextureTest() : mFBO(0), mTextureRGBA(0), mTextureBGRA(0) | |
| { | |
| setWindowWidth(32); | |
| setWindowHeight(32); | |
| setConfigRedBits(8); | |
| setConfigGreenBits(8); | |
| setConfigBlueBits(8); | |
| setConfigAlphaBits(8); | |
| } | |
| void testSetUp() override | |
| { | |
| glGenTextures(1, &mTextureRGBA); | |
| glGenTextures(1, &mTextureBGRA); | |
| glGenFramebuffers(1, &mFBO); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| } | |
| void testTearDown() override | |
| { | |
| glDeleteFramebuffers(1, &mFBO); | |
| glDeleteTextures(1, &mTextureRGBA); | |
| glDeleteTextures(1, &mTextureBGRA); | |
| } | |
| void initTextureRGBA(GLenum textureTarget, | |
| GLint levels, | |
| GLint attachmentLevel, | |
| GLint attachmentLayer) | |
| { | |
| glBindTexture(textureTarget, mTextureRGBA); | |
| glTexStorage3D(textureTarget, levels, GL_RGBA8, kSize, kSize, kSize); | |
| glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTextureRGBA, | |
| attachmentLevel, attachmentLayer); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| initializeTextureData(textureTarget, levels, GL_RGBA); | |
| } | |
| void initTextureBGRA(GLenum textureTarget, | |
| GLint levels, | |
| GLint attachmentLevel, | |
| GLint attachmentLayer) | |
| { | |
| glBindTexture(textureTarget, mTextureBGRA); | |
| for (GLint level = 0; level < levels; ++level) | |
| { | |
| glTexImage3D(textureTarget, level, GL_BGRA_EXT, kSize >> level, kSize >> level, | |
| textureTarget == GL_TEXTURE_3D ? kSize >> level : kSize, 0, GL_BGRA_EXT, | |
| GL_UNSIGNED_BYTE, nullptr); | |
| } | |
| glTexParameteri(textureTarget, GL_TEXTURE_BASE_LEVEL, 0); | |
| glTexParameteri(textureTarget, GL_TEXTURE_MAX_LEVEL, levels - 1); | |
| glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTextureBGRA, | |
| attachmentLevel, attachmentLayer); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| initializeTextureData(textureTarget, levels, GL_BGRA_EXT); | |
| } | |
| void testRead(GLenum textureTarget, GLint levels, GLint attachmentLevel, GLint attachmentLayer) | |
| { | |
| initTextureRGBA(textureTarget, levels, attachmentLevel, attachmentLayer); | |
| verifyColor(attachmentLevel, attachmentLayer); | |
| // Skip BGRA test on GL/Nvidia, leading to internal incomplete framebuffer error. | |
| // http://anglebug.com/42266676 | |
| ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL()); | |
| if (IsGLExtensionEnabled("GL_EXT_texture_format_BGRA8888")) | |
| { | |
| initTextureBGRA(textureTarget, levels, attachmentLevel, attachmentLayer); | |
| verifyColor(attachmentLevel, attachmentLayer); | |
| } | |
| } | |
| void initPBO() | |
| { | |
| // Create a buffer big enough to hold mip 0 + allow some offset during readback. | |
| glGenBuffers(1, &mBuffer); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mBuffer); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, sizeof(angle::GLColor) * 16 * 2, nullptr, | |
| GL_STREAM_COPY); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| void testPBORead(GLenum textureTarget, | |
| GLint levels, | |
| GLint attachmentLevel, | |
| GLint attachmentLayer) | |
| { | |
| initPBO(); | |
| initTextureRGBA(textureTarget, levels, attachmentLevel, attachmentLayer); | |
| verifyPBO(attachmentLevel, attachmentLayer); | |
| // Skip BGRA test on GL/Nvidia, leading to internal incomplete framebuffer error. | |
| // http://anglebug.com/42266676 | |
| ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL()); | |
| if (IsGLExtensionEnabled("GL_EXT_texture_format_BGRA8888")) | |
| { | |
| initTextureBGRA(textureTarget, levels, attachmentLevel, attachmentLayer); | |
| verifyPBO(attachmentLevel, attachmentLayer); | |
| } | |
| } | |
| // Give each {level,layer} pair a (probably) unique color via random. | |
| GLuint getColorValue(GLint level, GLint layer) | |
| { | |
| mRNG.reseed(level + layer * 32); | |
| return mRNG.randomUInt(); | |
| } | |
| void verifyColor(GLint level, GLint layer) | |
| { | |
| const angle::GLColor colorValue(getColorValue(level, layer)); | |
| const GLint size = kSize >> level; | |
| EXPECT_PIXEL_RECT_EQ(0, 0, size, size, colorValue); | |
| } | |
| void verifyPBO(GLint level, GLint layer) | |
| { | |
| const GLint size = kSize >> level; | |
| const GLsizei offset = kSize * (level + layer); | |
| glReadPixels(0, 0, size, size, GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<void *>(offset)); | |
| const std::vector<angle::GLColor> expectedColor(size * size, getColorValue(level, layer)); | |
| std::vector<angle::GLColor> actualColor(size * size); | |
| auto mapped = MapBufferRange<const angle::GLColor>( | |
| GL_PIXEL_PACK_BUFFER, offset, sizeof(angle::GLColor) * size * size, GL_MAP_READ_BIT); | |
| ASSERT_FALSE(mapped.empty()); | |
| Span(actualColor).copy_from(mapped); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| EXPECT_EQ(expectedColor, actualColor); | |
| } | |
| void initializeTextureData(GLenum textureTarget, GLint levels, GLenum format) | |
| { | |
| for (GLint level = 0; level < levels; ++level) | |
| { | |
| GLint mipSize = kSize >> level; | |
| GLint layers = (textureTarget == GL_TEXTURE_3D ? mipSize : kSize); | |
| size_t layerSize = mipSize * mipSize; | |
| std::vector<GLuint> textureData(layers * layerSize); | |
| for (GLint layer = 0; layer < layers; ++layer) | |
| { | |
| GLuint colorValue = getColorValue(level, layer); | |
| size_t offset = (layer * layerSize); | |
| if (format == GL_BGRA_EXT) | |
| { | |
| const GLuint rb = colorValue & 0x00FF00FF; | |
| const GLuint br = (rb & 0xFF) << 16 | rb >> 16; | |
| const GLuint ga = colorValue & 0xFF00FF00; | |
| colorValue = ga | br; | |
| } | |
| std::fill(textureData.begin() + offset, textureData.begin() + offset + layerSize, | |
| colorValue); | |
| } | |
| glTexSubImage3D(textureTarget, level, 0, 0, 0, mipSize, mipSize, layers, format, | |
| GL_UNSIGNED_BYTE, textureData.data()); | |
| } | |
| } | |
| static constexpr GLint kSize = 4; | |
| angle::RNG mRNG; | |
| GLuint mFBO; | |
| GLuint mTextureRGBA; | |
| GLuint mTextureBGRA; | |
| GLuint mBuffer; | |
| }; | |
| // Test 3D attachment readback. | |
| TEST_P(ReadPixelsTextureTest, BasicAttachment3D) | |
| { | |
| testRead(GL_TEXTURE_3D, 1, 0, 0); | |
| } | |
| // Test 3D attachment readback, non-zero mip. | |
| TEST_P(ReadPixelsTextureTest, MipAttachment3D) | |
| { | |
| testRead(GL_TEXTURE_3D, 2, 1, 0); | |
| } | |
| // Test 3D attachment readback, non-zero layer. | |
| TEST_P(ReadPixelsTextureTest, LayerAttachment3D) | |
| { | |
| testRead(GL_TEXTURE_3D, 1, 0, 1); | |
| } | |
| // Test 3D attachment readback, non-zero mip and layer. | |
| TEST_P(ReadPixelsTextureTest, MipLayerAttachment3D) | |
| { | |
| testRead(GL_TEXTURE_3D, 2, 1, 1); | |
| } | |
| // Test 2D array attachment readback. | |
| TEST_P(ReadPixelsTextureTest, BasicAttachment2DArray) | |
| { | |
| testRead(GL_TEXTURE_2D_ARRAY, 1, 0, 0); | |
| } | |
| // Test 3D attachment readback, non-zero mip. | |
| TEST_P(ReadPixelsTextureTest, MipAttachment2DArray) | |
| { | |
| testRead(GL_TEXTURE_2D_ARRAY, 2, 1, 0); | |
| } | |
| // Test 3D attachment readback, non-zero layer. | |
| TEST_P(ReadPixelsTextureTest, LayerAttachment2DArray) | |
| { | |
| testRead(GL_TEXTURE_2D_ARRAY, 1, 0, 1); | |
| } | |
| // Test 3D attachment readback, non-zero mip and layer. | |
| TEST_P(ReadPixelsTextureTest, MipLayerAttachment2DArray) | |
| { | |
| testRead(GL_TEXTURE_2D_ARRAY, 2, 1, 1); | |
| } | |
| // Test 3D attachment PBO readback. | |
| TEST_P(ReadPixelsTextureTest, BasicAttachment3DPBO) | |
| { | |
| testPBORead(GL_TEXTURE_3D, 1, 0, 0); | |
| } | |
| // Test 3D attachment readback, non-zero mip. | |
| TEST_P(ReadPixelsTextureTest, MipAttachment3DPBO) | |
| { | |
| testPBORead(GL_TEXTURE_3D, 2, 1, 0); | |
| } | |
| // Test 3D attachment readback, non-zero layer. | |
| TEST_P(ReadPixelsTextureTest, LayerAttachment3DPBO) | |
| { | |
| testPBORead(GL_TEXTURE_3D, 1, 0, 1); | |
| } | |
| // Test 3D attachment readback, non-zero mip and layer. | |
| TEST_P(ReadPixelsTextureTest, MipLayerAttachment3DPBO) | |
| { | |
| testPBORead(GL_TEXTURE_3D, 2, 1, 1); | |
| } | |
| // Test 2D array attachment readback. | |
| TEST_P(ReadPixelsTextureTest, BasicAttachment2DArrayPBO) | |
| { | |
| testPBORead(GL_TEXTURE_2D_ARRAY, 1, 0, 0); | |
| } | |
| // Test 3D attachment readback, non-zero mip. | |
| TEST_P(ReadPixelsTextureTest, MipAttachment2DArrayPBO) | |
| { | |
| testPBORead(GL_TEXTURE_2D_ARRAY, 2, 1, 0); | |
| } | |
| // Test 3D attachment readback, non-zero layer. | |
| TEST_P(ReadPixelsTextureTest, LayerAttachment2DArrayPBO) | |
| { | |
| testPBORead(GL_TEXTURE_2D_ARRAY, 1, 0, 1); | |
| } | |
| // Test 3D attachment readback, non-zero mip and layer. | |
| TEST_P(ReadPixelsTextureTest, MipLayerAttachment2DArrayPBO) | |
| { | |
| testPBORead(GL_TEXTURE_2D_ARRAY, 2, 1, 1); | |
| } | |
| // a test class to be used for error checking of glReadPixels | |
| class ReadPixelsErrorTest : public ReadPixelsTest | |
| { | |
| protected: | |
| ReadPixelsErrorTest() : mTexture(0), mFBO(0) {} | |
| void testSetUp() override | |
| { | |
| glGenTextures(1, &mTexture); | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 1); | |
| glGenFramebuffers(1, &mFBO); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| void testTearDown() override | |
| { | |
| glDeleteTextures(1, &mTexture); | |
| glDeleteFramebuffers(1, &mFBO); | |
| } | |
| void testUnsupportedTypeConversions(std::vector<GLenum> internalFormats, | |
| std::vector<GLenum> unsupportedTypes) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| for (GLenum internalFormat : internalFormats) | |
| { | |
| GLRenderbuffer rbo; | |
| glBindRenderbuffer(GL_RENDERBUFFER, rbo); | |
| glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, 1, 1); | |
| ASSERT_GL_NO_ERROR(); | |
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| GLenum implementationFormat, implementationType; | |
| glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, | |
| reinterpret_cast<GLint *>(&implementationFormat)); | |
| ASSERT_GL_NO_ERROR(); | |
| glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, | |
| reinterpret_cast<GLint *>(&implementationType)); | |
| ASSERT_GL_NO_ERROR(); | |
| for (GLenum type : unsupportedTypes) | |
| { | |
| uint8_t pixel[8] = {}; | |
| if (implementationFormat != GL_RGBA || implementationType != type) | |
| { | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, type, pixel); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| } | |
| } | |
| } | |
| GLuint mTexture; | |
| GLuint mFBO; | |
| }; | |
| // The test verifies that glReadPixels generates a GL_INVALID_OPERATION error | |
| // when the read buffer is GL_NONE. | |
| // Reference: GLES 3.0.4, Section 4.3.2 Reading Pixels | |
| TEST_P(ReadPixelsErrorTest, ReadBufferIsNone) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glReadBuffer(GL_NONE); | |
| std::vector<GLubyte> pixels(4); | |
| EXPECT_GL_NO_ERROR(); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| // The test verifies (x + width) and (y + height) integer overflows. | |
| TEST_P(ReadPixelsErrorTest, Overflow) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| std::vector<GLubyte> pixels(4); | |
| ASSERT_GL_NO_ERROR(); | |
| glReadPixels(1, 0, 2147483647, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| glReadPixels(0, 1, 4, 2147483647, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| // The test verifies internal limits on the number of read bytes. | |
| TEST_P(ReadPixelsErrorTest, MemoryLimit) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| std::vector<GLubyte> pixels(4); | |
| ASSERT_GL_NO_ERROR(); | |
| // Params overflow UINT32 used for data length computations | |
| glReadPixels(0, 0, 32768, 32768, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| // Params overflow INT32 used for buffer size | |
| glReadPixels(0, 0, 16384, 32768, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| // The test verifies that glReadPixels generates a GL_INVALID_OPERATION | |
| // error when reading signed 8-bit color buffers using incompatible types. | |
| TEST_P(ReadPixelsErrorTest, ColorBufferSnorm8) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| testUnsupportedTypeConversions({GL_R8_SNORM, GL_RG8_SNORM, GL_RGBA8_SNORM}, | |
| {GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT}); | |
| } | |
| // The test verifies that glReadPixels generates a GL_INVALID_OPERATION | |
| // error when reading signed 16-bit color buffers using incompatible types. | |
| TEST_P(ReadPixelsErrorTest, ColorBufferSnorm16) | |
| { | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_render_snorm")); | |
| ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16")); | |
| testUnsupportedTypeConversions({GL_R16_SNORM_EXT, GL_RG16_SNORM_EXT, GL_RGBA16_SNORM_EXT}, | |
| {GL_BYTE, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT}); | |
| } | |
| // The test verifies that glReadnPixels* generates a GL_INVALID_OPERATION error if | |
| // the buffer size required to store the requested data is greater than bufSize if | |
| // PBO is bound. | |
| TEST_P(ReadPixelsErrorTest, PBOBufSizeTest) | |
| { | |
| GLuint PBO; | |
| glGenBuffers(1, &PBO); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, PBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, 4, nullptr, GL_STATIC_DRAW); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| if (IsGLExtensionEnabled("GL_KHR_robustness")) | |
| { | |
| glReadnPixelsKHR(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 2, 0); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| if (IsGLExtensionEnabled("GL_EXT_robustness")) | |
| { | |
| glReadnPixelsEXT(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 2, 0); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| } | |
| glDeleteBuffers(1, &PBO); | |
| } | |
| // texture internal format is GL_RGBA32F | |
| class ReadPixelsFloat32TypePBOTest : public ReadPixelsPBOTest | |
| { | |
| protected: | |
| ReadPixelsFloat32TypePBOTest() : ReadPixelsPBOTest() {} | |
| void testSetUp() override | |
| { | |
| glGenBuffers(1, &mPBO); | |
| glGenFramebuffers(1, &mFBO); | |
| // buffer size sufficient enough for glReadPixels when data != 0 | |
| reset(4 * 4 * 1 * 4 + 16, 4, 1); | |
| } | |
| void reset(GLuint bufferSize, GLuint fboWidth, GLuint fboHeight) override | |
| { | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | |
| glDeleteTextures(1, &mTexture); | |
| glGenTextures(1, &mTexture); | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, fboWidth, fboHeight); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| mFBOWidth = fboWidth; | |
| mFBOHeight = fboHeight; | |
| mPBOBufferSize = bufferSize; | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| }; | |
| // Test basic usage of PBOs. | |
| TEST_P(ReadPixelsFloat32TypePBOTest, Basic) | |
| { | |
| glClearColor(0.5f, 0.2f, 0.3f, 0.4f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, mPBO); | |
| glReadPixels(0, 0, mFBOWidth, mFBOHeight, GL_RGBA, GL_FLOAT, reinterpret_cast<void *>(2)); | |
| EXPECT_GL_ERROR(GL_INVALID_OPERATION); | |
| glReadPixels(0, 0, mFBOWidth, mFBOHeight, GL_RGBA, GL_FLOAT, 0); | |
| EXPECT_GL_NO_ERROR(); | |
| auto dataColor = | |
| MapBufferRange<const GLColor32F>(GL_PIXEL_PACK_BUFFER, 0, mPBOBufferSize, GL_MAP_READ_BIT); | |
| EXPECT_GL_NO_ERROR(); | |
| EXPECT_EQ(GLColor32F(0.5f, 0.2f, 0.3f, 0.4f), dataColor[0]); | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| // a test class to be used for error checking of glReadPixels with WebGLCompatibility | |
| class ReadPixelsWebGLErrorTest : public ReadPixelsTest | |
| { | |
| protected: | |
| ReadPixelsWebGLErrorTest() : mTexture(0), mFBO(0) { setWebGLCompatibilityEnabled(true); } | |
| void testSetUp() override | |
| { | |
| glGenTextures(1, &mTexture); | |
| glBindTexture(GL_TEXTURE_2D, mTexture); | |
| glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 1); | |
| glGenFramebuffers(1, &mFBO); | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| void testTearDown() override | |
| { | |
| glDeleteTextures(1, &mTexture); | |
| glDeleteFramebuffers(1, &mFBO); | |
| } | |
| GLuint mTexture; | |
| GLuint mFBO; | |
| }; | |
| // Test that WebGL context readpixels generates an error when reading GL_UNSIGNED_INT_24_8 type. | |
| TEST_P(ReadPixelsWebGLErrorTest, TypeIsUnsignedInt24_8) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| glReadBuffer(GL_COLOR_ATTACHMENT0); | |
| std::vector<GLuint> pixels(4); | |
| EXPECT_GL_NO_ERROR(); | |
| glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_INT_24_8, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_ENUM); | |
| } | |
| // Test that WebGL context readpixels generates an error when reading GL_DEPTH_COMPONENT format. | |
| TEST_P(ReadPixelsWebGLErrorTest, FormatIsDepthComponent) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); | |
| glReadBuffer(GL_COLOR_ATTACHMENT0); | |
| std::vector<GLubyte> pixels(4); | |
| EXPECT_GL_NO_ERROR(); | |
| glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, pixels.data()); | |
| EXPECT_GL_ERROR(GL_INVALID_ENUM); | |
| } | |
| // Test class for reading pixels from framebuffers with multiple color attachments. | |
| class ReadPixelsMultipleColorAttachmentsTest : public ANGLETest<> | |
| { | |
| protected: | |
| static constexpr int kSize = 16; | |
| void makeAttachedTexture(GLTexture &texture, GLenum attachment) | |
| { | |
| glBindTexture(GL_TEXTURE_2D, texture); | |
| glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, kSize, kSize); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture, 0); | |
| } | |
| void verifyReadColor(GLenum readBuffer, const GLColor &color) | |
| { | |
| glReadBuffer(readBuffer); | |
| EXPECT_PIXEL_RECT_EQ(0, 0, kSize, kSize, color); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| }; | |
| // Test that reading pixels from each color attachment of a framebuffer with multiple color | |
| // attachments returns that attachment's data. | |
| TEST_P(ReadPixelsMultipleColorAttachmentsTest, ReadFromEachAttachment) | |
| { | |
| constexpr char kFS[] = R"(#version 300 es | |
| precision highp float; | |
| layout(location = 0) out vec4 color0; | |
| layout(location = 1) out vec4 color1; | |
| layout(location = 2) out vec4 color2; | |
| layout(location = 3) out vec4 color3; | |
| void main() | |
| { | |
| color0 = vec4(1.0, 0.0, 0.0, 1.0); | |
| color1 = vec4(0.0, 1.0, 0.0, 1.0); | |
| color2 = vec4(0.0, 0.0, 1.0, 1.0); | |
| color3 = vec4(1.0, 1.0, 0.0, 1.0); | |
| })"; | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| constexpr size_t kAttachmentCount = 4; | |
| std::array<GLTexture, kAttachmentCount> textures; | |
| std::array<GLenum, kAttachmentCount> drawBuffers; | |
| for (size_t i = 0; i < kAttachmentCount; ++i) | |
| { | |
| drawBuffers[i] = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i); | |
| makeAttachedTexture(textures[i], drawBuffers[i]); | |
| } | |
| glDrawBuffers(kAttachmentCount, drawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); | |
| drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f); | |
| ASSERT_GL_NO_ERROR(); | |
| const std::array<GLColor, kAttachmentCount> kColors = {GLColor::red, GLColor::green, | |
| GLColor::blue, GLColor::yellow}; | |
| // Read the attachments back in an order that switches the read buffer between reads. | |
| for (size_t i : {1u, 3u, 0u, 2u, 1u}) | |
| { | |
| verifyReadColor(static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i), kColors[i]); | |
| } | |
| } | |
| // Test that reading into a pixel pack buffer from a framebuffer with multiple color attachments | |
| // returns the selected attachment's data. | |
| TEST_P(ReadPixelsMultipleColorAttachmentsTest, ReadFromEachAttachmentWithPBO) | |
| { | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| std::array<GLTexture, 2> textures; | |
| makeAttachedTexture(textures[0], GL_COLOR_ATTACHMENT0); | |
| makeAttachedTexture(textures[1], GL_COLOR_ATTACHMENT1); | |
| constexpr std::array<GLenum, 2> kDrawBuffers = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; | |
| glDrawBuffers(2, kDrawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| constexpr std::array<float, 4> kRed = {1.0f, 0.0f, 0.0f, 1.0f}; | |
| constexpr std::array<float, 4> kGreen = {0.0f, 1.0f, 0.0f, 1.0f}; | |
| glClearBufferfv(GL_COLOR, 0, kRed.data()); | |
| glClearBufferfv(GL_COLOR, 1, kGreen.data()); | |
| ASSERT_GL_NO_ERROR(); | |
| GLBuffer pbo; | |
| glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); | |
| glBufferData(GL_PIXEL_PACK_BUFFER, kSize * kSize * 4, nullptr, GL_STREAM_READ); | |
| const std::array<GLColor, 2> kColors = {GLColor::red, GLColor::green}; | |
| for (size_t i : {1u, 0u, 1u}) | |
| { | |
| glReadBuffer(static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i)); | |
| glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | |
| ASSERT_GL_NO_ERROR(); | |
| const void *mappedPtr = | |
| glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, kSize * kSize * 4, GL_MAP_READ_BIT); | |
| ASSERT_NE(nullptr, mappedPtr); | |
| const auto &pixels = *static_cast<const std::array<GLColor, kSize * kSize> *>(mappedPtr); | |
| for (size_t j = 0; j < pixels.size(); ++j) | |
| { | |
| EXPECT_EQ(kColors[i], pixels[j]) << "pixel " << j; | |
| } | |
| glUnmapBuffer(GL_PIXEL_PACK_BUFFER); | |
| ASSERT_GL_NO_ERROR(); | |
| } | |
| } | |
| // Test that a read area extending outside a framebuffer with multiple renderbuffer color | |
| // attachments only writes the in-bounds region of the destination. | |
| TEST_P(ReadPixelsMultipleColorAttachmentsTest, ClippedReadFromRenderbufferAttachment) | |
| { | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| std::array<GLRenderbuffer, 2> renderbuffers; | |
| for (size_t i = 0; i < 2; ++i) | |
| { | |
| glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]); | |
| glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize); | |
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i), | |
| GL_RENDERBUFFER, renderbuffers[i]); | |
| } | |
| constexpr std::array<GLenum, 2> kDrawBuffers = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; | |
| glDrawBuffers(2, kDrawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| constexpr std::array<float, 4> kRed = {1.0f, 0.0f, 0.0f, 1.0f}; | |
| constexpr std::array<float, 4> kBlue = {0.0f, 0.0f, 1.0f, 1.0f}; | |
| glClearBufferfv(GL_COLOR, 0, kRed.data()); | |
| glClearBufferfv(GL_COLOR, 1, kBlue.data()); | |
| ASSERT_GL_NO_ERROR(); | |
| // Read an area that extends past every edge of the framebuffer. | |
| constexpr int kOffset = 4; | |
| constexpr int kReadSize = kSize + 2 * kOffset; | |
| const GLColor kSentinel(1, 2, 3, 4); | |
| std::vector<GLColor> pixels(kReadSize * kReadSize, kSentinel); | |
| glReadBuffer(GL_COLOR_ATTACHMENT1); | |
| glReadPixels(-kOffset, -kOffset, kReadSize, kReadSize, GL_RGBA, GL_UNSIGNED_BYTE, | |
| pixels.data()); | |
| EXPECT_GL_NO_ERROR(); | |
| for (int y = 0; y < kReadSize; ++y) | |
| { | |
| for (int x = 0; x < kReadSize; ++x) | |
| { | |
| const bool inBounds = | |
| x >= kOffset && x < kOffset + kSize && y >= kOffset && y < kOffset + kSize; | |
| EXPECT_EQ(inBounds ? GLColor::blue : kSentinel, pixels[y * kReadSize + x]) | |
| << "at (" << x << ", " << y << ")"; | |
| } | |
| } | |
| } | |
| // Test reading from a framebuffer whose color attachments are layers of a 2D array texture. | |
| TEST_P(ReadPixelsMultipleColorAttachmentsTest, ReadFromTextureArrayLayerAttachments) | |
| { | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| GLTexture texture; | |
| glBindTexture(GL_TEXTURE_2D_ARRAY, texture); | |
| glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, kSize, kSize, 2); | |
| // Attach the layers in reverse order. | |
| glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, 1); | |
| glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texture, 0, 0); | |
| constexpr std::array<GLenum, 2> kDrawBuffers = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; | |
| glDrawBuffers(2, kDrawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| constexpr std::array<float, 4> kGreen = {0.0f, 1.0f, 0.0f, 1.0f}; | |
| constexpr std::array<float, 4> kYellow = {1.0f, 1.0f, 0.0f, 1.0f}; | |
| glClearBufferfv(GL_COLOR, 0, kGreen.data()); | |
| glClearBufferfv(GL_COLOR, 1, kYellow.data()); | |
| ASSERT_GL_NO_ERROR(); | |
| verifyReadColor(GL_COLOR_ATTACHMENT1, GLColor::yellow); | |
| verifyReadColor(GL_COLOR_ATTACHMENT0, GLColor::green); | |
| } | |
| // Test reading integer data from each color attachment of a framebuffer with multiple integer | |
| // color attachments. | |
| TEST_P(ReadPixelsMultipleColorAttachmentsTest, ReadFromEachIntegerAttachment) | |
| { | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| std::array<GLTexture, 2> textures; | |
| for (size_t i = 0; i < 2; ++i) | |
| { | |
| glBindTexture(GL_TEXTURE_2D, textures[i]); | |
| glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8UI, kSize, kSize); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i), | |
| GL_TEXTURE_2D, textures[i], 0); | |
| } | |
| constexpr std::array<GLenum, 2> kDrawBuffers = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; | |
| glDrawBuffers(2, kDrawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| constexpr std::array<std::array<GLuint, 4>, 2> kValues = {{{11, 22, 33, 44}, {55, 66, 77, 88}}}; | |
| glClearBufferuiv(GL_COLOR, 0, kValues[0].data()); | |
| glClearBufferuiv(GL_COLOR, 1, kValues[1].data()); | |
| ASSERT_GL_NO_ERROR(); | |
| for (size_t i : {1u, 0u}) | |
| { | |
| glReadBuffer(static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i)); | |
| const GLColor32UI expectedColor(kValues[i][0], kValues[i][1], kValues[i][2], kValues[i][3]); | |
| EXPECT_PIXEL_RECT32UI_EQ(0, 0, kSize, kSize, expectedColor); | |
| EXPECT_GL_NO_ERROR(); | |
| } | |
| } | |
| // Test reading from a single color attachment bound at a non-zero slot, both when | |
| // GL_COLOR_ATTACHMENT0 was never attached and when it was detached after an MRT draw. | |
| TEST_P(ReadPixelsMultipleColorAttachmentsTest, ReadFromSingleNonZeroAttachment) | |
| { | |
| // Case 1: Only GL_COLOR_ATTACHMENT1 is attached (GL_COLOR_ATTACHMENT0 was never attached). | |
| { | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| GLTexture tex1; | |
| makeAttachedTexture(tex1, GL_COLOR_ATTACHMENT1); | |
| constexpr std::array<GLenum, 2> kDrawBuffers = {GL_NONE, GL_COLOR_ATTACHMENT1}; | |
| glDrawBuffers(2, kDrawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| constexpr std::array<float, 4> kGreen = {0.0f, 1.0f, 0.0f, 1.0f}; | |
| glClearBufferfv(GL_COLOR, 1, kGreen.data()); | |
| ASSERT_GL_NO_ERROR(); | |
| verifyReadColor(GL_COLOR_ATTACHMENT1, GLColor::green); | |
| } | |
| // Case 2: GL_COLOR_ATTACHMENT0 is detached after an MRT draw, leaving only | |
| // GL_COLOR_ATTACHMENT1 bound. | |
| { | |
| constexpr char kFS[] = R"(#version 300 es | |
| precision highp float; | |
| layout(location = 0) out vec4 color0; | |
| layout(location = 1) out vec4 color1; | |
| void main() | |
| { | |
| color0 = vec4(1.0, 0.0, 0.0, 1.0); | |
| color1 = vec4(0.0, 0.0, 1.0, 1.0); | |
| })"; | |
| GLFramebuffer fbo; | |
| glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
| GLTexture tex0; | |
| GLTexture tex1; | |
| makeAttachedTexture(tex0, GL_COLOR_ATTACHMENT0); | |
| makeAttachedTexture(tex1, GL_COLOR_ATTACHMENT1); | |
| constexpr std::array<GLenum, 2> kDrawBuffers = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; | |
| glDrawBuffers(2, kDrawBuffers.data()); | |
| ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); | |
| ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); | |
| drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f); | |
| ASSERT_GL_NO_ERROR(); | |
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | |
| verifyReadColor(GL_COLOR_ATTACHMENT1, GLColor::blue); | |
| } | |
| } | |
| } // anonymous namespace | |
| // Use this to select which configurations (e.g. which renderer, which GLES major version) these | |
| // tests should be run against. | |
| ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND( | |
| ReadPixelsTest, | |
| ES3_METAL().enable(Feature::CopyTextureToBufferForReadOptimization)); | |
| ANGLE_INSTANTIATE_TEST_ES2(ReadPixelsPBONVTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsPBOTest); | |
| ANGLE_INSTANTIATE_TEST_ES3_AND( | |
| ReadPixelsPBOTest, | |
| ES3_OPENGL().enable(Feature::PackLastRowSeparatelyWhenFillingPackBuffer), | |
| ES3_OPENGLES().enable(Feature::PackLastRowSeparatelyWhenFillingPackBuffer)); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsFloat32TypePBOTest); | |
| ANGLE_INSTANTIATE_TEST_ES3(ReadPixelsFloat32TypePBOTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsPBODrawTest); | |
| ANGLE_INSTANTIATE_TEST_ES3_AND(ReadPixelsPBODrawTest, | |
| ES3_VULKAN().enable(Feature::ForceFallbackFormat)); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsTextureNorm16PBOTest); | |
| ANGLE_INSTANTIATE_TEST_ES3(ReadPixelsTextureNorm16PBOTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsMultisampleTest); | |
| ANGLE_INSTANTIATE_TEST_ES3(ReadPixelsMultisampleTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsTextureTest); | |
| ANGLE_INSTANTIATE_TEST_ES3(ReadPixelsTextureTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsErrorTest); | |
| ANGLE_INSTANTIATE_TEST_ES3(ReadPixelsErrorTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsWebGLErrorTest); | |
| ANGLE_INSTANTIATE_TEST_ES3(ReadPixelsWebGLErrorTest); | |
| GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ReadPixelsMultipleColorAttachmentsTest); | |
| ANGLE_INSTANTIATE_TEST_ES3_AND( | |
| ReadPixelsMultipleColorAttachmentsTest, | |
| ES3_OPENGL().enable(Feature::ReadPixelsViaSingleAttachmentFramebuffer), | |
| ES3_OPENGLES().enable(Feature::ReadPixelsViaSingleAttachmentFramebuffer)); |