Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 1 | #include "ANGLETest.h" |
| 2 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 3 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 4 | ANGLE_TYPED_TEST_CASE(FramebufferFormatsTest, ES2_D3D9, ES2_D3D11); |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 5 | |
| 6 | template<typename T> |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 7 | class FramebufferFormatsTest : public ANGLETest |
| 8 | { |
| 9 | protected: |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 10 | FramebufferFormatsTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform()) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 11 | { |
| 12 | setWindowWidth(128); |
| 13 | setWindowHeight(128); |
| 14 | setConfigRedBits(8); |
| 15 | setConfigGreenBits(8); |
| 16 | setConfigBlueBits(8); |
| 17 | setConfigAlphaBits(8); |
| 18 | } |
| 19 | |
| 20 | void checkBitCount(GLuint fbo, GLenum channel, GLint minBits) |
| 21 | { |
| 22 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 23 | |
| 24 | GLint bits = 0; |
| 25 | glGetIntegerv(channel, &bits); |
| 26 | |
| 27 | if (minBits == 0) |
| 28 | { |
| 29 | EXPECT_EQ(minBits, bits); |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | EXPECT_GE(bits, minBits); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void testBitCounts(GLuint fbo, GLint minRedBits, GLint minGreenBits, GLint minBlueBits, |
| 38 | GLint minAlphaBits, GLint minDepthBits, GLint minStencilBits) |
| 39 | { |
| 40 | checkBitCount(fbo, GL_RED_BITS, minRedBits); |
| 41 | checkBitCount(fbo, GL_GREEN_BITS, minGreenBits); |
| 42 | checkBitCount(fbo, GL_BLUE_BITS, minBlueBits); |
| 43 | checkBitCount(fbo, GL_ALPHA_BITS, minAlphaBits); |
| 44 | checkBitCount(fbo, GL_DEPTH_BITS, minDepthBits); |
| 45 | checkBitCount(fbo, GL_STENCIL_BITS, minStencilBits); |
| 46 | } |
| 47 | |
| 48 | void testTextureFormat(GLenum internalFormat, GLint minRedBits, GLint minGreenBits, GLint minBlueBits, |
| 49 | GLint minAlphaBits) |
| 50 | { |
| 51 | GLuint tex = 0; |
| 52 | glGenTextures(1, &tex); |
| 53 | glBindTexture(GL_TEXTURE_2D, tex); |
| 54 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1); |
| 55 | |
| 56 | GLuint fbo = 0; |
| 57 | glGenFramebuffers(1, &fbo); |
| 58 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 59 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); |
| 60 | |
| 61 | testBitCounts(fbo, minRedBits, minGreenBits, minBlueBits, minAlphaBits, 0, 0); |
| 62 | |
| 63 | glDeleteTextures(1, &tex); |
| 64 | glDeleteFramebuffers(1, &fbo); |
| 65 | } |
| 66 | |
| 67 | virtual void SetUp() |
| 68 | { |
| 69 | ANGLETest::SetUp(); |
| 70 | } |
| 71 | |
| 72 | virtual void TearDown() |
| 73 | { |
| 74 | ANGLETest::TearDown(); |
| 75 | } |
| 76 | }; |
| 77 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 78 | TYPED_TEST(FramebufferFormatsTest, RGBA4) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 79 | { |
| 80 | testTextureFormat(GL_RGBA4, 4, 4, 4, 4); |
| 81 | } |
| 82 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 83 | TYPED_TEST(FramebufferFormatsTest, RGB565) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 84 | { |
| 85 | testTextureFormat(GL_RGB565, 5, 6, 5, 0); |
| 86 | } |
| 87 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 88 | TYPED_TEST(FramebufferFormatsTest, RGB8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 89 | { |
| 90 | testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0); |
| 91 | } |
| 92 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 93 | TYPED_TEST(FramebufferFormatsTest, BGRA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 94 | { |
| 95 | testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8); |
| 96 | } |
| 97 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 98 | TYPED_TEST(FramebufferFormatsTest, RGBA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 99 | { |
| 100 | testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8); |
| 101 | } |
| 102 | |