Commit f8c2f5cb by Geoff Lang

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/179101Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent 86f601cb
...@@ -1475,7 +1475,7 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo ...@@ -1475,7 +1475,7 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo
if (mode == GL_POINTS) if (mode == GL_POINTS)
{ {
drawIndexedPoints(count, type, indices, elementArrayBuffer); drawIndexedPoints(count, type, indices, indexInfo.minIndex, elementArrayBuffer);
} }
else if (mode == GL_LINE_LOOP) else if (mode == GL_LINE_LOOP)
{ {
...@@ -1679,16 +1679,16 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1679,16 +1679,16 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
} }
template <typename T> template <typename T>
static void drawPoints(IDirect3DDevice9* device, GLsizei count, const GLvoid *indices) static void drawPoints(IDirect3DDevice9* device, GLsizei count, const GLvoid *indices, int minIndex)
{ {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
unsigned int indexValue = static_cast<unsigned int>(static_cast<const T*>(indices)[i]); unsigned int indexValue = static_cast<unsigned int>(static_cast<const T*>(indices)[i]) - minIndex;
device->DrawPrimitive(D3DPT_POINTLIST, indexValue, 1); device->DrawPrimitive(D3DPT_POINTLIST, indexValue, 1);
} }
} }
void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer) void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer)
{ {
// Drawing index point lists is unsupported in d3d9, fall back to a regular DrawPrimitive call // Drawing index point lists is unsupported in d3d9, fall back to a regular DrawPrimitive call
// for each individual point. This call is not expected to happen often. // for each individual point. This call is not expected to happen often.
...@@ -1702,9 +1702,9 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi ...@@ -1702,9 +1702,9 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi
switch (type) switch (type)
{ {
case GL_UNSIGNED_BYTE: drawPoints<GLubyte>(mDevice, count, indices); break; case GL_UNSIGNED_BYTE: drawPoints<GLubyte>(mDevice, count, indices, minIndex); break;
case GL_UNSIGNED_SHORT: drawPoints<GLushort>(mDevice, count, indices); break; case GL_UNSIGNED_SHORT: drawPoints<GLushort>(mDevice, count, indices, minIndex); break;
case GL_UNSIGNED_INT: drawPoints<GLuint>(mDevice, count, indices); break; case GL_UNSIGNED_INT: drawPoints<GLuint>(mDevice, count, indices, minIndex); break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
......
...@@ -241,7 +241,7 @@ class Renderer9 : public Renderer ...@@ -241,7 +241,7 @@ class Renderer9 : public Renderer
void applyUniformnbv(gl::Uniform *targetUniform, const GLint *v); void applyUniformnbv(gl::Uniform *targetUniform, const GLint *v);
void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer); void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged); bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
gl::Renderbuffer *getNullColorbuffer(gl::Renderbuffer *depthbuffer); gl::Renderbuffer *getNullColorbuffer(gl::Renderbuffer *depthbuffer);
......
#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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment