Cleanup descriptor layout handling

This commit is contained in:
2023-09-03 17:07:23 +02:00
parent b328db0075
commit 446e11e3b8
7 changed files with 49 additions and 20 deletions

View File

@@ -17,11 +17,15 @@ namespace openVulkanoCpp::Scene
{
public:
ICloseable* renderCamera = nullptr;
static constexpr inline size_t SIZE = sizeof(Math::Matrix4f) * 3 + sizeof(Math::Vector4f) + sizeof(float) * 8 + 16;
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER_DYNAMIC, 1, ShaderProgramType::ALL_GRAPHICS };
protected:
Math::Matrix4f m_viewProjection{1}, m_view{1}, m_projection{1};
Math::Vector4f m_camPosition{};
float m_nearPlane, m_farPlane, m_width, m_height;
float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0;
std::array<uint8_t, 16> m_userData{};
Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {}
@@ -35,11 +39,6 @@ namespace openVulkanoCpp::Scene
//if (renderCamera) renderCamera->Close();
}
public:
static constexpr size_t SIZE = sizeof(Math::Matrix4f) * 3 + sizeof(Math::Vector4f) + sizeof(float) * 8;
void* GetData() { return &m_viewProjection; }
void Init(float width, float height, float nearPlane, float farPlane)
{
m_width = width;
@@ -50,6 +49,9 @@ namespace openVulkanoCpp::Scene
UpdateProjectionMatrix();
}
public:
void* GetData() { return &m_viewProjection; }
virtual void SetSize(const float width, const float height)
{
if (m_width == width && m_height == height) return;
@@ -125,13 +127,16 @@ namespace openVulkanoCpp::Scene
{
return {m_viewProjection};
}
/**
* The 16 byte of user data can be used to transmit additional data about the camera to the shader.
* @return reference to the custom data array
*/
[[nodiscard]] std::array<uint8_t, 16>& GetUserData() { return m_userData; }
};
class PerspectiveCamera : public Camera
{
protected:
float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0;
public:
PerspectiveCamera() = default;
~PerspectiveCamera() override = default;
@@ -157,6 +162,11 @@ namespace openVulkanoCpp::Scene
m_perPixelScaleFactor = m_height / m_scaleFactor;
}
[[nodiscard]] int GetPixelPerMeter(float distance) const
{
return static_cast<int>(m_perPixelScaleFactor / distance);
}
void SetSize(const float width, const float height) override
{
m_aspect = width / height;
@@ -221,7 +231,6 @@ namespace openVulkanoCpp::Scene
class OrthographicCamera : public Camera
{
std::array<float, 4> placeholder;
public:
void UpdateProjectionMatrix() final
{