blob: 7aa6c8ca066bfaa893a2a30e2a6c300222999f53 [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()
Jamie Madill77a72f62015-04-14 11:18:32 -04006 : mEGLWindow(nullptr)
Geoff Lang8a079e52013-10-18 16:13:33 -04007{
Geoff Langdd323e92015-06-09 15:16:31 -04008 mEGLWindow = new EGLWindow(1280, 720, GetParam().majorVersion, GetParam().eglParameters);
Geoff Lang0d3683c2014-10-23 11:08:16 -04009}
10
11ANGLETest::~ANGLETest()
12{
Jamie Madill77a72f62015-04-14 11:18:32 -040013 SafeDelete(mEGLWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -040014}
15
Geoff Lang8a079e52013-10-18 16:13:33 -040016void ANGLETest::SetUp()
17{
Geoff Lang0d3683c2014-10-23 11:08:16 -040018 if (!ResizeWindow(mEGLWindow->getWidth(), mEGLWindow->getHeight()))
Jamie Madill4119ed32014-10-01 10:41:40 -040019 {
20 FAIL() << "Failed to resize ANGLE test window.";
21 }
22
Geoff Lang8a079e52013-10-18 16:13:33 -040023 if (!createEGLContext())
24 {
25 FAIL() << "egl context creation failed.";
26 }
Corentin Wallezb828b322015-07-16 17:51:30 -040027
28 // Swap the buffers so that the default framebuffer picks up the resize
29 // which will allow follow-up test code to assume the framebuffer covers
30 // the whole window.
31 swapBuffers();
Corentin Wallez096725b2015-07-20 16:58:57 -040032
33 // This Viewport command is not strictly necessary but we add it so that programs
34 // taking OpenGL traces can guess the size of the default framebuffer and show it
35 // in their UIs
36 glViewport(0, 0, mEGLWindow->getWidth(), mEGLWindow->getHeight());
Geoff Lang8a079e52013-10-18 16:13:33 -040037}
38
39void ANGLETest::TearDown()
40{
41 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -040042 mOSWindow->messageLoop();
43
Geoff Lang8a079e52013-10-18 16:13:33 -040044 if (!destroyEGLContext())
45 {
46 FAIL() << "egl context destruction failed.";
47 }
Jamie Madill8add0eb2014-08-26 13:16:35 -040048
49 // Check for quit message
50 Event myEvent;
51 while (mOSWindow->popEvent(&myEvent))
52 {
53 if (myEvent.Type == Event::EVENT_CLOSED)
54 {
55 exit(0);
56 }
57 }
Geoff Lang8a079e52013-10-18 16:13:33 -040058}
59
60void ANGLETest::swapBuffers()
61{
Jamie Madill77a72f62015-04-14 11:18:32 -040062 if (mEGLWindow->isGLInitialized())
63 {
64 mEGLWindow->swap();
65 }
Geoff Lang8a079e52013-10-18 16:13:33 -040066}
67
Austin Kinross4fd18b12014-12-22 12:32:05 -080068void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale)
Geoff Lang8a079e52013-10-18 16:13:33 -040069{
70 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
71
72 glUseProgram(program);
73
74 const GLfloat vertices[] =
75 {
Austin Kinross4fd18b12014-12-22 12:32:05 -080076 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
77 -1.0f * quadScale, -1.0f * quadScale, quadDepth,
78 1.0f * quadScale, -1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040079
Austin Kinross4fd18b12014-12-22 12:32:05 -080080 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
81 1.0f * quadScale, -1.0f * quadScale, quadDepth,
82 1.0f * quadScale, 1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040083 };
84
85 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
86 glEnableVertexAttribArray(positionLocation);
87
88 glDrawArrays(GL_TRIANGLES, 0, 6);
89
90 glDisableVertexAttribArray(positionLocation);
91 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
92
93 glUseProgram(0);
94}
95
Geoff Langefc551f2013-10-31 10:20:28 -040096GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
97{
98 GLuint shader = glCreateShader(type);
99
100 const char *sourceArray[1] = { source.c_str() };
101 glShaderSource(shader, 1, sourceArray, NULL);
102 glCompileShader(shader);
103
104 GLint compileResult;
105 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
106
107 if (compileResult == 0)
108 {
109 GLint infoLogLength;
110 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
111
112 std::vector<GLchar> infoLog(infoLogLength);
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400113 glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400114
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400115 std::cerr << "shader compilation failed: " << &infoLog[0];
Geoff Langefc551f2013-10-31 10:20:28 -0400116
117 glDeleteShader(shader);
118 shader = 0;
119 }
120
121 return shader;
122}
123
Geoff Lang8a079e52013-10-18 16:13:33 -0400124bool ANGLETest::extensionEnabled(const std::string &extName)
125{
126 const char* extString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
127 return strstr(extString, extName.c_str()) != NULL;
128}
129
Geoff Lang8a079e52013-10-18 16:13:33 -0400130void ANGLETest::setWindowWidth(int width)
131{
Jamie Madill62af5462014-08-26 13:16:37 -0400132 mEGLWindow->setWidth(width);
Geoff Lang8a079e52013-10-18 16:13:33 -0400133}
134
135void ANGLETest::setWindowHeight(int height)
136{
Jamie Madill62af5462014-08-26 13:16:37 -0400137 mEGLWindow->setHeight(height);
Geoff Lang8a079e52013-10-18 16:13:33 -0400138}
139
Geoff Langefc551f2013-10-31 10:20:28 -0400140void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400141{
Jamie Madill62af5462014-08-26 13:16:37 -0400142 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400143}
144
Geoff Langefc551f2013-10-31 10:20:28 -0400145void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400146{
Jamie Madill62af5462014-08-26 13:16:37 -0400147 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400148}
149
Geoff Langefc551f2013-10-31 10:20:28 -0400150void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400151{
Jamie Madill62af5462014-08-26 13:16:37 -0400152 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400153}
154
Geoff Langefc551f2013-10-31 10:20:28 -0400155void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400156{
Jamie Madill62af5462014-08-26 13:16:37 -0400157 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400158}
159
Geoff Langefc551f2013-10-31 10:20:28 -0400160void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400161{
Jamie Madill62af5462014-08-26 13:16:37 -0400162 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400163}
164
Geoff Langefc551f2013-10-31 10:20:28 -0400165void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400166{
Jamie Madill62af5462014-08-26 13:16:37 -0400167 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400168}
169
170void ANGLETest::setMultisampleEnabled(bool enabled)
171{
Jamie Madill62af5462014-08-26 13:16:37 -0400172 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400173}
174
175int ANGLETest::getClientVersion() const
176{
Jamie Madill62af5462014-08-26 13:16:37 -0400177 return mEGLWindow->getClientVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400178}
179
Geoff Langb9266272015-01-29 13:25:14 +0000180EGLWindow *ANGLETest::getEGLWindow() const
181{
182 return mEGLWindow;
183}
184
Geoff Lang8a079e52013-10-18 16:13:33 -0400185int ANGLETest::getWindowWidth() const
186{
Jamie Madill62af5462014-08-26 13:16:37 -0400187 return mEGLWindow->getWidth();
Geoff Lang8a079e52013-10-18 16:13:33 -0400188}
189
190int ANGLETest::getWindowHeight() const
191{
Jamie Madill62af5462014-08-26 13:16:37 -0400192 return mEGLWindow->getHeight();
Geoff Lang8a079e52013-10-18 16:13:33 -0400193}
194
Geoff Langefc551f2013-10-31 10:20:28 -0400195bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400196{
Jamie Madill62af5462014-08-26 13:16:37 -0400197 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400198}
199
200bool ANGLETest::createEGLContext()
201{
Jamie Madill62af5462014-08-26 13:16:37 -0400202 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400203}
204
205bool ANGLETest::destroyEGLContext()
206{
Jamie Madill62af5462014-08-26 13:16:37 -0400207 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400208 return true;
209}
Geoff Langbb134672013-10-23 13:06:46 -0400210
Geoff Lang0d3683c2014-10-23 11:08:16 -0400211bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400212{
213 mOSWindow = CreateOSWindow();
214 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
215 {
216 return false;
217 }
218
Geoff Lang0d3683c2014-10-23 11:08:16 -0400219 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400220
221 return true;
222}
223
Geoff Lang0d3683c2014-10-23 11:08:16 -0400224bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400225{
226 if (mOSWindow)
227 {
228 mOSWindow->destroy();
229 delete mOSWindow;
230 mOSWindow = NULL;
231 }
232
233 return true;
234}
235
Geoff Lang0d3683c2014-10-23 11:08:16 -0400236bool ANGLETest::ResizeWindow(int width, int height)
Jamie Madill8add0eb2014-08-26 13:16:35 -0400237{
238 return mOSWindow->resize(width, height);
239}
240
Geoff Lang0d3683c2014-10-23 11:08:16 -0400241void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400242{
Jamie Madill4119ed32014-10-01 10:41:40 -0400243 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400244}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400245
Jamie Madillc3b9b262015-01-30 14:00:51 -0500246bool ANGLETest::isIntel() const
247{
248 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
249 return (rendererString.find("Intel") != std::string::npos);
250}
251
252bool ANGLETest::isAMD() const
253{
254 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
255 return (rendererString.find("AMD") != std::string::npos) ||
256 (rendererString.find("ATI") != std::string::npos);
257}
258
259bool ANGLETest::isNVidia() const
260{
261 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
262 return (rendererString.find("NVIDIA") != std::string::npos);
263}
264
265EGLint ANGLETest::getPlatformRenderer() const
266{
Jamie Madillf6859912015-01-30 17:05:35 -0500267 assert(mEGLWindow);
268 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500269}
270
Geoff Lang0d3683c2014-10-23 11:08:16 -0400271OSWindow *ANGLETest::mOSWindow = NULL;
272
273void ANGLETestEnvironment::SetUp()
274{
275 if (!ANGLETest::InitTestWindow())
276 {
277 FAIL() << "Failed to create ANGLE test window.";
278 }
279}
280
281void ANGLETestEnvironment::TearDown()
282{
283 ANGLETest::DestroyTestWindow();
284}