blob: 68a91da15893776bca79c583925881c09ffb5555 [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
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
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.
Jamie Madillfa05f602015-05-07 13:47:11 -040078TEST_P(CubeMapTextureTest, RenderToFacesConsecutively)
Geoff Lang58795982015-01-07 14:25:10 -050079{
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);
Geoff Langc4e93662017-05-01 10:45:59 -040093 for (GLenum face = 0; face < 6; face++)
94 {
95 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
96 GL_UNSIGNED_BYTE, nullptr);
97 }
Geoff Lang58795982015-01-07 14:25:10 -050098 EXPECT_GL_NO_ERROR();
99
100 GLuint fbo = 0;
101 glGenFramebuffers(1, &fbo);
102 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
103 EXPECT_GL_NO_ERROR();
104
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700105 for (GLenum face = 0; face < 6; face++)
Geoff Lang58795982015-01-07 14:25:10 -0500106 {
107 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, tex, 0);
108 EXPECT_GL_NO_ERROR();
109
110 glUseProgram(mProgram);
111
112 const GLfloat *faceColor = faceColors + (face * 4);
113 glUniform4f(mColorLocation, faceColor[0], faceColor[1], faceColor[2], faceColor[3]);
114
115 drawQuad(mProgram, "position", 0.5f);
116 EXPECT_GL_NO_ERROR();
117 }
118
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700119 for (GLenum face = 0; face < 6; face++)
Geoff Lang58795982015-01-07 14:25:10 -0500120 {
121 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, tex, 0);
122 EXPECT_GL_NO_ERROR();
123
124 const GLfloat *faceColor = faceColors + (face * 4);
125 EXPECT_PIXEL_EQ(0, 0, faceColor[0] * 255, faceColor[1] * 255, faceColor[2] * 255, faceColor[3] * 255);
126 EXPECT_GL_NO_ERROR();
127 }
128
129 glDeleteFramebuffers(1, &fbo);
130 glDeleteTextures(1, &tex);
131
132 EXPECT_GL_NO_ERROR();
133}
Jamie Madillfa05f602015-05-07 13:47:11 -0400134
135// 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 -0500136ANGLE_INSTANTIATE_TEST(CubeMapTextureTest,
137 ES2_D3D11(),
138 ES2_D3D11_FL9_3(),
139 ES2_OPENGL(),
140 ES3_OPENGL(),
141 ES2_OPENGLES(),
142 ES3_OPENGLES());