blob: 9d850a6d3c008fdf3cf499ac256bdd88f3abef20 [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;
Olli Etuahoa314b612016-03-10 16:43:00 +020055
56 static const GLColor red;
57 static const GLColor green;
58 static const GLColor blue;
59 static const GLColor cyan;
60 static const GLColor black;
Olli Etuaho190028d2016-05-13 12:11:29 +030061 static const GLColor white;
Jamie Madill0dfa8072016-01-22 15:27:21 -050062};
63
64// Useful to cast any type to GLubyte.
65template <typename TR, typename TG, typename TB, typename TA>
66GLColor MakeGLColor(TR r, TG g, TB b, TA a)
67{
68 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
69 static_cast<GLubyte>(a));
Corentin Wallezd3970de2015-05-14 11:07:48 -040070}
71
Jamie Madill0dfa8072016-01-22 15:27:21 -050072bool operator==(const GLColor &a, const GLColor &b);
73std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
74GLColor ReadColor(GLint x, GLint y);
75
76} // namespace angle
77
78#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
79 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
80
Olli Etuaho6ee394a2016-02-18 13:30:09 +020081#define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
82
Jamie Madille2509a32016-02-01 14:09:05 -050083#define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
84
Jamie Madill0dfa8072016-01-22 15:27:21 -050085// TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
Corentin Wallezd3970de2015-05-14 11:07:48 -040086#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
87{ \
88 GLubyte pixel[4]; \
89 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
90 EXPECT_GL_NO_ERROR(); \
91 EXPECT_NEAR((r), pixel[0], abs_error); \
92 EXPECT_NEAR((g), pixel[1], abs_error); \
93 EXPECT_NEAR((b), pixel[2], abs_error); \
94 EXPECT_NEAR((a), pixel[3], abs_error); \
95}
96
97class EGLWindow;
98class OSWindow;
99
100class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
101{
102 protected:
103 ANGLETest();
104 ~ANGLETest();
105
106 public:
107 static bool InitTestWindow();
108 static bool DestroyTestWindow();
Corentin Wallezd3970de2015-05-14 11:07:48 -0400109 static void SetWindowVisible(bool isVisible);
Cooper Partind7561452015-09-10 10:23:29 -0700110 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400111
112 protected:
113 virtual void SetUp();
114 virtual void TearDown();
115
116 virtual void swapBuffers();
117
Jamie Madill52b09c22016-04-11 14:12:31 -0400118 void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
119
120 void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
121 void drawQuad(GLuint program,
122 const std::string &positionAttribName,
123 GLfloat positionAttribZ,
124 GLfloat positionAttribXYScale);
125 void drawQuad(GLuint program,
126 const std::string &positionAttribName,
127 GLfloat positionAttribZ,
128 GLfloat positionAttribXYScale,
129 bool useVertexBuffer);
130 static std::array<Vector3, 6> GetQuadVertices();
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400131 void drawIndexedQuad(GLuint program,
132 const std::string &positionAttribName,
133 GLfloat positionAttribZ);
134 void drawIndexedQuad(GLuint program,
135 const std::string &positionAttribName,
136 GLfloat positionAttribZ,
137 GLfloat positionAttribXYScale);
138
Corentin Wallezd3970de2015-05-14 11:07:48 -0400139 static GLuint compileShader(GLenum type, const std::string &source);
140 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -0400141 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400142
143 void setWindowWidth(int width);
144 void setWindowHeight(int height);
145 void setConfigRedBits(int bits);
146 void setConfigGreenBits(int bits);
147 void setConfigBlueBits(int bits);
148 void setConfigAlphaBits(int bits);
149 void setConfigDepthBits(int bits);
150 void setConfigStencilBits(int bits);
151 void setMultisampleEnabled(bool enabled);
Geoff Lang70d0f492015-12-10 17:45:46 -0500152 void setDebugEnabled(bool enabled);
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500153 void setNoErrorEnabled(bool enabled);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400154
155 int getClientVersion() const;
156
157 EGLWindow *getEGLWindow() const;
158 int getWindowWidth() const;
159 int getWindowHeight() const;
160 bool isMultisampleEnabled() const;
161
Jamie Madill518b9fa2016-03-02 11:26:02 -0500162 bool isOpenGL() const;
Olli Etuaho87fc71c2016-05-11 14:25:21 +0300163 bool isGLES() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400164 EGLint getPlatformRenderer() const;
165
Austin Kinrossd544cc92016-01-11 15:26:42 -0800166 void ignoreD3D11SDKLayersWarnings();
167
Corentin Wallezd3970de2015-05-14 11:07:48 -0400168 private:
169 bool createEGLContext();
170 bool destroyEGLContext();
171
Austin Kinrossd544cc92016-01-11 15:26:42 -0800172 void checkD3D11SDKLayersMessages();
173
Corentin Wallezd3970de2015-05-14 11:07:48 -0400174 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400175 int mWidth;
176 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400177
Austin Kinrossd544cc92016-01-11 15:26:42 -0800178 bool mIgnoreD3D11SDKLayersWarnings;
179
Jamie Madillbc4c4bc2016-03-23 21:04:43 -0400180 // Used for indexed quad rendering
181 GLuint mQuadVertexBuffer;
182
Corentin Wallezd3970de2015-05-14 11:07:48 -0400183 static OSWindow *mOSWindow;
184};
185
186class ANGLETestEnvironment : public testing::Environment
187{
188 public:
189 virtual void SetUp();
190 virtual void TearDown();
191};
192
Jamie Madill518b9fa2016-03-02 11:26:02 -0500193bool IsIntel();
194bool IsAMD();
195bool IsNVIDIA();
196// Note: FL9_3 is explicitly *not* considered D3D11.
197bool IsD3D11();
198bool IsD3D11_FL93();
199// Is a D3D9-class renderer.
200bool IsD3D9();
201// Is D3D9 or SM9_3 renderer.
202bool IsD3DSM3();
Corentin Wallez9e3c6152016-03-29 21:58:33 -0400203bool IsLinux();
Jamie Madill518b9fa2016-03-02 11:26:02 -0500204bool IsOSX();
205
Corentin Wallezd3970de2015-05-14 11:07:48 -0400206#endif // ANGLE_TESTS_ANGLE_TEST_H_