blob: 514fbc68ed4319d1e13a3be71a737b0c6dccad1d [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 Etuaho5804dc82018-04-13 14:11:46 +030028 mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
Geoff Lang58795982015-01-07 14:25:10 -050029 if (mProgram == 0)
30 {
31 FAIL() << "shader compilation failed.";
32 }
33
Olli Etuaho5804dc82018-04-13 14:11:46 +030034 mColorLocation = glGetUniformLocation(mProgram, essl1_shaders::ColorUniform());
Geoff Lang58795982015-01-07 14:25:10 -050035
36 glUseProgram(mProgram);
37
38 glClearColor(0, 0, 0, 0);
39 glClearDepthf(0.0);
40 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
41
42 glEnable(GL_BLEND);
43 glDisable(GL_DEPTH_TEST);
44
45 ASSERT_GL_NO_ERROR();
46 }
47
48 virtual void TearDown()
49 {
50 glDeleteProgram(mProgram);
51
52 ANGLETest::TearDown();
53 }
54
55 GLuint mProgram;
56 GLint mColorLocation;
57};
58
59// Verify that rendering to the faces of a cube map consecutively will correctly render to each face.
Jamie Madillfa05f602015-05-07 13:47:11 -040060TEST_P(CubeMapTextureTest, RenderToFacesConsecutively)
Geoff Lang58795982015-01-07 14:25:10 -050061{
62 const GLfloat faceColors[] =
63 {
64 1.0f, 0.0f, 0.0f, 1.0f,
65 0.0f, 1.0f, 0.0f, 1.0f,
66 0.0f, 0.0f, 1.0f, 1.0f,
67 1.0f, 1.0f, 0.0f, 1.0f,
68 1.0f, 0.0f, 1.0f, 1.0f,
69 0.0f, 1.0f, 1.0f, 1.0f,
70 };
71
72 GLuint tex = 0;
73 glGenTextures(1, &tex);
74 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
Geoff Langc4e93662017-05-01 10:45:59 -040075 for (GLenum face = 0; face < 6; face++)
76 {
77 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
78 GL_UNSIGNED_BYTE, nullptr);
79 }
Geoff Lang58795982015-01-07 14:25:10 -050080 EXPECT_GL_NO_ERROR();
81
82 GLuint fbo = 0;
83 glGenFramebuffers(1, &fbo);
84 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
85 EXPECT_GL_NO_ERROR();
86
Cooper Partin4d61f7e2015-08-12 10:56:50 -070087 for (GLenum face = 0; face < 6; face++)
Geoff Lang58795982015-01-07 14:25:10 -050088 {
89 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, tex, 0);
90 EXPECT_GL_NO_ERROR();
91
92 glUseProgram(mProgram);
93
94 const GLfloat *faceColor = faceColors + (face * 4);
95 glUniform4f(mColorLocation, faceColor[0], faceColor[1], faceColor[2], faceColor[3]);
96
Olli Etuaho5804dc82018-04-13 14:11:46 +030097 drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lang58795982015-01-07 14:25:10 -050098 EXPECT_GL_NO_ERROR();
99 }
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 const GLfloat *faceColor = faceColors + (face * 4);
107 EXPECT_PIXEL_EQ(0, 0, faceColor[0] * 255, faceColor[1] * 255, faceColor[2] * 255, faceColor[3] * 255);
108 EXPECT_GL_NO_ERROR();
109 }
110
111 glDeleteFramebuffers(1, &fbo);
112 glDeleteTextures(1, &tex);
113
114 EXPECT_GL_NO_ERROR();
115}
Jamie Madillfa05f602015-05-07 13:47:11 -0400116
117// 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 -0500118ANGLE_INSTANTIATE_TEST(CubeMapTextureTest,
119 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -0400120 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -0500121 ES2_D3D11_FL9_3(),
122 ES2_OPENGL(),
123 ES3_OPENGL(),
124 ES2_OPENGLES(),
125 ES3_OPENGLES());