Upstream version 10.38.220.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / tests / angle_tests / DepthStencilFormatsTest.cpp
1 #include "ANGLETest.h"
2
3 class DepthStencilFormatsTest : public ANGLETest
4 {
5 protected:
6     DepthStencilFormatsTest()
7     {
8         setWindowWidth(128);
9         setWindowHeight(128);
10         setConfigRedBits(8);
11         setConfigGreenBits(8);
12         setConfigBlueBits(8);
13         setConfigAlphaBits(8);
14         setClientVersion(2);
15     }
16
17     bool checkTexImageFormatSupport(GLenum format, GLenum type)
18     {
19         EXPECT_GL_NO_ERROR();
20
21         GLuint tex = 0;
22         glGenTextures(1, &tex);
23         glBindTexture(GL_TEXTURE_2D, tex);
24         glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, type, NULL);
25         glDeleteTextures(1, &tex);
26
27         return (glGetError() == GL_NO_ERROR);
28     }
29
30     bool checkTexStorageFormatSupport(GLenum internalFormat)
31     {
32         EXPECT_GL_NO_ERROR();
33
34         GLuint tex = 0;
35         glGenTextures(1, &tex);
36         glBindTexture(GL_TEXTURE_2D, tex);
37         glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
38         glDeleteTextures(1, &tex);
39
40         return (glGetError() == GL_NO_ERROR);
41     }
42
43     bool checkRenderbufferFormatSupport(GLenum internalFormat)
44     {
45         EXPECT_GL_NO_ERROR();
46
47         GLuint rb = 0;
48         glGenRenderbuffers(1, &rb);
49         glBindRenderbuffer(GL_RENDERBUFFER, rb);
50         glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, 1, 1);
51         glDeleteRenderbuffers(1, &rb);
52
53         return (glGetError() == GL_NO_ERROR);
54     }
55
56     virtual void SetUp()
57     {
58         ANGLETest::SetUp();
59     }
60
61     virtual void TearDown()
62     {
63         ANGLETest::TearDown();
64     }
65 };
66
67 TEST_F(DepthStencilFormatsTest, DepthTexture)
68 {
69     bool shouldHaveTextureSupport = extensionEnabled("GL_ANGLE_depth_texture");
70     EXPECT_EQ(shouldHaveTextureSupport, checkTexImageFormatSupport(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT));
71     EXPECT_EQ(shouldHaveTextureSupport, checkTexImageFormatSupport(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT));
72
73     if (extensionEnabled("GL_EXT_texture_storage"))
74     {
75         EXPECT_EQ(shouldHaveTextureSupport, checkTexStorageFormatSupport(GL_DEPTH_COMPONENT16));
76         EXPECT_EQ(shouldHaveTextureSupport, checkTexStorageFormatSupport(GL_DEPTH_COMPONENT32_OES));
77     }
78 }
79
80 TEST_F(DepthStencilFormatsTest, PackedDepthStencil)
81 {
82     // Expected to fail in D3D9 if GL_OES_packed_depth_stencil is not present.
83     // Expected to fail in D3D11 if GL_OES_packed_depth_stencil or GL_ANGLE_depth_texture is not present.
84
85     bool shouldHaveRenderbufferSupport = extensionEnabled("GL_OES_packed_depth_stencil");
86     EXPECT_EQ(shouldHaveRenderbufferSupport, checkRenderbufferFormatSupport(GL_DEPTH24_STENCIL8_OES));
87
88     bool shouldHaveTextureSupport = extensionEnabled("GL_OES_packed_depth_stencil") &&
89                                     extensionEnabled("GL_ANGLE_depth_texture");
90     EXPECT_EQ(shouldHaveTextureSupport, checkTexImageFormatSupport(GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES));
91
92     if (extensionEnabled("GL_EXT_texture_storage"))
93     {
94         EXPECT_EQ(shouldHaveTextureSupport, checkTexStorageFormatSupport(GL_DEPTH24_STENCIL8_OES));
95     }
96 }