Renamed (Set)BufferFunction to (Set)BufferFactory

Former-commit-id: 6165dcd881716461a9886be6ce7fd6bb2b335ef0
This commit is contained in:
Lynix 2015-01-04 18:23:06 +01:00
parent b3d72ec094
commit d560975e09
3 changed files with 18 additions and 16 deletions

View File

@ -25,7 +25,7 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
friend class NzUtility; friend class NzUtility;
public: public:
using BufferFunction = NzAbstractBuffer* (*)(NzBuffer* parent, nzBufferType type); using BufferFactory = NzAbstractBuffer* (*)(NzBuffer* parent, nzBufferType type);
NzBuffer(nzBufferType type); NzBuffer(nzBufferType type);
NzBuffer(nzBufferType type, unsigned int size, nzDataStorage storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzBuffer(nzBufferType type, unsigned int size, nzDataStorage storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
@ -55,7 +55,7 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
void Unmap() const; void Unmap() const;
static bool IsSupported(nzDataStorage storage); static bool IsSupported(nzDataStorage storage);
static void SetBufferFunction(nzDataStorage storage, BufferFunction func); static void SetBufferFactory(nzDataStorage storage, BufferFactory func);
private: private:
static bool Initialize(); static bool Initialize();
@ -67,7 +67,7 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
NzAbstractBuffer* m_impl; NzAbstractBuffer* m_impl;
unsigned int m_size; unsigned int m_size;
static BufferFunction s_bufferFunctions[nzDataStorage_Max+1]; static BufferFactory s_bufferFactories[nzDataStorage_Max+1];
}; };
#endif // NAZARA_BUFFER_HPP #endif // NAZARA_BUFFER_HPP

View File

@ -692,7 +692,10 @@ bool NzRenderer::Initialize()
return false; return false;
} }
NzBuffer::SetBufferFunction(nzDataStorage_Hardware, [](NzBuffer* parent, nzBufferType type) -> NzAbstractBuffer* { return new NzHardwareBuffer(parent, type); } ); NzBuffer::SetBufferFactory(nzDataStorage_Hardware, [](NzBuffer* parent, nzBufferType type) -> NzAbstractBuffer*
{
return new NzHardwareBuffer(parent, type);
});
for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) for (unsigned int i = 0; i <= nzMatrixType_Max; ++i)
{ {

View File

@ -16,7 +16,7 @@
namespace namespace
{ {
NzAbstractBuffer* SoftwareBufferFunction(NzBuffer* parent, nzBufferType type) NzAbstractBuffer* SoftwareBufferFactory(NzBuffer* parent, nzBufferType type)
{ {
return new NzSoftwareBuffer(parent, type); return new NzSoftwareBuffer(parent, type);
} }
@ -59,7 +59,6 @@ bool NzBuffer::CopyContent(const NzBuffer& buffer)
#endif #endif
NzBufferMapper<NzBuffer> mapper(buffer, nzBufferAccess_ReadOnly); NzBufferMapper<NzBuffer> mapper(buffer, nzBufferAccess_ReadOnly);
return Fill(mapper.GetPointer(), 0, buffer.GetSize()); return Fill(mapper.GetPointer(), 0, buffer.GetSize());
} }
@ -68,13 +67,13 @@ bool NzBuffer::Create(unsigned int size, nzDataStorage storage, nzBufferUsage us
Destroy(); Destroy();
// Notre buffer est-il supporté ? // Notre buffer est-il supporté ?
if (!s_bufferFunctions[storage]) if (!IsSupported(storage))
{ {
NazaraError("Buffer storage not supported"); NazaraError("Buffer storage not supported");
return false; return false;
} }
std::unique_ptr<NzAbstractBuffer> impl(s_bufferFunctions[storage](this, m_type)); std::unique_ptr<NzAbstractBuffer> impl(s_bufferFactories[storage](this, m_type));
if (!impl->Create(size, usage)) if (!impl->Create(size, usage))
{ {
NazaraError("Failed to create buffer"); NazaraError("Failed to create buffer");
@ -228,7 +227,7 @@ bool NzBuffer::SetStorage(nzDataStorage storage)
return false; return false;
} }
NzAbstractBuffer* impl = s_bufferFunctions[storage](this, m_type); NzAbstractBuffer* impl = s_bufferFactories[storage](this, m_type);
if (!impl->Create(m_size, m_usage)) if (!impl->Create(m_size, m_usage))
{ {
NazaraError("Failed to create buffer"); NazaraError("Failed to create buffer");
@ -269,29 +268,29 @@ void NzBuffer::Unmap() const
#endif #endif
if (!m_impl->Unmap()) if (!m_impl->Unmap())
NazaraWarning("Failed to unmap buffer (it's content is undefined)"); ///TODO: Unexpected ? NazaraWarning("Failed to unmap buffer (it's content may be undefined)"); ///TODO: Unexpected ?
} }
bool NzBuffer::IsSupported(nzDataStorage storage) bool NzBuffer::IsSupported(nzDataStorage storage)
{ {
return s_bufferFunctions[storage] != nullptr; return s_bufferFactories[storage] != nullptr;
} }
void NzBuffer::SetBufferFunction(nzDataStorage storage, BufferFunction func) void NzBuffer::SetBufferFactory(nzDataStorage storage, BufferFactory func)
{ {
s_bufferFunctions[storage] = func; s_bufferFactories[storage] = func;
} }
bool NzBuffer::Initialize() bool NzBuffer::Initialize()
{ {
s_bufferFunctions[nzDataStorage_Software] = SoftwareBufferFunction; s_bufferFactories[nzDataStorage_Software] = SoftwareBufferFactory;
return true; return true;
} }
void NzBuffer::Uninitialize() void NzBuffer::Uninitialize()
{ {
std::memset(s_bufferFunctions, 0, (nzDataStorage_Max+1)*sizeof(NzBuffer::BufferFunction)); std::memset(s_bufferFactories, 0, (nzDataStorage_Max+1)*sizeof(NzBuffer::BufferFactory));
} }
NzBuffer::BufferFunction NzBuffer::s_bufferFunctions[nzDataStorage_Max+1] = {0}; NzBuffer::BufferFactory NzBuffer::s_bufferFactories[nzDataStorage_Max+1] = {0};