Re-implemented line loop support.

TRAC #14870 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@530 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent ee04e455
...@@ -2599,10 +2599,15 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -2599,10 +2599,15 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
display->startScene(); display->startScene();
device->DrawPrimitive(primitiveType, 0, primitiveCount); device->DrawPrimitive(primitiveType, 0, primitiveCount);
if (mode == GL_LINE_LOOP) // Draw the last segment separately
{
drawClosingLine(first, first + count - 1);
}
} }
} }
void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
{ {
if (!mState.currentProgram) if (!mState.currentProgram)
{ {
...@@ -2659,7 +2664,13 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* ...@@ -2659,7 +2664,13 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void*
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
display->startScene(); display->startScene();
device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, primitiveCount); device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, primitiveCount);
if (mode == GL_LINE_LOOP) // Draw the last segment separately
{
drawClosingLine(count, type, indices);
}
} }
} }
...@@ -2742,6 +2753,93 @@ void Context::flush() ...@@ -2742,6 +2753,93 @@ void Context::flush()
} }
} }
void Context::drawClosingLine(unsigned int first, unsigned int last)
{
IDirect3DDevice9 *device = getDevice();
IDirect3DIndexBuffer9 *indexBuffer = NULL;
HRESULT result = D3DERR_INVALIDCALL;
if (supports32bitIndices())
{
result = device->CreateIndexBuffer(8, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &indexBuffer, 0);
if (SUCCEEDED(result))
{
unsigned int *data;
result = indexBuffer->Lock(0, 0, (void**)&data, 0);
if (SUCCEEDED(result))
{
data[0] = last;
data[1] = first;
}
}
}
else
{
result = device->CreateIndexBuffer(4, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, 0);
if (SUCCEEDED(result))
{
unsigned short *data;
result = indexBuffer->Lock(0, 0, (void**)&data, 0);
if (SUCCEEDED(result))
{
data[0] = last;
data[1] = first;
}
}
}
if (SUCCEEDED(result))
{
indexBuffer->Unlock();
device->SetIndices(indexBuffer);
device->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, 2, 0, 1);
indexBuffer->Release();
}
else
{
ERR("Could not create an index buffer for closing a line loop.");
error(GL_OUT_OF_MEMORY);
}
}
void Context::drawClosingLine(GLsizei count, GLenum type, const void *indices)
{
unsigned int first = 0;
unsigned int last = 0;
if (mState.elementArrayBuffer.get())
{
Buffer *indexBuffer = mState.elementArrayBuffer.get();
intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset;
}
switch (type)
{
case GL_UNSIGNED_BYTE:
first = static_cast<const GLubyte*>(indices)[0];
last = static_cast<const GLubyte*>(indices)[count - 1];
break;
case GL_UNSIGNED_SHORT:
first = static_cast<const GLushort*>(indices)[0];
last = static_cast<const GLushort*>(indices)[count - 1];
break;
case GL_UNSIGNED_INT:
first = static_cast<const GLuint*>(indices)[0];
last = static_cast<const GLuint*>(indices)[count - 1];
break;
default: UNREACHABLE();
}
drawClosingLine(first, last);
}
void Context::recordInvalidEnum() void Context::recordInvalidEnum()
{ {
mInvalidEnum = true; mInvalidEnum = true;
......
...@@ -390,10 +390,14 @@ class Context ...@@ -390,10 +390,14 @@ class Context
void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels); void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels);
void clear(GLbitfield mask); void clear(GLbitfield mask);
void drawArrays(GLenum mode, GLint first, GLsizei count); void drawArrays(GLenum mode, GLint first, GLsizei count);
void drawElements(GLenum mode, GLsizei count, GLenum type, const void* indices); void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
void finish(); void finish();
void flush(); void flush();
// Draw the last segment of a line loop
void drawClosingLine(unsigned int first, unsigned int last);
void drawClosingLine(GLsizei count, GLenum type, const void *indices);
void recordInvalidEnum(); void recordInvalidEnum();
void recordInvalidValue(); void recordInvalidValue();
void recordInvalidOperation(); void recordInvalidOperation();
......
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