Added read-only const access to buffers
Former-commit-id: 555f079e277869bc8f32732f24dfee704e17f324
This commit is contained in:
parent
e32e012c5a
commit
6fefa3fdd2
|
|
@ -46,10 +46,11 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
|
|||
bool IsValid() const;
|
||||
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
const void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0) const;
|
||||
|
||||
bool SetStorage(nzBufferStorage storage);
|
||||
|
||||
bool Unmap();
|
||||
bool Unmap() const;
|
||||
|
||||
static bool IsSupported(nzBufferStorage storage);
|
||||
static void SetBufferFunction(nzBufferStorage storage, BufferFunction func);
|
||||
|
|
|
|||
|
|
@ -33,10 +33,11 @@ class NAZARA_API NzIndexBuffer : public NzResource
|
|||
bool IsSequential() const;
|
||||
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
const void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0) const;
|
||||
|
||||
bool SetStorage(nzBufferStorage storage);
|
||||
|
||||
bool Unmap();
|
||||
bool Unmap() const;
|
||||
|
||||
private:
|
||||
NzBuffer* m_buffer;
|
||||
|
|
|
|||
|
|
@ -33,10 +33,11 @@ class NAZARA_API NzVertexBuffer : public NzResource
|
|||
bool IsHardware() const;
|
||||
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
const void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0) const;
|
||||
|
||||
bool SetStorage(nzBufferStorage storage);
|
||||
|
||||
bool Unmap();
|
||||
bool Unmap() const;
|
||||
|
||||
private:
|
||||
NzBuffer* m_buffer;
|
||||
|
|
|
|||
|
|
@ -235,6 +235,31 @@ void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int len
|
|||
return m_impl->Map(access, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize);
|
||||
}
|
||||
|
||||
const void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not valid");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (access != nzBufferAccess_ReadOnly)
|
||||
{
|
||||
NazaraError("Buffer access must be read-only when used const");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset+length > m_length)
|
||||
{
|
||||
NazaraError("Exceeding buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Map(access, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize);
|
||||
}
|
||||
|
||||
bool NzBuffer::SetStorage(nzBufferStorage storage)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
|
|
@ -297,7 +322,7 @@ bool NzBuffer::SetStorage(nzBufferStorage storage)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NzBuffer::Unmap()
|
||||
bool NzBuffer::Unmap() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
|
|
|
|||
|
|
@ -185,6 +185,25 @@ void* NzIndexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned in
|
|||
return m_buffer->Map(access, m_startIndex+offset, (length) ? length : m_indexCount-offset);
|
||||
}
|
||||
|
||||
const void* NzIndexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Impossible to map sequential buffers");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset+length > m_indexCount)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Map(access, m_startIndex+offset, (length) ? length : m_indexCount-offset);
|
||||
}
|
||||
|
||||
bool NzIndexBuffer::SetStorage(nzBufferStorage storage)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
|
|
@ -198,7 +217,7 @@ bool NzIndexBuffer::SetStorage(nzBufferStorage storage)
|
|||
return m_buffer->SetStorage(storage);
|
||||
}
|
||||
|
||||
bool NzIndexBuffer::Unmap()
|
||||
bool NzIndexBuffer::Unmap() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_buffer)
|
||||
|
|
|
|||
|
|
@ -151,12 +151,25 @@ void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned i
|
|||
return m_buffer->Map(access, m_startVertex+offset, (length) ? length : m_vertexCount-offset);
|
||||
}
|
||||
|
||||
const void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (offset+length > m_vertexCount)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Map(access, m_startVertex+offset, (length) ? length : m_vertexCount-offset);
|
||||
}
|
||||
|
||||
bool NzVertexBuffer::SetStorage(nzBufferStorage storage)
|
||||
{
|
||||
return m_buffer->SetStorage(storage);
|
||||
}
|
||||
|
||||
bool NzVertexBuffer::Unmap()
|
||||
bool NzVertexBuffer::Unmap() const
|
||||
{
|
||||
return m_buffer->Unmap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue