Files
OpenVulkano/openVulkanoCpp/Scene/Drawable.hpp
2025-01-06 16:28:27 +01:00

76 lines
1.7 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Scene/IRayIntersectable.hpp"
#include "DrawEncoder.hpp"
#include <memory>
#include <vector>
#ifdef _WIN32
# undef TRANSPARENT
#endif
namespace OpenVulkano::Scene
{
class Node;
class Scene;
class Shader;
enum class DrawPhase
{
BACKGROUND = 0, MAIN, TRANSPARENT, POST
};
class Drawable : public IRayIntersectable
{
std::vector<Node*> m_nodes;
Scene* m_scene = nullptr;
Shader* m_shader = nullptr;
const DrawEncoder m_encoder;
const DrawPhase m_drawPhase;
bool m_isHittable = false;
public:
explicit Drawable(const DrawEncoder& encoder,
const DrawPhase phase = DrawPhase::MAIN)
: m_encoder(encoder), m_drawPhase(phase) {}
~Drawable() override {/* if (m_scene) Drawable::Close();*/ }
virtual void Close();
void SetShader(Shader* shader) { m_shader = shader; }
std::optional<RayHit> Intersect(const Ray& ray) const override { return {}; }
void SetIsHittable(bool hittable) { m_isHittable = hittable; }
bool IsHittable() const { return m_isHittable; }
[[nodiscard]] Scene* GetScene() const { return m_scene; }
[[nodiscard]] const auto& GetNodes() const { return m_nodes; }
[[nodiscard]] const DrawEncoder& GetEncoder() const { return m_encoder; }
[[nodiscard]] DrawPhase GetDrawPhase() const { return m_drawPhase; }
[[nodiscard]] Shader* GetShader() const { return m_shader; }
private:
friend class Node;
friend class Scene;
void SetScene(Scene* scene);
void AddNode(Node* node);
void RemoveNode(Node* node);
};
}