rendertarget multi frame rewrite
This commit is contained in:
parent
7f46ac13fa
commit
2b22c16ce7
13 changed files with 225 additions and 276 deletions
|
|
@ -25,6 +25,7 @@ import :Transform2D;
|
|||
import :RenderingElement2DBase;
|
||||
|
||||
export namespace Crafter {
|
||||
template<std::uint8_t Frames>
|
||||
struct RendertargetBase {
|
||||
#ifdef CRAFTER_TIMING
|
||||
std::vector<std::tuple<const Transform*, std::uint32_t, std::uint32_t, std::chrono::nanoseconds>> renderTimings;
|
||||
|
|
@ -33,7 +34,7 @@ export namespace Crafter {
|
|||
std::int32_t sizeX;
|
||||
std::int32_t sizeY;
|
||||
std::vector<Transform2D*> elements;
|
||||
std::vector<ClipRect> dirtyRects;
|
||||
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,19 +43,21 @@ export namespace Crafter {
|
|||
transform.scaled.position.y = 0;
|
||||
}
|
||||
void AddDirtyRect(ScaleData2D scale) {
|
||||
dirtyRects.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));
|
||||
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>
|
||||
struct Rendertarget : RendertargetBase {
|
||||
Vector<T, Channels, Alignment>* buffer;
|
||||
template<typename T, std::uint8_t Channels, std::uint8_t Alignment, std::uint8_t Frames>
|
||||
struct Rendertarget : RendertargetBase<Frames> {
|
||||
Vector<T, Channels, Alignment>* buffer[Frames];
|
||||
Rendertarget() = default;
|
||||
Rendertarget(std::int16_t sizeX, std::int16_t sizeY) : RendertargetBase(sizeX, sizeY) {
|
||||
Rendertarget(std::int16_t sizeX, std::int16_t sizeY) : RendertargetBase<Frames>(sizeX, sizeY) {
|
||||
|
||||
}
|
||||
void RenderElement(Transform2D* elementTransform) {
|
||||
RenderingElement2DBase* element = dynamic_cast<RenderingElement2DBase*>(elementTransform);
|
||||
void RenderElement(Transform2D* elementTransform, std::uint8_t frame) {
|
||||
RenderingElement2DBase<Frames>* element = dynamic_cast<RenderingElement2DBase<Frames>*>(elementTransform);
|
||||
if(element) {
|
||||
#ifdef CRAFTER_TIMING
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
|
@ -64,7 +67,7 @@ export namespace Crafter {
|
|||
return;
|
||||
}
|
||||
|
||||
for(ClipRect dirty : dirtyRects) {
|
||||
for(ClipRect dirty : this->dirtyRects[frame]) {
|
||||
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);
|
||||
|
|
@ -82,7 +85,7 @@ export namespace Crafter {
|
|||
for (std::int32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int32_t src_x = x - element->scaled.position.x;
|
||||
|
||||
buffer[y * sizeX + x] = src_buffer[src_y * src_width + src_x];
|
||||
this->buffer[frame][y * this->sizeX + x] = src_buffer[src_y * src_width + src_x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -99,7 +102,7 @@ export namespace Crafter {
|
|||
if (src_pixel.a == 0) {
|
||||
continue;
|
||||
}
|
||||
buffer[y * sizeX + x] = src_pixel;
|
||||
this->buffer[frame][y * this->sizeX + x] = src_pixel;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -111,7 +114,7 @@ export namespace Crafter {
|
|||
for (std::int32_t x = dirty.left; x < dirty.right; x++) {
|
||||
std::int32_t src_x = x - element->scaled.position.x;
|
||||
Vector<T, Channels, Alignment> src = src_buffer[src_y * src_width + src_x];
|
||||
Vector<T, Channels, Alignment> dst = buffer[y * sizeX + x];
|
||||
Vector<T, Channels, Alignment> dst = buffer[frame][y * this->sizeX + x];
|
||||
|
||||
if(src.a == 0) {
|
||||
continue;
|
||||
|
|
@ -121,7 +124,7 @@ export namespace Crafter {
|
|||
float dstA = dst.a / 255.0f;
|
||||
|
||||
float outA = srcA + dstA * (1.0f - srcA);
|
||||
buffer[y * sizeX + x] = Vector<T, Channels, Alignment>(
|
||||
this->buffer[frame][y * this->sizeX + x] = Vector<T, Channels, Alignment>(
|
||||
static_cast<T>((src.r * srcA + dst.r * dstA * (1.0f - srcA)) / outA),
|
||||
static_cast<T>((src.g * srcA + dst.g * dstA * (1.0f - srcA)) / outA),
|
||||
static_cast<T>((src.b * srcA + dst.b * dstA * (1.0f - srcA)) / outA),
|
||||
|
|
@ -139,12 +142,11 @@ 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);
|
||||
this->RenderElement(child, frame);
|
||||
}
|
||||
}
|
||||
void Render() {
|
||||
elements.erase(std::remove(elements.begin(), elements.end(), static_cast<Transform2D*>(nullptr)), elements.end());
|
||||
std::sort(elements.begin(), elements.end(), [](Transform2D* a, Transform2D* b){ return a->anchor.z < b->anchor.z; });
|
||||
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; });
|
||||
|
||||
//std::vector<ClipRect> newClip;
|
||||
// for (std::uint32_t i = 0; i < dirtyRects.size(); i++) {
|
||||
|
|
@ -245,19 +247,19 @@ export namespace Crafter {
|
|||
// ++rectIndex;
|
||||
// }
|
||||
|
||||
if (!dirtyRects.empty()) {
|
||||
for (ClipRect rect : dirtyRects) {
|
||||
if (!this->dirtyRects[frame].empty()) {
|
||||
for (ClipRect rect : this->dirtyRects[frame]) {
|
||||
for (std::int32_t y = rect.top; y < rect.bottom; y++) {
|
||||
for (std::int32_t x = rect.left; x < rect.right; x++) {
|
||||
buffer[y * sizeX + x] = {0, 0, 0, 0};
|
||||
this->buffer[frame][y * this->sizeX + x] = {0, 0, 0, 0};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Transform2D* child : elements) {
|
||||
RenderElement(child);
|
||||
for(Transform2D* child : this->elements) {
|
||||
RenderElement(child, frame);
|
||||
}
|
||||
dirtyRects.clear();
|
||||
this->dirtyRects[frame].clear();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue