blob: d1db7e7a79246f2046f7f436c548a043057feada [file] [log] [blame]
Geoff Lang58795982015-01-07 14:25:10 -05001#include "ANGLETest.h"
2
3// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4ANGLE_TYPED_TEST_CASE(CubeMapTextureTest, ES2_D3D11);
5
6template<typename T>
7class CubeMapTextureTest : public ANGLETest
8{
9protected:
10 CubeMapTextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform())
11 {
12 setWindowWidth(256);
13 setWindowHeight(256);
14 setConfigRedBits(8);
15 setConfigGreenBits(8);
16 setConfigBlueBits(8);
17 setConfigAlphaBits(8);
18 }
19
20 virtual void SetUp()
21 {
22 ANGLETest::SetUp();
23
24 const std::string vsSource = SHADER_SOURCE
25 (
26 attribute highp vec4 position;
27 void main(void)
28 {
29 gl_Position = position;
30 }
31 );
32
33 const std::string fsSource = SHADER_SOURCE
34 (
35 uniform highp vec4 color;
36 void main(void)
37 {
38 gl_FragColor = color;
39 }
40 );
41
42 mProgram = CompileProgram(vsSource, fsSource);
43 if (mProgram == 0)
44 {
45 FAIL() << "shader compilation failed.";
46 }
47
48 mColorLocation = glGetUniformLocation(mProgram, "color");
49
50 glUseProgram(mProgram);
51
52 glClearColor(0, 0, 0, 0);
53 glClearDepthf(0.0);
54 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
55
56 glEnable(GL_BLEND);
57 glDisable(GL_DEPTH_TEST);
58
59 ASSERT_GL_NO_ERROR();
60 }
61
62 virtual void TearDown()
63 {
64 glDeleteProgram(mProgram);
65
66 ANGLETest::TearDown();
67 }
68
69 GLuint mProgram;
70 GLint mColorLocation;
71};
72
73// Verify that rendering to the faces of a cube map consecutively will correctly render to each face.
74TYPED_TEST(CubeMapTextureTest, RenderToFacesConsecutively)
75{
76 const GLfloat faceColors[] =
77 {
78 1.0f, 0.0f, 0.0f, 1.0f,
79 0.0f, 1.0f, 0.0f, 1.0f,
80 0.0f, 0.0f, 1.0f, 1.0f,
81 1.0f, 1.0f, 0.0f, 1.0f,
82 1.0f, 0.0f, 1.0f, 1.0f,
83 0.0f, 1.0f, 1.0f, 1.0f,
84 };
85
86 GLuint tex = 0;
87 glGenTextures(1, &tex);
88 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
89 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8_OES, 1, 1);
90 EXPECT_GL_NO_ERROR();
91
92 GLuint fbo = 0;
93 glGenFramebuffers(1, &fbo);
94 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
95 EXPECT_GL_NO_ERROR();
96
97 for (size_t face = 0; face < 6; face++)
98 {
99 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, tex, 0);
100 EXPECT_GL_NO_ERROR();
101
102 glUseProgram(mProgram);
103
104 const GLfloat *faceColor = faceColors + (face * 4);
105 glUniform4f(mColorLocation, faceColor[0], faceColor[1], faceColor[2], faceColor[3]);
106
107 drawQuad(mProgram, "position", 0.5f);
108 EXPECT_GL_NO_ERROR();
109 }
110
111 for (size_t face = 0; face < 6; face++)
112 {
113 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, tex, 0);
114 EXPECT_GL_NO_ERROR();
115
116 const GLfloat *faceColor = faceColors + (face * 4);
117 EXPECT_PIXEL_EQ(0, 0, faceColor[0] * 255, faceColor[1] * 255, faceColor[2] * 255, faceColor[3] * 255);
118 EXPECT_GL_NO_ERROR();
119 }
120
121 glDeleteFramebuffers(1, &fbo);
122 glDeleteTextures(1, &tex);
123
124 EXPECT_GL_NO_ERROR();
125}