Merge branch 'ubo' into vulkan

This commit is contained in:
Lynix
2018-06-12 19:07:58 +02:00
64 changed files with 1041 additions and 430 deletions

View File

@@ -44,6 +44,8 @@ namespace Ndk
inline bool DoesRequireRealTimeReflections() const;
template<typename Func> void ForEachRenderable(const Func& func) const;
inline void EnsureBoundingVolumeUpdate() const;
inline void EnsureTransformMatrixUpdate() const;

View File

@@ -107,6 +107,18 @@ namespace Ndk
return m_reflectiveMaterialCount != 0 && m_reflectionMap;
}
/*!
* \brief Calls a function for every renderable attached to this component
*
* \param func Callback function which will be called with renderable data
*/
template<typename Func>
void GraphicsComponent::ForEachRenderable(const Func& func) const
{
for (const auto& renderableData : m_renderables)
func(renderableData.renderable, renderableData.data.localMatrix, renderableData.data.renderOrder);
}
/*!
* \brief Ensures the bounding volume is up to date
*/

View File

@@ -62,12 +62,19 @@ namespace Ndk
const DebugComponent& entityDebug = m_entityOwner->GetComponent<DebugComponent>();
const GraphicsComponent& entityGfx = m_entityOwner->GetComponent<GraphicsComponent>();
Nz::Boxf aabb = entityGfx.GetBoundingVolume().aabb;
Nz::Matrix4f transformMatrix = Nz::Matrix4f::Identity();
transformMatrix.SetScale(entityGfx.GetBoundingVolume().aabb.GetLengths());
transformMatrix.SetTranslation(entityGfx.GetBoundingVolume().aabb.GetCenter());
transformMatrix.SetScale(aabb.GetLengths());
transformMatrix.SetTranslation(aabb.GetCenter());
renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect);
}
std::unique_ptr<InstancedRenderable> Clone() const override
{
return nullptr;
}
};
class OBBDebugRenderable : public DebugRenderable
@@ -82,11 +89,21 @@ namespace Ndk
const DebugComponent& entityDebug = m_entityOwner->GetComponent<DebugComponent>();
const GraphicsComponent& entityGfx = m_entityOwner->GetComponent<GraphicsComponent>();
Nz::Boxf obb = entityGfx.GetBoundingVolume().obb.localBox;
Nz::Matrix4f transformMatrix = instanceData.transformMatrix;
transformMatrix.ApplyScale(entityGfx.GetBoundingVolume().obb.localBox.GetLengths());
Nz::Vector3f obbCenter = transformMatrix.Transform(obb.GetCenter(), 0.f); //< Apply rotation/scale to obb center, to display it at a correct position
transformMatrix.ApplyScale(obb.GetLengths());
transformMatrix.ApplyTranslation(obbCenter);
renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect);
}
std::unique_ptr<InstancedRenderable> Clone() const override
{
return nullptr;
}
};
}
@@ -300,9 +317,7 @@ namespace Ndk
Nz::MeshRef mesh = Nz::Mesh::New();
mesh->CreateStatic();
Nz::StaticMeshRef subMesh = Nz::StaticMesh::New(mesh);
subMesh->Create(vertexBuffer);
subMesh->SetIndexBuffer(indexBuffer);
Nz::StaticMeshRef subMesh = Nz::StaticMesh::New(vertexBuffer, indexBuffer);
subMesh->SetPrimitiveMode(Nz::PrimitiveMode_LineList);
subMesh->SetMaterialIndex(0);
subMesh->GenerateAABB();