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

@@ -20,7 +20,7 @@ m_startIndex(startIndex)
{
#ifdef NAZARA_DEBUG
nzUInt8 indexSize = m_buffer->GetSize();
if (indexSize != 1 && indexSize != 2 && indexSize != 4)
if (indexSize != 2 && indexSize != 4)
{
NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')');
m_buffer = nullptr;
@@ -33,22 +33,12 @@ m_startIndex(startIndex)
}
}
NzIndexBuffer::NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferStorage storage, nzBufferUsage usage) :
NzIndexBuffer::NzIndexBuffer(unsigned int length, bool largeIndices, nzBufferStorage storage, nzBufferUsage usage) :
m_ownsBuffer(true),
m_indexCount(length),
m_startIndex(0)
{
#ifdef NAZARA_DEBUG
if (indexSize != 1 && indexSize != 2 && indexSize != 4)
{
NazaraError("Invalid index size");
m_buffer = nullptr;
throw std::runtime_error("Constructor failed");
}
#endif
m_buffer = new NzBuffer(nzBufferType_Index, length, indexSize, storage, usage);
m_buffer = new NzBuffer(nzBufferType_Index, length, (largeIndices) ? 4 : 2, storage, usage);
m_buffer->AddResourceReference();
m_buffer->SetPersistent(false);
}
@@ -109,19 +99,6 @@ NzBuffer* NzIndexBuffer::GetBuffer() const
return m_buffer;
}
nzUInt8 NzIndexBuffer::GetIndexSize() const
{
#if NAZARA_UTILITY_SAFE
if (!m_buffer)
{
NazaraError("Sequential buffers have no index size");
return 0;
}
#endif
return m_buffer->GetTypeSize();
}
void* NzIndexBuffer::GetPointer()
{
#if NAZARA_UTILITY_SAFE
@@ -158,6 +135,19 @@ unsigned int NzIndexBuffer::GetStartIndex() const
return m_startIndex;
}
bool NzIndexBuffer::HasLargeIndices() const
{
#if NAZARA_UTILITY_SAFE
if (!m_buffer)
{
NazaraError("Sequential buffers have no index size");
return 0;
}
#endif
return (m_buffer->GetTypeSize() == 4);
}
bool NzIndexBuffer::IsHardware() const
{
#if NAZARA_UTILITY_SAFE