blob: 0bb1973f5f8df87d569a55cee03871b63b59ca16 [file] [log] [blame]
Geoff Lang8a079e52013-10-18 16:13:33 -04001#include "ANGLETest.h"
Jamie Madill62af5462014-08-26 13:16:37 -04002#include "EGLWindow.h"
Jamie Madill8add0eb2014-08-26 13:16:35 -04003#include "OSWindow.h"
4
Jamie Madillfa05f602015-05-07 13:47:11 -04005ANGLETest::ANGLETest()
Corentin Wallezf3357ee2015-07-22 14:10:19 -04006 : mEGLWindow(nullptr),
Jamie Madill2511d062015-09-11 15:19:56 -04007 mWidth(16),
8 mHeight(16)
Geoff Lang8a079e52013-10-18 16:13:33 -04009{
Geoff Lang5ade8452015-09-02 11:00:30 -040010 mEGLWindow =
11 new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -040012}
13
14ANGLETest::~ANGLETest()
15{
Jamie Madill77a72f62015-04-14 11:18:32 -040016 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -040017}
18
Geoff Lang8a079e52013-10-18 16:13:33 -040019void ANGLETest::SetUp()
20{
Corentin Wallezb44440d2015-07-22 17:54:20 -040021 // Resize the window before creating the context so that the first make current
22 // sets the viewport and scissor box to the right size.
23 bool needSwap = false;
24 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +000025 {
Corentin Wallezb44440d2015-07-22 17:54:20 -040026 if (!mOSWindow->resize(mWidth, mHeight))
27 {
28 FAIL() << "Failed to resize ANGLE test window.";
29 }
30 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +000031 }
32
Geoff Lang8a079e52013-10-18 16:13:33 -040033 if (!createEGLContext())
34 {
35 FAIL() << "egl context creation failed.";
36 }
Corentin Wallezb828b322015-07-16 17:51:30 -040037
Corentin Wallezb44440d2015-07-22 17:54:20 -040038 if (needSwap)
39 {
40 // Swap the buffers so that the default framebuffer picks up the resize
41 // which will allow follow-up test code to assume the framebuffer covers
42 // the whole window.
43 swapBuffers();
44 }
Corentin Wallez096725b2015-07-20 16:58:57 -040045
Geoff Lang7f8dc492015-07-23 21:29:33 +000046 // This Viewport command is not strictly necessary but we add it so that programs
47 // taking OpenGL traces can guess the size of the default framebuffer and show it
48 // in their UIs
49 glViewport(0, 0, mWidth, mHeight);
Geoff Lang8a079e52013-10-18 16:13:33 -040050}
51
52void ANGLETest::TearDown()
53{
54 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -040055 mOSWindow->messageLoop();
56
Geoff Lang8a079e52013-10-18 16:13:33 -040057 if (!destroyEGLContext())
58 {
59 FAIL() << "egl context destruction failed.";
60 }
Jamie Madill8add0eb2014-08-26 13:16:35 -040061
62 // Check for quit message
63 Event myEvent;
64 while (mOSWindow->popEvent(&myEvent))
65 {
66 if (myEvent.Type == Event::EVENT_CLOSED)
67 {
68 exit(0);
69 }
70 }
Geoff Lang8a079e52013-10-18 16:13:33 -040071}
72
73void ANGLETest::swapBuffers()
74{
Jamie Madill77a72f62015-04-14 11:18:32 -040075 if (mEGLWindow->isGLInitialized())
76 {
77 mEGLWindow->swap();
78 }
Geoff Lang8a079e52013-10-18 16:13:33 -040079}
80
Austin Kinross4fd18b12014-12-22 12:32:05 -080081void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale)
Geoff Lang8a079e52013-10-18 16:13:33 -040082{
83 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
84
85 glUseProgram(program);
86
87 const GLfloat vertices[] =
88 {
Austin Kinross4fd18b12014-12-22 12:32:05 -080089 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
90 -1.0f * quadScale, -1.0f * quadScale, quadDepth,
91 1.0f * quadScale, -1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040092
Austin Kinross4fd18b12014-12-22 12:32:05 -080093 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
94 1.0f * quadScale, -1.0f * quadScale, quadDepth,
95 1.0f * quadScale, 1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040096 };
97
98 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
99 glEnableVertexAttribArray(positionLocation);
100
101 glDrawArrays(GL_TRIANGLES, 0, 6);
102
103 glDisableVertexAttribArray(positionLocation);
104 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
105
106 glUseProgram(0);
107}
108
Geoff Langefc551f2013-10-31 10:20:28 -0400109GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
110{
111 GLuint shader = glCreateShader(type);
112
113 const char *sourceArray[1] = { source.c_str() };
114 glShaderSource(shader, 1, sourceArray, NULL);
115 glCompileShader(shader);
116
117 GLint compileResult;
118 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
119
120 if (compileResult == 0)
121 {
122 GLint infoLogLength;
123 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
124
Jamie Madilld2c52e32015-10-14 17:07:05 -0400125 if (infoLogLength == 0)
126 {
127 std::cerr << "shader compilation failed with empty log." << std::endl;
128 }
129 else
130 {
131 std::vector<GLchar> infoLog(infoLogLength);
132 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400133
Jamie Madilld2c52e32015-10-14 17:07:05 -0400134 std::cerr << "shader compilation failed: " << &infoLog[0];
135 }
Geoff Langefc551f2013-10-31 10:20:28 -0400136
137 glDeleteShader(shader);
138 shader = 0;
139 }
140
141 return shader;
142}
143
Geoff Lang63046e22015-07-21 12:43:50 -0400144static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
145{
146 return strstr(allExtensions, extName.c_str()) != nullptr;
147}
148
Geoff Lang8a079e52013-10-18 16:13:33 -0400149bool ANGLETest::extensionEnabled(const std::string &extName)
150{
Geoff Lang63046e22015-07-21 12:43:50 -0400151 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
152 extName);
153}
154
155bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
156{
157 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
158}
159
160bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
161{
162 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400163}
164
Geoff Lang8a079e52013-10-18 16:13:33 -0400165void ANGLETest::setWindowWidth(int width)
166{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400167 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400168}
169
170void ANGLETest::setWindowHeight(int height)
171{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400172 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400173}
174
Geoff Langefc551f2013-10-31 10:20:28 -0400175void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400176{
Jamie Madill62af5462014-08-26 13:16:37 -0400177 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400178}
179
Geoff Langefc551f2013-10-31 10:20:28 -0400180void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400181{
Jamie Madill62af5462014-08-26 13:16:37 -0400182 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400183}
184
Geoff Langefc551f2013-10-31 10:20:28 -0400185void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400186{
Jamie Madill62af5462014-08-26 13:16:37 -0400187 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400188}
189
Geoff Langefc551f2013-10-31 10:20:28 -0400190void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400191{
Jamie Madill62af5462014-08-26 13:16:37 -0400192 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400193}
194
Geoff Langefc551f2013-10-31 10:20:28 -0400195void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400196{
Jamie Madill62af5462014-08-26 13:16:37 -0400197 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400198}
199
Geoff Langefc551f2013-10-31 10:20:28 -0400200void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400201{
Jamie Madill62af5462014-08-26 13:16:37 -0400202 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400203}
204
205void ANGLETest::setMultisampleEnabled(bool enabled)
206{
Jamie Madill62af5462014-08-26 13:16:37 -0400207 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400208}
209
210int ANGLETest::getClientVersion() const
211{
Geoff Lang5ade8452015-09-02 11:00:30 -0400212 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400213}
214
Geoff Langb9266272015-01-29 13:25:14 +0000215EGLWindow *ANGLETest::getEGLWindow() const
216{
217 return mEGLWindow;
218}
219
Geoff Lang8a079e52013-10-18 16:13:33 -0400220int ANGLETest::getWindowWidth() const
221{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400222 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400223}
224
225int ANGLETest::getWindowHeight() const
226{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400227 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400228}
229
Geoff Langefc551f2013-10-31 10:20:28 -0400230bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400231{
Jamie Madill62af5462014-08-26 13:16:37 -0400232 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400233}
234
235bool ANGLETest::createEGLContext()
236{
Jamie Madill62af5462014-08-26 13:16:37 -0400237 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400238}
239
240bool ANGLETest::destroyEGLContext()
241{
Jamie Madill62af5462014-08-26 13:16:37 -0400242 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400243 return true;
244}
Geoff Langbb134672013-10-23 13:06:46 -0400245
Geoff Lang0d3683c2014-10-23 11:08:16 -0400246bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400247{
248 mOSWindow = CreateOSWindow();
249 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
250 {
251 return false;
252 }
253
Geoff Lang0d3683c2014-10-23 11:08:16 -0400254 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400255
256 return true;
257}
258
Geoff Lang0d3683c2014-10-23 11:08:16 -0400259bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400260{
261 if (mOSWindow)
262 {
263 mOSWindow->destroy();
264 delete mOSWindow;
265 mOSWindow = NULL;
266 }
267
268 return true;
269}
270
Geoff Lang0d3683c2014-10-23 11:08:16 -0400271void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400272{
Jamie Madill4119ed32014-10-01 10:41:40 -0400273 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400274}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400275
Jamie Madillc3b9b262015-01-30 14:00:51 -0500276bool ANGLETest::isIntel() const
277{
278 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
279 return (rendererString.find("Intel") != std::string::npos);
280}
281
282bool ANGLETest::isAMD() const
283{
284 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
285 return (rendererString.find("AMD") != std::string::npos) ||
286 (rendererString.find("ATI") != std::string::npos);
287}
288
289bool ANGLETest::isNVidia() const
290{
291 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
292 return (rendererString.find("NVIDIA") != std::string::npos);
293}
294
Jamie Madilld55d2832015-10-27 13:59:19 -0400295bool ANGLETest::isD3D11() const
296{
297 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
298 return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
299}
300
Jamie Madillc3b9b262015-01-30 14:00:51 -0500301EGLint ANGLETest::getPlatformRenderer() const
302{
Jamie Madillf6859912015-01-30 17:05:35 -0500303 assert(mEGLWindow);
304 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500305}
306
Geoff Lang0d3683c2014-10-23 11:08:16 -0400307OSWindow *ANGLETest::mOSWindow = NULL;
308
309void ANGLETestEnvironment::SetUp()
310{
311 if (!ANGLETest::InitTestWindow())
312 {
313 FAIL() << "Failed to create ANGLE test window.";
314 }
315}
316
317void ANGLETestEnvironment::TearDown()
318{
319 ANGLETest::DestroyTestWindow();
320}