It is now possible to initialize VertexBuffer without VertexDeclaration

Former-commit-id: 3f8e82925dea8644384b4ceb962a06101bccc1a3
This commit is contained in:
Lynix 2013-08-16 00:26:35 +02:00
parent 3569ef531f
commit 42a1b9cbe6
3 changed files with 29 additions and 21 deletions

View File

@ -29,8 +29,8 @@
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci /// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Le nombre maximum d'instances pouvant être géré par le Renderer // La taille du buffer d'Instancing (définit le nombre maximum d'instances en un rendu)
#define NAZARA_RENDERER_INSTANCE_BUFFER_SIZE 8192*64 #define NAZARA_RENDERER_INSTANCE_BUFFER_SIZE 8192*64 // 8192 matrices 4x4 flottantes
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) // Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 #define NAZARA_RENDERER_MEMORYLEAKTRACKER 0

View File

@ -628,7 +628,7 @@ bool NzRenderer::Initialize()
{ {
try try
{ {
s_instanceBuffer.Reset(NzVertexDeclaration::Get(nzVertexLayout_Matrix4), NAZARA_RENDERER_INSTANCE_BUFFER_SIZE/sizeof(NzMatrix4f), nzBufferStorage_Hardware, nzBufferUsage_Dynamic); s_instanceBuffer.Reset(nullptr, NAZARA_RENDERER_INSTANCE_BUFFER_SIZE, nzBufferStorage_Hardware, nzBufferUsage_Dynamic);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {

View File

@ -97,6 +97,14 @@ bool NzVertexBuffer::IsValid() const
void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int startVertex, unsigned int length) void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int startVertex, unsigned int length)
{ {
#if NAZARA_UTILITY_SAFE
if (!m_vertexDeclaration)
{
NazaraError("No vertex declaration");
return nullptr;
}
#endif
unsigned int stride = m_vertexDeclaration->GetStride(); unsigned int stride = m_vertexDeclaration->GetStride();
return MapRaw(access, startVertex*stride, length*stride); return MapRaw(access, startVertex*stride, length*stride);
@ -104,6 +112,14 @@ void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int startVertex, unsig
void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int startVertex, unsigned int length) const void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int startVertex, unsigned int length) const
{ {
#if NAZARA_UTILITY_SAFE
if (!m_vertexDeclaration)
{
NazaraError("No vertex declaration");
return nullptr;
}
#endif
unsigned int stride = m_vertexDeclaration->GetStride(); unsigned int stride = m_vertexDeclaration->GetStride();
return MapRaw(access, startVertex*stride, length*stride); return MapRaw(access, startVertex*stride, length*stride);
@ -112,10 +128,16 @@ void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int startVertex, unsig
void* NzVertexBuffer::MapRaw(nzBufferAccess access, unsigned int offset, unsigned int size) void* NzVertexBuffer::MapRaw(nzBufferAccess access, unsigned int offset, unsigned int size)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (!m_buffer)
{
NazaraError("No buffer");
return nullptr;
}
if (m_startOffset + offset + size > m_endOffset) if (m_startOffset + offset + size > m_endOffset)
{ {
NazaraError("Exceeding virtual buffer size"); NazaraError("Exceeding virtual buffer size");
return false; return nullptr;
} }
#endif #endif
@ -144,15 +166,9 @@ void NzVertexBuffer::Reset()
void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset) void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (!vertexDeclaration)
{
NazaraError("Vertex declaration is invalid");
return;
}
if (!buffer || !buffer->IsValid()) if (!buffer || !buffer->IsValid())
{ {
NazaraError("Buffer is invalid"); NazaraError("Invalid buffer");
return; return;
} }
@ -179,21 +195,13 @@ void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffe
m_buffer = buffer; m_buffer = buffer;
m_endOffset = endOffset; m_endOffset = endOffset;
m_startOffset = startOffset; m_startOffset = startOffset;
m_vertexCount = (endOffset - startOffset) / vertexDeclaration->GetStride(); m_vertexCount = (vertexDeclaration) ? ((endOffset - startOffset) / vertexDeclaration->GetStride()) : 0;
m_vertexDeclaration = vertexDeclaration; m_vertexDeclaration = vertexDeclaration;
} }
void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage, nzBufferUsage usage) void NzVertexBuffer::Reset(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage, nzBufferUsage usage)
{ {
#if NAZARA_UTILITY_SAFE m_endOffset = length * ((vertexDeclaration) ? vertexDeclaration->GetStride() : 1);
if (!vertexDeclaration)
{
NazaraError("Vertex declaration is invalid");
return;
}
#endif
m_endOffset = length*vertexDeclaration->GetStride();
m_startOffset = 0; m_startOffset = 0;
m_vertexCount = length; m_vertexCount = length;