blob: f6ceae0f6b2a067f3144bd03151edad6895a9651 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
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
Corentin Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Geoff Lang58795982015-01-07 14:25:10 -05008
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
Geoff Lang58795982015-01-07 14:25:10 -050010
Geoff Lang58795982015-01-07 14:25:10 -050011class CubeMapTextureTest : public ANGLETest
12{
Jamie Madillfa05f602015-05-07 13:47:11 -040013 protected:
14 CubeMapTextureTest()
Geoff Lang58795982015-01-07 14:25:10 -050015 {
16 setWindowWidth(256);
17 setWindowHeight(256);
18 setConfigRedBits(8);
19 setConfigGreenBits(8);
20 setConfigBlueBits(8);
21 setConfigAlphaBits(8);
22 }
23
24 virtual void SetUp()
25 {
26 ANGLETest::SetUp();
27
Olli Etuahoa20af6d2017-09-18 13:32:29 +030028 const std::string vsSource =
29 R"(attribute highp vec4 position;
Geoff Lang58795982015-01-07 14:25:10 -050030 void main(void)
31 {
32 gl_Position = position;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030033 })";
Geoff Lang58795982015-01-07 14:25:10 -050034
Olli Etuahoa20af6d2017-09-18 13:32:29 +030035 const std::string fsSource =
36 R"(uniform highp vec4 color;
Geoff Lang58795982015-01-07 14:25:10 -050037 void main(void)
38 {
39 gl_FragColor = color;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030040 })";
Geoff Lang58795982015-01-07 14:25:10 -050041
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.
Jamie Madillfa05f602015-05-07 13:47:11 -040074TEST_P(CubeMapTextureTest, RenderToFacesConsecutively)
Geoff Lang58795982015-01-07 14:25:10 -050075{
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);
Geoff Langc4e93662017-05-01 10:45:59 -040089 for (GLenum face = 0; face < 6; face++)
90 {
91 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
92 GL_UNSIGNED_BYTE, nullptr);
93 }
Geoff Lang58795982015-01-07 14:25:10 -050094 EXPECT_GL_NO_ERROR();
95
96 GLuint fbo = 0;
97 glGenFramebuffers(1, &fbo);
98 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
99 EXPECT_GL_NO_ERROR();
100
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700101 for (GLenum face = 0; face < 6; face++)
Geoff Lang58795982015-01-07 14:25:10 -0500102 {
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
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700115 for (GLenum face = 0; face < 6; face++)
Geoff Lang58795982015-01-07 14:25:10 -0500116 {
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}
Jamie Madillfa05f602015-05-07 13:47:11 -0400130
131// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500132ANGLE_INSTANTIATE_TEST(CubeMapTextureTest,
133 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -0400134 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -0500135 ES2_D3D11_FL9_3(),
136 ES2_OPENGL(),
137 ES3_OPENGL(),
138 ES2_OPENGLES(),
139 ES3_OPENGLES());