rendertarget multi frame rewrite complete
This commit is contained in:
parent
2b22c16ce7
commit
bc97c13a0b
6 changed files with 76 additions and 22 deletions
|
|
@ -153,11 +153,15 @@ export namespace Crafter {
|
|||
}
|
||||
|
||||
public:
|
||||
~DescriptorPool() {
|
||||
vkDestroyDescriptorPool(Device::device, descriptorPool, nullptr);
|
||||
}
|
||||
void BuildPool(std::span<const VkDescriptorPoolSize> poolSizes, std::span<const VkDescriptorSetLayout> setLayouts) {
|
||||
if(descriptorPool != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorPool(Device::device, descriptorPool, nullptr);
|
||||
}
|
||||
|
||||
sets.resize(setLayouts.size());
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptorPoolInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ export namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string_view> ResizeText(RendertargetBase<Frames>& window, Transform2D& parent, const std::string_view text, float& size, Font& font, std::uint8_t frame, TextOverflowMode overflowMode = TextOverflowMode::Clip, TextScaleMode scaleMode = TextScaleMode::None) {
|
||||
std::vector<std::string_view> ResizeText(RendertargetBase<Frames>& window, Transform2D& parent, const std::string_view text, float& size, Font& font, TextOverflowMode overflowMode = TextOverflowMode::Clip, TextScaleMode scaleMode = TextScaleMode::None) {
|
||||
float scale = stbtt_ScaleForPixelHeight(&font.font, size);
|
||||
int baseline = (int)(font.ascent * scale);
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ export namespace Crafter {
|
|||
|
||||
return lines;
|
||||
}
|
||||
void RenderText(std::span<const std::string_view> lines, float size, Vector<std::uint8_t, 4> color, Font& font, std::uint8_t frame, TextAlignment alignment = TextAlignment::Left, std::uint32_t offsetX = 0, std::uint32_t offsetY = 0, OpaqueType opaque = OpaqueType::FullyOpaque) {
|
||||
void RenderText(std::span<const std::string_view> lines, float size, Vector<std::uint8_t, 4> color, Font& font, TextAlignment alignment = TextAlignment::Left, std::uint32_t offsetX = 0, std::uint32_t offsetY = 0, OpaqueType opaque = OpaqueType::FullyOpaque) {
|
||||
float scale = stbtt_ScaleForPixelHeight(&font.font, size);
|
||||
int baseline = (int)(font.ascent * scale);
|
||||
std::uint32_t lineHeight = (font.ascent - font.descent) * scale;
|
||||
|
|
|
|||
|
|
@ -97,16 +97,22 @@ export namespace Crafter {
|
|||
template<std::uint8_t Frames = 1>
|
||||
struct RenderingElement2DBase : Transform2D {
|
||||
ScaleData2D oldScale[Frames];
|
||||
bool redraw[Frames];
|
||||
std::vector<Vector<std::uint8_t, 4>> buffer;
|
||||
OpaqueType opaque;
|
||||
RenderingElement2DBase(Anchor2D anchor) : Transform2D(anchor) {
|
||||
for(std::uint8_t i = 0; i < Frames; i++) {
|
||||
this->scaled[i].size.x = 0;
|
||||
this->scaled.size.x = 0;
|
||||
}
|
||||
}
|
||||
RenderingElement2DBase(Anchor2D anchor, OpaqueType opaque) : Transform2D(anchor), opaque(opaque) {
|
||||
for(std::uint8_t i = 0; i < Frames; i++) {
|
||||
this->scaled[i].size.x = 0;
|
||||
this->scaled.size.x = 0;
|
||||
}
|
||||
}
|
||||
void Redraw() {
|
||||
for(std::uint8_t i = 0; i < Frames; i++) {
|
||||
redraw[i] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ export namespace Crafter {
|
|||
Transform2D transform;
|
||||
std::int32_t sizeX;
|
||||
std::int32_t sizeY;
|
||||
std::vector<Transform2D*> elements;
|
||||
std::vector<ClipRect> dirtyRects[Frames];
|
||||
RendertargetBase() = default;
|
||||
RendertargetBase(std::int16_t sizeX, std::int16_t sizeY) : sizeX(sizeX), sizeY(sizeY), transform({0, 0, 1, 1, 0, 0, 0}){
|
||||
transform.scaled.size.x = sizeX;
|
||||
|
|
@ -42,11 +40,6 @@ export namespace Crafter {
|
|||
transform.scaled.position.x = 0;
|
||||
transform.scaled.position.y = 0;
|
||||
}
|
||||
void AddDirtyRect(ScaleData2D scale) {
|
||||
for(std::uint8_t i = 0; i < Frames; i++) {
|
||||
dirtyRects[i].emplace_back(std::max(scale.position.x, std::int32_t(0)), std::min(scale.position.x + scale.size.x, sizeX), std::max(scale.position.y, std::int32_t(0)), std::min(scale.position.y + scale.size.y, sizeY));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, std::uint8_t Channels, std::uint8_t Alignment, std::uint8_t Frames>
|
||||
|
|
@ -56,7 +49,7 @@ export namespace Crafter {
|
|||
Rendertarget(std::int16_t sizeX, std::int16_t sizeY) : RendertargetBase<Frames>(sizeX, sizeY) {
|
||||
|
||||
}
|
||||
void RenderElement(Transform2D* elementTransform, std::uint8_t frame) {
|
||||
void RenderElement(Transform2D* elementTransform, std::uint8_t frame, std::vector<ClipRect>&& dirtyRects) {
|
||||
RenderingElement2DBase<Frames>* element = dynamic_cast<RenderingElement2DBase<Frames>*>(elementTransform);
|
||||
if(element) {
|
||||
#ifdef CRAFTER_TIMING
|
||||
|
|
@ -67,7 +60,7 @@ export namespace Crafter {
|
|||
return;
|
||||
}
|
||||
|
||||
for(ClipRect dirty : this->dirtyRects[frame]) {
|
||||
for(ClipRect dirty : dirtyRects) {
|
||||
dirty.left = std::max(element->scaled.position.x, dirty.left);
|
||||
dirty.top = std::max(element->scaled.position.y, dirty.top);
|
||||
dirty.right = std::min(element->scaled.position.x+element->scaled.size.x, dirty.right);
|
||||
|
|
@ -142,11 +135,31 @@ export namespace Crafter {
|
|||
}
|
||||
std::sort(elementTransform->children.begin(), elementTransform->children.end(), [](Transform2D* a, Transform2D* b){ return a->anchor.z < b->anchor.z; });
|
||||
for(Transform2D* child : elementTransform->children) {
|
||||
this->RenderElement(child, frame);
|
||||
this->RenderElement(child, frame, std::move(dirtyRects));
|
||||
}
|
||||
}
|
||||
void Render(std::uint8_t frame) {
|
||||
std::sort(this->elements.begin(), this->elements.end(), [](Transform2D* a, Transform2D* b){ return a->anchor.z < b->anchor.z; });
|
||||
|
||||
void AddOldRects(Transform2D* elementTransform, std::uint8_t frame, std::vector<ClipRect>& clipRects) {
|
||||
RenderingElement2DBase<Frames>* element = dynamic_cast<RenderingElement2DBase<Frames>*>(elementTransform);
|
||||
if(element) {
|
||||
if(element->scaled.position.x != element->oldScale[frame].position.x || element->scaled.position.y != element->oldScale[frame].position.y || element->scaled.size.x != element->oldScale[frame].size.x || element->scaled.size.y != element->oldScale[frame].size.y || element->redraw[frame]) {
|
||||
clipRects.emplace_back(std::max(element->scaled.position.x, std::int32_t(0)), std::min(element->scaled.position.x + element->scaled.size.x, this->sizeX), std::max(element->scaled.position.y, std::int32_t(0)), std::min(element->scaled.position.y + element->scaled.size.y, this->sizeY));
|
||||
clipRects.emplace_back(std::max(element->oldScale[frame].position.x, std::int32_t(0)), std::min(element->oldScale[frame].position.x + element->oldScale[frame].size.x, this->sizeX), std::max(element->oldScale[frame].position.y, std::int32_t(0)), std::min(element->oldScale[frame].position.y + element->oldScale[frame].size.y, this->sizeY));
|
||||
element->oldScale[frame] = element->scaled;
|
||||
element->redraw[frame] = false;
|
||||
}
|
||||
}
|
||||
for(Transform2D* child : elementTransform->children) {
|
||||
AddOldRects(child, frame, clipRects);
|
||||
}
|
||||
}
|
||||
|
||||
bool Render(std::uint8_t frame) {
|
||||
std::sort(this->transform.children.begin(), this->transform.children.end(), [](Transform2D* a, Transform2D* b){ return a->anchor.z < b->anchor.z; });
|
||||
std::vector<ClipRect> clipRects;
|
||||
for(Transform2D* child : this->transform.children) {
|
||||
AddOldRects(child, frame, clipRects);
|
||||
}
|
||||
|
||||
//std::vector<ClipRect> newClip;
|
||||
// for (std::uint32_t i = 0; i < dirtyRects.size(); i++) {
|
||||
|
|
@ -247,8 +260,8 @@ export namespace Crafter {
|
|||
// ++rectIndex;
|
||||
// }
|
||||
|
||||
if (!this->dirtyRects[frame].empty()) {
|
||||
for (ClipRect rect : this->dirtyRects[frame]) {
|
||||
if (!clipRects.empty()) {
|
||||
for (ClipRect rect : clipRects) {
|
||||
for (std::int32_t y = rect.top; y < rect.bottom; y++) {
|
||||
for (std::int32_t x = rect.left; x < rect.right; x++) {
|
||||
this->buffer[frame][y * this->sizeX + x] = {0, 0, 0, 0};
|
||||
|
|
@ -256,10 +269,12 @@ export namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
for(Transform2D* child : this->elements) {
|
||||
RenderElement(child, frame);
|
||||
for(Transform2D* child : this->transform.children) {
|
||||
RenderElement(child, frame, std::move(clipRects));
|
||||
}
|
||||
this->dirtyRects[frame].clear();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ export namespace Crafter {
|
|||
std::uint32_t height;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> lastFrameBegin;
|
||||
Event<void> onClose;
|
||||
Event<void> onBeforeUpdate;
|
||||
Event<FrameTime> onUpdate;
|
||||
bool open = true;
|
||||
bool updating = false;
|
||||
|
|
@ -180,6 +181,8 @@ export namespace Crafter {
|
|||
void SetPipelineRT(PipelineRTVulkan& pipeline);
|
||||
VkCommandBuffer StartInit();
|
||||
void FinishInit();
|
||||
VkCommandBuffer GetCmd();
|
||||
void EndCmd(VkCommandBuffer cmd);
|
||||
void CreateSwapchain();
|
||||
static constexpr std::uint8_t numFrames = 3;
|
||||
VkSurfaceKHR vulkanSurface = VK_NULL_HANDLE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue