blob: 53eaabab55da6b6b68586d8a5adfe470d05ec5c4 [file] [log] [blame]
Geoff Langb6a673a2014-06-05 14:19:16 -04001#include "ANGLETest.h"
2
Austin Kinross18b931d2014-09-29 12:58:31 -07003// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lang0d3683c2014-10-23 11:08:16 -04004ANGLE_TYPED_TEST_CASE(FramebufferFormatsTest, ES2_D3D9, ES2_D3D11);
Austin Kinross18b931d2014-09-29 12:58:31 -07005
6template<typename T>
Geoff Langb6a673a2014-06-05 14:19:16 -04007class FramebufferFormatsTest : public ANGLETest
8{
9protected:
Geoff Lang0d3683c2014-10-23 11:08:16 -040010 FramebufferFormatsTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform())
Geoff Langb6a673a2014-06-05 14:19:16 -040011 {
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 Kinross18b931d2014-09-29 12:58:31 -070078TYPED_TEST(FramebufferFormatsTest, RGBA4)
Geoff Langb6a673a2014-06-05 14:19:16 -040079{
80 testTextureFormat(GL_RGBA4, 4, 4, 4, 4);
81}
82
Austin Kinross18b931d2014-09-29 12:58:31 -070083TYPED_TEST(FramebufferFormatsTest, RGB565)
Geoff Langb6a673a2014-06-05 14:19:16 -040084{
85 testTextureFormat(GL_RGB565, 5, 6, 5, 0);
86}
87
Austin Kinross18b931d2014-09-29 12:58:31 -070088TYPED_TEST(FramebufferFormatsTest, RGB8)
Geoff Langb6a673a2014-06-05 14:19:16 -040089{
90 testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0);
91}
92
Austin Kinross18b931d2014-09-29 12:58:31 -070093TYPED_TEST(FramebufferFormatsTest, BGRA8)
Geoff Langb6a673a2014-06-05 14:19:16 -040094{
95 testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8);
96}
97
Austin Kinross18b931d2014-09-29 12:58:31 -070098TYPED_TEST(FramebufferFormatsTest, RGBA8)
Geoff Langb6a673a2014-06-05 14:19:16 -040099{
100 testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8);
101}
102