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