Hash :
d55d283c
Author :
Date :
2015-10-27T13:59:19
Add a test for flat shader 'provoking vertex'. The provoking vertex, or leading vertex, is the vertex in a triangle which produces the value that gets used for a flat-shaded triangle. Flat shading means the same value gets used for the entire triangle. It seems as though D3D and OpenGL have different definitions of which vertex is the leading/provoking one; GL says it is the *last* vertex of a primitive, while while D3D says it is the first. Additional complexity comes about from triangle strips, which switch winding order, and primitive restart, which defines new primitives in the middle of prior primitives. BUG=angleproject:754 Change-Id: If1217cba33dabf3b1e4ad13fd639d049cb16fe44 Reviewed-on: https://chromium-review.googlesource.com/309152 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
#include "ANGLETest.h"
#include "EGLWindow.h"
#include "OSWindow.h"
ANGLETest::ANGLETest()
: mEGLWindow(nullptr),
mWidth(16),
mHeight(16)
{
mEGLWindow =
new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
}
ANGLETest::~ANGLETest()
{
SafeDelete(mEGLWindow);
}
void ANGLETest::SetUp()
{
// Resize the window before creating the context so that the first make current
// sets the viewport and scissor box to the right size.
bool needSwap = false;
if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
{
if (!mOSWindow->resize(mWidth, mHeight))
{
FAIL() << "Failed to resize ANGLE test window.";
}
needSwap = true;
}
if (!createEGLContext())
{
FAIL() << "egl context creation failed.";
}
if (needSwap)
{
// Swap the buffers so that the default framebuffer picks up the resize
// which will allow follow-up test code to assume the framebuffer covers
// the whole window.
swapBuffers();
}
// This Viewport command is not strictly necessary but we add it so that programs
// taking OpenGL traces can guess the size of the default framebuffer and show it
// in their UIs
glViewport(0, 0, mWidth, mHeight);
}
void ANGLETest::TearDown()
{
swapBuffers();
mOSWindow->messageLoop();
if (!destroyEGLContext())
{
FAIL() << "egl context destruction failed.";
}
// Check for quit message
Event myEvent;
while (mOSWindow->popEvent(&myEvent))
{
if (myEvent.Type == Event::EVENT_CLOSED)
{
exit(0);
}
}
}
void ANGLETest::swapBuffers()
{
if (mEGLWindow->isGLInitialized())
{
mEGLWindow->swap();
}
}
void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale)
{
GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
glUseProgram(program);
const GLfloat vertices[] =
{
-1.0f * quadScale, 1.0f * quadScale, quadDepth,
-1.0f * quadScale, -1.0f * quadScale, quadDepth,
1.0f * quadScale, -1.0f * quadScale, quadDepth,
-1.0f * quadScale, 1.0f * quadScale, quadDepth,
1.0f * quadScale, -1.0f * quadScale, quadDepth,
1.0f * quadScale, 1.0f * quadScale, quadDepth,
};
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
glUseProgram(0);
}
GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
{
GLuint shader = glCreateShader(type);
const char *sourceArray[1] = { source.c_str() };
glShaderSource(shader, 1, sourceArray, NULL);
glCompileShader(shader);
GLint compileResult;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
if (compileResult == 0)
{
GLint infoLogLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
if (infoLogLength == 0)
{
std::cerr << "shader compilation failed with empty log." << std::endl;
}
else
{
std::vector<GLchar> infoLog(infoLogLength);
glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
std::cerr << "shader compilation failed: " << &infoLog[0];
}
glDeleteShader(shader);
shader = 0;
}
return shader;
}
static bool checkExtensionExists(const char *allExtensions, const std::string &extName)
{
return strstr(allExtensions, extName.c_str()) != nullptr;
}
bool ANGLETest::extensionEnabled(const std::string &extName)
{
return checkExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
extName);
}
bool ANGLETest::eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
{
return checkExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
}
bool ANGLETest::eglClientExtensionEnabled(const std::string &extName)
{
return checkExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
}
void ANGLETest::setWindowWidth(int width)
{
mWidth = width;
}
void ANGLETest::setWindowHeight(int height)
{
mHeight = height;
}
void ANGLETest::setConfigRedBits(int bits)
{
mEGLWindow->setConfigRedBits(bits);
}
void ANGLETest::setConfigGreenBits(int bits)
{
mEGLWindow->setConfigGreenBits(bits);
}
void ANGLETest::setConfigBlueBits(int bits)
{
mEGLWindow->setConfigBlueBits(bits);
}
void ANGLETest::setConfigAlphaBits(int bits)
{
mEGLWindow->setConfigAlphaBits(bits);
}
void ANGLETest::setConfigDepthBits(int bits)
{
mEGLWindow->setConfigDepthBits(bits);
}
void ANGLETest::setConfigStencilBits(int bits)
{
mEGLWindow->setConfigStencilBits(bits);
}
void ANGLETest::setMultisampleEnabled(bool enabled)
{
mEGLWindow->setMultisample(enabled);
}
int ANGLETest::getClientVersion() const
{
return mEGLWindow->getClientMajorVersion();
}
EGLWindow *ANGLETest::getEGLWindow() const
{
return mEGLWindow;
}
int ANGLETest::getWindowWidth() const
{
return mWidth;
}
int ANGLETest::getWindowHeight() const
{
return mHeight;
}
bool ANGLETest::isMultisampleEnabled() const
{
return mEGLWindow->isMultisample();
}
bool ANGLETest::createEGLContext()
{
return mEGLWindow->initializeGL(mOSWindow);
}
bool ANGLETest::destroyEGLContext()
{
mEGLWindow->destroyGL();
return true;
}
bool ANGLETest::InitTestWindow()
{
mOSWindow = CreateOSWindow();
if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
{
return false;
}
mOSWindow->setVisible(true);
return true;
}
bool ANGLETest::DestroyTestWindow()
{
if (mOSWindow)
{
mOSWindow->destroy();
delete mOSWindow;
mOSWindow = NULL;
}
return true;
}
void ANGLETest::SetWindowVisible(bool isVisible)
{
mOSWindow->setVisible(isVisible);
}
bool ANGLETest::isIntel() const
{
std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
return (rendererString.find("Intel") != std::string::npos);
}
bool ANGLETest::isAMD() const
{
std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
return (rendererString.find("AMD") != std::string::npos) ||
(rendererString.find("ATI") != std::string::npos);
}
bool ANGLETest::isNVidia() const
{
std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
return (rendererString.find("NVIDIA") != std::string::npos);
}
bool ANGLETest::isD3D11() const
{
std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
}
EGLint ANGLETest::getPlatformRenderer() const
{
assert(mEGLWindow);
return mEGLWindow->getPlatform().renderer;
}
OSWindow *ANGLETest::mOSWindow = NULL;
void ANGLETestEnvironment::SetUp()
{
if (!ANGLETest::InitTestWindow())
{
FAIL() << "Failed to create ANGLE test window.";
}
}
void ANGLETestEnvironment::TearDown()
{
ANGLETest::DestroyTestWindow();
}