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. |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame^] | 4 | ANGLE_TYPED_TEST_CASE(FramebufferFormatsTest, ES2_D3D9, ES2_D3D11, ES3_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 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame^] | 67 | void testRenderbufferMultisampleFormat(int minESVersion, GLenum attachmentType, GLenum internalFormat) |
| 68 | { |
| 69 | if (T::GetGlesMajorVersion() < minESVersion) |
| 70 | { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // Check that multisample is supported with at least two samples (minimum required is 1) |
| 75 | bool supports2Samples = false; |
| 76 | |
| 77 | if (T::GetGlesMajorVersion() == 2) |
| 78 | { |
| 79 | if (extensionEnabled("ANGLE_framebuffer_multisample")) |
| 80 | { |
| 81 | int maxSamples; |
| 82 | glGetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSamples); |
| 83 | supports2Samples = maxSamples >= 2; |
| 84 | } |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | assert(T::GetGlesMajorVersion() >= 3); |
| 89 | int maxSamples; |
| 90 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 91 | supports2Samples = maxSamples >= 2; |
| 92 | } |
| 93 | |
| 94 | if (!supports2Samples) |
| 95 | { |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | GLuint framebufferID; |
| 100 | glGenFramebuffers(1, &framebufferID); |
| 101 | glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); |
| 102 | |
| 103 | GLuint renderbufferID; |
| 104 | glGenRenderbuffers(1, &renderbufferID); |
| 105 | glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID); |
| 106 | |
| 107 | EXPECT_GL_NO_ERROR(); |
| 108 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128); |
| 109 | EXPECT_GL_NO_ERROR(); |
| 110 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, renderbufferID); |
| 111 | EXPECT_GL_NO_ERROR(); |
| 112 | |
| 113 | glDeleteRenderbuffers(1, &renderbufferID); |
| 114 | glDeleteFramebuffers(1, &framebufferID); |
| 115 | } |
| 116 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 117 | virtual void SetUp() |
| 118 | { |
| 119 | ANGLETest::SetUp(); |
| 120 | } |
| 121 | |
| 122 | virtual void TearDown() |
| 123 | { |
| 124 | ANGLETest::TearDown(); |
| 125 | } |
| 126 | }; |
| 127 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 128 | TYPED_TEST(FramebufferFormatsTest, RGBA4) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 129 | { |
| 130 | testTextureFormat(GL_RGBA4, 4, 4, 4, 4); |
| 131 | } |
| 132 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 133 | TYPED_TEST(FramebufferFormatsTest, RGB565) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 134 | { |
| 135 | testTextureFormat(GL_RGB565, 5, 6, 5, 0); |
| 136 | } |
| 137 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 138 | TYPED_TEST(FramebufferFormatsTest, RGB8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 139 | { |
| 140 | testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0); |
| 141 | } |
| 142 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 143 | TYPED_TEST(FramebufferFormatsTest, BGRA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 144 | { |
| 145 | testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8); |
| 146 | } |
| 147 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 148 | TYPED_TEST(FramebufferFormatsTest, RGBA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 149 | { |
| 150 | testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8); |
| 151 | } |
| 152 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame^] | 153 | TYPED_TEST(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16) |
| 154 | { |
| 155 | testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16); |
| 156 | } |
| 157 | |
| 158 | TYPED_TEST(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24) |
| 159 | { |
| 160 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24); |
| 161 | } |
| 162 | |
| 163 | TYPED_TEST(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F) |
| 164 | { |
| 165 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F); |
| 166 | } |
| 167 | |
| 168 | TYPED_TEST(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8) |
| 169 | { |
| 170 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8); |
| 171 | } |
| 172 | |
| 173 | TYPED_TEST(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8) |
| 174 | { |
| 175 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8); |
| 176 | } |
| 177 | |
| 178 | TYPED_TEST(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8) |
| 179 | { |
| 180 | testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8); |
| 181 | } |