blob: 17badb4145c58da3cf35fb13ab37c7fbeba568e5 [file] [log] [blame]
Corentin Wallezd3970de2015-05-14 11:07:48 -04001//
2// Copyright (c) 2012 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//
Jamie Madill508a5b72015-12-08 11:26:14 -05006// ANGLETest:
7// Implementation of common ANGLE testing fixture.
8//
Corentin Wallezd3970de2015-05-14 11:07:48 -04009
10#ifndef ANGLE_TESTS_ANGLE_TEST_H_
11#define ANGLE_TESTS_ANGLE_TEST_H_
12
13#include <gtest/gtest.h>
14#include <algorithm>
Jamie Madill52b09c22016-04-11 14:12:31 -040015#include <array>
Corentin Wallezd3970de2015-05-14 11:07:48 -040016
17#include "angle_gl.h"
18#include "angle_test_configs.h"
19#include "common/angleutils.h"
20#include "shader_utils.h"
Jamie Madill1fbc59f2016-02-24 15:25:51 -050021#include "Vector.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -040022
Corentin Wallez322653b2015-06-17 18:33:56 +020023#define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
Jamie Madill0dfa8072016-01-22 15:27:21 -050024#define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040025
Corentin Wallez322653b2015-06-17 18:33:56 +020026#define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
Jamie Madill0dfa8072016-01-22 15:27:21 -050027#define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040028
29#define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
30#define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
31
Nico Weber0c93b8a2015-12-09 15:31:40 -050032// EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u.
Nico Weber08bf81d2015-12-09 16:23:32 -050033#define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a))
34#define ASSERT_EGL_FALSE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_FALSE), (a))
Nico Weber0c93b8a2015-12-09 15:31:40 -050035#define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a))
36#define EXPECT_EGL_FALSE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), (a))
37
Corentin Wallezd3970de2015-05-14 11:07:48 -040038#define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
39#define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
40
Corentin Wallez322653b2015-06-17 18:33:56 +020041#define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
42#define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
43
Jamie Madill0dfa8072016-01-22 15:27:21 -050044namespace angle
45{
46struct GLColor
47{
48 GLColor();
49 GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
Jamie Madille2509a32016-02-01 14:09:05 -050050 GLColor(GLuint colorValue);
Jamie Madill0dfa8072016-01-22 15:27:21 -050051
Jamie Madill1fbc59f2016-02-24 15:25:51 -050052 Vector4 toNormalizedVector() const;
53
Jamie Madill0dfa8072016-01-22 15:27:21 -050054 GLubyte R, G, B, A;
55};
56
57// Useful to cast any type to GLubyte.
58template <typename TR, typename TG, typename TB, typename TA>
59GLColor MakeGLColor(TR r, TG g, TB b, TA a)
60{
61 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
62 static_cast<GLubyte>(a));
Corentin Wallezd3970de2015-05-14 11:07:48 -040063}
64
Jamie Madill0dfa8072016-01-22 15:27:21 -050065bool operator==(const GLColor &a, const GLColor &b);
66std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
67GLColor ReadColor(GLint x, GLint y);
68
Olli Etuahob97a3e72016-04-13 14:31:52 +030069template <typename T>
70void FillWithRGBA(size_t pixelCount, T red, T green, T blue, T alpha, T *outArray)
71{
72 for (size_t i = 0u; i < pixelCount; ++i)
73 {
74 outArray[i * 4u] = red;
75 outArray[i * 4u + 1u] = green;
76 outArray[i * 4u + 2u] = blue;
77 outArray[i * 4u + 3u] = alpha;
78 }
79}
80
Jamie Madill0dfa8072016-01-22 15:27:21 -050081} // namespace angle
82
83#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
84 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
85
Olli Etuaho6ee394a2016-02-18 13:30:09 +020086#define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
87
Jamie Madille2509a32016-02-01 14:09:05 -050088#define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
89
Jamie Madill0dfa8072016-01-22 15:27:21 -050090// TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
Corentin Wallezd3970de2015-05-14 11:07:48 -040091#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
92{ \
93 GLubyte pixel[4]; \
94 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
95 EXPECT_GL_NO_ERROR(); \
96 EXPECT_NEAR((r), pixel[0], abs_error); \
97 EXPECT_NEAR((g), pixel[1], abs_error); \
98 EXPECT_NEAR((b), pixel[2], abs_error); \
99 EXPECT_NEAR((a), pixel[3], abs_error); \
100}
101
102class EGLWindow;
103class OSWindow;
104
105class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
106{
107 protected:
108 ANGLETest();
109 ~ANGLETest();
110
111 public:
112 static bool InitTestWindow();
113 static bool DestroyTestWindow();
Corentin Wallezd3970de2015-05-14 11:07:48 -0400114 static void SetWindowVisible(bool isVisible);
Cooper Partind7561452015-09-10 10:23:29 -0700115 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400116
117 protected:
118 virtual void SetUp();
119 virtual void TearDown();
120
121 virtual void swapBuffers();
122
Jamie Madill52b09c22016-04-11 14:12:31 -0400123 void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
124
125 void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
126 void drawQuad(GLuint program,
127 const std::string &positionAttribName,
128 GLfloat positionAttribZ,
129 GLfloat positionAttribXYScale);
130 void drawQuad(GLuint program,
131 const std::string &positionAttribName,
132 GLfloat positionAttribZ,
133 GLfloat positionAttribXYScale,
134 bool useVertexBuffer);
135 static std::array<Vector3, 6> GetQuadVertices();
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400136 void drawIndexedQuad(GLuint program,
137 const std::string &positionAttribName,
138 GLfloat positionAttribZ);
139 void drawIndexedQuad(GLuint program,
140 const std::string &positionAttribName,
141 GLfloat positionAttribZ,
142 GLfloat positionAttribXYScale);
143
Corentin Wallezd3970de2015-05-14 11:07:48 -0400144 static GLuint compileShader(GLenum type, const std::string &source);
145 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -0400146 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400147
148 void setWindowWidth(int width);
149 void setWindowHeight(int height);
150 void setConfigRedBits(int bits);
151 void setConfigGreenBits(int bits);
152 void setConfigBlueBits(int bits);
153 void setConfigAlphaBits(int bits);
154 void setConfigDepthBits(int bits);
155 void setConfigStencilBits(int bits);
156 void setMultisampleEnabled(bool enabled);
Geoff Lang70d0f492015-12-10 17:45:46 -0500157 void setDebugEnabled(bool enabled);
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500158 void setNoErrorEnabled(bool enabled);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400159
160 int getClientVersion() const;
161
162 EGLWindow *getEGLWindow() const;
163 int getWindowWidth() const;
164 int getWindowHeight() const;
165 bool isMultisampleEnabled() const;
166
Jamie Madill518b9fa2016-03-02 11:26:02 -0500167 bool isOpenGL() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400168 EGLint getPlatformRenderer() const;
169
Austin Kinrossd544cc92016-01-11 15:26:42 -0800170 void ignoreD3D11SDKLayersWarnings();
171
Corentin Wallezd3970de2015-05-14 11:07:48 -0400172 private:
173 bool createEGLContext();
174 bool destroyEGLContext();
175
Austin Kinrossd544cc92016-01-11 15:26:42 -0800176 void checkD3D11SDKLayersMessages();
177
Corentin Wallezd3970de2015-05-14 11:07:48 -0400178 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400179 int mWidth;
180 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400181
Austin Kinrossd544cc92016-01-11 15:26:42 -0800182 bool mIgnoreD3D11SDKLayersWarnings;
183
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400184 // Used for indexed quad rendering
185 GLuint mQuadVertexBuffer;
186
Corentin Wallezd3970de2015-05-14 11:07:48 -0400187 static OSWindow *mOSWindow;
188};
189
190class ANGLETestEnvironment : public testing::Environment
191{
192 public:
193 virtual void SetUp();
194 virtual void TearDown();
195};
196
Jamie Madill518b9fa2016-03-02 11:26:02 -0500197bool IsIntel();
198bool IsAMD();
199bool IsNVIDIA();
200// Note: FL9_3 is explicitly *not* considered D3D11.
201bool IsD3D11();
202bool IsD3D11_FL93();
203// Is a D3D9-class renderer.
204bool IsD3D9();
205// Is D3D9 or SM9_3 renderer.
206bool IsD3DSM3();
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400207bool IsLinux();
Jamie Madill518b9fa2016-03-02 11:26:02 -0500208bool IsOSX();
209
Corentin Wallezd3970de2015-05-14 11:07:48 -0400210#endif // ANGLE_TESTS_ANGLE_TEST_H_