blob: fe1a1e7d7776e15a09daa42ce60caf865792ece4 [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{
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
125 std::vector<GLchar> infoLog(infoLogLength);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700126 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400127
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400128 std::cerr << "shader compilation failed: " << &infoLog[0];
Geoff Langefc551f2013-10-31 10:20:28 -0400129
130 glDeleteShader(shader);
131 shader = 0;
132 }
133
134 return shader;
135}
136
Geoff Lang63046e22015-07-21 12:43:50 -0400137static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
138{
139 return strstr(allExtensions, extName.c_str()) != nullptr;
140}
141
Geoff Lang8a079e52013-10-18 16:13:33 -0400142bool ANGLETest::extensionEnabled(const std::string &extName)
143{
Geoff Lang63046e22015-07-21 12:43:50 -0400144 return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
145 extName);
146}
147
148bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
149{
150 return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
151}
152
153bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
154{
155 return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
Geoff Lang8a079e52013-10-18 16:13:33 -0400156}
157
Geoff Lang8a079e52013-10-18 16:13:33 -0400158void ANGLETest::setWindowWidth(int width)
159{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400160 mWidth = width;
Geoff Lang8a079e52013-10-18 16:13:33 -0400161}
162
163void ANGLETest::setWindowHeight(int height)
164{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400165 mHeight = height;
Geoff Lang8a079e52013-10-18 16:13:33 -0400166}
167
Geoff Langefc551f2013-10-31 10:20:28 -0400168void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400169{
Jamie Madill62af5462014-08-26 13:16:37 -0400170 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400171}
172
Geoff Langefc551f2013-10-31 10:20:28 -0400173void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400174{
Jamie Madill62af5462014-08-26 13:16:37 -0400175 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400176}
177
Geoff Langefc551f2013-10-31 10:20:28 -0400178void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400179{
Jamie Madill62af5462014-08-26 13:16:37 -0400180 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400181}
182
Geoff Langefc551f2013-10-31 10:20:28 -0400183void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400184{
Jamie Madill62af5462014-08-26 13:16:37 -0400185 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400186}
187
Geoff Langefc551f2013-10-31 10:20:28 -0400188void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400189{
Jamie Madill62af5462014-08-26 13:16:37 -0400190 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400191}
192
Geoff Langefc551f2013-10-31 10:20:28 -0400193void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400194{
Jamie Madill62af5462014-08-26 13:16:37 -0400195 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400196}
197
198void ANGLETest::setMultisampleEnabled(bool enabled)
199{
Jamie Madill62af5462014-08-26 13:16:37 -0400200 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400201}
202
203int ANGLETest::getClientVersion() const
204{
Geoff Lang5ade8452015-09-02 11:00:30 -0400205 return mEGLWindow->getClientMajorVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400206}
207
Geoff Langb9266272015-01-29 13:25:14 +0000208EGLWindow *ANGLETest::getEGLWindow() const
209{
210 return mEGLWindow;
211}
212
Geoff Lang8a079e52013-10-18 16:13:33 -0400213int ANGLETest::getWindowWidth() const
214{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400215 return mWidth;
Geoff Lang8a079e52013-10-18 16:13:33 -0400216}
217
218int ANGLETest::getWindowHeight() const
219{
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400220 return mHeight;
Geoff Lang8a079e52013-10-18 16:13:33 -0400221}
222
Geoff Langefc551f2013-10-31 10:20:28 -0400223bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400224{
Jamie Madill62af5462014-08-26 13:16:37 -0400225 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400226}
227
228bool ANGLETest::createEGLContext()
229{
Jamie Madill62af5462014-08-26 13:16:37 -0400230 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400231}
232
233bool ANGLETest::destroyEGLContext()
234{
Jamie Madill62af5462014-08-26 13:16:37 -0400235 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400236 return true;
237}
Geoff Langbb134672013-10-23 13:06:46 -0400238
Geoff Lang0d3683c2014-10-23 11:08:16 -0400239bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400240{
241 mOSWindow = CreateOSWindow();
242 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
243 {
244 return false;
245 }
246
Geoff Lang0d3683c2014-10-23 11:08:16 -0400247 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400248
249 return true;
250}
251
Geoff Lang0d3683c2014-10-23 11:08:16 -0400252bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400253{
254 if (mOSWindow)
255 {
256 mOSWindow->destroy();
257 delete mOSWindow;
258 mOSWindow = NULL;
259 }
260
261 return true;
262}
263
Geoff Lang0d3683c2014-10-23 11:08:16 -0400264void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400265{
Jamie Madill4119ed32014-10-01 10:41:40 -0400266 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400267}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400268
Jamie Madillc3b9b262015-01-30 14:00:51 -0500269bool ANGLETest::isIntel() const
270{
271 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
272 return (rendererString.find("Intel") != std::string::npos);
273}
274
275bool ANGLETest::isAMD() const
276{
277 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
278 return (rendererString.find("AMD") != std::string::npos) ||
279 (rendererString.find("ATI") != std::string::npos);
280}
281
282bool ANGLETest::isNVidia() const
283{
284 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
285 return (rendererString.find("NVIDIA") != std::string::npos);
286}
287
288EGLint ANGLETest::getPlatformRenderer() const
289{
Jamie Madillf6859912015-01-30 17:05:35 -0500290 assert(mEGLWindow);
291 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500292}
293
Geoff Lang0d3683c2014-10-23 11:08:16 -0400294OSWindow *ANGLETest::mOSWindow = NULL;
295
296void ANGLETestEnvironment::SetUp()
297{
298 if (!ANGLETest::InitTestWindow())
299 {
300 FAIL() << "Failed to create ANGLE test window.";
301 }
302}
303
304void ANGLETestEnvironment::TearDown()
305{
306 ANGLETest::DestroyTestWindow();
307}