Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -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 | // |
| 6 | |
| 7 | #ifndef ANGLE_TESTS_ANGLE_TEST_H_ |
| 8 | #define ANGLE_TESTS_ANGLE_TEST_H_ |
| 9 | |
| 10 | #include "gtest/gtest.h" |
| 11 | |
| 12 | #define GL_GLEXT_PROTOTYPES |
| 13 | |
| 14 | #include <GLES3/gl3.h> |
| 15 | #include <GLES3/gl3ext.h> |
| 16 | #include <GLES2/gl2.h> |
| 17 | #include <GLES2/gl2ext.h> |
| 18 | #include <EGL/egl.h> |
| 19 | #include <EGL/eglext.h> |
Jamie Madill | 4b8c3eb | 2014-01-14 16:09:43 -0500 | [diff] [blame] | 20 | #include <algorithm> |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 21 | |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 22 | #define EXPECT_GL_ERROR(err) EXPECT_EQ((err), glGetError()) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 23 | #define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR) |
| 24 | |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 25 | #define ASSERT_GL_ERROR(err) ASSERT_EQ((err), glGetError()) |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 26 | #define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR) |
| 27 | |
| 28 | #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \ |
| 29 | { \ |
| 30 | GLubyte pixel[4]; \ |
| 31 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 32 | EXPECT_GL_NO_ERROR(); \ |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 33 | EXPECT_EQ((r), pixel[0]); \ |
| 34 | EXPECT_EQ((g), pixel[1]); \ |
| 35 | EXPECT_EQ((b), pixel[2]); \ |
| 36 | EXPECT_EQ((a), pixel[3]); \ |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | #define SHADER_SOURCE(...) #__VA_ARGS__ |
| 40 | |
| 41 | class ANGLETest : public testing::Test |
| 42 | { |
| 43 | protected: |
| 44 | ANGLETest(); |
| 45 | |
| 46 | public: |
| 47 | static bool InitTestWindow(); |
| 48 | static bool DestroyTestWindow(); |
| 49 | static bool ReizeWindow(int width, int height); |
| 50 | |
| 51 | protected: |
| 52 | virtual void SetUp(); |
| 53 | virtual void TearDown(); |
| 54 | |
| 55 | virtual void swapBuffers(); |
| 56 | |
| 57 | static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 58 | static GLuint compileShader(GLenum type, const std::string &source); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 59 | static GLuint compileProgram(const std::string &vsSource, const std::string &fsSource); |
| 60 | static bool extensionEnabled(const std::string &extName); |
| 61 | |
| 62 | void setClientVersion(int clientVersion); |
| 63 | void setWindowWidth(int width); |
| 64 | void setWindowHeight(int height); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 65 | void setConfigRedBits(int bits); |
| 66 | void setConfigGreenBits(int bits); |
| 67 | void setConfigBlueBits(int bits); |
| 68 | void setConfigAlphaBits(int bits); |
| 69 | void setConfigDepthBits(int bits); |
| 70 | void setConfigStencilBits(int bits); |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 71 | void setMultisampleEnabled(bool enabled); |
| 72 | |
| 73 | int getClientVersion() const; |
| 74 | int getWindowWidth() const; |
| 75 | int getWindowHeight() const; |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 76 | int getConfigRedBits() const; |
| 77 | int getConfigGreenBits() const; |
| 78 | int getConfigBlueBits() const; |
| 79 | int getConfigAlphaBits() const; |
| 80 | int getConfigDepthBits() const; |
| 81 | int getConfigStencilBits() const; |
| 82 | bool isMultisampleEnabled() const; |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | bool createEGLContext(); |
| 86 | bool destroyEGLContext(); |
| 87 | |
| 88 | int mClientVersion; |
| 89 | int mWidth; |
| 90 | int mHeight; |
| 91 | int mRedBits; |
| 92 | int mGreenBits; |
| 93 | int mBlueBits; |
| 94 | int mAlphaBits; |
| 95 | int mDepthBits; |
| 96 | int mStencilBits; |
| 97 | bool mMultisample; |
| 98 | |
| 99 | EGLConfig mConfig; |
| 100 | EGLSurface mSurface; |
| 101 | EGLContext mContext; |
| 102 | |
| 103 | static EGLDisplay mDisplay; |
| 104 | static EGLNativeWindowType mNativeWindow; |
| 105 | static EGLNativeDisplayType mNativeDisplay; |
| 106 | }; |
| 107 | |
Geoff Lang | bb13467 | 2013-10-23 13:06:46 -0400 | [diff] [blame] | 108 | class ANGLETestEnvironment : public testing::Environment |
| 109 | { |
| 110 | public: |
| 111 | virtual void SetUp(); |
| 112 | virtual void TearDown(); |
| 113 | }; |
| 114 | |
Geoff Lang | 8a079e5 | 2013-10-18 16:13:33 -0400 | [diff] [blame] | 115 | #endif // ANGLE_TESTS_ANGLE_TEST_H_ |