rendertarget multi frame rewrite
This commit is contained in:
parent
7f46ac13fa
commit
2b22c16ce7
13 changed files with 225 additions and 276 deletions
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
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 as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
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 Crafter.Graphics:GridElement_impl;
|
||||
import :GridElement;
|
||||
import :Rendertarget;
|
||||
import :Types;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
||||
GridElement::GridElement(std::uint32_t columns, std::uint32_t rows, std::int32_t spacingX, std::int32_t spacingY, std::int32_t paddingX, std::int32_t paddingY, Anchor2D anchor) : Transform2D(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY), paddingX(paddingX), paddingY(paddingY) {
|
||||
|
||||
}
|
||||
|
||||
void GridElement::UpdatePositionScaled(RendertargetBase& window) {
|
||||
std::int32_t cellWidth = (paddingX * 2) - (spacingX * (columns - 1)) / columns;
|
||||
std::int32_t cellHeight = (paddingY * 2) - (spacingY * (rows - 1)) / rows;
|
||||
|
||||
std::size_t childIndex = 0;
|
||||
for (std::uint32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
||||
for (std::uint32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
||||
Transform2D* child = children[childIndex];
|
||||
|
||||
// Calculate position for this child
|
||||
std::int32_t childX = (cellWidth * col) + (spacingX * col) + paddingX;
|
||||
|
||||
std::int32_t childY = (cellHeight * row) + (spacingY * row) + paddingY;
|
||||
|
||||
// Apply relative positioning
|
||||
child->anchor.x = childX;
|
||||
child->anchor.y = childY;
|
||||
child->anchor.width = cellWidth;
|
||||
child->anchor.height = cellHeight;
|
||||
|
||||
// Update child position
|
||||
child->UpdatePosition(window, *this);
|
||||
childIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GridElement::UpdatePosition(RendertargetBase& window, Transform2D& parent) {
|
||||
ScaleElement(parent);
|
||||
UpdatePositionScaled(window);
|
||||
}
|
||||
|
|
@ -30,34 +30,4 @@ using namespace Crafter;
|
|||
|
||||
Anchor2D::Anchor2D(float x, float y, float width, float height, float offsetX, float offsetY, std::int32_t z, bool maintainAspectRatio): x(x), y(y), width(width), height(height), offsetX(offsetX), offsetY(offsetY), z(z), maintainAspectRatio(maintainAspectRatio) {
|
||||
|
||||
}
|
||||
|
||||
Transform2D::Transform2D(Anchor2D anchor) : anchor(anchor) {
|
||||
|
||||
}
|
||||
|
||||
void Transform2D::UpdatePosition(RendertargetBase& window, Transform2D& parent) {
|
||||
ScaleElement(parent);
|
||||
for(Transform2D* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
}
|
||||
|
||||
void Transform2D::ScaleElement(Transform2D& parent) {
|
||||
if(anchor.maintainAspectRatio) {
|
||||
if(parent.scaled.size.x > parent.scaled.size.y) {
|
||||
scaled.size.x = anchor.width * parent.scaled.size.y;
|
||||
scaled.size.y = anchor.height * parent.scaled.size.y;
|
||||
} else {
|
||||
scaled.size.x = anchor.width * parent.scaled.size.x;
|
||||
scaled.size.y = anchor.height * parent.scaled.size.x;
|
||||
}
|
||||
} else {
|
||||
|
||||
scaled.size.x = anchor.width * parent.scaled.size.x;
|
||||
scaled.size.y = anchor.height * parent.scaled.size.y;
|
||||
}
|
||||
|
||||
scaled.position.x = parent.scaled.position.x + (anchor.x * parent.scaled.size.x - anchor.offsetX * scaled.size.x);
|
||||
scaled.position.y = parent.scaled.position.y + (anchor.y * parent.scaled.size.y - anchor.offsetY * scaled.size.y);
|
||||
}
|
||||
|
|
@ -420,8 +420,8 @@ Window::Window(std::uint32_t width, std::uint32_t height) : width(width), height
|
|||
}
|
||||
|
||||
// Map the shared memory file
|
||||
renderer.buffer = reinterpret_cast<Vector<std::uint8_t, 4, 4>*>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
||||
if (renderer.buffer == MAP_FAILED) {
|
||||
renderer.buffer[0] = reinterpret_cast<Vector<std::uint8_t, 4, 4>*>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
||||
if (renderer.buffer[0] == MAP_FAILED) {
|
||||
throw std::runtime_error("mmap failed");
|
||||
}
|
||||
|
||||
|
|
@ -562,13 +562,13 @@ void Window::SetTitle(const std::string_view title) {
|
|||
}
|
||||
|
||||
void Window::SetCusorImage(std::uint16_t sizeX, std::uint16_t sizeY) {
|
||||
new (&cursorRenderer) Rendertarget<std::uint8_t, 4, 4>(sizeX, sizeY);
|
||||
new (&cursorRenderer) Rendertarget<std::uint8_t, 4, 4, 1>(sizeX, sizeY);
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
if(cursorSurface == nullptr) {
|
||||
cursorSurface = wl_compositor_create_surface(Device::compositor);
|
||||
} else {
|
||||
wl_buffer_destroy(cursorWlBuffer);
|
||||
munmap(cursorRenderer.buffer, cursorBufferOldSize);
|
||||
munmap(cursorRenderer.buffer[0], cursorBufferOldSize);
|
||||
}
|
||||
|
||||
int stride = sizeX * 4;
|
||||
|
|
@ -581,8 +581,8 @@ void Window::SetCusorImage(std::uint16_t sizeX, std::uint16_t sizeY) {
|
|||
throw std::runtime_error(std::format("creating a buffer file for {}B failed", size));
|
||||
}
|
||||
|
||||
cursorRenderer.buffer = reinterpret_cast<Vector<std::uint8_t, 4, 4>*>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
||||
if (cursorRenderer.buffer == MAP_FAILED) {
|
||||
cursorRenderer.buffer[0] = reinterpret_cast<Vector<std::uint8_t, 4, 4>*>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
||||
if (cursorRenderer.buffer[0] == MAP_FAILED) {
|
||||
throw std::runtime_error("mmap failed");
|
||||
}
|
||||
|
||||
|
|
@ -607,9 +607,9 @@ void Window::SetCusorImageDefault() {
|
|||
}
|
||||
|
||||
void Window::UpdateCursorImage() {
|
||||
cursorRenderer.Render();
|
||||
cursorRenderer.Render(0);
|
||||
for(std::uint32_t i = 0; i < cursorBufferOldSize / 4; i++) {
|
||||
std::swap(cursorRenderer.buffer[i].b, cursorRenderer.buffer[i].r);
|
||||
std::swap(cursorRenderer.buffer[0][i].b, cursorRenderer.buffer[0][i].r);
|
||||
}
|
||||
wl_surface_attach(cursorSurface, cursorWlBuffer, 0, 0);
|
||||
wl_surface_damage(cursorSurface, 0, 0, 9999999, 99999999);
|
||||
|
|
@ -686,9 +686,7 @@ void Window::Update() {
|
|||
|
||||
void Window::Render() {
|
||||
#ifdef CRAFTER_GRAPHICS_RENDERER_SOFTWARE
|
||||
// elements.erase(std::remove(elements.begin(), elements.end(), static_cast<Transform*>(nullptr)), elements.end());
|
||||
// std::sort(elements.begin(), elements.end(), [](Transform* a, Transform* b){ return a->anchor.z < b->anchor.z; });
|
||||
renderer.Render();
|
||||
renderer.Render(0);
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
wl_surface_attach(surface, buffer, 0, 0);
|
||||
wl_surface_commit(surface);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue