blob: eeb417e2a7640b9298672958fc30821d19dab1ca [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),
7 mWidth(0),
8 mHeight(0)
Geoff Lang8a079e52013-10-18 16:13:33 -04009{
Corentin Wallezf3357ee2015-07-22 14:10:19 -040010 mEGLWindow = new EGLWindow(GetParam().majorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -040011}
12
13ANGLETest::~ANGLETest()
14{
Jamie Madill77a72f62015-04-14 11:18:32 -040015 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -040016}
17
Geoff Lang8a079e52013-10-18 16:13:33 -040018void ANGLETest::SetUp()
19{
Corentin Wallezb44440d2015-07-22 17:54:20 -040020 // Resize the window before creating the context so that the first make current
21 // sets the viewport and scissor box to the right size.
22 bool needSwap = false;
23 if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
Geoff Lang7f8dc492015-07-23 21:29:33 +000024 {
Corentin Wallezb44440d2015-07-22 17:54:20 -040025 if (!mOSWindow->resize(mWidth, mHeight))
26 {
27 FAIL() << "Failed to resize ANGLE test window.";
28 }
29 needSwap = true;
Geoff Lang7f8dc492015-07-23 21:29:33 +000030 }
31
Geoff Lang8a079e52013-10-18 16:13:33 -040032 if (!createEGLContext())
33 {
34 FAIL() << "egl context creation failed.";
35 }
Corentin Wallezb828b322015-07-16 17:51:30 -040036
Corentin Wallezb44440d2015-07-22 17:54:20 -040037 if (needSwap)
38 {
39 // Swap the buffers so that the default framebuffer picks up the resize
40 // which will allow follow-up test code to assume the framebuffer covers
41 // the whole window.
42 swapBuffers();
43 }
Corentin Wallez096725b2015-07-20 16:58:57 -040044
Geoff Lang7f8dc492015-07-23 21:29:33 +000045 // This Viewport command is not strictly necessary but we add it so that programs
46 // taking OpenGL traces can guess the size of the default framebuffer and show it
47 // in their UIs
48 glViewport(0, 0, mWidth, mHeight);
Geoff Lang8a079e52013-10-18 16:13:33 -040049}
50
51void ANGLETest::TearDown()
52{
53 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -040054 mOSWindow->messageLoop();
55
Geoff Lang8a079e52013-10-18 16:13:33 -040056 if (!destroyEGLContext())
57 {
58 FAIL() << "egl context destruction failed.";
59 }
Jamie Madill8add0eb2014-08-26 13:16:35 -040060
61 // Check for quit message
62 Event myEvent;
63 while (mOSWindow->popEvent(&myEvent))
64 {
65 if (myEvent.Type == Event::EVENT_CLOSED)
66 {
67 exit(0);
68 }
69 }
Geoff Lang8a079e52013-10-18 16:13:33 -040070}
71
72void ANGLETest::swapBuffers()
73{
Jamie Madill77a72f62015-04-14 11:18:32 -040074 if (mEGLWindow->isGLInitialized())
75 {
76 mEGLWindow->swap();
77 }
Geoff Lang8a079e52013-10-18 16:13:33 -040078}
79
Austin Kinross4fd18b12014-12-22 12:32:05 -080080void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale)
Geoff Lang8a079e52013-10-18 16:13:33 -040081{
82 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
83
84 glUseProgram(program);
85
86 const GLfloat vertices[] =
87 {
Austin Kinross4fd18b12014-12-22 12:32:05 -080088 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
89 -1.0f * quadScale, -1.0f * quadScale, quadDepth,
90 1.0f * quadScale, -1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040091
Austin Kinross4fd18b12014-12-22 12:32:05 -080092 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
93 1.0f * quadScale, -1.0f * quadScale, quadDepth,
94 1.0f * quadScale, 1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040095 };
96
97 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
98 glEnableVertexAttribArray(positionLocation);
99
100 glDrawArrays(GL_TRIANGLES, 0, 6);
101
102 glDisableVertexAttribArray(positionLocation);
103 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
104
105 glUseProgram(0);
106}
107
Geoff Langefc551f2013-10-31 10:20:28 -0400108GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
109{
110 GLuint shader = glCreateShader(type);
111
112 const char *sourceArray[1] = { source.c_str() };
113 glShaderSource(shader, 1, sourceArray, NULL);
114 glCompileShader(shader);
115
116 GLint compileResult;
117 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
118
119 if (compileResult == 0)
120 {
121 GLint infoLogLength;
122 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
123
124 std::vector<GLchar> infoLog(infoLogLength);
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400125 glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400126
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400127 std::cerr << "shader compilation failed: " << &infoLog[0];
Geoff Langefc551f2013-10-31 10:20:28 -0400128
129 glDeleteShader(shader);
130 shader = 0;
131 }
132
133 return shader;
134}
135
Geoff Lang63046e22015-07-21 12:43:50 -0400136static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
137{
138 return strstr(allExtensions, extName.c_str()) != nullptr;
139}
140
Geoff Lang8a079e52013-10-18 16:13:33 -0400141bool ANGLETest::extensionEnabled(const std::string &extName)
142{
Geoff Lang63046e22015-07-21 12:43:50 -0400143 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
144 extName);
145}
146
147bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
148{
149 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
150}
151
152bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
153{
154 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400155}
156
Geoff Lang8a079e52013-10-18 16:13:33 -0400157void ANGLETest::setWindowWidth(int width)
158{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400159 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400160}
161
162void ANGLETest::setWindowHeight(int height)
163{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400164 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400165}
166
Geoff Langefc551f2013-10-31 10:20:28 -0400167void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400168{
Jamie Madill62af5462014-08-26 13:16:37 -0400169 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400170}
171
Geoff Langefc551f2013-10-31 10:20:28 -0400172void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400173{
Jamie Madill62af5462014-08-26 13:16:37 -0400174 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400175}
176
Geoff Langefc551f2013-10-31 10:20:28 -0400177void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400178{
Jamie Madill62af5462014-08-26 13:16:37 -0400179 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400180}
181
Geoff Langefc551f2013-10-31 10:20:28 -0400182void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400183{
Jamie Madill62af5462014-08-26 13:16:37 -0400184 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400185}
186
Geoff Langefc551f2013-10-31 10:20:28 -0400187void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400188{
Jamie Madill62af5462014-08-26 13:16:37 -0400189 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400190}
191
Geoff Langefc551f2013-10-31 10:20:28 -0400192void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400193{
Jamie Madill62af5462014-08-26 13:16:37 -0400194 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400195}
196
197void ANGLETest::setMultisampleEnabled(bool enabled)
198{
Jamie Madill62af5462014-08-26 13:16:37 -0400199 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400200}
201
202int ANGLETest::getClientVersion() const
203{
Jamie Madill62af5462014-08-26 13:16:37 -0400204 return mEGLWindow->getClientVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400205}
206
Geoff Langb9266272015-01-29 13:25:14 +0000207EGLWindow *ANGLETest::getEGLWindow() const
208{
209 return mEGLWindow;
210}
211
Geoff Lang8a079e52013-10-18 16:13:33 -0400212int ANGLETest::getWindowWidth() const
213{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400214 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400215}
216
217int ANGLETest::getWindowHeight() const
218{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400219 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400220}
221
Geoff Langefc551f2013-10-31 10:20:28 -0400222bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400223{
Jamie Madill62af5462014-08-26 13:16:37 -0400224 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400225}
226
227bool ANGLETest::createEGLContext()
228{
Jamie Madill62af5462014-08-26 13:16:37 -0400229 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400230}
231
232bool ANGLETest::destroyEGLContext()
233{
Jamie Madill62af5462014-08-26 13:16:37 -0400234 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400235 return true;
236}
Geoff Langbb134672013-10-23 13:06:46 -0400237
Geoff Lang0d3683c2014-10-23 11:08:16 -0400238bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400239{
240 mOSWindow = CreateOSWindow();
241 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
242 {
243 return false;
244 }
245
Geoff Lang0d3683c2014-10-23 11:08:16 -0400246 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400247
248 return true;
249}
250
Geoff Lang0d3683c2014-10-23 11:08:16 -0400251bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400252{
253 if (mOSWindow)
254 {
255 mOSWindow->destroy();
256 delete mOSWindow;
257 mOSWindow = NULL;
258 }
259
260 return true;
261}
262
Geoff Lang0d3683c2014-10-23 11:08:16 -0400263void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400264{
Jamie Madill4119ed32014-10-01 10:41:40 -0400265 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400266}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400267
Jamie Madillc3b9b262015-01-30 14:00:51 -0500268bool ANGLETest::isIntel() const
269{
270 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
271 return (rendererString.find("Intel") != std::string::npos);
272}
273
274bool ANGLETest::isAMD() const
275{
276 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
277 return (rendererString.find("AMD") != std::string::npos) ||
278 (rendererString.find("ATI") != std::string::npos);
279}
280
281bool ANGLETest::isNVidia() const
282{
283 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
284 return (rendererString.find("NVIDIA") != std::string::npos);
285}
286
287EGLint ANGLETest::getPlatformRenderer() const
288{
Jamie Madillf6859912015-01-30 17:05:35 -0500289 assert(mEGLWindow);
290 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500291}
292
Geoff Lang0d3683c2014-10-23 11:08:16 -0400293OSWindow *ANGLETest::mOSWindow = NULL;
294
295void ANGLETestEnvironment::SetUp()
296{
297 if (!ANGLETest::InitTestWindow())
298 {
299 FAIL() << "Failed to create ANGLE test window.";
300 }
301}
302
303void ANGLETestEnvironment::TearDown()
304{
305 ANGLETest::DestroyTestWindow();
306}