WIP (VertexDeclaration)
This commit is contained in:
@@ -1,40 +1,32 @@
|
||||
// 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/Algorithm.hpp>
|
||||
#include <Nazara/Core/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.");
|
||||
static_assert(AlwaysFalse<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<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>
|
||||
|
||||
@@ -356,35 +356,25 @@ namespace Nz
|
||||
{
|
||||
VertexComponent_Unused = -1,
|
||||
|
||||
// We limit to 16 components by vertex since it's the minimal number supported by the GPU
|
||||
VertexComponent_InstanceData0,
|
||||
VertexComponent_InstanceData1,
|
||||
VertexComponent_InstanceData2,
|
||||
VertexComponent_InstanceData3,
|
||||
VertexComponent_InstanceData4,
|
||||
VertexComponent_InstanceData5,
|
||||
VertexComponent_Color,
|
||||
VertexComponent_Normal,
|
||||
VertexComponent_Position,
|
||||
VertexComponent_Tangent,
|
||||
VertexComponent_TexCoord,
|
||||
VertexComponent_Userdata0,
|
||||
VertexComponent_Userdata1,
|
||||
VertexComponent_Userdata2,
|
||||
VertexComponent_Userdata3,
|
||||
VertexComponent_Userdata4,
|
||||
VertexComponent_Userdata,
|
||||
|
||||
VertexComponent_FirstInstanceData = VertexComponent_InstanceData0,
|
||||
VertexComponent_FirstVertexData = VertexComponent_Color,
|
||||
VertexComponent_LastInstanceData = VertexComponent_InstanceData5,
|
||||
VertexComponent_LastVertexData = VertexComponent_Userdata4,
|
||||
VertexComponent_Max = VertexComponent_Userdata
|
||||
};
|
||||
|
||||
VertexComponent_Max = VertexComponent_Userdata4
|
||||
enum class VertexInputRate
|
||||
{
|
||||
Instance,
|
||||
Vertex
|
||||
};
|
||||
|
||||
enum VertexLayout
|
||||
{
|
||||
// Declarations meant for the rendering
|
||||
// Predefined declarations for rendering
|
||||
VertexLayout_XY,
|
||||
VertexLayout_XY_Color,
|
||||
VertexLayout_XY_UV,
|
||||
@@ -397,7 +387,7 @@ namespace Nz
|
||||
VertexLayout_XYZ_Normal_UV_Tangent_Skinning,
|
||||
VertexLayout_XYZ_UV,
|
||||
|
||||
// Declarations meant for the instancing
|
||||
// Predefined declarations for instancing
|
||||
VertexLayout_Matrix4,
|
||||
|
||||
VertexLayout_Max = VertexLayout_Matrix4
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <array>
|
||||
@@ -30,52 +30,57 @@ namespace Nz
|
||||
friend class Utility;
|
||||
|
||||
public:
|
||||
VertexDeclaration();
|
||||
VertexDeclaration(const VertexDeclaration& declaration);
|
||||
~VertexDeclaration();
|
||||
struct Component;
|
||||
struct ComponentEntry;
|
||||
|
||||
void DisableComponent(VertexComponent component);
|
||||
void EnableComponent(VertexComponent component, ComponentType type, std::size_t offset);
|
||||
VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components);
|
||||
VertexDeclaration(const VertexDeclaration&) = delete;
|
||||
VertexDeclaration(VertexDeclaration&&) noexcept = default;
|
||||
~VertexDeclaration() = default;
|
||||
|
||||
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;
|
||||
inline const Component* FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const;
|
||||
|
||||
void SetStride(std::size_t stride);
|
||||
template<typename T> const Component* GetComponentByType(VertexComponent vertexComponent, std::size_t componentIndex = 0) const;
|
||||
|
||||
VertexDeclaration& operator=(const VertexDeclaration& declaration);
|
||||
inline const Component& GetComponent(std::size_t componentIndex) const;
|
||||
inline std::size_t GetComponentCount() const;
|
||||
inline VertexInputRate GetInputRate() const;
|
||||
inline std::size_t GetStride() const;
|
||||
|
||||
static VertexDeclaration* Get(VertexLayout layout);
|
||||
inline bool HasComponent(VertexComponent component, std::size_t componentIndex = 0) const;
|
||||
template<typename T> bool HasComponentOfType(VertexComponent vertexComponent, std::size_t componentIndex = 0) const;
|
||||
|
||||
VertexDeclaration& operator=(const VertexDeclaration&) = delete;
|
||||
VertexDeclaration& operator=(VertexDeclaration&&) noexcept = default;
|
||||
|
||||
static const VertexDeclarationRef& Get(VertexLayout layout);
|
||||
static bool IsTypeSupported(ComponentType type);
|
||||
template<typename... Args> static VertexDeclarationRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnVertexDeclarationRelease, const VertexDeclaration* /*vertexDeclaration*/);
|
||||
struct Component
|
||||
{
|
||||
ComponentType type;
|
||||
VertexComponent component;
|
||||
std::size_t componentIndex;
|
||||
std::size_t offset;
|
||||
};
|
||||
|
||||
struct ComponentEntry
|
||||
{
|
||||
VertexComponent component;
|
||||
ComponentType type;
|
||||
std::size_t componentIndex;
|
||||
};
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct Component
|
||||
{
|
||||
ComponentType type; // Le type de donnée
|
||||
bool enabled = false; // Ce composant est-il activé ?/
|
||||
std::size_t offset; // La position, en octets, de la première donnée
|
||||
|
||||
/*
|
||||
** -Lynix:
|
||||
** Il serait aussi possible de préciser le stride de façon indépendante, ce que je ne permets pas
|
||||
** pour décomplexifier l'interface en enlevant quelque chose que je juge inutile.
|
||||
** Si vous pensez que ça peut être utile, n'hésitez pas à me le faire savoir !
|
||||
** PS: Même cas pour le diviseur (instancing)
|
||||
*/
|
||||
};
|
||||
|
||||
std::array<Component, VertexComponent_Max + 1> m_components;
|
||||
std::vector<Component> m_components;
|
||||
std::size_t m_stride;
|
||||
VertexInputRate m_inputRate;
|
||||
|
||||
static std::array<VertexDeclaration, VertexLayout_Max + 1> s_declarations;
|
||||
static std::array<VertexDeclarationRef, VertexLayout_Max + 1> s_declarations;
|
||||
static VertexDeclarationLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,32 +1,87 @@
|
||||
// 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/Algorithm.hpp>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
#include <Nazara/Utility/Algorithm.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline auto Nz::VertexDeclaration::FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
|
||||
{
|
||||
assert(componentIndex == 0 || vertexComponent == VertexComponent_Userdata);
|
||||
|
||||
for (const Component& component : m_components)
|
||||
{
|
||||
if (component.component == vertexComponent && component.componentIndex == componentIndex)
|
||||
return &component;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline auto VertexDeclaration::GetComponent(std::size_t componentIndex) const -> const Component&
|
||||
{
|
||||
return m_components[componentIndex];
|
||||
}
|
||||
|
||||
inline std::size_t VertexDeclaration::GetComponentCount() const
|
||||
{
|
||||
return m_components.size();
|
||||
}
|
||||
|
||||
inline VertexInputRate VertexDeclaration::GetInputRate() const
|
||||
{
|
||||
return m_inputRate;
|
||||
}
|
||||
|
||||
inline std::size_t VertexDeclaration::GetStride() const
|
||||
{
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
inline bool VertexDeclaration::HasComponent(VertexComponent component, std::size_t componentIndex) const
|
||||
{
|
||||
return FindComponent(component, componentIndex) != nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto VertexDeclaration::GetComponentByType(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
|
||||
{
|
||||
NazaraAssert(componentIndex == 0 || vertexComponent == VertexComponent_Userdata, "Only userdata vertex component can have component indexes");
|
||||
if (const Component* component = FindComponent(vertexComponent, componentIndex))
|
||||
{
|
||||
if (GetComponentTypeOf<T>() == component->type)
|
||||
return component;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool VertexDeclaration::HasComponentOfType(VertexComponent vertexComponent, std::size_t componentIndex) const
|
||||
{
|
||||
return GetComponentByType<T>(vertexComponent, componentIndex) != nullptr;
|
||||
}
|
||||
|
||||
const VertexDeclarationRef& VertexDeclaration::Get(VertexLayout layout)
|
||||
{
|
||||
NazaraAssert(layout <= VertexLayout_Max, "Vertex layout out of enum");
|
||||
|
||||
return s_declarations[layout];
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
VertexDeclarationRef VertexDeclaration::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<VertexDeclaration> object(new VertexDeclaration(std::forward<Args>(args)...));
|
||||
std::unique_ptr<VertexDeclaration> object = std::make_unique<VertexDeclaration>(std::forward<Args>(args)...);
|
||||
object->SetPersistent(false);
|
||||
|
||||
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>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
|
||||
|
||||
@@ -18,6 +19,7 @@ namespace Nz
|
||||
inline VkPolygonMode ToVulkan(FaceFilling faceFilling);
|
||||
inline VkPrimitiveTopology ToVulkan(PrimitiveMode primitiveMode);
|
||||
inline VkCompareOp ToVulkan(RendererComparison comparison);
|
||||
inline VkShaderStageFlagBits ToVulkan(ShaderStageType stageType);
|
||||
inline VkStencilOp ToVulkan(StencilOperation stencilOp);
|
||||
NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,18 @@ namespace Nz
|
||||
return VK_COMPARE_OP_NEVER;
|
||||
}
|
||||
|
||||
VkShaderStageFlagBits ToVulkan(ShaderStageType stageType)
|
||||
{
|
||||
switch (stageType)
|
||||
{
|
||||
case ShaderStageType::Fragment: return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
case ShaderStageType::Vertex: return VK_SHADER_STAGE_VERTEX_BIT;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled ShaderStageType 0x" + String::Number(static_cast<std::size_t>(stageType), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
VkStencilOp ToVulkan(StencilOperation stencilOp)
|
||||
{
|
||||
switch (stencilOp)
|
||||
|
||||
@@ -23,19 +23,37 @@ namespace Nz
|
||||
VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo);
|
||||
~VulkanRenderPipeline() = default;
|
||||
|
||||
static std::vector<VkPipelineColorBlendAttachmentState> BuildColorBlendAttachmentState(const RenderPipelineInfo& pipelineInfo);
|
||||
static std::vector<VkPipelineColorBlendAttachmentState> BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo);
|
||||
static VkPipelineColorBlendStateCreateInfo BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState);
|
||||
static VkPipelineDepthStencilStateCreateInfo BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo);
|
||||
static VkPipelineDynamicStateCreateInfo BuildDynamicStateInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkDynamicState>& dynamicStates);
|
||||
static std::vector<VkDynamicState> BuildDynamicStateList(const RenderPipelineInfo& pipelineInfo);
|
||||
static VkPipelineInputAssemblyStateCreateInfo BuildInputAssemblyInfo(const RenderPipelineInfo& pipelineInfo);
|
||||
static VkPipelineRasterizationStateCreateInfo BuildRasterizationInfo(const RenderPipelineInfo& pipelineInfo);
|
||||
static VkPipelineViewportStateCreateInfo BuildViewportInfo(const RenderPipelineInfo& pipelineInfo);
|
||||
static VkStencilOpState BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front);
|
||||
static std::vector<VkPipelineShaderStageCreateInfo> BuildShaderStageInfo(const RenderPipelineInfo& pipelineInfo);
|
||||
|
||||
static CreateInfo BuildCreateInfo(const RenderPipelineInfo& pipelineInfo);
|
||||
|
||||
struct CreateInfo
|
||||
{
|
||||
struct StateData
|
||||
{
|
||||
VkPipelineVertexInputStateCreateInfo vertexInputState;
|
||||
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState;
|
||||
VkPipelineViewportStateCreateInfo viewportState;
|
||||
VkPipelineRasterizationStateCreateInfo rasterizationState;
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencilState;
|
||||
VkPipelineColorBlendStateCreateInfo colorBlendState;
|
||||
VkPipelineDynamicStateCreateInfo dynamicState;
|
||||
};
|
||||
|
||||
std::vector<VkPipelineColorBlendAttachmentState> colorBlendAttachmentState;
|
||||
std::vector<VkDynamicState> dynamicStates;
|
||||
std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
|
||||
VkGraphicsPipelineCreateInfo createInfo;
|
||||
std::unique_ptr<StateData> stateData;
|
||||
VkGraphicsPipelineCreateInfo pipelineInfo;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Nz
|
||||
bool Create(const Vk::DeviceHandle& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize);
|
||||
|
||||
inline const Vk::ShaderModule& GetHandle() const;
|
||||
inline ShaderStageType GetStageType() const;
|
||||
|
||||
VulkanShaderStage& operator=(const VulkanShaderStage&) = delete;
|
||||
VulkanShaderStage& operator=(VulkanShaderStage&&) noexcept = default;
|
||||
|
||||
@@ -11,6 +11,11 @@ namespace Nz
|
||||
{
|
||||
return m_shaderModule;
|
||||
}
|
||||
|
||||
inline ShaderStageType VulkanShaderStage::GetStageType() const
|
||||
{
|
||||
return m_stage;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user