From ec9470ceb63ba3aef53f2c28fc9b46316fc29406 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 21 Jun 2012 09:49:47 +0200 Subject: [PATCH] Moved buffers to Utility Fixed NzVector4::operator/ Replaced enumName_Count by enumName_Max Renamed (Index/Vertex)Buffer::GetBufferPtr by GetPointer --- .gitignore | 3 - include/Nazara/Math/Vector3.hpp | 2 +- include/Nazara/Math/Vector3.inl | 4 +- include/Nazara/Math/Vector4.inl | 2 +- include/Nazara/Renderer/OpenGL.hpp | 1 + include/Nazara/Renderer/Renderer.hpp | 6 +- include/Nazara/Renderer/Shader.hpp | 2 +- .../Nazara/{Renderer => Utility}/Buffer.hpp | 22 ++- .../Nazara/Utility}/BufferImpl.hpp | 8 +- include/Nazara/Utility/Image.hpp | 2 +- .../{Renderer => Utility}/IndexBuffer.hpp | 8 +- include/Nazara/Utility/PixelFormat.hpp | 6 +- include/Nazara/Utility/PixelFormat.inl | 13 +- .../{Renderer => Utility}/VertexBuffer.hpp | 8 +- .../VertexDeclaration.hpp | 0 src/Nazara/Renderer/GLSLShader.cpp | 6 +- src/Nazara/Renderer/GLSLShader.hpp | 2 +- src/Nazara/Renderer/HardwareBuffer.cpp | 2 +- src/Nazara/Renderer/HardwareBuffer.hpp | 4 +- src/Nazara/Renderer/OpenGL.cpp | 3 + src/Nazara/Renderer/Renderer.cpp | 62 ++++--- src/Nazara/Renderer/Texture.cpp | 6 +- src/Nazara/{Renderer => Utility}/Buffer.cpp | 174 ++++++++++-------- .../{Renderer => Utility}/BufferImpl.cpp | 4 +- .../{Renderer => Utility}/IndexBuffer.cpp | 83 ++++----- src/Nazara/Utility/PixelFormat.cpp | 4 +- .../{Renderer => Utility}/SoftwareBuffer.cpp | 37 +--- .../{Renderer => Utility}/SoftwareBuffer.hpp | 6 +- src/Nazara/Utility/Utility.cpp | 15 +- .../{Renderer => Utility}/VertexBuffer.cpp | 32 ++-- .../VertexDeclaration.cpp | 22 +-- 31 files changed, 291 insertions(+), 258 deletions(-) rename include/Nazara/{Renderer => Utility}/Buffer.hpp (69%) rename {src/Nazara/Renderer => include/Nazara/Utility}/BufferImpl.hpp (85%) rename include/Nazara/{Renderer => Utility}/IndexBuffer.hpp (85%) rename include/Nazara/{Renderer => Utility}/VertexBuffer.hpp (85%) rename include/Nazara/{Renderer => Utility}/VertexDeclaration.hpp (100%) rename src/Nazara/{Renderer => Utility}/Buffer.cpp (55%) rename src/Nazara/{Renderer => Utility}/BufferImpl.cpp (72%) rename src/Nazara/{Renderer => Utility}/IndexBuffer.cpp (76%) rename src/Nazara/{Renderer => Utility}/SoftwareBuffer.cpp (71%) rename src/Nazara/{Renderer => Utility}/SoftwareBuffer.hpp (91%) rename src/Nazara/{Renderer => Utility}/VertexBuffer.cpp (74%) rename src/Nazara/{Renderer => Utility}/VertexDeclaration.cpp (83%) diff --git a/.gitignore b/.gitignore index fd6451f19..a4daea85f 100644 --- a/.gitignore +++ b/.gitignore @@ -54,9 +54,6 @@ $RECYCLE.BIN/ [Dd]ebug*/ [Rr]elease/ -build/ - - [Tt]est[Rr]esult [Bb]uild[Ll]og.* diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 04e3834c2..af4a2b934 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -17,7 +17,7 @@ template class NzVector3 NzVector3(T X, T Y, T Z); explicit NzVector3(T scale); NzVector3(T vec[3]); - NzVector3(const NzVector2& vec); + NzVector3(const NzVector2& vec, T Z = 0.0); template explicit NzVector3(const NzVector3& vec); NzVector3(const NzVector3& vec) = default; ~NzVector3() = default; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 73eff32fe..aec284b9b 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -39,10 +39,10 @@ z(vec[2]) } template -NzVector3::NzVector3(const NzVector2& vec) : +NzVector3::NzVector3(const NzVector2& vec, T Z) : x(vec.x), y(vec.y), -z(0) +z(Z) { } diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 6620c7f35..e5ec906fd 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -383,7 +383,7 @@ NzVector4 operator/(T scale, const NzVector4& vec) throw std::domain_error(ss.ToString()); } - return NzVector3(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); + return NzVector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); } #include diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 8f5e92d85..adb36a520 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -37,6 +37,7 @@ class NAZARA_API NzOpenGL DebugOutput, FP64, FrameBufferObject, + PixelBufferObject, SeparateShaderObjects, Texture3D, TextureCompression_s3tc, diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index 6296f22f5..4a0f80492 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -59,13 +59,13 @@ enum nzRendererCap nzRendererCap_HardwareBuffer, nzRendererCap_MultipleRenderTargets, nzRendererCap_OcclusionQuery, - nzRendererCap_SoftwareBuffer, + nzRendererCap_PixelBufferObject, nzRendererCap_Texture3D, nzRendererCap_TextureCubemap, nzRendererCap_TextureMulti, nzRendererCap_TextureNPOT, - nzRendererCap_Count + nzRendererCap_Max = nzRendererCap_TextureNPOT }; enum nzRendererClear @@ -183,7 +183,7 @@ class NAZARA_API NzRenderer const NzVertexBuffer* m_vertexBuffer; const NzVertexDeclaration* m_vertexDeclaration; bool m_vaoUpdated; - bool m_capabilities[nzRendererCap_Count]; + bool m_capabilities[nzRendererCap_Max+1]; bool m_stencilFuncUpdated; bool m_stencilOpUpdated; unsigned int m_maxAnisotropyLevel; diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index b060c9bde..2ef694110 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -30,7 +30,7 @@ enum nzShaderType nzShaderType_Geometry, nzShaderType_Vertex, - nzShaderType_Count + nzShaderType_Max = nzShaderType_Vertex }; class NzRenderer; diff --git a/include/Nazara/Renderer/Buffer.hpp b/include/Nazara/Utility/Buffer.hpp similarity index 69% rename from include/Nazara/Renderer/Buffer.hpp rename to include/Nazara/Utility/Buffer.hpp index c023ade1c..b07d022a9 100644 --- a/include/Nazara/Renderer/Buffer.hpp +++ b/include/Nazara/Utility/Buffer.hpp @@ -22,7 +22,9 @@ enum nzBufferAccess enum nzBufferStorage { nzBufferStorage_Hardware, - nzBufferStorage_Software + nzBufferStorage_Software, + + nzBufferStorage_Max = nzBufferStorage_Software }; enum nzBufferType @@ -39,27 +41,31 @@ enum nzBufferUsage class NzBufferImpl; class NzRenderer; +class NzUtility; class NAZARA_API NzBuffer : public NzResource, NzNonCopyable { friend class NzRenderer; + friend class NzUtility; public: + typedef NzBufferImpl* (*BufferFunction)(NzBuffer* parent, nzBufferType type); + NzBuffer(nzBufferType type); - NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferUsage usage = nzBufferUsage_Static); + NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); ~NzBuffer(); bool CopyContent(NzBuffer& buffer); - bool Create(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage = nzBufferUsage_Static); + bool Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); void Destroy(); bool Fill(const void* data, unsigned int offset, unsigned int length); - void* GetBufferPtr(); - const void* GetBufferPtr() const; NzBufferImpl* GetImpl() const; unsigned int GetLength() const; + void* GetPointer(); + const void* GetPointer() const; unsigned int GetSize() const; nzBufferStorage GetStorage() const; nzBufferType GetType() const; @@ -67,13 +73,18 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable nzBufferUsage GetUsage() const; bool IsHardware() const; + bool IsValid() const; void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0); bool Unmap(); static bool IsSupported(nzBufferStorage storage); + static void SetBufferFunction(nzBufferStorage storage, BufferFunction func); private: + static bool Initialize(); + static void Uninitialize(); + nzBufferStorage m_storage; nzBufferType m_type; nzBufferUsage m_usage; @@ -81,6 +92,7 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable NzBufferImpl* m_impl; unsigned int m_length; + static BufferFunction s_bufferFunctions[nzBufferStorage_Max+1]; }; #endif // NAZARA_BUFFER_HPP diff --git a/src/Nazara/Renderer/BufferImpl.hpp b/include/Nazara/Utility/BufferImpl.hpp similarity index 85% rename from src/Nazara/Renderer/BufferImpl.hpp rename to include/Nazara/Utility/BufferImpl.hpp index 74795abe9..7821c3c76 100644 --- a/src/Nazara/Renderer/BufferImpl.hpp +++ b/include/Nazara/Utility/BufferImpl.hpp @@ -7,22 +7,20 @@ #ifndef NAZARA_BUFFERIMPL_HPP #define NAZARA_BUFFERIMPL_HPP -#include +#include -class NzBufferImpl +class NAZARA_API NzBufferImpl { public: NzBufferImpl() = default; virtual ~NzBufferImpl(); - virtual void Bind() = 0; - virtual bool Create(unsigned int size, nzBufferUsage usage = nzBufferUsage_Static) = 0; virtual void Destroy() = 0; virtual bool Fill(const void* data, unsigned int offset, unsigned int size) = 0; - virtual void* GetBufferPtr() = 0; + virtual void* GetPointer() = 0; virtual bool IsHardware() const = 0; diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 71cddbaa3..a85055c45 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -35,7 +35,7 @@ enum nzImageType nzImageType_3D, nzImageType_Cubemap, - nzImageType_Count + nzImageType_Max = nzImageType_Cubemap }; struct NzImageParams diff --git a/include/Nazara/Renderer/IndexBuffer.hpp b/include/Nazara/Utility/IndexBuffer.hpp similarity index 85% rename from include/Nazara/Renderer/IndexBuffer.hpp rename to include/Nazara/Utility/IndexBuffer.hpp index b3a50b1d0..bfcfe0133 100644 --- a/include/Nazara/Renderer/IndexBuffer.hpp +++ b/include/Nazara/Utility/IndexBuffer.hpp @@ -8,23 +8,23 @@ #define NAZARA_INDEXBUFFER_HPP #include -#include +#include class NAZARA_API NzIndexBuffer { public: NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount); - NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferUsage usage = nzBufferUsage_Static); + NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzIndexBuffer(const NzIndexBuffer& indexBuffer); ~NzIndexBuffer(); bool Fill(const void* data, unsigned int offset, unsigned int length); NzBuffer* GetBuffer() const; - void* GetBufferPtr(); - const void* GetBufferPtr() const; nzUInt8 GetIndexSize() const; unsigned int GetIndexCount() const; + void* GetPointer(); + const void* GetPointer() const; unsigned int GetStartIndex() const; bool IsHardware() const; diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 3736c2efe..755236779 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -46,7 +46,7 @@ enum nzPixelFormat nzPixelFormat_Stencil16, */ - nzPixelFormat_Count + nzPixelFormat_Max = nzPixelFormat_RGBA8 }; class NzUtility; @@ -69,7 +69,7 @@ class NzPixelFormat static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat); static bool IsValid(nzPixelFormat format); - static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction); + static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func); static NzString ToString(nzPixelFormat format); @@ -77,7 +77,7 @@ class NzPixelFormat static bool Initialize(); static void Uninitialize(); - static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Count][nzPixelFormat_Count]; + static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1]; }; #include diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index 2ea636d04..fa5a7da9d 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -129,7 +129,6 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) case nzPixelFormat_RGBA8: return 4; - case nzPixelFormat_Count: case nzPixelFormat_Undefined: NazaraError("Invalid pixel format"); return 0; @@ -159,7 +158,6 @@ inline bool NzPixelFormat::HasAlpha(nzPixelFormat format) case nzPixelFormat_RGB8: return false; - case nzPixelFormat_Count: case nzPixelFormat_Undefined: break; } @@ -192,15 +190,7 @@ inline bool NzPixelFormat::IsConversionSupported(nzPixelFormat srcFormat, nzPixe inline bool NzPixelFormat::IsValid(nzPixelFormat format) { - switch (format) - { - case nzPixelFormat_Count: - case nzPixelFormat_Undefined: - return false; - - default: - return true; - } + return format != nzPixelFormat_Undefined; } inline void NzPixelFormat::SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func) @@ -269,7 +259,6 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format) case nzPixelFormat_RGBA8: return "RGBA8"; - case nzPixelFormat_Count: case nzPixelFormat_Undefined: break; } diff --git a/include/Nazara/Renderer/VertexBuffer.hpp b/include/Nazara/Utility/VertexBuffer.hpp similarity index 85% rename from include/Nazara/Renderer/VertexBuffer.hpp rename to include/Nazara/Utility/VertexBuffer.hpp index a4634d78a..30deaf5a7 100644 --- a/include/Nazara/Renderer/VertexBuffer.hpp +++ b/include/Nazara/Utility/VertexBuffer.hpp @@ -8,21 +8,21 @@ #define NAZARA_VERTEXBUFFER_HPP #include -#include +#include class NAZARA_API NzVertexBuffer { public: NzVertexBuffer(NzBuffer* buffer, unsigned int startVertex, unsigned int vertexCount); - NzVertexBuffer(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage = nzBufferUsage_Static); + NzVertexBuffer(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzVertexBuffer(const NzVertexBuffer& vertexBuffer); ~NzVertexBuffer(); bool Fill(const void* data, unsigned int offset, unsigned int length); NzBuffer* GetBuffer() const; - void* GetBufferPtr(); - const void* GetBufferPtr() const; + void* GetPointer(); + const void* GetPointer() const; unsigned int GetStartVertex() const; nzUInt8 GetTypeSize() const; unsigned int GetVertexCount() const; diff --git a/include/Nazara/Renderer/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp similarity index 100% rename from include/Nazara/Renderer/VertexDeclaration.hpp rename to include/Nazara/Utility/VertexDeclaration.hpp diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLShader.cpp index 7518a3643..e60cd8be9 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLShader.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include namespace @@ -24,7 +24,7 @@ namespace 4 // nzElementUsage_TexCoord }; - const GLenum shaderType[nzShaderType_Count] = { + const GLenum shaderType[nzShaderType_Max+1] = { GL_FRAGMENT_SHADER, // nzShaderType_Fragment GL_GEOMETRY_SHADER, // nzShaderType_Geometry GL_VERTEX_SHADER // nzShaderType_Vertex @@ -136,7 +136,7 @@ bool NzGLSLShader::Create() glBindAttribLocation(m_program, attribIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer()); } - for (int i = 0; i < nzShaderType_Count; ++i) + for (int i = 0; i <= nzShaderType_Max; ++i) m_shaders[i] = 0; return true; diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLShader.hpp index 658e6e67d..f32d783ec 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLShader.hpp @@ -63,7 +63,7 @@ class NzGLSLShader : public NzShaderImpl mutable std::map m_idCache; std::map m_textures; GLuint m_program; - GLuint m_shaders[nzShaderType_Count]; + GLuint m_shaders[nzShaderType_Max+1]; NzShader* m_parent; NzString m_log; }; diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index c017967be..ddb98776b 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -188,7 +188,7 @@ bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int return true; } -void* NzHardwareBuffer::GetBufferPtr() +void* NzHardwareBuffer::GetPointer() { return nullptr; } diff --git a/src/Nazara/Renderer/HardwareBuffer.hpp b/src/Nazara/Renderer/HardwareBuffer.hpp index f1652098e..7834fe9fe 100644 --- a/src/Nazara/Renderer/HardwareBuffer.hpp +++ b/src/Nazara/Renderer/HardwareBuffer.hpp @@ -8,8 +8,8 @@ #define NAZARA_HARDWAREBUFFER_HPP #include -#include #include +#include class NzHardwareBuffer : public NzBufferImpl { @@ -24,7 +24,7 @@ class NzHardwareBuffer : public NzBufferImpl bool Fill(const void* data, unsigned int offset, unsigned int length); - void* GetBufferPtr(); + void* GetPointer(); bool IsHardware() const; diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index d6144728d..d119ada59 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -400,6 +400,9 @@ bool NzOpenGL::Initialize() } } + // PixelBufferObject + openGLextensions[NzOpenGL::PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object")); + // SeparateShaderObjects if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) { diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index ce8e0ab53..5bfcf65f5 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -6,16 +6,17 @@ #include #include #include -#include #include #include -#include +#include #include #include #include -#include -#include +#include +#include #include +#include +#include #include #include @@ -128,6 +129,11 @@ namespace GL_REPLACE, // nzStencilOperation_Replace GL_ZERO // nzStencilOperation_Zero }; + + NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type) + { + return new NzHardwareBuffer(parent, type); + } } NzRenderer::NzRenderer() @@ -219,7 +225,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f return; } - glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast(m_indexBuffer->GetBufferPtr()) + firstIndex*indexSize); + glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast(m_indexBuffer->GetPointer()) + firstIndex*indexSize); } void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount) @@ -333,15 +339,13 @@ bool NzRenderer::Initialize() m_utilityModule = new NzUtility; m_utilityModule->Initialize(); } + else + m_utilityModule = nullptr; if (NzOpenGL::Initialize()) { NzContext::EnsureContext(); - const NzContext* context = NzContext::GetReference(); - bool compatibility = context->GetParameters().compatibilityProfile; - - m_vaoUpdated = false; m_indexBuffer = nullptr; m_shader = nullptr; m_stencilCompare = nzRendererComparison_Always; @@ -353,6 +357,7 @@ bool NzRenderer::Initialize() m_stencilReference = 0; m_stencilZFail = nzStencilOperation_Keep; m_target = nullptr; + m_vaoUpdated = false; m_vertexBuffer = nullptr; m_vertexDeclaration = nullptr; @@ -362,7 +367,7 @@ bool NzRenderer::Initialize() m_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 m_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0 m_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 - m_capabilities[nzRendererCap_SoftwareBuffer] = compatibility || NzOpenGL::GetVersion() <= 300; // Déprécié en OpenGL 3 + m_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject); m_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D); m_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 m_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 @@ -398,6 +403,8 @@ bool NzRenderer::Initialize() else m_maxTextureUnit = 1; + NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); + s_initialized = true; return true; @@ -497,9 +504,16 @@ void NzRenderer::SetFaceFilling(nzFaceFilling fillingMode) glPolygonMode(GL_FRONT_AND_BACK, faceFillingMode[fillingMode]); } - bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer) { + #if NAZARA_RENDERER_SAFE + if (indexBuffer && !indexBuffer->IsHardware()) + { + NazaraError("Buffer must be hardware"); + return false; + } + #endif + if (indexBuffer != m_indexBuffer) { m_indexBuffer = indexBuffer; @@ -635,6 +649,14 @@ bool NzRenderer::SetTarget(NzRenderTarget* target) bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) { + #if NAZARA_RENDERER_SAFE + if (vertexBuffer && !vertexBuffer->IsHardware()) + { + NazaraError("Buffer must be hardware"); + return false; + } + #endif + if (m_vertexBuffer != vertexBuffer) { m_vertexBuffer = vertexBuffer; @@ -675,13 +697,7 @@ void NzRenderer::SetViewport(const NzRectui& viewport) } unsigned int width = m_target->GetWidth(); - if (viewport.x+viewport.width >= width) - { - NazaraError("Rectangle dimensions are out of bounds"); - return; - } - - if (viewport.y+viewport.height >= height) + if (viewport.x+viewport.width > width || viewport.y+viewport.height > height) { NazaraError("Rectangle dimensions are out of bounds"); return; @@ -812,9 +828,10 @@ bool NzRenderer::EnsureStateUpdate() if (update) { - m_vertexBuffer->GetBuffer()->GetImpl()->Bind(); + NzHardwareBuffer* vertexBuffer = static_cast(m_vertexBuffer->GetBuffer()->GetImpl()); + vertexBuffer->Bind(); - const nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->GetBufferPtr()); + const nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->GetPointer()); ///FIXME: Améliorer les déclarations pour permettre de faire ça plus simplement for (int i = 0; i < 12; ++i) // Solution temporaire, à virer @@ -836,7 +853,10 @@ bool NzRenderer::EnsureStateUpdate() } if (m_indexBuffer) - m_indexBuffer->GetBuffer()->GetImpl()->Bind(); + { + NzHardwareBuffer* indexBuffer = static_cast(m_indexBuffer->GetBuffer()->GetImpl()); + indexBuffer->Bind(); + } } if (vaoSupported) diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 8283fc32c..eae6087c4 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -124,7 +124,6 @@ namespace return true; case nzPixelFormat_Undefined: - case nzPixelFormat_Count: NazaraInternalError("Invalid pixel format"); return false; } @@ -252,8 +251,8 @@ namespace return true; } - static unsigned short lockedLevel[nzImageType_Count] = {0}; - static GLuint lockedPrevious[nzImageType_Count] = {0}; + static unsigned short lockedLevel[nzImageType_Max+1] = {0}; + static GLuint lockedPrevious[nzImageType_Max+1] = {0}; void LockTexture(NzTextureImpl* impl) { @@ -1576,7 +1575,6 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format) } case nzPixelFormat_Undefined: - case nzPixelFormat_Count: break; } diff --git a/src/Nazara/Renderer/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp similarity index 55% rename from src/Nazara/Renderer/Buffer.cpp rename to src/Nazara/Utility/Buffer.cpp index d5fa5b961..54d16bada 100644 --- a/src/Nazara/Renderer/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -2,22 +2,21 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include +#include namespace { - nzRendererCap storageToCapability[] = { - nzRendererCap_HardwareBuffer, // nzBufferStorage_Hardware - nzRendererCap_SoftwareBuffer, // nzBufferStorage_Software - }; + NzBufferImpl* SoftwareBufferFunction(NzBuffer* parent, nzBufferType type) + { + return new NzSoftwareBuffer(parent, type); + } } NzBuffer::NzBuffer(nzBufferType type) : @@ -28,11 +27,11 @@ m_length(0) { } -NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferUsage usage) : +NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) : m_type(type), m_impl(nullptr) { - Create(length, typeSize, usage); + Create(length, typeSize, storage, usage); #ifdef NAZARA_DEBUG if (!m_impl) @@ -50,6 +49,26 @@ NzBuffer::~NzBuffer() bool NzBuffer::CopyContent(NzBuffer& buffer) { + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer must be valid"); + return false; + } + + if (!buffer.IsValid()) + { + NazaraError("Source buffer must be valid"); + return false; + } + + if (!buffer.GetTypeSize() != m_typeSize) + { + NazaraError("Source buffer type size does not match buffer type size"); + return false; + } + #endif + void* ptr = buffer.Map(nzBufferAccess_ReadOnly); if (!ptr) { @@ -57,7 +76,7 @@ bool NzBuffer::CopyContent(NzBuffer& buffer) return false; } - bool r = Fill(ptr, 0, m_length); + bool r = Fill(ptr, 0, buffer.GetLength()); if (!buffer.Unmap()) NazaraWarning("Failed to unmap source buffer"); @@ -65,41 +84,28 @@ bool NzBuffer::CopyContent(NzBuffer& buffer) return r; } -bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage) +bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) { Destroy(); // On tente d'abord de faire un buffer hardware, si supporté - if (NazaraRenderer->HasCapability(nzRendererCap_HardwareBuffer)) + if (s_bufferFunctions[storage]) { - m_impl = new NzHardwareBuffer(this, m_type); - if (!m_impl->Create(length*typeSize, usage)) + NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); + if (!impl->Create(length*typeSize, usage)) { - NazaraWarning("Failed to create hardware buffer, trying to create software buffer..."); + NazaraError("Failed to create buffer"); + delete impl; - delete m_impl; - m_impl = nullptr; + return false; } + + m_impl = impl; } - - if (!m_impl) + else { - if (!NazaraRenderer->HasCapability(nzRendererCap_SoftwareBuffer)) - { - // Ne devrait jamais arriver - NazaraError("Software buffer not supported"); - return false; - } - - m_impl = new NzSoftwareBuffer(this, m_type); - if (!m_impl->Create(length*typeSize, usage)) - { - NazaraError("Failed to create software buffer"); - delete m_impl; - m_impl = nullptr; - - return false; - } + NazaraError("Buffer storage not supported"); + return false; } m_length = length; @@ -122,10 +128,10 @@ void NzBuffer::Destroy() bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_impl) { - NazaraError("Buffer not created"); + NazaraError("Buffer not valid"); return false; } @@ -139,32 +145,6 @@ bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length) return m_impl->Fill(data, offset*m_typeSize, length*m_typeSize); } -void* NzBuffer::GetBufferPtr() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Buffer not created"); - return nullptr; - } - #endif - - return m_impl->GetBufferPtr(); -} - -const void* NzBuffer::GetBufferPtr() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Buffer not created"); - return nullptr; - } - #endif - - return m_impl->GetBufferPtr(); -} - NzBufferImpl* NzBuffer::GetImpl() const { return m_impl; @@ -175,6 +155,32 @@ unsigned int NzBuffer::GetLength() const return m_length; } +void* NzBuffer::GetPointer() +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + #endif + + return m_impl->GetPointer(); +} + +const void* NzBuffer::GetPointer() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + #endif + + return m_impl->GetPointer(); +} + unsigned int NzBuffer::GetSize() const { return m_length*m_typeSize; @@ -205,12 +211,17 @@ bool NzBuffer::IsHardware() const return m_storage == nzBufferStorage_Hardware; } +bool NzBuffer::IsValid() const +{ + return m_impl != nullptr; +} + void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_impl) { - NazaraError("Buffer not created"); + NazaraError("Buffer not valid"); return nullptr; } @@ -226,10 +237,10 @@ void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int len bool NzBuffer::Unmap() { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_impl) { - NazaraError("Buffer not created"); + NazaraError("Buffer not valid"); return false; } #endif @@ -239,5 +250,24 @@ bool NzBuffer::Unmap() bool NzBuffer::IsSupported(nzBufferStorage storage) { - return NazaraRenderer->HasCapability(storageToCapability[storage]); + return s_bufferFunctions[storage] != nullptr; } + +void NzBuffer::SetBufferFunction(nzBufferStorage storage, BufferFunction func) +{ + s_bufferFunctions[storage] = func; +} + +bool NzBuffer::Initialize() +{ + s_bufferFunctions[nzBufferStorage_Software] = SoftwareBufferFunction; + + return true; +} + +void NzBuffer::Uninitialize() +{ + std::memset(s_bufferFunctions, 0, (nzBufferStorage_Max+1)*sizeof(NzBuffer::BufferFunction)); +} + +NzBuffer::BufferFunction NzBuffer::s_bufferFunctions[nzBufferStorage_Max+1] = {0}; diff --git a/src/Nazara/Renderer/BufferImpl.cpp b/src/Nazara/Utility/BufferImpl.cpp similarity index 72% rename from src/Nazara/Renderer/BufferImpl.cpp rename to src/Nazara/Utility/BufferImpl.cpp index 99f034067..93ad045c4 100644 --- a/src/Nazara/Renderer/BufferImpl.cpp +++ b/src/Nazara/Utility/BufferImpl.cpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include +#include +#include NzBufferImpl::~NzBufferImpl() = default; diff --git a/src/Nazara/Renderer/IndexBuffer.cpp b/src/Nazara/Utility/IndexBuffer.cpp similarity index 76% rename from src/Nazara/Renderer/IndexBuffer.cpp rename to src/Nazara/Utility/IndexBuffer.cpp index 2e822d5d9..9ed69c525 100644 --- a/src/Nazara/Renderer/IndexBuffer.cpp +++ b/src/Nazara/Utility/IndexBuffer.cpp @@ -2,11 +2,11 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include -#include +#include #include -#include +#include NzIndexBuffer::NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount) : m_buffer(buffer), @@ -31,7 +31,7 @@ m_startIndex(startIndex) } } -NzIndexBuffer::NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferUsage usage) : +NzIndexBuffer::NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferStorage storage, nzBufferUsage usage) : m_ownsBuffer(true), m_indexCount(length), m_startIndex(0) @@ -46,13 +46,14 @@ m_startIndex(0) } #endif - m_buffer = new NzBuffer(nzBufferType_Index, length, indexSize, usage); + m_buffer = new NzBuffer(nzBufferType_Index, length, indexSize, storage, usage); m_buffer->AddResourceReference(); m_buffer->SetPersistent(false); } NzIndexBuffer::NzIndexBuffer(const NzIndexBuffer& indexBuffer) : m_buffer(indexBuffer.m_buffer), +m_ownsBuffer(indexBuffer.m_ownsBuffer), m_indexCount(indexBuffer.m_indexCount), m_startIndex(indexBuffer.m_startIndex) { @@ -60,7 +61,9 @@ m_startIndex(indexBuffer.m_startIndex) { if (m_ownsBuffer) { - m_buffer = new NzBuffer(nzBufferType_Index, indexBuffer.m_buffer->GetLength(), indexBuffer.m_buffer->GetSize(), indexBuffer.m_buffer->GetUsage()); + NzBuffer* buffer = indexBuffer.m_buffer; + + m_buffer = new NzBuffer(nzBufferType_Index, buffer->GetLength(), buffer->GetSize(), buffer->GetStorage(), buffer->GetUsage()); m_buffer->AddResourceReference(); m_buffer->SetPersistent(false); m_buffer->CopyContent(*indexBuffer.m_buffer); @@ -71,8 +74,6 @@ m_startIndex(indexBuffer.m_startIndex) m_buffer->AddResourceReference(); } } - else - m_buffer = nullptr; } NzIndexBuffer::~NzIndexBuffer() @@ -83,7 +84,7 @@ NzIndexBuffer::~NzIndexBuffer() bool NzIndexBuffer::Fill(const void* data, unsigned int offset, unsigned int length) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_buffer) { NazaraError("Impossible to fill sequential buffer"); @@ -105,38 +106,12 @@ NzBuffer* NzIndexBuffer::GetBuffer() const return m_buffer; } -void* NzIndexBuffer::GetBufferPtr() -{ - #if NAZARA_RENDERER_SAFE - if (!m_buffer) - { - NazaraError("Sequential index buffer: Buffer has no pointer"); - return nullptr; - } - #endif - - return reinterpret_cast(m_buffer->GetBufferPtr()) + m_startIndex*m_buffer->GetTypeSize(); -} - -const void* NzIndexBuffer::GetBufferPtr() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_buffer) - { - NazaraError("Sequential index buffer: Buffer has no pointer"); - return nullptr; - } - #endif - - return reinterpret_cast(m_buffer->GetBufferPtr()) + m_startIndex*m_buffer->GetTypeSize(); -} - nzUInt8 NzIndexBuffer::GetIndexSize() const { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_buffer) { - NazaraError("Sequential index buffer: Buffer has no index size"); + NazaraError("Sequential index buffer has no index size"); return 0; } #endif @@ -144,6 +119,32 @@ nzUInt8 NzIndexBuffer::GetIndexSize() const return m_buffer->GetTypeSize(); } +void* NzIndexBuffer::GetPointer() +{ + #if NAZARA_UTILITY_SAFE + if (!m_buffer) + { + NazaraError("Sequential index buffer: Buffer has no pointer"); + return nullptr; + } + #endif + + return reinterpret_cast(m_buffer->GetPointer()) + m_startIndex*m_buffer->GetTypeSize(); +} + +const void* NzIndexBuffer::GetPointer() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_buffer) + { + NazaraError("Sequential index buffer has no pointer"); + return nullptr; + } + #endif + + return reinterpret_cast(m_buffer->GetPointer()) + m_startIndex*m_buffer->GetTypeSize(); +} + unsigned int NzIndexBuffer::GetIndexCount() const { return m_indexCount; @@ -156,10 +157,10 @@ unsigned int NzIndexBuffer::GetStartIndex() const bool NzIndexBuffer::IsHardware() const { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_buffer) { - NazaraError("Sequential index buffer is neither hardware or software"); + NazaraWarning("Sequential index buffers are neither hardware or software"); return false; } #endif @@ -174,7 +175,7 @@ bool NzIndexBuffer::IsSequential() const void* NzIndexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_buffer) { NazaraError("Impossible to map sequential index buffer"); @@ -193,7 +194,7 @@ void* NzIndexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned in bool NzIndexBuffer::Unmap() { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_buffer) { NazaraError("Impossible to unlock sequential index buffer"); diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index 1a189181e..999aba443 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -1314,7 +1314,7 @@ bool NzPixelFormat::Initialize() void NzPixelFormat::Uninitialize() { - std::memset(s_convertFunctions, 0, nzPixelFormat_Count*nzPixelFormat_Count*sizeof(NzPixelFormat::ConvertFunction)); + std::memset(s_convertFunctions, 0, (nzPixelFormat_Max+1)*(nzPixelFormat_Max+1)*sizeof(NzPixelFormat::ConvertFunction)); } -NzPixelFormat::ConvertFunction NzPixelFormat::s_convertFunctions[nzPixelFormat_Count][nzPixelFormat_Count] = {{0}}; ///FIXME: Fonctionne correctement ? +NzPixelFormat::ConvertFunction NzPixelFormat::s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1] = {{0}}; ///FIXME: Fonctionne correctement ? diff --git a/src/Nazara/Renderer/SoftwareBuffer.cpp b/src/Nazara/Utility/SoftwareBuffer.cpp similarity index 71% rename from src/Nazara/Renderer/SoftwareBuffer.cpp rename to src/Nazara/Utility/SoftwareBuffer.cpp index c579a7e40..0fb3537c9 100644 --- a/src/Nazara/Renderer/SoftwareBuffer.cpp +++ b/src/Nazara/Utility/SoftwareBuffer.cpp @@ -2,22 +2,12 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include +#include #include -#include -#include +#include #include #include -#include - -namespace -{ - GLenum bufferTarget[] = { - GL_ELEMENT_ARRAY_BUFFER, // nzBufferType_Index, - GL_ARRAY_BUFFER, // nzBufferType_Vertex - }; -} +#include NzSoftwareBuffer::NzSoftwareBuffer(NzBuffer* parent, nzBufferType type) : m_type(type) @@ -29,19 +19,6 @@ NzSoftwareBuffer::~NzSoftwareBuffer() { } -void NzSoftwareBuffer::Bind() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBindBuffer(bufferTarget[m_type], 0); -} - bool NzSoftwareBuffer::Create(unsigned int size, nzBufferUsage usage) { NazaraUnused(usage); @@ -69,7 +46,7 @@ void NzSoftwareBuffer::Destroy() bool NzSoftwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (m_mapped) { NazaraError("Buffer already mapped"); @@ -82,7 +59,7 @@ bool NzSoftwareBuffer::Fill(const void* data, unsigned int offset, unsigned int return true; } -void* NzSoftwareBuffer::GetBufferPtr() +void* NzSoftwareBuffer::GetPointer() { return m_buffer; } @@ -97,7 +74,7 @@ void* NzSoftwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned NazaraUnused(access); NazaraUnused(size); - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (m_mapped) { NazaraError("Buffer already mapped"); @@ -112,7 +89,7 @@ void* NzSoftwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned bool NzSoftwareBuffer::Unmap() { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!m_mapped) { NazaraError("Buffer not mapped"); diff --git a/src/Nazara/Renderer/SoftwareBuffer.hpp b/src/Nazara/Utility/SoftwareBuffer.hpp similarity index 91% rename from src/Nazara/Renderer/SoftwareBuffer.hpp rename to src/Nazara/Utility/SoftwareBuffer.hpp index 704f8e65f..56f5be074 100644 --- a/src/Nazara/Renderer/SoftwareBuffer.hpp +++ b/src/Nazara/Utility/SoftwareBuffer.hpp @@ -8,7 +8,7 @@ #define NAZARA_SOFTWAREBUFFER_HPP #include -#include +#include class NzSoftwareBuffer : public NzBufferImpl { @@ -16,14 +16,12 @@ class NzSoftwareBuffer : public NzBufferImpl NzSoftwareBuffer(NzBuffer* parent, nzBufferType type); ~NzSoftwareBuffer(); - void Bind(); - bool Create(unsigned int size, nzBufferUsage usage = nzBufferUsage_Static); void Destroy(); bool Fill(const void* data, unsigned int offset, unsigned int length); - void* GetBufferPtr(); + void* GetPointer(); bool IsHardware() const; diff --git a/src/Nazara/Utility/Utility.cpp b/src/Nazara/Utility/Utility.cpp index 3d1bfe716..a7c7ede20 100644 --- a/src/Nazara/Utility/Utility.cpp +++ b/src/Nazara/Utility/Utility.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -31,9 +32,15 @@ bool NzUtility::Initialize() } #endif + if (!NzBuffer::Initialize()) + { + NazaraError("Failed to initialize buffers"); + return false; + } + if (!NzPixelFormat::Initialize()) { - NazaraError("Failed to initialize pixel format"); + NazaraError("Failed to initialize pixel formats"); return false; } @@ -45,10 +52,10 @@ bool NzUtility::Initialize() return false; } - // Loaders spécialisés + /// Loaders spécialisés NzLoaders_PCX_Register(); // Loader de fichiers .PCX (1, 4, 8, 24) - // Loaders génériques (En dernier pour donner la priorité aux loaders spécialisés) + /// Loaders génériques (En dernier pour donner la priorité aux loaders spécialisés) NzLoaders_STB_Register(); // Loader générique (STB) s_initialized = true; @@ -70,8 +77,8 @@ void NzUtility::Uninitialize() NzLoaders_PCX_Unregister(); NzWindow::Uninitialize(); - NzPixelFormat::Uninitialize(); + NzBuffer::Uninitialize(); s_initialized = false; } diff --git a/src/Nazara/Renderer/VertexBuffer.cpp b/src/Nazara/Utility/VertexBuffer.cpp similarity index 74% rename from src/Nazara/Renderer/VertexBuffer.cpp rename to src/Nazara/Utility/VertexBuffer.cpp index fed64316b..46758303e 100644 --- a/src/Nazara/Renderer/VertexBuffer.cpp +++ b/src/Nazara/Utility/VertexBuffer.cpp @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include -#include +#include NzVertexBuffer::NzVertexBuffer(NzBuffer* buffer, unsigned int startVertex, unsigned int vertexCount) : m_buffer(buffer), @@ -12,15 +12,23 @@ m_ownsBuffer(false), m_startVertex(startVertex), m_vertexCount(vertexCount) { + #ifdef NAZARA_DEBUG + if (!m_buffer) + { + NazaraError("Passed buffer is null"); + return; + } + #endif + m_buffer->AddResourceReference(); } -NzVertexBuffer::NzVertexBuffer(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage) : +NzVertexBuffer::NzVertexBuffer(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) : m_ownsBuffer(true), m_startVertex(0), m_vertexCount(length) { - m_buffer = new NzBuffer(nzBufferType_Vertex, length, typeSize, usage); + m_buffer = new NzBuffer(nzBufferType_Vertex, length, typeSize, storage, usage); m_buffer->AddResourceReference(); m_buffer->SetPersistent(false); } @@ -32,7 +40,9 @@ m_vertexCount(vertexBuffer.m_vertexCount) { if (m_ownsBuffer) { - m_buffer = new NzBuffer(nzBufferType_Vertex, vertexBuffer.m_buffer->GetLength(), vertexBuffer.m_buffer->GetSize(), vertexBuffer.m_buffer->GetUsage()); + NzBuffer* buffer = vertexBuffer.m_buffer; + + m_buffer = new NzBuffer(nzBufferType_Vertex, buffer->GetLength(), buffer->GetSize(), buffer->GetStorage(), buffer->GetUsage()); m_buffer->AddResourceReference(); m_buffer->SetPersistent(false); m_buffer->CopyContent(*vertexBuffer.m_buffer); @@ -51,7 +61,7 @@ NzVertexBuffer::~NzVertexBuffer() bool NzVertexBuffer::Fill(const void* data, unsigned int offset, unsigned int length) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (offset+length > m_vertexCount) { NazaraError("Exceeding virtual buffer size"); @@ -67,14 +77,14 @@ NzBuffer* NzVertexBuffer::GetBuffer() const return m_buffer; } -void* NzVertexBuffer::GetBufferPtr() +void* NzVertexBuffer::GetPointer() { - return reinterpret_cast(m_buffer->GetBufferPtr()) + m_startVertex*m_buffer->GetTypeSize(); + return reinterpret_cast(m_buffer->GetPointer()) + m_startVertex*m_buffer->GetTypeSize(); } -const void* NzVertexBuffer::GetBufferPtr() const +const void* NzVertexBuffer::GetPointer() const { - return reinterpret_cast(m_buffer->GetBufferPtr()) + m_startVertex*m_buffer->GetTypeSize(); + return reinterpret_cast(m_buffer->GetPointer()) + m_startVertex*m_buffer->GetTypeSize(); } unsigned int NzVertexBuffer::GetStartVertex() const @@ -99,7 +109,7 @@ bool NzVertexBuffer::IsHardware() const void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (offset+length > m_vertexCount) { NazaraError("Exceeding virtual buffer size"); diff --git a/src/Nazara/Renderer/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp similarity index 83% rename from src/Nazara/Renderer/VertexDeclaration.cpp rename to src/Nazara/Utility/VertexDeclaration.cpp index e764543ca..7288cd3cc 100644 --- a/src/Nazara/Renderer/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -2,11 +2,10 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include -#include -#include -#include +#include +#include namespace { @@ -32,11 +31,9 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e if (stream >= m_streams.size()) m_streams.resize(stream+1); - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE else // Seulement si le stream ne vient pas d'être créé (Autrement c'est inutile) { - bool fp64 = NazaraRenderer->HasCapability(nzRendererCap_FP64); - for (unsigned int j = 0; j < i; ++j) { if (elements[j].stream == stream && elements[j].usage == elements[i].usage && elements[j].usageIndex == elements[i].usageIndex) @@ -44,11 +41,6 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e NazaraError("Element usage (" + NzString::Number(elements[j].usage, 16) + ") collision on stream " + NzString::Number(stream) + " with usage index " + NzString::Number(elements[j].usageIndex)); return false; } - else if (!fp64 && elements[j].type >= nzElementType_Double1 && elements[j].type <= nzElementType_Double4) - { - NazaraError("FP64 not supported"); - return false; - } } } #endif @@ -78,7 +70,7 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e const NzVertexDeclaration::Element* NzVertexDeclaration::GetElement(unsigned int i, unsigned int stream) const { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (stream >= m_streams.size()) { NazaraError("Stream out of range"); @@ -97,7 +89,7 @@ const NzVertexDeclaration::Element* NzVertexDeclaration::GetElement(unsigned int unsigned int NzVertexDeclaration::GetElementCount(unsigned int stream) const { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (stream >= m_streams.size()) { NazaraError("Stream out of range"); @@ -115,7 +107,7 @@ unsigned int NzVertexDeclaration::GetStreamCount() const unsigned int NzVertexDeclaration::GetStride(unsigned int stream) const { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (stream >= m_streams.size()) { NazaraError("Stream out of range");