blob: bffd4d170660284c2fa6fe6236fe8584478c5d79 [file] [log] [blame]
Geoff Langb6a673a2014-06-05 14:19:16 -04001#include "ANGLETest.h"
2
3class FramebufferFormatsTest : public ANGLETest
4{
5protected:
6 FramebufferFormatsTest()
7 {
8 setWindowWidth(128);
9 setWindowHeight(128);
10 setConfigRedBits(8);
11 setConfigGreenBits(8);
12 setConfigBlueBits(8);
13 setConfigAlphaBits(8);
14 }
15
16 void checkBitCount(GLuint fbo, GLenum channel, GLint minBits)
17 {
18 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
19
20 GLint bits = 0;
21 glGetIntegerv(channel, &bits);
22
23 if (minBits == 0)
24 {
25 EXPECT_EQ(minBits, bits);
26 }
27 else
28 {
29 EXPECT_GE(bits, minBits);
30 }
31 }
32
33 void testBitCounts(GLuint fbo, GLint minRedBits, GLint minGreenBits, GLint minBlueBits,
34 GLint minAlphaBits, GLint minDepthBits, GLint minStencilBits)
35 {
36 checkBitCount(fbo, GL_RED_BITS, minRedBits);
37 checkBitCount(fbo, GL_GREEN_BITS, minGreenBits);
38 checkBitCount(fbo, GL_BLUE_BITS, minBlueBits);
39 checkBitCount(fbo, GL_ALPHA_BITS, minAlphaBits);
40 checkBitCount(fbo, GL_DEPTH_BITS, minDepthBits);
41 checkBitCount(fbo, GL_STENCIL_BITS, minStencilBits);
42 }
43
44 void testTextureFormat(GLenum internalFormat, GLint minRedBits, GLint minGreenBits, GLint minBlueBits,
45 GLint minAlphaBits)
46 {
47 GLuint tex = 0;
48 glGenTextures(1, &tex);
49 glBindTexture(GL_TEXTURE_2D, tex);
50 glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
51
52 GLuint fbo = 0;
53 glGenFramebuffers(1, &fbo);
54 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
55 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
56
57 testBitCounts(fbo, minRedBits, minGreenBits, minBlueBits, minAlphaBits, 0, 0);
58
59 glDeleteTextures(1, &tex);
60 glDeleteFramebuffers(1, &fbo);
61 }
62
63 virtual void SetUp()
64 {
65 ANGLETest::SetUp();
66 }
67
68 virtual void TearDown()
69 {
70 ANGLETest::TearDown();
71 }
72};
73
Jamie Madillb759a742014-07-17 10:40:49 -040074TEST_F(FramebufferFormatsTest, RGBA4)
Geoff Langb6a673a2014-06-05 14:19:16 -040075{
76 testTextureFormat(GL_RGBA4, 4, 4, 4, 4);
77}
78
Jamie Madillb759a742014-07-17 10:40:49 -040079TEST_F(FramebufferFormatsTest, RGB565)
Geoff Langb6a673a2014-06-05 14:19:16 -040080{
81 testTextureFormat(GL_RGB565, 5, 6, 5, 0);
82}
83
Jamie Madillb759a742014-07-17 10:40:49 -040084TEST_F(FramebufferFormatsTest, RGB8)
Geoff Langb6a673a2014-06-05 14:19:16 -040085{
86 testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0);
87}
88
Jamie Madillb759a742014-07-17 10:40:49 -040089TEST_F(FramebufferFormatsTest, BGRA8)
Geoff Langb6a673a2014-06-05 14:19:16 -040090{
91 testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8);
92}
93
Jamie Madillb759a742014-07-17 10:40:49 -040094TEST_F(FramebufferFormatsTest, RGBA8)
Geoff Langb6a673a2014-06-05 14:19:16 -040095{
96 testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8);
97}
98