Index buffer no longer permit 8 bits index size

Modern graphics cards don't like 8 bits index size, so I introduced
"Large indices" option, it means 32 bits indices when used otherwise the
index size is 16 bits


Former-commit-id: 213902de6704ceef16c6ea311ba0c6c5d2f6e665
This commit is contained in:
Lynix
2012-12-02 17:01:02 +01:00
parent 437c7047c9
commit b06acfcffd
4 changed files with 68 additions and 137 deletions

View File

@@ -187,29 +187,20 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
glDrawArrays(NzOpenGL::PrimitiveType[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount());
else
{
nzUInt8 indexSize = s_indexBuffer->GetIndexSize();
GLenum type;
switch (indexSize)
const nzUInt8* ptr = reinterpret_cast<const nzUInt8*>(s_indexBuffer->GetPointer());
if (s_indexBuffer->HasLargeIndices())
{
case 1:
type = GL_UNSIGNED_BYTE;
break;
case 2:
type = GL_UNSIGNED_SHORT;
break;
case 4:
type = GL_UNSIGNED_INT;
break;
default:
NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')');
return;
ptr += firstIndex*sizeof(nzUInt32);
type = GL_UNSIGNED_INT;
}
else
{
ptr += firstIndex*sizeof(nzUInt16);
type = GL_UNSIGNED_SHORT;
}
glDrawElements(NzOpenGL::PrimitiveType[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(s_indexBuffer->GetPointer()) + firstIndex*indexSize);
glDrawElements(NzOpenGL::PrimitiveType[primitive], indexCount, type, ptr);
}
}