Vertex declaration changes (#135)

* Add type to ComponentType conversion

* Change type to ComponentType conversion

* Change assert to condition, add check on particle mapper.

* Change particle life type

* Changes as requested

* Fix Travis try 1

* Changes as requested

* move IsSuitableForComponent to inl
This commit is contained in:
larnin
2017-10-02 15:21:03 +02:00
committed by Jérôme Leclercq
parent bbac0838dd
commit 40a678889d
13 changed files with 125 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -8,18 +8,24 @@
#define NAZARA_ALGORITHM_UTILITY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Utility/IndexIterator.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/SkeletalMesh.hpp>
namespace Nz
{
class Joint;
class VertexStruct_XYZ_Normal_UV_Tangent;
class VertexStruct_XYZ_Normal_UV_Tangent_Skinning;
using MeshVertex = VertexStruct_XYZ_Normal_UV_Tangent;
using SkeletalMeshVertex = VertexStruct_XYZ_Normal_UV_Tangent_Skinning;
struct SkinningData
{
@@ -59,6 +65,10 @@ namespace Nz
NAZARA_UTILITY_API void SkinPositionNormalTangent(const SkinningData& data, unsigned int startVertex, unsigned int vertexCount);
NAZARA_UTILITY_API void TransformVertices(VertexPointers vertexPointers, unsigned int vertexCount, const Matrix4f& matrix);
template<typename T> constexpr ComponentType ComponentTypeId();
template<typename T> constexpr const ComponentType GetComponentTypeOf();
}
#include <Nazara/Utility/Algorithm.inl>
#endif // NAZARA_ALGORITHM_UTILITY_HPP

View File

@@ -0,0 +1,45 @@
#pragma once
#include <Nazara/Utility/Algorithm.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
namespace Detail
{
template<typename T>
struct IsSuitableForComponent
{
constexpr static bool value = false;
};
}
template<typename T> constexpr ComponentType ComponentTypeId()
{
static_assert(Detail::IsSuitableForComponent<T>::value, "This type cannot be used as a component.");
return ComponentType{};
}
template<> constexpr ComponentType ComponentTypeId<Color>() { return ComponentType_Color; }
template<> constexpr ComponentType ComponentTypeId<double>() { return ComponentType_Double1; }
template<> constexpr ComponentType ComponentTypeId<Vector2d>() { return ComponentType_Double2; }
template<> constexpr ComponentType ComponentTypeId<Vector3d>() { return ComponentType_Double3; }
template<> constexpr ComponentType ComponentTypeId<Vector4d>() { return ComponentType_Double4; }
template<> constexpr ComponentType ComponentTypeId<float>() { return ComponentType_Float1; }
template<> constexpr ComponentType ComponentTypeId<Vector2f>() { return ComponentType_Float2; }
template<> constexpr ComponentType ComponentTypeId<Vector3f>() { return ComponentType_Float3; }
template<> constexpr ComponentType ComponentTypeId<Vector4f>() { return ComponentType_Float4; }
template<> constexpr ComponentType ComponentTypeId<int>() { return ComponentType_Int1; }
template<> constexpr ComponentType ComponentTypeId<Vector2i>() { return ComponentType_Int2; }
template<> constexpr ComponentType ComponentTypeId<Vector3i>() { return ComponentType_Int3; }
template<> constexpr ComponentType ComponentTypeId<Vector4i>() { return ComponentType_Int4; }
template<> constexpr ComponentType ComponentTypeId<Quaternionf>() { return ComponentType_Quaternion; }
template<typename T>
constexpr const ComponentType GetComponentTypeOf()
{
return ComponentTypeId<std::decay_t<T>>();
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -36,6 +36,13 @@ namespace Nz
bool center = false; ///< If true, will center the mesh vertices around the origin
bool optimizeIndexBuffers = true; ///< Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
/* The declaration must have a Vector3f position component enabled
* If the declaration has a Vector2f UV component enabled, UV are generated
* If the declaration has a Vector3f Normals component enabled, Normals are generated.
* If the declaration has a Vector3f Tangents component enabled, Tangents are generated.
*/
VertexDeclaration* vertexDeclaration = VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent);
bool IsValid() const;
};

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -38,6 +38,8 @@ namespace Nz
void EnableComponent(VertexComponent component, ComponentType type, std::size_t offset);
void GetComponent(VertexComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const;
bool HasComponent(VertexComponent component) const;
template<typename T> bool HasComponentOfType(VertexComponent component) const;
std::size_t GetStride() const;
void SetStride(std::size_t stride);

View File

@@ -1,9 +1,10 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Utility/Algorithm.hpp>
namespace Nz
{
@@ -15,6 +16,17 @@ namespace Nz
return object.release();
}
template<typename T>
bool VertexDeclaration::HasComponentOfType(VertexComponent component) const
{
bool enabled;
Nz::ComponentType type;
GetComponent(component, &enabled, &type, nullptr);
return enabled && GetComponentTypeOf<T>() == type;
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -27,6 +27,7 @@ namespace Nz
~VertexMapper();
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component);
template<typename T> bool HasComponentOfType(VertexComponent component) const;
void Unmap();

View File

@@ -1,9 +1,10 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Utility/Algorithm.hpp>
namespace Nz
{
@@ -19,7 +20,7 @@ namespace Nz
std::size_t offset;
declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled)
if (enabled && GetComponentTypeOf<T>() == type)
{
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ?
return SparsePtr<T>(static_cast<UInt8*>(m_mapper.GetPointer()) + offset, declaration->GetStride());
@@ -30,6 +31,12 @@ namespace Nz
return SparsePtr<T>();
}
}
template<typename T>
bool VertexMapper::HasComponentOfType(VertexComponent component) const
{
return m_mapper.GetBuffer()->GetVertexDeclaration()->HasComponentOfType<T>(component);
}
}
#include <Nazara/Utility/DebugOff.hpp>