Hash :
a56a86e6
Author :
Date :
2014-04-22T13:14:06
Update the VertexAttribute test expectations. When we switched from converting 8-bit normalized signed int from a full 32-bit float expansion to a 4-channel 8-bit format, we broke an ANGLE test. Giving the test a slightly looser bound produces the correct output, due to floating point rounding. BUG=angle:612 Change-Id: I8781e6efe83341e22d31d35b35e0048889bcd540 Reviewed-on: https://chromium-review.googlesource.com/196532 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shannon Woods <shannonwoods@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
#include "ANGLETest.h"
class VertexAttributeTest : public ANGLETest
{
protected:
VertexAttributeTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
mProgram = 0;
mTestAttrib = -1;
mExpectedAttrib = -1;
}
struct TestData
{
GLenum type;
GLboolean normalized;
const void *inputData;
const GLfloat *expectedData;
};
void runTest(const TestData& test)
{
GLint viewportSize[4];
glGetIntegerv(GL_VIEWPORT, viewportSize);
GLint midPixelX = (viewportSize[0] + viewportSize[2]) / 2;
GLint midPixelY = (viewportSize[1] + viewportSize[3]) / 2;
for (size_t i = 0; i < 4; i++)
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(mTestAttrib, i + 1, test.type, test.normalized, 0, test.inputData);
glVertexAttribPointer(mExpectedAttrib, i + 1, GL_FLOAT, GL_FALSE, 0, test.expectedData);
glEnableVertexAttribArray(mTestAttrib);
glEnableVertexAttribArray(mExpectedAttrib);
drawQuad(mProgram, "position", 0.5f);
glDisableVertexAttribArray(mTestAttrib);
glDisableVertexAttribArray(mExpectedAttrib);
// We need to offset our checks from triangle edges to ensure we don't fall on a single tri
// Avoid making assumptions of drawQuad with four checks to check the four possible tri regions
EXPECT_PIXEL_EQ((midPixelX + viewportSize[0]) / 2, midPixelY, 255, 255, 255, 255);
EXPECT_PIXEL_EQ((midPixelX + viewportSize[2]) / 2, midPixelY, 255, 255, 255, 255);
EXPECT_PIXEL_EQ(midPixelX, (midPixelY + viewportSize[1]) / 2, 255, 255, 255, 255);
EXPECT_PIXEL_EQ(midPixelX, (midPixelY + viewportSize[3]) / 2, 255, 255, 255, 255);
}
}
virtual void SetUp()
{
ANGLETest::SetUp();
const std::string testVertexShaderSource = SHADER_SOURCE
(
attribute highp vec4 position;
attribute highp vec4 test;
attribute highp vec4 expected;
varying highp vec4 color;
void main(void)
{
gl_Position = position;
color = vec4(lessThan(abs(test - expected), vec4(1.0 / 64.0)));
}
);
const std::string testFragmentShaderSource = SHADER_SOURCE
(
varying highp vec4 color;
void main(void)
{
gl_FragColor = color;
}
);
mProgram = compileProgram(testVertexShaderSource, testFragmentShaderSource);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
mTestAttrib = glGetAttribLocation(mProgram, "test");
mExpectedAttrib = glGetAttribLocation(mProgram, "expected");
glUseProgram(mProgram);
glClearColor(0, 0, 0, 0);
glClearDepthf(0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
}
virtual void TearDown()
{
glDeleteProgram(mProgram);
ANGLETest::TearDown();
}
static const size_t mVertexCount = 24;
GLuint mProgram;
GLint mTestAttrib;
GLint mExpectedAttrib;
};
TEST_F(VertexAttributeTest, unsigned_byte_unormalized)
{
GLubyte inputData[mVertexCount] = { 0, 1, 2, 3, 4, 5, 6, 7, 125, 126, 127, 128, 129, 250, 251, 252, 253, 254, 255 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = inputData[i];
}
TestData data = { GL_UNSIGNED_BYTE, GL_FALSE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, unsigned_byte_normalized)
{
GLubyte inputData[mVertexCount] = { 0, 1, 2, 3, 4, 5, 6, 7, 125, 126, 127, 128, 129, 250, 251, 252, 253, 254, 255 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = inputData[i] / 255.0f;
}
TestData data = { GL_UNSIGNED_BYTE, GL_TRUE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, byte_unnormalized)
{
GLbyte inputData[mVertexCount] = { 0, 1, 2, 3, 4, -1, -2, -3, -4, 125, 126, 127, -128, -127, -126 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = inputData[i];
}
TestData data = { GL_BYTE, GL_FALSE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, byte_normalized)
{
GLbyte inputData[mVertexCount] = { 0, 1, 2, 3, 4, -1, -2, -3, -4, 125, 126, 127, -128, -127, -126 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = ((2.0f * inputData[i]) + 1.0f) / 255.0f;
}
TestData data = { GL_BYTE, GL_TRUE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, unsigned_short_unormalized)
{
GLushort inputData[mVertexCount] = { 0, 1, 2, 3, 254, 255, 256, 32766, 32767, 32768, 65533, 65534, 65535 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = inputData[i];
}
TestData data = { GL_UNSIGNED_SHORT, GL_FALSE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, unsigned_short_normalized)
{
GLushort inputData[mVertexCount] = { 0, 1, 2, 3, 254, 255, 256, 32766, 32767, 32768, 65533, 65534, 65535 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = inputData[i] / 65535.0f;
}
TestData data = { GL_UNSIGNED_SHORT, GL_TRUE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, short_unnormalized)
{
GLshort inputData[mVertexCount] = { 0, 1, 2, 3, -1, -2, -3, -4, 32766, 32767, -32768, -32767, -32766 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = inputData[i];
}
TestData data = { GL_SHORT, GL_FALSE, inputData, expectedData };
runTest(data);
}
TEST_F(VertexAttributeTest, short_normalized)
{
GLshort inputData[mVertexCount] = { 0, 1, 2, 3, -1, -2, -3, -4, 32766, 32767, -32768, -32767, -32766 };
GLfloat expectedData[mVertexCount];
for (size_t i = 0; i < mVertexCount; i++)
{
expectedData[i] = ((2.0f * inputData[i]) + 1.0f) / 65535.0f;
}
TestData data = { GL_SHORT, GL_TRUE, inputData, expectedData };
runTest(data);
}