rendertarget multi frame rewrite complete
This commit is contained in:
parent
2b22c16ce7
commit
bc97c13a0b
6 changed files with 76 additions and 22 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue