blob: dad58f05f475a712399023e33712d4299abcb1c3 [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();
Geoff Lang8a079e52013-10-18 16:13:33 -040032}
33
34void ANGLETest::TearDown()
35{
36 swapBuffers();
Jamie Madill9e16d402014-09-08 17:36:33 -040037 mOSWindow->messageLoop();
38
Geoff Lang8a079e52013-10-18 16:13:33 -040039 if (!destroyEGLContext())
40 {
41 FAIL() << "egl context destruction failed.";
42 }
Jamie Madill8add0eb2014-08-26 13:16:35 -040043
44 // Check for quit message
45 Event myEvent;
46 while (mOSWindow->popEvent(&myEvent))
47 {
48 if (myEvent.Type == Event::EVENT_CLOSED)
49 {
50 exit(0);
51 }
52 }
Geoff Lang8a079e52013-10-18 16:13:33 -040053}
54
55void ANGLETest::swapBuffers()
56{
Jamie Madill77a72f62015-04-14 11:18:32 -040057 if (mEGLWindow->isGLInitialized())
58 {
59 mEGLWindow->swap();
60 }
Geoff Lang8a079e52013-10-18 16:13:33 -040061}
62
Austin Kinross4fd18b12014-12-22 12:32:05 -080063void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale)
Geoff Lang8a079e52013-10-18 16:13:33 -040064{
65 GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
66
67 glUseProgram(program);
68
69 const GLfloat vertices[] =
70 {
Austin Kinross4fd18b12014-12-22 12:32:05 -080071 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
72 -1.0f * quadScale, -1.0f * quadScale, quadDepth,
73 1.0f * quadScale, -1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040074
Austin Kinross4fd18b12014-12-22 12:32:05 -080075 -1.0f * quadScale, 1.0f * quadScale, quadDepth,
76 1.0f * quadScale, -1.0f * quadScale, quadDepth,
77 1.0f * quadScale, 1.0f * quadScale, quadDepth,
Geoff Lang8a079e52013-10-18 16:13:33 -040078 };
79
80 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
81 glEnableVertexAttribArray(positionLocation);
82
83 glDrawArrays(GL_TRIANGLES, 0, 6);
84
85 glDisableVertexAttribArray(positionLocation);
86 glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
87
88 glUseProgram(0);
89}
90
Geoff Langefc551f2013-10-31 10:20:28 -040091GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
92{
93 GLuint shader = glCreateShader(type);
94
95 const char *sourceArray[1] = { source.c_str() };
96 glShaderSource(shader, 1, sourceArray, NULL);
97 glCompileShader(shader);
98
99 GLint compileResult;
100 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
101
102 if (compileResult == 0)
103 {
104 GLint infoLogLength;
105 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
106
107 std::vector<GLchar> infoLog(infoLogLength);
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400108 glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
Geoff Langefc551f2013-10-31 10:20:28 -0400109
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400110 std::cerr << "shader compilation failed: " << &infoLog[0];
Geoff Langefc551f2013-10-31 10:20:28 -0400111
112 glDeleteShader(shader);
113 shader = 0;
114 }
115
116 return shader;
117}
118
Geoff Lang8a079e52013-10-18 16:13:33 -0400119bool ANGLETest::extensionEnabled(const std::string &extName)
120{
121 const char* extString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
122 return strstr(extString, extName.c_str()) != NULL;
123}
124
Geoff Lang8a079e52013-10-18 16:13:33 -0400125void ANGLETest::setWindowWidth(int width)
126{
Jamie Madill62af5462014-08-26 13:16:37 -0400127 mEGLWindow->setWidth(width);
Geoff Lang8a079e52013-10-18 16:13:33 -0400128}
129
130void ANGLETest::setWindowHeight(int height)
131{
Jamie Madill62af5462014-08-26 13:16:37 -0400132 mEGLWindow->setHeight(height);
Geoff Lang8a079e52013-10-18 16:13:33 -0400133}
134
Geoff Langefc551f2013-10-31 10:20:28 -0400135void ANGLETest::setConfigRedBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400136{
Jamie Madill62af5462014-08-26 13:16:37 -0400137 mEGLWindow->setConfigRedBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400138}
139
Geoff Langefc551f2013-10-31 10:20:28 -0400140void ANGLETest::setConfigGreenBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400141{
Jamie Madill62af5462014-08-26 13:16:37 -0400142 mEGLWindow->setConfigGreenBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400143}
144
Geoff Langefc551f2013-10-31 10:20:28 -0400145void ANGLETest::setConfigBlueBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400146{
Jamie Madill62af5462014-08-26 13:16:37 -0400147 mEGLWindow->setConfigBlueBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400148}
149
Geoff Langefc551f2013-10-31 10:20:28 -0400150void ANGLETest::setConfigAlphaBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400151{
Jamie Madill62af5462014-08-26 13:16:37 -0400152 mEGLWindow->setConfigAlphaBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400153}
154
Geoff Langefc551f2013-10-31 10:20:28 -0400155void ANGLETest::setConfigDepthBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400156{
Jamie Madill62af5462014-08-26 13:16:37 -0400157 mEGLWindow->setConfigDepthBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400158}
159
Geoff Langefc551f2013-10-31 10:20:28 -0400160void ANGLETest::setConfigStencilBits(int bits)
Geoff Lang8a079e52013-10-18 16:13:33 -0400161{
Jamie Madill62af5462014-08-26 13:16:37 -0400162 mEGLWindow->setConfigStencilBits(bits);
Geoff Lang8a079e52013-10-18 16:13:33 -0400163}
164
165void ANGLETest::setMultisampleEnabled(bool enabled)
166{
Jamie Madill62af5462014-08-26 13:16:37 -0400167 mEGLWindow->setMultisample(enabled);
Geoff Lang8a079e52013-10-18 16:13:33 -0400168}
169
170int ANGLETest::getClientVersion() const
171{
Jamie Madill62af5462014-08-26 13:16:37 -0400172 return mEGLWindow->getClientVersion();
Geoff Lang8a079e52013-10-18 16:13:33 -0400173}
174
Geoff Langb9266272015-01-29 13:25:14 +0000175EGLWindow *ANGLETest::getEGLWindow() const
176{
177 return mEGLWindow;
178}
179
Geoff Lang8a079e52013-10-18 16:13:33 -0400180int ANGLETest::getWindowWidth() const
181{
Jamie Madill62af5462014-08-26 13:16:37 -0400182 return mEGLWindow->getWidth();
Geoff Lang8a079e52013-10-18 16:13:33 -0400183}
184
185int ANGLETest::getWindowHeight() const
186{
Jamie Madill62af5462014-08-26 13:16:37 -0400187 return mEGLWindow->getHeight();
Geoff Lang8a079e52013-10-18 16:13:33 -0400188}
189
Geoff Langefc551f2013-10-31 10:20:28 -0400190bool ANGLETest::isMultisampleEnabled() const
Geoff Lang8a079e52013-10-18 16:13:33 -0400191{
Jamie Madill62af5462014-08-26 13:16:37 -0400192 return mEGLWindow->isMultisample();
Geoff Lang8a079e52013-10-18 16:13:33 -0400193}
194
195bool ANGLETest::createEGLContext()
196{
Jamie Madill62af5462014-08-26 13:16:37 -0400197 return mEGLWindow->initializeGL(mOSWindow);
Geoff Lang8a079e52013-10-18 16:13:33 -0400198}
199
200bool ANGLETest::destroyEGLContext()
201{
Jamie Madill62af5462014-08-26 13:16:37 -0400202 mEGLWindow->destroyGL();
Geoff Lang8a079e52013-10-18 16:13:33 -0400203 return true;
204}
Geoff Langbb134672013-10-23 13:06:46 -0400205
Geoff Lang0d3683c2014-10-23 11:08:16 -0400206bool ANGLETest::InitTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400207{
208 mOSWindow = CreateOSWindow();
209 if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
210 {
211 return false;
212 }
213
Geoff Lang0d3683c2014-10-23 11:08:16 -0400214 mOSWindow->setVisible(true);
Jamie Madill8add0eb2014-08-26 13:16:35 -0400215
216 return true;
217}
218
Geoff Lang0d3683c2014-10-23 11:08:16 -0400219bool ANGLETest::DestroyTestWindow()
Jamie Madill8add0eb2014-08-26 13:16:35 -0400220{
221 if (mOSWindow)
222 {
223 mOSWindow->destroy();
224 delete mOSWindow;
225 mOSWindow = NULL;
226 }
227
228 return true;
229}
230
Geoff Lang0d3683c2014-10-23 11:08:16 -0400231bool ANGLETest::ResizeWindow(int width, int height)
Jamie Madill8add0eb2014-08-26 13:16:35 -0400232{
233 return mOSWindow->resize(width, height);
234}
235
Geoff Lang0d3683c2014-10-23 11:08:16 -0400236void ANGLETest::SetWindowVisible(bool isVisible)
Geoff Langbb134672013-10-23 13:06:46 -0400237{
Jamie Madill4119ed32014-10-01 10:41:40 -0400238 mOSWindow->setVisible(isVisible);
Geoff Langbb134672013-10-23 13:06:46 -0400239}
Geoff Lang0d3683c2014-10-23 11:08:16 -0400240
Jamie Madillc3b9b262015-01-30 14:00:51 -0500241bool ANGLETest::isIntel() const
242{
243 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
244 return (rendererString.find("Intel") != std::string::npos);
245}
246
247bool ANGLETest::isAMD() const
248{
249 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
250 return (rendererString.find("AMD") != std::string::npos) ||
251 (rendererString.find("ATI") != std::string::npos);
252}
253
254bool ANGLETest::isNVidia() const
255{
256 std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
257 return (rendererString.find("NVIDIA") != std::string::npos);
258}
259
260EGLint ANGLETest::getPlatformRenderer() const
261{
Jamie Madillf6859912015-01-30 17:05:35 -0500262 assert(mEGLWindow);
263 return mEGLWindow->getPlatform().renderer;
Jamie Madillc3b9b262015-01-30 14:00:51 -0500264}
265
Geoff Lang0d3683c2014-10-23 11:08:16 -0400266OSWindow *ANGLETest::mOSWindow = NULL;
267
268void ANGLETestEnvironment::SetUp()
269{
270 if (!ANGLETest::InitTestWindow())
271 {
272 FAIL() << "Failed to create ANGLE test window.";
273 }
274}
275
276void ANGLETestEnvironment::TearDown()
277{
278 ANGLETest::DestroyTestWindow();
279}