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:
parent
bbac0838dd
commit
40a678889d
|
|
@ -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 - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
#include <Nazara/Utility/Algorithm.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -26,7 +27,7 @@ namespace Nz
|
|||
std::size_t offset;
|
||||
m_declaration->GetComponent(component, &enabled, &type, &offset);
|
||||
|
||||
if (enabled)
|
||||
if (enabled && GetComponentTypeOf<T>() == type)
|
||||
{
|
||||
///TODO: Check the ratio between the type of the attribute and the template type ?
|
||||
return SparsePtr<T>(m_ptr + offset, m_declaration->GetStride());
|
||||
|
|
@ -57,7 +58,7 @@ namespace Nz
|
|||
std::size_t offset;
|
||||
m_declaration->GetComponent(component, &enabled, &type, &offset);
|
||||
|
||||
if (enabled)
|
||||
if (enabled && GetComponentTypeOf<T>() == type)
|
||||
{
|
||||
///TODO: Check the ratio between the type of the attribute and the template type ?
|
||||
return SparsePtr<const T>(m_ptr + offset, m_declaration->GetStride());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ namespace Nz
|
|||
// ParticleLayout_Billboard : ParticleStruct_Billboard
|
||||
declaration = &s_declarations[ParticleLayout_Billboard];
|
||||
declaration->EnableComponent(ParticleComponent_Color, ComponentType_Color, NazaraOffsetOf(ParticleStruct_Billboard, color));
|
||||
declaration->EnableComponent(ParticleComponent_Life, ComponentType_Int1, NazaraOffsetOf(ParticleStruct_Billboard, life));
|
||||
declaration->EnableComponent(ParticleComponent_Life, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Billboard, life));
|
||||
declaration->EnableComponent(ParticleComponent_Normal, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Billboard, normal));
|
||||
declaration->EnableComponent(ParticleComponent_Position, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Billboard, position));
|
||||
declaration->EnableComponent(ParticleComponent_Rotation, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Billboard, rotation));
|
||||
|
|
@ -297,7 +297,7 @@ namespace Nz
|
|||
|
||||
// ParticleLayout_Model : ParticleStruct_Model
|
||||
declaration = &s_declarations[ParticleLayout_Model];
|
||||
declaration->EnableComponent(ParticleComponent_Life, ComponentType_Int1, NazaraOffsetOf(ParticleStruct_Model, life));
|
||||
declaration->EnableComponent(ParticleComponent_Life, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Model, life));
|
||||
declaration->EnableComponent(ParticleComponent_Position, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Model, position));
|
||||
declaration->EnableComponent(ParticleComponent_Rotation, ComponentType_Quaternion, NazaraOffsetOf(ParticleStruct_Model, rotation));
|
||||
declaration->EnableComponent(ParticleComponent_Velocity, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Model, velocity));
|
||||
|
|
@ -307,7 +307,7 @@ namespace Nz
|
|||
// ParticleLayout_Sprite : ParticleStruct_Sprite
|
||||
declaration = &s_declarations[ParticleLayout_Sprite];
|
||||
declaration->EnableComponent(ParticleComponent_Color, ComponentType_Color, NazaraOffsetOf(ParticleStruct_Sprite, color));
|
||||
declaration->EnableComponent(ParticleComponent_Life, ComponentType_Int1, NazaraOffsetOf(ParticleStruct_Sprite, life));
|
||||
declaration->EnableComponent(ParticleComponent_Life, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Sprite, life));
|
||||
declaration->EnableComponent(ParticleComponent_Position, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Sprite, position));
|
||||
declaration->EnableComponent(ParticleComponent_Rotation, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Sprite, rotation));
|
||||
declaration->EnableComponent(ParticleComponent_Velocity, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Sprite, velocity));
|
||||
|
|
|
|||
|
|
@ -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 - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
#include <Nazara/Utility/Joint.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <unordered_map>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -31,6 +31,8 @@
|
|||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -41,6 +41,12 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
if (vertexDeclaration == nullptr)
|
||||
{
|
||||
NazaraError("The vertex declaration can't be null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +107,7 @@ namespace Nz
|
|||
NazaraAssert(m_impl, "Mesh should be created first");
|
||||
NazaraAssert(m_impl->animationType == AnimationType_Static, "Submesh building only works for static meshes");
|
||||
NazaraAssert(params.IsValid(), "Invalid parameters");
|
||||
NazaraAssert(params.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Position), "The vertex declaration doesn't have a Vector3 position component");
|
||||
|
||||
Boxf aabb;
|
||||
IndexBufferRef indexBuffer;
|
||||
|
|
@ -109,7 +116,7 @@ namespace Nz
|
|||
Matrix4f matrix(primitive.matrix);
|
||||
matrix *= params.matrix;
|
||||
|
||||
VertexDeclaration* declaration = VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent);
|
||||
VertexDeclaration* declaration = params.vertexDeclaration;
|
||||
|
||||
switch (primitive.type)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -120,6 +120,15 @@ namespace Nz
|
|||
*offset = vertexComponent.offset;
|
||||
}
|
||||
|
||||
bool VertexDeclaration::HasComponent(VertexComponent component) const
|
||||
{
|
||||
bool enabled;
|
||||
|
||||
GetComponent(component, &enabled, nullptr, nullptr);
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
std::size_t VertexDeclaration::GetStride() const
|
||||
{
|
||||
return m_stride;
|
||||
|
|
|
|||
Loading…
Reference in New Issue