From b54be6e25f8b01276028ecddbc54bc8e918ed4b4 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 10 Jul 2014 18:31:56 +0200 Subject: [PATCH] Renamed AttributeUsage and AttributeType ... to VertexComponent and ComponentType. -Renderer: Renamed IsVertexAttributeSupported static method to IsComponentTypeSupported -VertexDeclaration: Added IsTypeSupported static method Renamed [Disable|Enable|Get]Attribute to [Disable|Enable|Get]Component Removed GetAttributeSize static method -VertexMapper: Renamed GetAttributePtr method to GetComponentPtr Former-commit-id: 7115856e1d389610c35b26f63af5d93a5ad5c690 --- include/Nazara/Renderer/OpenGL.hpp | 4 +- include/Nazara/Renderer/Renderer.hpp | 2 +- include/Nazara/Utility/Enums.hpp | 96 +++++----- include/Nazara/Utility/Utility.hpp | 4 + include/Nazara/Utility/VertexDeclaration.hpp | 14 +- include/Nazara/Utility/VertexMapper.hpp | 2 +- include/Nazara/Utility/VertexMapper.inl | 8 +- src/Nazara/Renderer/OpenGL.cpp | 82 ++++---- src/Nazara/Renderer/Renderer.cpp | 138 +++++++------- src/Nazara/Renderer/Shader.cpp | 32 ++-- src/Nazara/Utility/StaticMesh.cpp | 2 +- src/Nazara/Utility/SubMesh.cpp | 20 +- src/Nazara/Utility/Utility.cpp | 38 ++++ src/Nazara/Utility/VertexDeclaration.cpp | 189 +++++++++---------- 14 files changed, 326 insertions(+), 305 deletions(-) diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 32903f4cf..df6c199d7 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -127,14 +127,13 @@ class NAZARA_API NzOpenGL static void Uninitialize(); static GLenum Attachment[nzAttachmentPoint_Max+1]; - static nzUInt8 AttributeIndex[nzAttributeUsage_Max+1]; - static GLenum AttributeType[nzAttributeType_Max+1]; static GLenum BlendFunc[nzBlendFunc_Max+1]; static GLenum BufferLock[nzBufferAccess_Max+1]; static GLenum BufferLockRange[nzBufferAccess_Max+1]; static GLenum BufferTarget[nzBufferType_Max+1]; static GLenum BufferTargetBinding[nzBufferType_Max+1]; static GLenum BufferUsage[nzBufferUsage_Max+1]; + static GLenum ComponentType[nzComponentType_Max+1]; static GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas près de changer static GLenum FaceFilling[nzFaceFilling_Max+1]; static GLenum FaceSide[nzFaceSide_Max+1]; @@ -149,6 +148,7 @@ class NAZARA_API NzOpenGL static GLenum TextureTarget[nzImageType_Max+1]; static GLenum TextureTargetBinding[nzImageType_Max+1]; static GLenum TextureTargetProxy[nzImageType_Max+1]; + static nzUInt8 VertexComponentIndex[nzVertexComponent_Max+1]; private: static void OnContextChanged(const NzContext* newContext); diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index 0c4969f8a..aff9101fa 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -70,9 +70,9 @@ class NAZARA_API NzRenderer static bool Initialize(); + static bool IsComponentTypeSupported(nzComponentType type); static bool IsEnabled(nzRendererParameter parameter); static bool IsInitialized(); - static bool IsVertexAttributeSupported(nzAttributeType attributeType); static void SetBlendFunc(nzBlendFunc srcBlend, nzBlendFunc dstBlend); static void SetClearColor(const NzColor& color); diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 4ac0a08e1..20a91f22d 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -15,54 +15,6 @@ enum nzAnimationType nzAnimationType_Max = nzAnimationType_Static }; -enum nzAttributeType -{ - nzAttributeType_Color, - nzAttributeType_Double1, - nzAttributeType_Double2, - nzAttributeType_Double3, - nzAttributeType_Double4, - nzAttributeType_Float1, - nzAttributeType_Float2, - nzAttributeType_Float3, - nzAttributeType_Float4, - nzAttributeType_Int1, - nzAttributeType_Int2, - nzAttributeType_Int3, - nzAttributeType_Int4, - - nzAttributeType_Max = nzAttributeType_Int4 -}; - -enum nzAttributeUsage -{ - nzAttributeUsage_Unused = -1, - - nzAttributeUsage_InstanceData0, - nzAttributeUsage_InstanceData1, - nzAttributeUsage_InstanceData2, - nzAttributeUsage_InstanceData3, - nzAttributeUsage_InstanceData4, - nzAttributeUsage_InstanceData5, - nzAttributeUsage_Normal, - nzAttributeUsage_Position, - nzAttributeUsage_Tangent, - nzAttributeUsage_TexCoord, - nzAttributeUsage_Userdata0, - nzAttributeUsage_Userdata1, - nzAttributeUsage_Userdata2, - nzAttributeUsage_Userdata3, - nzAttributeUsage_Userdata4, - nzAttributeUsage_Userdata5, - - nzAttributeUsage_FirstInstanceData = nzAttributeUsage_InstanceData0, - nzAttributeUsage_FirstVertexData = nzAttributeUsage_Normal, - nzAttributeUsage_LastInstanceData = nzAttributeUsage_InstanceData5, - nzAttributeUsage_LastVertexData = nzAttributeUsage_Userdata5, - - nzAttributeUsage_Max = nzAttributeUsage_Userdata5 -}; - enum nzBufferAccess { nzBufferAccess_DiscardAndWrite, @@ -98,6 +50,25 @@ enum nzBufferUsage nzBufferUsage_Max = nzBufferUsage_Static }; +enum nzComponentType +{ + nzComponentType_Color, + nzComponentType_Double1, + nzComponentType_Double2, + nzComponentType_Double3, + nzComponentType_Double4, + nzComponentType_Float1, + nzComponentType_Float2, + nzComponentType_Float3, + nzComponentType_Float4, + nzComponentType_Int1, + nzComponentType_Int2, + nzComponentType_Int3, + nzComponentType_Int4, + + nzComponentType_Max = nzComponentType_Int4 +}; + enum nzCubemapFace { // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap @@ -245,6 +216,35 @@ enum nzPrimitiveMode nzPrimitiveMode_Max = nzPrimitiveMode_TriangleFan }; +enum nzVertexComponent +{ + nzVertexComponent_Unused = -1, + + nzVertexComponent_InstanceData0, + nzVertexComponent_InstanceData1, + nzVertexComponent_InstanceData2, + nzVertexComponent_InstanceData3, + nzVertexComponent_InstanceData4, + nzVertexComponent_InstanceData5, + nzVertexComponent_Normal, + nzVertexComponent_Position, + nzVertexComponent_Tangent, + nzVertexComponent_TexCoord, + nzVertexComponent_Userdata0, + nzVertexComponent_Userdata1, + nzVertexComponent_Userdata2, + nzVertexComponent_Userdata3, + nzVertexComponent_Userdata4, + nzVertexComponent_Userdata5, + + nzVertexComponent_FirstInstanceData = nzVertexComponent_InstanceData0, + nzVertexComponent_FirstVertexData = nzVertexComponent_Normal, + nzVertexComponent_LastInstanceData = nzVertexComponent_InstanceData5, + nzVertexComponent_LastVertexData = nzVertexComponent_Userdata5, + + nzVertexComponent_Max = nzVertexComponent_Userdata5 +}; + enum nzVertexLayout { // Déclarations destinées au rendu diff --git a/include/Nazara/Utility/Utility.hpp b/include/Nazara/Utility/Utility.hpp index 7da29a3ce..94749ec4b 100644 --- a/include/Nazara/Utility/Utility.hpp +++ b/include/Nazara/Utility/Utility.hpp @@ -9,6 +9,7 @@ #include #include +#include class NAZARA_API NzUtility { @@ -22,6 +23,9 @@ class NAZARA_API NzUtility static void Uninitialize(); + static unsigned int ComponentCount[nzComponentType_Max+1]; + static std::size_t ComponentStride[nzComponentType_Max+1]; + private: static unsigned int s_moduleReferenceCounter; }; diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 8a6215941..a34875944 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -28,10 +28,10 @@ class NAZARA_API NzVertexDeclaration : public NzResource NzVertexDeclaration(NzVertexDeclaration& declaration); ~NzVertexDeclaration(); - void DisableAttribute(nzAttributeUsage usage); - void EnableAttribute(nzAttributeUsage usage, nzAttributeType type, unsigned int offset); + void DisableComponent(nzVertexComponent component); + void EnableComponent(nzVertexComponent component, nzComponentType type, unsigned int offset); - void GetAttribute(nzAttributeUsage usage, bool* enabled, nzAttributeType* type, unsigned int* offset) const; + void GetComponent(nzVertexComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const; unsigned int GetStride() const; void SetStride(unsigned int stride); @@ -39,15 +39,15 @@ class NAZARA_API NzVertexDeclaration : public NzResource NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); static NzVertexDeclaration* Get(nzVertexLayout layout); - static unsigned int GetAttributeSize(nzAttributeType type); + static bool IsTypeSupported(nzComponentType type); private: static bool Initialize(); static void Uninitialize(); - struct Attribute + struct Component { - nzAttributeType type; + nzComponentType type; bool enabled = false; unsigned int offset; @@ -60,7 +60,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource */ }; - Attribute m_attributes[nzAttributeUsage_Max+1]; + Component m_components[nzVertexComponent_Max+1]; unsigned int m_stride; static NzVertexDeclaration s_declarations[nzVertexLayout_Max+1]; diff --git a/include/Nazara/Utility/VertexMapper.hpp b/include/Nazara/Utility/VertexMapper.hpp index d6a3845c0..446d1450d 100644 --- a/include/Nazara/Utility/VertexMapper.hpp +++ b/include/Nazara/Utility/VertexMapper.hpp @@ -24,7 +24,7 @@ class NAZARA_API NzVertexMapper NzVertexMapper(NzSubMesh* subMesh); ~NzVertexMapper(); - template NzSparsePtr GetAttributePtr(nzAttributeUsage attribute); + template NzSparsePtr GetComponentPtr(nzVertexComponent component); unsigned int GetVertexCount() const; void Unmap(); diff --git a/include/Nazara/Utility/VertexMapper.inl b/include/Nazara/Utility/VertexMapper.inl index d66f5bd93..19bfa18c6 100644 --- a/include/Nazara/Utility/VertexMapper.inl +++ b/include/Nazara/Utility/VertexMapper.inl @@ -5,12 +5,12 @@ #include template -NzSparsePtr NzVertexMapper::GetAttributePtr(nzAttributeUsage attribute) +NzSparsePtr NzVertexMapper::GetComponentPtr(nzVertexComponent component) { bool enabled; - nzAttributeType type; + nzComponentType type; unsigned int offset; - m_declaration->GetAttribute(attribute, &enabled, &type, &offset); + m_declaration->GetComponent(component, &enabled, &type, &offset); if (enabled) { @@ -19,7 +19,7 @@ NzSparsePtr NzVertexMapper::GetAttributePtr(nzAttributeUsage attribute) } else { - NazaraError("Attribute 0x" + NzString::Number(attribute, 16) + " is not enabled"); + NazaraError("Attribute 0x" + NzString::Number(component, 16) + " is not enabled"); return NzSparsePtr(); } } diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index dc61be353..7441b916b 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1854,47 +1854,6 @@ GLenum NzOpenGL::Attachment[] = static_assert(nzAttachmentPoint_Max+1 == 4, "Attachment array is incomplete"); -nzUInt8 NzOpenGL::AttributeIndex[] = -{ - 10, // nzAttributeUsage_InstanceData0 - 11, // nzAttributeUsage_InstanceData1 - 12, // nzAttributeUsage_InstanceData2 - 13, // nzAttributeUsage_InstanceData3 - 14, // nzAttributeUsage_InstanceData4 - 15, // nzAttributeUsage_InstanceData5 - 2, // nzAttributeUsage_Normal - 0, // nzAttributeUsage_Position - 3, // nzAttributeUsage_Tangent - 1, // nzAttributeUsage_TexCoord - 4, // nzAttributeUsage_Userdata0 - 5, // nzAttributeUsage_Userdata1 - 6, // nzAttributeUsage_Userdata2 - 7, // nzAttributeUsage_Userdata3 - 8, // nzAttributeUsage_Userdata4 - 9 // nzAttributeUsage_Userdata5 -}; - -static_assert(nzAttributeUsage_Max+1 == 16, "Attribute index array is incomplete"); - -GLenum NzOpenGL::AttributeType[] = -{ - GL_UNSIGNED_BYTE, // nzAttributeType_Color - GL_DOUBLE, // nzAttributeType_Double1 - GL_DOUBLE, // nzAttributeType_Double2 - GL_DOUBLE, // nzAttributeType_Double3 - GL_DOUBLE, // nzAttributeType_Double4 - GL_FLOAT, // nzAttributeType_Float1 - GL_FLOAT, // nzAttributeType_Float2 - GL_FLOAT, // nzAttributeType_Float3 - GL_FLOAT, // nzAttributeType_Float4 - GL_INT, // nzAttributeType_Int1 - GL_INT, // nzAttributeType_Int2 - GL_INT, // nzAttributeType_Int3 - GL_INT // nzAttributeType_Int4 -}; - -static_assert(nzAttributeType_Max+1 == 13, "Attribute type array is incomplete"); - GLenum NzOpenGL::BlendFunc[] = { GL_DST_ALPHA, // nzBlendFunc_DestAlpha @@ -1958,6 +1917,25 @@ GLenum NzOpenGL::BufferUsage[] = static_assert(nzBufferUsage_Max+1 == 2, "Buffer usage array is incomplete"); +GLenum NzOpenGL::ComponentType[] = +{ + GL_UNSIGNED_BYTE, // nzComponentType_Color + GL_DOUBLE, // nzComponentType_Double1 + GL_DOUBLE, // nzComponentType_Double2 + GL_DOUBLE, // nzComponentType_Double3 + GL_DOUBLE, // nzComponentType_Double4 + GL_FLOAT, // nzComponentType_Float1 + GL_FLOAT, // nzComponentType_Float2 + GL_FLOAT, // nzComponentType_Float3 + GL_FLOAT, // nzComponentType_Float4 + GL_INT, // nzComponentType_Int1 + GL_INT, // nzComponentType_Int2 + GL_INT, // nzComponentType_Int3 + GL_INT // nzComponentType_Int4 +}; + +static_assert(nzComponentType_Max+1 == 13, "Attribute type array is incomplete"); + GLenum NzOpenGL::CubemapFace[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX @@ -2117,6 +2095,28 @@ GLenum NzOpenGL::TextureTargetProxy[] = static_assert(nzImageType_Max+1 == 6, "Texture target proxy array is incomplete"); +nzUInt8 NzOpenGL::VertexComponentIndex[] = +{ + 10, // nzVertexComponent_InstanceData0 + 11, // nzVertexComponent_InstanceData1 + 12, // nzVertexComponent_InstanceData2 + 13, // nzVertexComponent_InstanceData3 + 14, // nzVertexComponent_InstanceData4 + 15, // nzVertexComponent_InstanceData5 + 2, // nzVertexComponent_Normal + 0, // nzVertexComponent_Position + 3, // nzVertexComponent_Tangent + 1, // nzVertexComponent_TexCoord + 4, // nzVertexComponent_Userdata0 + 5, // nzVertexComponent_Userdata1 + 6, // nzVertexComponent_Userdata2 + 7, // nzVertexComponent_Userdata3 + 8, // nzVertexComponent_Userdata4 + 9 // nzVertexComponent_Userdata5 +}; + +static_assert(nzVertexComponent_Max+1 == 16, "Attribute index array is incomplete"); + PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; PFNGLATTACHSHADERPROC glAttachShader = nullptr; PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender = nullptr; diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 2f46170d4..19666be01 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -897,6 +897,34 @@ bool NzRenderer::Initialize() return true; } +bool NzRenderer::IsComponentTypeSupported(nzComponentType type) +{ + switch (type) + { + case nzComponentType_Color: + case nzComponentType_Float1: + case nzComponentType_Float2: + case nzComponentType_Float3: + case nzComponentType_Float4: + return true; // Supportés nativement + + case nzComponentType_Double1: + case nzComponentType_Double2: + case nzComponentType_Double3: + case nzComponentType_Double4: + return glVertexAttribLPointer != nullptr; // Fonction requise pour envoyer des doubles + + case nzComponentType_Int1: + case nzComponentType_Int2: + case nzComponentType_Int3: + case nzComponentType_Int4: + return glVertexAttribIPointer != nullptr; // Fonction requise pour envoyer des entiers + } + + NazaraError("Attribute type out of enum (0x" + NzString::Number(type, 16) + ')'); + return false; +} + bool NzRenderer::IsEnabled(nzRendererParameter parameter) { #ifdef NAZARA_DEBUG @@ -915,34 +943,6 @@ bool NzRenderer::IsInitialized() return s_moduleReferenceCounter != 0; } -bool NzRenderer::IsVertexAttributeSupported(nzAttributeType attributeType) -{ - switch (attributeType) - { - case nzAttributeType_Color: - case nzAttributeType_Float1: - case nzAttributeType_Float2: - case nzAttributeType_Float3: - case nzAttributeType_Float4: - return true; // Supportés nativement - - case nzAttributeType_Double1: - case nzAttributeType_Double2: - case nzAttributeType_Double3: - case nzAttributeType_Double4: - return glVertexAttribLPointer != nullptr; // Fonction requise pour envoyer des doubles - - case nzAttributeType_Int1: - case nzAttributeType_Int2: - case nzAttributeType_Int3: - case nzAttributeType_Int4: - return glVertexAttribIPointer != nullptr; // Fonction requise pour envoyer des entiers - } - - NazaraError("Attribute type out of enum"); - return false; -} - void NzRenderer::SetBlendFunc(nzBlendFunc srcBlend, nzBlendFunc dstBlend) { #ifdef NAZARA_DEBUG @@ -1766,51 +1766,51 @@ bool NzRenderer::EnsureStateUpdate() bufferOffset = s_vertexBuffer->GetStartOffset(); vertexDeclaration = s_vertexBuffer->GetVertexDeclaration(); stride = vertexDeclaration->GetStride(); - for (unsigned int i = nzAttributeUsage_FirstVertexData; i <= nzAttributeUsage_LastVertexData; ++i) + for (unsigned int i = nzVertexComponent_FirstVertexData; i <= nzVertexComponent_LastVertexData; ++i) { - nzAttributeType type; + nzComponentType type; bool enabled; unsigned int offset; - vertexDeclaration->GetAttribute(static_cast(i), &enabled, &type, &offset); + vertexDeclaration->GetComponent(static_cast(i), &enabled, &type, &offset); - if (!IsVertexAttributeSupported(type)) + if (!IsComponentTypeSupported(type)) { - NazaraError("Invalid declaration: Vertex attribute 0x" + NzString::Number(i, 16) + " (0x" + NzString::Number(type, 16) + ") is not supported"); + NazaraError("Invalid declaration: Vertex component 0x" + NzString::Number(i, 16) + " (type: 0x" + NzString::Number(type, 16) + ") is not supported"); updateFailed = true; break; } if (enabled) { - glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); - if (type <= nzAttributeType_Double1 && type >= nzAttributeType_Double4) + glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]); + if (type <= nzComponentType_Double1 && type >= nzComponentType_Double4) { - glVertexAttribLPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetAttributeSize(type), - NzOpenGL::AttributeType[type], + glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[i], + NzUtility::ComponentCount[type], + NzOpenGL::ComponentType[type], stride, reinterpret_cast(bufferOffset + offset)); } - else if (type <= nzAttributeType_Int1 && type >= nzAttributeType_Int4) + else if (type <= nzComponentType_Int1 && type >= nzComponentType_Int4) { - glVertexAttribIPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetAttributeSize(type), - NzOpenGL::AttributeType[type], + glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[i], + NzUtility::ComponentCount[type], + NzOpenGL::ComponentType[type], stride, reinterpret_cast(bufferOffset + offset)); } else { - glVertexAttribPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetAttributeSize(type), - NzOpenGL::AttributeType[type], - (type == nzAttributeType_Color) ? GL_TRUE : GL_FALSE, + glVertexAttribPointer(NzOpenGL::VertexComponentIndex[i], + NzUtility::ComponentCount[type], + NzOpenGL::ComponentType[type], + (type == nzComponentType_Color) ? GL_TRUE : GL_FALSE, stride, reinterpret_cast(bufferOffset + offset)); } } else - glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]); } if (!updateFailed) @@ -1823,59 +1823,59 @@ bool NzRenderer::EnsureStateUpdate() bufferOffset = s_instanceBuffer.GetStartOffset(); vertexDeclaration = s_instanceBuffer.GetVertexDeclaration(); stride = vertexDeclaration->GetStride(); - for (unsigned int i = nzAttributeUsage_FirstInstanceData; i <= nzAttributeUsage_LastInstanceData; ++i) + for (unsigned int i = nzVertexComponent_FirstInstanceData; i <= nzVertexComponent_LastInstanceData; ++i) { - nzAttributeType type; + nzComponentType type; bool enabled; unsigned int offset; - vertexDeclaration->GetAttribute(static_cast(i), &enabled, &type, &offset); + vertexDeclaration->GetComponent(static_cast(i), &enabled, &type, &offset); - if (!IsVertexAttributeSupported(type)) + if (!IsComponentTypeSupported(type)) { - NazaraError("Invalid declaration: Vertex attribute 0x" + NzString::Number(i, 16) + " (0x" + NzString::Number(type, 16) + ") is not supported"); + NazaraError("Invalid declaration: Vertex component 0x" + NzString::Number(i, 16) + " (type: 0x" + NzString::Number(type, 16) + ") is not supported"); updateFailed = true; break; } if (enabled) { - glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); - if (type <= nzAttributeType_Double1 && type >= nzAttributeType_Double4) + glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]); + if (type <= nzComponentType_Double1 && type >= nzComponentType_Double4) { - glVertexAttribLPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetAttributeSize(type), - NzOpenGL::AttributeType[type], + glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[i], + NzUtility::ComponentCount[type], + NzOpenGL::ComponentType[type], stride, reinterpret_cast(bufferOffset + offset)); } - else if (type <= nzAttributeType_Int1 && type >= nzAttributeType_Int4) + else if (type <= nzComponentType_Int1 && type >= nzComponentType_Int4) { - glVertexAttribIPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetAttributeSize(type), - NzOpenGL::AttributeType[type], + glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[i], + NzUtility::ComponentCount[type], + NzOpenGL::ComponentType[type], stride, reinterpret_cast(bufferOffset + offset)); } else { - glVertexAttribPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetAttributeSize(type), - NzOpenGL::AttributeType[type], - (type == nzAttributeType_Color) ? GL_TRUE : GL_FALSE, + glVertexAttribPointer(NzOpenGL::VertexComponentIndex[i], + NzUtility::ComponentCount[type], + NzOpenGL::ComponentType[type], + (type == nzComponentType_Color) ? GL_TRUE : GL_FALSE, stride, reinterpret_cast(bufferOffset + offset)); } - glVertexAttribDivisor(NzOpenGL::AttributeIndex[i], 1); + glVertexAttribDivisor(NzOpenGL::VertexComponentIndex[i], 1); } else - glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]); } } else { - for (unsigned int i = nzAttributeUsage_FirstInstanceData; i <= nzAttributeUsage_LastInstanceData; ++i) - glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + for (unsigned int i = nzVertexComponent_FirstInstanceData; i <= nzVertexComponent_LastInstanceData; ++i) + glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]); } // Et on active l'index buffer (Un seul index buffer par VAO) diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index 9364597ef..3f68daec4 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -149,22 +149,22 @@ bool NzShader::Create() m_linked = false; - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData0], "InstanceData0"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData1], "InstanceData1"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData2], "InstanceData2"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData3], "InstanceData3"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData4], "InstanceData4"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData5], "InstanceData5"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Normal], "VertexNormal"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Position], "VertexPosition"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Tangent], "VertexTangent"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_TexCoord], "VertexTexCoord"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata0], "VertexUserdata0"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata1], "VertexUserdata1"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata2], "VertexUserdata2"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata3], "VertexUserdata3"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata4], "VertexUserdata4"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata5], "VertexUserdata5"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData0], "InstanceData0"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData1], "InstanceData1"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData2], "InstanceData2"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData3], "InstanceData3"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData4], "InstanceData4"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData5], "InstanceData5"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Normal], "VertexNormal"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Position], "VertexPosition"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Tangent], "VertexTangent"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_TexCoord], "VertexTexCoord"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata0], "VertexUserdata0"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata1], "VertexUserdata1"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata2], "VertexUserdata2"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata3], "VertexUserdata3"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata4], "VertexUserdata4"); + glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata5], "VertexUserdata5"); if (NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets)) { diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index e0df0765b..b54126008 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -26,7 +26,7 @@ void NzStaticMesh::Center() NzVector3f offset(m_aabb.x + m_aabb.width/2.f, m_aabb.y + m_aabb.height/2.f, m_aabb.z + m_aabb.depth/2.f); NzVertexMapper mapper(this); - NzSparsePtr position = mapper.GetAttributePtr(nzAttributeUsage_Position); + NzSparsePtr position = mapper.GetComponentPtr(nzVertexComponent_Position); unsigned int vertexCount = mapper.GetVertexCount(); for (unsigned int i = 0; i < vertexCount; ++i) diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index 9ccb18f93..f44380a2f 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -27,8 +27,8 @@ void NzSubMesh::GenerateNormals() NzVertexMapper mapper(this); unsigned int vertexCount = mapper.GetVertexCount(); - NzSparsePtr normals = mapper.GetAttributePtr(nzAttributeUsage_Normal); - NzSparsePtr positions = mapper.GetAttributePtr(nzAttributeUsage_Position); + NzSparsePtr normals = mapper.GetComponentPtr(nzVertexComponent_Normal); + NzSparsePtr positions = mapper.GetComponentPtr(nzVertexComponent_Position); for (unsigned int i = 0; i < vertexCount; ++i) normals[i].MakeZero(); @@ -58,10 +58,10 @@ void NzSubMesh::GenerateNormalsAndTangents() NzVertexMapper mapper(this); unsigned int vertexCount = mapper.GetVertexCount(); - NzSparsePtr normals = mapper.GetAttributePtr(nzAttributeUsage_Normal); - NzSparsePtr positions = mapper.GetAttributePtr(nzAttributeUsage_Position); - NzSparsePtr tangents = mapper.GetAttributePtr(nzAttributeUsage_Tangent); - NzSparsePtr texCoords = mapper.GetAttributePtr(nzAttributeUsage_TexCoord); + NzSparsePtr normals = mapper.GetComponentPtr(nzVertexComponent_Normal); + NzSparsePtr positions = mapper.GetComponentPtr(nzVertexComponent_Position); + NzSparsePtr tangents = mapper.GetComponentPtr(nzVertexComponent_Tangent); + NzSparsePtr texCoords = mapper.GetComponentPtr(nzVertexComponent_TexCoord); for (unsigned int i = 0; i < vertexCount; ++i) { @@ -113,10 +113,10 @@ void NzSubMesh::GenerateTangents() { NzVertexMapper mapper(this); - NzSparsePtr normals = mapper.GetAttributePtr(nzAttributeUsage_Normal); - NzSparsePtr positions = mapper.GetAttributePtr(nzAttributeUsage_Position); - NzSparsePtr tangents = mapper.GetAttributePtr(nzAttributeUsage_Tangent); - NzSparsePtr texCoords = mapper.GetAttributePtr(nzAttributeUsage_TexCoord); + NzSparsePtr normals = mapper.GetComponentPtr(nzVertexComponent_Normal); + NzSparsePtr positions = mapper.GetComponentPtr(nzVertexComponent_Position); + NzSparsePtr tangents = mapper.GetComponentPtr(nzVertexComponent_Tangent); + NzSparsePtr texCoords = mapper.GetComponentPtr(nzVertexComponent_TexCoord); NzTriangleIterator iterator(this); do diff --git a/src/Nazara/Utility/Utility.cpp b/src/Nazara/Utility/Utility.cpp index 76d41a468..639272c79 100644 --- a/src/Nazara/Utility/Utility.cpp +++ b/src/Nazara/Utility/Utility.cpp @@ -126,4 +126,42 @@ void NzUtility::Uninitialize() NzCore::Uninitialize(); } +unsigned int NzUtility::ComponentCount[nzComponentType_Max+1] = +{ + 4, // nzComponentType_Color + 1, // nzComponentType_Double1 + 2, // nzComponentType_Double2 + 3, // nzComponentType_Double3 + 4, // nzComponentType_Double4 + 1, // nzComponentType_Float1 + 2, // nzComponentType_Float2 + 3, // nzComponentType_Float3 + 4, // nzComponentType_Float4 + 1, // nzComponentType_Int1 + 2, // nzComponentType_Int2 + 3, // nzComponentType_Int3 + 4 // nzComponentType_Int4 +}; + +static_assert(nzComponentType_Max+1 == 13, "Component count array is incomplete"); + +unsigned int NzUtility::ComponentStride[nzComponentType_Max+1] = +{ + 4*sizeof(nzUInt8), // nzComponentType_Color + 1*sizeof(double), // nzComponentType_Double1 + 2*sizeof(double), // nzComponentType_Double2 + 3*sizeof(double), // nzComponentType_Double3 + 4*sizeof(double), // nzComponentType_Double4 + 1*sizeof(float), // nzComponentType_Float1 + 2*sizeof(float), // nzComponentType_Float2 + 3*sizeof(float), // nzComponentType_Float3 + 4*sizeof(float), // nzComponentType_Float4 + 1*sizeof(nzUInt32), // nzComponentType_Int1 + 2*sizeof(nzUInt32), // nzComponentType_Int2 + 3*sizeof(nzUInt32), // nzComponentType_Int3 + 4*sizeof(nzUInt32) // nzComponentType_Int4 +}; + +static_assert(nzComponentType_Max+1 == 13, "Component stride array is incomplete"); + unsigned int NzUtility::s_moduleReferenceCounter = 0; diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index b282e570b..6b09def22 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -8,51 +8,11 @@ #include #include #include +#include #include #include #include -namespace -{ - unsigned int attributeSize[] = - { - 4, // nzAttributeType_Color - 1, // nzAttributeType_Double1 - 2, // nzAttributeType_Double2 - 3, // nzAttributeType_Double3 - 4, // nzAttributeType_Double4 - 1, // nzAttributeType_Float1 - 2, // nzAttributeType_Float2 - 3, // nzAttributeType_Float3 - 4, // nzAttributeType_Float4 - 1, // nzAttributeType_Int1 - 2, // nzAttributeType_Int2 - 3, // nzAttributeType_Int3 - 4 // nzAttributeType_Int4 - }; - - static_assert(sizeof(attributeSize)/sizeof(unsigned int) == nzAttributeType_Max+1, "Attribute size array is incomplete"); - - unsigned int attributeStride[] = - { - 4*sizeof(nzUInt8), // nzAttributeType_Color - 1*sizeof(double), // nzAttributeType_Double1 - 2*sizeof(double), // nzAttributeType_Double2 - 3*sizeof(double), // nzAttributeType_Double3 - 4*sizeof(double), // nzAttributeType_Double4 - 1*sizeof(float), // nzAttributeType_Float1 - 2*sizeof(float), // nzAttributeType_Float2 - 3*sizeof(float), // nzAttributeType_Float3 - 4*sizeof(float), // nzAttributeType_Float4 - 1*sizeof(nzUInt32), // nzAttributeType_Int1 - 2*sizeof(nzUInt32), // nzAttributeType_Int2 - 3*sizeof(nzUInt32), // nzAttributeType_Int3 - 4*sizeof(nzUInt32) // nzAttributeType_Int4 - }; - - static_assert(sizeof(attributeStride)/sizeof(unsigned int) == nzAttributeType_Max+1, "Attribute stride array is incomplete"); -} - NzVertexDeclaration::NzVertexDeclaration() : m_stride(0) { @@ -62,7 +22,7 @@ NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration& declaration) : NzResource(), m_stride(declaration.m_stride) { - std::memcpy(m_attributes, declaration.m_attributes, sizeof(Attribute)*(nzAttributeUsage_Max+1)); + std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1)); } NzVertexDeclaration::~NzVertexDeclaration() @@ -70,85 +30,93 @@ NzVertexDeclaration::~NzVertexDeclaration() NotifyDestroy(); } -void NzVertexDeclaration::DisableAttribute(nzAttributeUsage usage) +void NzVertexDeclaration::DisableComponent(nzVertexComponent component) { #ifdef NAZARA_DEBUG - if (usage > nzAttributeUsage_Max) + if (component > nzVertexComponent_Max) { - NazaraError("Attribute usage out of enum"); + NazaraError("Vertex component out of enum"); return; } #endif #if NAZARA_UTILITY_SAFE - if (usage == nzAttributeUsage_Unused) + if (component == nzVertexComponent_Unused) { - NazaraError("Cannot disable \"unused\" attribute"); + NazaraError("Cannot disable \"unused\" component"); return; } #endif - Attribute& attribute = m_attributes[usage]; - if (attribute.enabled) + Component& vertexComponent = m_components[component]; + if (vertexComponent.enabled) { - attribute.enabled = false; - m_stride -= attributeStride[attribute.type]; + vertexComponent.enabled = false; + m_stride -= NzUtility::ComponentStride[vertexComponent.type]; } } -void NzVertexDeclaration::EnableAttribute(nzAttributeUsage usage, nzAttributeType type, unsigned int offset) +void NzVertexDeclaration::EnableComponent(nzVertexComponent component, nzComponentType type, unsigned int offset) { #ifdef NAZARA_DEBUG - if (usage > nzAttributeUsage_Max) + if (component > nzVertexComponent_Max) { - NazaraError("Attribute usage out of enum"); + NazaraError("Vertex component out of enum"); return; } #endif - if (usage != nzAttributeUsage_Unused) + #if NAZARA_UTILITY_SAFE + if (!IsTypeSupported(type)) { - Attribute& attribute = m_attributes[usage]; - if (attribute.enabled) - m_stride -= attributeStride[attribute.type]; + NazaraError("Component type 0x" + NzString::Number(type, 16) + " is not supported by vertex declarations"); + return; + } + #endif + + if (component != nzVertexComponent_Unused) + { + Component& vertexComponent = m_components[component]; + if (vertexComponent.enabled) + m_stride -= NzUtility::ComponentStride[vertexComponent.type]; else - attribute.enabled = true; + vertexComponent.enabled = true; - attribute.offset = offset; - attribute.type = type; + vertexComponent.offset = offset; + vertexComponent.type = type; } - m_stride += attributeStride[type]; + m_stride += NzUtility::ComponentStride[type]; } -void NzVertexDeclaration::GetAttribute(nzAttributeUsage usage, bool* enabled, nzAttributeType* type, unsigned int* offset) const +void NzVertexDeclaration::GetComponent(nzVertexComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const { #ifdef NAZARA_DEBUG - if (usage > nzAttributeUsage_Max) + if (component > nzVertexComponent_Max) { - NazaraError("Attribute usage out of enum"); + NazaraError("Vertex component out of enum"); return; } #endif #if NAZARA_UTILITY_SAFE - if (usage == nzAttributeUsage_Unused) + if (component == nzVertexComponent_Unused) { - NazaraError("Cannot get \"unused\" attribute"); + NazaraError("Cannot get \"unused\" component"); return; } #endif - const Attribute& attribute = m_attributes[usage]; + const Component& vertexComponent = m_components[component]; if (enabled) - *enabled = attribute.enabled; + *enabled = vertexComponent.enabled; if (type) - *type = attribute.type; + *type = vertexComponent.type; if (offset) - *offset = attribute.offset; + *offset = vertexComponent.offset; } unsigned int NzVertexDeclaration::GetStride() const @@ -163,7 +131,7 @@ void NzVertexDeclaration::SetStride(unsigned int stride) NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration) { - std::memcpy(m_attributes, declaration.m_attributes, sizeof(Attribute)*(nzAttributeUsage_Max+1)); + std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1)); m_stride = declaration.m_stride; return *this; @@ -182,17 +150,28 @@ NzVertexDeclaration* NzVertexDeclaration::Get(nzVertexLayout layout) return &s_declarations[layout]; } -unsigned int NzVertexDeclaration::GetAttributeSize(nzAttributeType type) +bool NzVertexDeclaration::IsTypeSupported(nzComponentType type) { - #ifdef NAZARA_DEBUG - if (type > nzAttributeType_Max) + switch (type) { - NazaraError("Attribute type out of enum"); - return 0; + case nzComponentType_Color: + case nzComponentType_Double1: + case nzComponentType_Double2: + case nzComponentType_Double3: + case nzComponentType_Double4: + case nzComponentType_Float1: + case nzComponentType_Float2: + case nzComponentType_Float3: + case nzComponentType_Float4: + case nzComponentType_Int1: + case nzComponentType_Int2: + case nzComponentType_Int3: + case nzComponentType_Int4: + return true; } - #endif - return attributeSize[type]; + NazaraError("Component type not handled (0x" + NzString::Number(type, 16) + ')'); + return false; } bool NzVertexDeclaration::Initialize() @@ -206,72 +185,72 @@ bool NzVertexDeclaration::Initialize() // nzVertexLayout_XY : NzVertexStruct_XY declaration = &s_declarations[nzVertexLayout_XY]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XY, position)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY, position)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY), "Invalid stride for declaration NzVertexStruct_XY"); // nzVertexLayout_XY_UV : NzVertexStruct_XY_UV declaration = &s_declarations[nzVertexLayout_XY_UV]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, position)); - declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, uv)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, position)); + declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, uv)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_UV), "Invalid stride for declaration nzVertexLayout_XY_UV"); // nzVertexLayout_XYZ : NzVertexStruct_XYZ declaration = &s_declarations[nzVertexLayout_XYZ]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ, position)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ, position)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ"); // nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal declaration = &s_declarations[nzVertexLayout_XYZ_Normal]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position)); - declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, normal)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position)); + declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, normal)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal), "Invalid stride for declaration nzVertexLayout_XYZ_Normal"); // nzVertexLayout_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal_UV declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, position)); - declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, normal)); - declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, uv)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, position)); + declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, normal)); + declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, uv)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV"); // nzVertexLayout_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV_Tangent declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, position)); - declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, normal)); - declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, uv)); - declaration->EnableAttribute(nzAttributeUsage_Tangent, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, tangent)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, position)); + declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, normal)); + declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, uv)); + declaration->EnableComponent(nzVertexComponent_Tangent, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, tangent)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent"); // nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, position)); - declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, normal)); - declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, uv)); - declaration->EnableAttribute(nzAttributeUsage_Tangent, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, tangent)); - declaration->EnableAttribute(nzAttributeUsage_Unused, nzAttributeType_Int1, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weightCount)); - declaration->EnableAttribute(nzAttributeUsage_Userdata0, nzAttributeType_Float4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weights)); - declaration->EnableAttribute(nzAttributeUsage_Userdata1, nzAttributeType_Int4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, jointIndexes)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, position)); + declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, normal)); + declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, uv)); + declaration->EnableComponent(nzVertexComponent_Tangent, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, tangent)); + declaration->EnableComponent(nzVertexComponent_Unused, nzComponentType_Int1, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weightCount)); + declaration->EnableComponent(nzVertexComponent_Userdata0, nzComponentType_Float4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weights)); + declaration->EnableComponent(nzVertexComponent_Userdata1, nzComponentType_Int4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, jointIndexes)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning"); // nzVertexLayout_XYZ_UV : NzVertexStruct_XYZ_UV declaration = &s_declarations[nzVertexLayout_XYZ_UV]; - declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_UV, position)); - declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_UV, uv)); + declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_UV, position)); + declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_UV, uv)); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_UV), "Invalid stride for declaration nzVertexLayout_XYZ_UV"); // nzVertexLayout_Matrix4 : NzMatrix4f declaration = &s_declarations[nzVertexLayout_Matrix4]; - declaration->EnableAttribute(nzAttributeUsage_InstanceData0, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m11)); - declaration->EnableAttribute(nzAttributeUsage_InstanceData1, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m21)); - declaration->EnableAttribute(nzAttributeUsage_InstanceData2, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m31)); - declaration->EnableAttribute(nzAttributeUsage_InstanceData3, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m41)); + declaration->EnableComponent(nzVertexComponent_InstanceData0, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m11)); + declaration->EnableComponent(nzVertexComponent_InstanceData1, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m21)); + declaration->EnableComponent(nzVertexComponent_InstanceData2, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m31)); + declaration->EnableComponent(nzVertexComponent_InstanceData3, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m41)); NazaraAssert(declaration->GetStride() == sizeof(NzMatrix4f), "Invalid stride for declaration nzVertexLayout_Matrix4"); }