Hash :
f8c2f5cb
Author :
Date :
2013-12-05T13:52:33
Fix indices not being offset to the bound vertex buffer when drawing indexed points in D3D9. bug=angle:535 Change-Id: I5b86874cddbd3b90fe141e94085f5a4afb9f3db3 Reviewed-on: https://chromium-review.googlesource.com/179101 Reviewed-by: Shannon Woods <shannonwoods@chromium.org> Tested-by: Shannon Woods <shannonwoods@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
#include "ANGLETest.h"
#include <array>
template <typename IndexType, GLenum IndexTypeName>
class IndexedPointsTest : public ANGLETest
{
protected:
IndexedPointsTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
float getIndexPositionX(size_t idx)
{
return (idx == 0 || idx == 3) ? -0.5f : 0.5f;
}
float getIndexPositionY(size_t idx)
{
return (idx == 2 || idx == 3) ? -0.5f : 0.5f;
}
virtual void SetUp()
{
ANGLETest::SetUp();
const std::string vertexShaderSource = SHADER_SOURCE
(
precision highp float;
attribute vec2 position;
void main()
{
gl_PointSize = 5.0;
gl_Position = vec4(position, 0.0, 1.0);
}
);
const std::string fragmentShaderSource = SHADER_SOURCE
(
precision highp float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
);
mProgram = compileProgram(vertexShaderSource, fragmentShaderSource);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
std::array<GLfloat, mPointCount * 2> vertices =
{
getIndexPositionX(0), getIndexPositionY(0),
getIndexPositionX(1), getIndexPositionY(1),
getIndexPositionX(2), getIndexPositionY(2),
getIndexPositionX(3), getIndexPositionY(3),
};
glGenBuffers(1, &mVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), vertices.data(), GL_STATIC_DRAW);
std::array<IndexType, mPointCount> indices = { 0, 1, 2, 3 };
glGenBuffers(1, &mIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(IndexType), indices.data(), GL_STATIC_DRAW);
}
virtual void TearDown()
{
glDeleteProgram(mProgram);
ANGLETest::TearDown();
}
void runTest(GLuint firstIndex)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
GLint viewportSize[4];
glGetIntegerv(GL_VIEWPORT, viewportSize);
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
GLint vertexLocation = glGetAttribLocation(mProgram, "position");
glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(vertexLocation);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glUseProgram(mProgram);
glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
for (size_t i = 0; i < mPointCount; i++)
{
GLuint x = viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) * (viewportSize[2] - viewportSize[0]);
GLuint y = viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) * (viewportSize[3] - viewportSize[1]);
if (i < firstIndex)
{
EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
}
else
{
EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
}
}
}
GLuint mProgram;
GLuint mVertexBuffer;
GLuint mIndexBuffer;
static const GLuint mPointCount = 4;
};
typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
TEST_F(IndexedPointsTestUByte, unsigned_byte_offset_0)
{
runTest(0);
}
TEST_F(IndexedPointsTestUByte, unsigned_byte_offset_1)
{
runTest(1);
}
TEST_F(IndexedPointsTestUByte, unsigned_byte_offset_2)
{
runTest(2);
}
TEST_F(IndexedPointsTestUByte, unsigned_byte_offset_3)
{
runTest(3);
}
typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
TEST_F(IndexedPointsTestUShort, unsigned_short_offset_0)
{
runTest(0);
}
TEST_F(IndexedPointsTestUShort, unsigned_short_offset_1)
{
runTest(1);
}
TEST_F(IndexedPointsTestUShort, unsigned_short_offset_2)
{
runTest(2);
}
TEST_F(IndexedPointsTestUShort, unsigned_short_offset_3)
{
runTest(3);
}
typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
TEST_F(IndexedPointsTestUInt, unsigned_int_offset_0)
{
if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
{
return;
}
runTest(0);
}
TEST_F(IndexedPointsTestUInt, unsigned_int_offset_1)
{
if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
{
return;
}
runTest(1);
}
TEST_F(IndexedPointsTestUInt, unsigned_int_offset_2)
{
if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
{
return;
}
runTest(2);
}
TEST_F(IndexedPointsTestUInt, unsigned_int_offset_3)
{
if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
{
return;
}
runTest(3);
}