Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 1 | // |
| 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 Madill | 508a5b7 | 2015-12-08 11:26:14 -0500 | [diff] [blame] | 6 | // ANGLETest: |
| 7 | // Implementation of common ANGLE testing fixture. |
| 8 | // |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 9 | |
| 10 | #ifndef ANGLE_TESTS_ANGLE_TEST_H_ |
| 11 | #define ANGLE_TESTS_ANGLE_TEST_H_ |
| 12 | |
| 13 | #include <gtest/gtest.h> |
| 14 | #include <algorithm> |
Jamie Madill | 52b09c2 | 2016-04-11 14:12:31 -0400 | [diff] [blame] | 15 | #include <array> |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 16 | |
| 17 | #include "angle_gl.h" |
| 18 | #include "angle_test_configs.h" |
| 19 | #include "common/angleutils.h" |
| 20 | #include "shader_utils.h" |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 21 | #include "Vector.h" |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 22 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 23 | #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError()) |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 24 | #define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()) |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 25 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 26 | #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError()) |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 27 | #define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()) |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 28 | |
| 29 | #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError()) |
| 30 | #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS) |
| 31 | |
Nico Weber | 0c93b8a | 2015-12-09 15:31:40 -0500 | [diff] [blame] | 32 | // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u. |
Nico Weber | 08bf81d | 2015-12-09 16:23:32 -0500 | [diff] [blame] | 33 | #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 Weber | 0c93b8a | 2015-12-09 15:31:40 -0500 | [diff] [blame] | 35 | #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 Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 38 | #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError()) |
| 39 | #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS) |
| 40 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 41 | #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 Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 44 | namespace angle |
| 45 | { |
| 46 | struct GLColor |
| 47 | { |
| 48 | GLColor(); |
| 49 | GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a); |
Jamie Madill | e2509a3 | 2016-02-01 14:09:05 -0500 | [diff] [blame] | 50 | GLColor(GLuint colorValue); |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 51 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 52 | Vector4 toNormalizedVector() const; |
| 53 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 54 | GLubyte R, G, B, A; |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 55 | |
| 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; |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | // Useful to cast any type to GLubyte. |
| 64 | template <typename TR, typename TG, typename TB, typename TA> |
| 65 | GLColor MakeGLColor(TR r, TG g, TB b, TA a) |
| 66 | { |
| 67 | return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b), |
| 68 | static_cast<GLubyte>(a)); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 71 | bool operator==(const GLColor &a, const GLColor &b); |
| 72 | std::ostream &operator<<(std::ostream &ostream, const GLColor &color); |
| 73 | GLColor ReadColor(GLint x, GLint y); |
| 74 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 75 | template <typename T> |
| 76 | void FillWithRGBA(size_t pixelCount, T red, T green, T blue, T alpha, T *outArray) |
| 77 | { |
| 78 | for (size_t i = 0u; i < pixelCount; ++i) |
| 79 | { |
| 80 | outArray[i * 4u] = red; |
| 81 | outArray[i * 4u + 1u] = green; |
| 82 | outArray[i * 4u + 2u] = blue; |
| 83 | outArray[i * 4u + 3u] = alpha; |
| 84 | } |
| 85 | } |
| 86 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 87 | } // namespace angle |
| 88 | |
| 89 | #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \ |
| 90 | EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y)) |
| 91 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 92 | #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A) |
| 93 | |
Jamie Madill | e2509a3 | 2016-02-01 14:09:05 -0500 | [diff] [blame] | 94 | #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y)) |
| 95 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 96 | // TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR. |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 97 | #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \ |
| 98 | { \ |
| 99 | GLubyte pixel[4]; \ |
| 100 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 101 | EXPECT_GL_NO_ERROR(); \ |
| 102 | EXPECT_NEAR((r), pixel[0], abs_error); \ |
| 103 | EXPECT_NEAR((g), pixel[1], abs_error); \ |
| 104 | EXPECT_NEAR((b), pixel[2], abs_error); \ |
| 105 | EXPECT_NEAR((a), pixel[3], abs_error); \ |
| 106 | } |
| 107 | |
| 108 | class EGLWindow; |
| 109 | class OSWindow; |
| 110 | |
| 111 | class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters> |
| 112 | { |
| 113 | protected: |
| 114 | ANGLETest(); |
| 115 | ~ANGLETest(); |
| 116 | |
| 117 | public: |
| 118 | static bool InitTestWindow(); |
| 119 | static bool DestroyTestWindow(); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 120 | static void SetWindowVisible(bool isVisible); |
Cooper Partin | d756145 | 2015-09-10 10:23:29 -0700 | [diff] [blame] | 121 | static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 122 | |
| 123 | protected: |
| 124 | virtual void SetUp(); |
| 125 | virtual void TearDown(); |
| 126 | |
| 127 | virtual void swapBuffers(); |
| 128 | |
Jamie Madill | 52b09c2 | 2016-04-11 14:12:31 -0400 | [diff] [blame] | 129 | void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale); |
| 130 | |
| 131 | void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ); |
| 132 | void drawQuad(GLuint program, |
| 133 | const std::string &positionAttribName, |
| 134 | GLfloat positionAttribZ, |
| 135 | GLfloat positionAttribXYScale); |
| 136 | void drawQuad(GLuint program, |
| 137 | const std::string &positionAttribName, |
| 138 | GLfloat positionAttribZ, |
| 139 | GLfloat positionAttribXYScale, |
| 140 | bool useVertexBuffer); |
| 141 | static std::array<Vector3, 6> GetQuadVertices(); |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 142 | void drawIndexedQuad(GLuint program, |
| 143 | const std::string &positionAttribName, |
| 144 | GLfloat positionAttribZ); |
| 145 | void drawIndexedQuad(GLuint program, |
| 146 | const std::string &positionAttribName, |
| 147 | GLfloat positionAttribZ, |
| 148 | GLfloat positionAttribXYScale); |
| 149 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 150 | static GLuint compileShader(GLenum type, const std::string &source); |
| 151 | static bool extensionEnabled(const std::string &extName); |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 152 | static bool eglClientExtensionEnabled(const std::string &extName); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 153 | |
| 154 | void setWindowWidth(int width); |
| 155 | void setWindowHeight(int height); |
| 156 | void setConfigRedBits(int bits); |
| 157 | void setConfigGreenBits(int bits); |
| 158 | void setConfigBlueBits(int bits); |
| 159 | void setConfigAlphaBits(int bits); |
| 160 | void setConfigDepthBits(int bits); |
| 161 | void setConfigStencilBits(int bits); |
| 162 | void setMultisampleEnabled(bool enabled); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 163 | void setDebugEnabled(bool enabled); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 164 | void setNoErrorEnabled(bool enabled); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 165 | |
| 166 | int getClientVersion() const; |
| 167 | |
| 168 | EGLWindow *getEGLWindow() const; |
| 169 | int getWindowWidth() const; |
| 170 | int getWindowHeight() const; |
| 171 | bool isMultisampleEnabled() const; |
| 172 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 173 | bool isOpenGL() const; |
Olli Etuaho | 87fc71c | 2016-05-11 14:25:21 +0300 | [diff] [blame] | 174 | bool isGLES() const; |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 175 | EGLint getPlatformRenderer() const; |
| 176 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 177 | void ignoreD3D11SDKLayersWarnings(); |
| 178 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 179 | private: |
| 180 | bool createEGLContext(); |
| 181 | bool destroyEGLContext(); |
| 182 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 183 | void checkD3D11SDKLayersMessages(); |
| 184 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 185 | EGLWindow *mEGLWindow; |
Corentin Wallez | f9ac8fe | 2015-07-23 13:40:15 -0400 | [diff] [blame] | 186 | int mWidth; |
| 187 | int mHeight; |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 188 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 189 | bool mIgnoreD3D11SDKLayersWarnings; |
| 190 | |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 191 | // Used for indexed quad rendering |
| 192 | GLuint mQuadVertexBuffer; |
| 193 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 194 | static OSWindow *mOSWindow; |
| 195 | }; |
| 196 | |
| 197 | class ANGLETestEnvironment : public testing::Environment |
| 198 | { |
| 199 | public: |
| 200 | virtual void SetUp(); |
| 201 | virtual void TearDown(); |
| 202 | }; |
| 203 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 204 | bool IsIntel(); |
| 205 | bool IsAMD(); |
| 206 | bool IsNVIDIA(); |
| 207 | // Note: FL9_3 is explicitly *not* considered D3D11. |
| 208 | bool IsD3D11(); |
| 209 | bool IsD3D11_FL93(); |
| 210 | // Is a D3D9-class renderer. |
| 211 | bool IsD3D9(); |
| 212 | // Is D3D9 or SM9_3 renderer. |
| 213 | bool IsD3DSM3(); |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 214 | bool IsLinux(); |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 215 | bool IsOSX(); |
| 216 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 217 | #endif // ANGLE_TESTS_ANGLE_TEST_H_ |