Added VertexDeclaration::HasElement

Former-commit-id: 30dccfba56bba0e56c08da79c3fde3bdf94119cb
This commit is contained in:
Lynix 2012-10-04 09:33:54 +02:00
parent 7bab3d9443
commit 10fc386865
2 changed files with 50 additions and 0 deletions

View File

@ -2,6 +2,8 @@
// This file is part of the "Nazara Engine - Utility module" // This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VERTEXDECLARATION_HPP #ifndef NAZARA_VERTEXDECLARATION_HPP
#define NAZARA_VERTEXDECLARATION_HPP #define NAZARA_VERTEXDECLARATION_HPP
@ -39,6 +41,9 @@ class NAZARA_API NzVertexDeclaration : public NzResource
unsigned int GetElementCount(nzElementStream stream) const; unsigned int GetElementCount(nzElementStream stream) const;
unsigned int GetStride(nzElementStream stream) const; unsigned int GetStride(nzElementStream stream) const;
bool HasElement(unsigned int i) const;
bool HasElement(nzElementStream stream, unsigned int i) const;
bool HasElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const;
bool HasStream(nzElementStream stream) const; bool HasStream(nzElementStream stream) const;
bool IsValid() const; bool IsValid() const;

View File

@ -244,16 +244,34 @@ const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, n
#endif #endif
int elementPos = m_sharedImpl->elementPos[stream][usage]; int elementPos = m_sharedImpl->elementPos[stream][usage];
#if NAZARA_UTILITY_SAFE
if (elementPos == -1) if (elementPos == -1)
{
NazaraError("Element not found");
return nullptr; return nullptr;
}
#endif
elementPos += usageIndex; elementPos += usageIndex;
#if NAZARA_UTILITY_SAFE
if (static_cast<unsigned int>(elementPos) >= m_sharedImpl->elements.size()) if (static_cast<unsigned int>(elementPos) >= m_sharedImpl->elements.size())
{
NazaraError("Element not found");
return nullptr; return nullptr;
}
#endif
NzVertexElement& element = m_sharedImpl->elements[elementPos]; NzVertexElement& element = m_sharedImpl->elements[elementPos];
#if NAZARA_UTILITY_SAFE
if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex)
{
NazaraError("Element not found");
return nullptr; return nullptr;
}
#endif
return &element; return &element;
} }
@ -318,6 +336,33 @@ unsigned int NzVertexDeclaration::GetStride(nzElementStream stream) const
return m_sharedImpl->stride[stream]; return m_sharedImpl->stride[stream];
} }
bool NzVertexDeclaration::HasElement(unsigned int i) const
{
return i < m_sharedImpl->elements.size();
}
bool NzVertexDeclaration::HasElement(nzElementStream stream, unsigned int i) const
{
return i < GetElementCount(stream);
}
bool NzVertexDeclaration::HasElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex) const
{
int elementPos = m_sharedImpl->elementPos[stream][usage];
if (elementPos == -1)
return false;
elementPos += usageIndex;
if (static_cast<unsigned int>(elementPos) >= m_sharedImpl->elements.size())
return false;
NzVertexElement& element = m_sharedImpl->elements[elementPos];
if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex)
return false;
return true;
}
bool NzVertexDeclaration::HasStream(nzElementStream stream) const bool NzVertexDeclaration::HasStream(nzElementStream stream) const
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE