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> |
| 15 | |
| 16 | #include "angle_gl.h" |
| 17 | #include "angle_test_configs.h" |
| 18 | #include "common/angleutils.h" |
| 19 | #include "shader_utils.h" |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 20 | #include "Vector.h" |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 21 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 22 | #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError()) |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 23 | #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] | 24 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 25 | #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError()) |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 26 | #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] | 27 | |
| 28 | #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError()) |
| 29 | #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS) |
| 30 | |
Nico Weber | 0c93b8a | 2015-12-09 15:31:40 -0500 | [diff] [blame] | 31 | // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u. |
Nico Weber | 08bf81d | 2015-12-09 16:23:32 -0500 | [diff] [blame] | 32 | #define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a)) |
| 33 | #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] | 34 | #define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a)) |
| 35 | #define EXPECT_EGL_FALSE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), (a)) |
| 36 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 37 | #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError()) |
| 38 | #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS) |
| 39 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 40 | #define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual)) |
| 41 | #define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual)) |
| 42 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 43 | namespace angle |
| 44 | { |
| 45 | struct GLColor |
| 46 | { |
| 47 | GLColor(); |
| 48 | GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a); |
Jamie Madill | e2509a3 | 2016-02-01 14:09:05 -0500 | [diff] [blame] | 49 | GLColor(GLuint colorValue); |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 50 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 51 | Vector4 toNormalizedVector() const; |
| 52 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 53 | GLubyte R, G, B, A; |
| 54 | }; |
| 55 | |
| 56 | // Useful to cast any type to GLubyte. |
| 57 | template <typename TR, typename TG, typename TB, typename TA> |
| 58 | GLColor MakeGLColor(TR r, TG g, TB b, TA a) |
| 59 | { |
| 60 | return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b), |
| 61 | static_cast<GLubyte>(a)); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 64 | bool operator==(const GLColor &a, const GLColor &b); |
| 65 | std::ostream &operator<<(std::ostream &ostream, const GLColor &color); |
| 66 | GLColor ReadColor(GLint x, GLint y); |
| 67 | |
| 68 | } // namespace angle |
| 69 | |
| 70 | #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \ |
| 71 | EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y)) |
| 72 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 73 | #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A) |
| 74 | |
Jamie Madill | e2509a3 | 2016-02-01 14:09:05 -0500 | [diff] [blame] | 75 | #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y)) |
| 76 | |
Jamie Madill | 0dfa807 | 2016-01-22 15:27:21 -0500 | [diff] [blame] | 77 | // 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] | 78 | #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \ |
| 79 | { \ |
| 80 | GLubyte pixel[4]; \ |
| 81 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 82 | EXPECT_GL_NO_ERROR(); \ |
| 83 | EXPECT_NEAR((r), pixel[0], abs_error); \ |
| 84 | EXPECT_NEAR((g), pixel[1], abs_error); \ |
| 85 | EXPECT_NEAR((b), pixel[2], abs_error); \ |
| 86 | EXPECT_NEAR((a), pixel[3], abs_error); \ |
| 87 | } |
| 88 | |
| 89 | class EGLWindow; |
| 90 | class OSWindow; |
| 91 | |
| 92 | class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters> |
| 93 | { |
| 94 | protected: |
| 95 | ANGLETest(); |
| 96 | ~ANGLETest(); |
| 97 | |
| 98 | public: |
| 99 | static bool InitTestWindow(); |
| 100 | static bool DestroyTestWindow(); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 101 | static void SetWindowVisible(bool isVisible); |
Cooper Partin | d756145 | 2015-09-10 10:23:29 -0700 | [diff] [blame] | 102 | static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 103 | |
| 104 | protected: |
| 105 | virtual void SetUp(); |
| 106 | virtual void TearDown(); |
| 107 | |
| 108 | virtual void swapBuffers(); |
| 109 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 110 | static void drawQuad(GLuint program, |
| 111 | const std::string &positionAttribName, |
| 112 | GLfloat positionAttribZ); |
| 113 | static void drawQuad(GLuint program, |
| 114 | const std::string &positionAttribName, |
| 115 | GLfloat positionAttribZ, |
| 116 | GLfloat positionAttribXYScale); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 117 | static GLuint compileShader(GLenum type, const std::string &source); |
| 118 | static bool extensionEnabled(const std::string &extName); |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 119 | static bool eglClientExtensionEnabled(const std::string &extName); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 120 | |
| 121 | void setWindowWidth(int width); |
| 122 | void setWindowHeight(int height); |
| 123 | void setConfigRedBits(int bits); |
| 124 | void setConfigGreenBits(int bits); |
| 125 | void setConfigBlueBits(int bits); |
| 126 | void setConfigAlphaBits(int bits); |
| 127 | void setConfigDepthBits(int bits); |
| 128 | void setConfigStencilBits(int bits); |
| 129 | void setMultisampleEnabled(bool enabled); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 130 | void setDebugEnabled(bool enabled); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 131 | void setNoErrorEnabled(bool enabled); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 132 | |
| 133 | int getClientVersion() const; |
| 134 | |
| 135 | EGLWindow *getEGLWindow() const; |
| 136 | int getWindowWidth() const; |
| 137 | int getWindowHeight() const; |
| 138 | bool isMultisampleEnabled() const; |
| 139 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame^] | 140 | bool isOpenGL() const; |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 141 | EGLint getPlatformRenderer() const; |
| 142 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 143 | void ignoreD3D11SDKLayersWarnings(); |
| 144 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 145 | private: |
| 146 | bool createEGLContext(); |
| 147 | bool destroyEGLContext(); |
| 148 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 149 | void checkD3D11SDKLayersMessages(); |
| 150 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 151 | EGLWindow *mEGLWindow; |
Corentin Wallez | f9ac8fe | 2015-07-23 13:40:15 -0400 | [diff] [blame] | 152 | int mWidth; |
| 153 | int mHeight; |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 154 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 155 | bool mIgnoreD3D11SDKLayersWarnings; |
| 156 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 157 | static OSWindow *mOSWindow; |
| 158 | }; |
| 159 | |
| 160 | class ANGLETestEnvironment : public testing::Environment |
| 161 | { |
| 162 | public: |
| 163 | virtual void SetUp(); |
| 164 | virtual void TearDown(); |
| 165 | }; |
| 166 | |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame^] | 167 | bool IsIntel(); |
| 168 | bool IsAMD(); |
| 169 | bool IsNVIDIA(); |
| 170 | // Note: FL9_3 is explicitly *not* considered D3D11. |
| 171 | bool IsD3D11(); |
| 172 | bool IsD3D11_FL93(); |
| 173 | // Is a D3D9-class renderer. |
| 174 | bool IsD3D9(); |
| 175 | // Is D3D9 or SM9_3 renderer. |
| 176 | bool IsD3DSM3(); |
| 177 | bool IsOSX(); |
| 178 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 179 | #endif // ANGLE_TESTS_ANGLE_TEST_H_ |