75 lines
No EOL
3.1 KiB
C++
75 lines
No EOL
3.1 KiB
C++
/*
|
|
Crafter®.Graphics
|
|
Copyright (C) 2026 Catcrafts®
|
|
catcrafts.net
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License version 3.0 as published by the Free Software Foundation;
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
module;
|
|
#include "../lib/stb_truetype.h"
|
|
export module Crafter.Graphics:RenderingElement2DVulkan;
|
|
import Crafter.Asset;
|
|
import std;
|
|
import :Transform2D;
|
|
import :Types;
|
|
import :Window;
|
|
|
|
export namespace Crafter {
|
|
struct __attribute__((packed)) RenderingElement2DVulkanTransformInfo {
|
|
ScaleData2D scaled; // 0 - 8 bytes
|
|
std::uint16_t bufferX; // 8 - 2 bytes
|
|
std::uint16_t bufferY; // 10 - 2 bytes
|
|
//12 bytes total;
|
|
}
|
|
|
|
|
|
template<bool Owning, bool Mapped>
|
|
struct RenderingElement2DVulkan {
|
|
std::uint16_t index;
|
|
std:array<VulkanBuffer<_Float16, Mapped, false>*, Window::NumFrames> buffers;
|
|
RenderingElement2DVulkan(Anchor2D anchor, std::uint16_t bufferWidth, std::uint16_t bufferHeight) requires(Owning) : index(renderingElement2DVulkans.size()-1) {
|
|
renderingElement2DVulkans.push_back(this);
|
|
}
|
|
RenderingElement2DVulkan(Anchor2D anchor, std::uint16_t bufferWidth, std::uint16_t bufferHeight, std:array<VulkanBuffer<_Float16, Mapped, false>*, Window::NumFrames> buffers) requires(!Owning) : buffers(buffers) {
|
|
renderingElement2DVulkans.push_back(this);
|
|
}
|
|
|
|
~RenderingElement2DVulkan() {
|
|
if constexpr(Owning) {
|
|
for(VulkanBuffer<_Float16, Mapped, false>* buffer : buffers) {
|
|
delete buffer;
|
|
}
|
|
}
|
|
}
|
|
|
|
RenderingElement2DVulkan(RenderingElement2DVulkan&) = delete;
|
|
RenderingElement2DVulkan& operator=(RenderingElement2DVulkan&) = delete;
|
|
|
|
void UpdatePosition(RendertargetBase<Frames>& window, Transform2D& parent) override {
|
|
ScaleData2D oldScale = this->scaled;
|
|
this->ScaleElement(parent);
|
|
if(oldScale.size.x != this->scaled.size.x || oldScale.size.y != this->scaled.size.y) {
|
|
this->buffer.resize(this->scaled.size.x * this->scaled.size.y);
|
|
}
|
|
for(Transform2D* child : this->children) {
|
|
child->UpdatePosition(window, *this);
|
|
}
|
|
}
|
|
};
|
|
|
|
inline static std::vector<RenderingElement2DVulkan*> renderingElement2DVulkans;
|
|
inline static std::vector<VkDescriptorBufferInfo> renderingElement2DVulkanDescriptors[Window::NumFrames];
|
|
inline static VulkanBuffer<RenderingElement2DVulkanTransformInfo, Mapped, false>* renderingElement2DVulkanTransformBuffer[Window::NumFrames];
|
|
} |