From 6ad5d6987036d00c05a088c5eb6e97034d89b826 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Mon, 7 Aug 2023 21:18:19 +0200 Subject: [PATCH] Add GridDrawable --- openVulkanoCpp/Scene/Prefabs/GridDrawable.cpp | 22 ++++++++++++++++ openVulkanoCpp/Scene/Prefabs/GridDrawable.hpp | 25 +++++++++++++++++++ .../Scene/GridDrawableVulkanEncoder.cpp | 24 ++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 openVulkanoCpp/Scene/Prefabs/GridDrawable.cpp create mode 100644 openVulkanoCpp/Scene/Prefabs/GridDrawable.hpp create mode 100644 openVulkanoCpp/Vulkan/Scene/GridDrawableVulkanEncoder.cpp diff --git a/openVulkanoCpp/Scene/Prefabs/GridDrawable.cpp b/openVulkanoCpp/Scene/Prefabs/GridDrawable.cpp new file mode 100644 index 0000000..1dffff4 --- /dev/null +++ b/openVulkanoCpp/Scene/Prefabs/GridDrawable.cpp @@ -0,0 +1,22 @@ +/* + * 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/. + */ + +#include "GridDrawable.hpp" + +namespace openVulkanoCpp::Scene +{ + GridDrawable::GridDrawable() + : Drawable(DrawEncoder::GetDrawEncoder(), DrawPhase::POST) + { + m_shader.cullMode = CullMode::NONE; + m_shader.topology = Topology::TRIANGLE_STRIP; + m_shader.AddShaderProgram(ShaderProgramType::VERTEX, "Shader/grid"); + m_shader.AddShaderProgram(ShaderProgramType::FRAGMENT, "Shader/grid"); + m_shader.alphaBlend = true; + + SetShader(&m_shader); + } +} \ No newline at end of file diff --git a/openVulkanoCpp/Scene/Prefabs/GridDrawable.hpp b/openVulkanoCpp/Scene/Prefabs/GridDrawable.hpp new file mode 100644 index 0000000..615f83d --- /dev/null +++ b/openVulkanoCpp/Scene/Prefabs/GridDrawable.hpp @@ -0,0 +1,25 @@ +/* + * 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/Drawable.hpp" +#include "Scene/Shader.hpp" + +namespace openVulkanoCpp::Scene +{ + class GridDrawable : public Drawable + { + Shader m_shader; + + public: + GridDrawable(); + + [[nodiscard]] Shader& GetShader() { return m_shader; } + + [[nodiscard]] Drawable* Copy() override { return new GridDrawable(); } + }; +} \ No newline at end of file diff --git a/openVulkanoCpp/Vulkan/Scene/GridDrawableVulkanEncoder.cpp b/openVulkanoCpp/Vulkan/Scene/GridDrawableVulkanEncoder.cpp new file mode 100644 index 0000000..386390e --- /dev/null +++ b/openVulkanoCpp/Vulkan/Scene/GridDrawableVulkanEncoder.cpp @@ -0,0 +1,24 @@ +/* + * 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/. + */ + +#include "Scene/Prefabs/GridDrawable.hpp" +#include "VulkanGeometry.hpp" +#include "Vulkan/VulkanDrawContext.hpp" + +using namespace openVulkanoCpp::Scene; + +namespace openVulkanoCpp::Vulkan +{ + void EncodeGridDrawable(Drawable* instance, Vulkan::VulkanDrawContext* drawContext) + { + drawContext->commandBuffer.draw(4, 1, 0, 0); + } +} + +namespace +{ + void* gridDrawableVulkanEncoderReg = DrawEncoder::RegisterVulkanEncodeFunction(&openVulkanoCpp::Vulkan::EncodeGridDrawable); +} \ No newline at end of file