render target improvements
This commit is contained in:
parent
1bc6293610
commit
789bb307d5
12 changed files with 368 additions and 428 deletions
|
|
@ -23,93 +23,12 @@ export module Crafter.Graphics:RenderingElement2D;
|
|||
import Crafter.Asset;
|
||||
import std;
|
||||
import :Transform2D;
|
||||
import :RenderingElement2DBase;
|
||||
import :Font;
|
||||
import :Types;
|
||||
import :Window;
|
||||
|
||||
export namespace Crafter {
|
||||
enum class TextAlignment {
|
||||
Left,
|
||||
Center,
|
||||
Right
|
||||
};
|
||||
|
||||
enum class TextOverflowMode {
|
||||
Clip,
|
||||
Wrap
|
||||
};
|
||||
|
||||
enum class TextScaleMode {
|
||||
None,
|
||||
Font,
|
||||
Element,
|
||||
Buffer
|
||||
};
|
||||
|
||||
struct RenderElement2DScalingOwning {
|
||||
std::vector<Vector<std::uint8_t, 4>> scalingBuffer;
|
||||
std::uint32_t bufferWidth;
|
||||
std::uint32_t bufferHeight;
|
||||
bool bufferUpdated = true;
|
||||
RenderElement2DScalingOwning() = default;
|
||||
RenderElement2DScalingOwning(std::uint32_t bufferWidth, std::uint32_t bufferHeight) : scalingBuffer(bufferWidth*bufferHeight), bufferWidth(bufferWidth), bufferHeight(bufferHeight) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct RenderElement2DScalingNonOwning {
|
||||
Vector<std::uint8_t, 4>* scalingBuffer;
|
||||
std::uint32_t bufferWidth;
|
||||
std::uint32_t bufferHeight;
|
||||
bool bufferUpdated = true;
|
||||
RenderElement2DScalingNonOwning() = default;
|
||||
RenderElement2DScalingNonOwning(Vector<std::uint8_t, 4>* scalingBuffer, std::uint32_t bufferWidth, std::uint32_t bufferHeight) : scalingBuffer(scalingBuffer), bufferWidth(bufferWidth), bufferHeight(bufferHeight) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct RenderElement2DRotating {
|
||||
float rotation;
|
||||
bool rotationUpdated = true;
|
||||
RenderElement2DRotating() = default;
|
||||
RenderElement2DRotating(float rotation) : rotation(rotation) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct EmptyScalingBase {};
|
||||
struct EmptyRotatingBase {};
|
||||
|
||||
template<bool Scaling, bool Owning>
|
||||
using ScalingBase =
|
||||
std::conditional_t<
|
||||
Scaling,
|
||||
std::conditional_t<Owning,
|
||||
RenderElement2DScalingOwning,
|
||||
RenderElement2DScalingNonOwning>,
|
||||
EmptyScalingBase
|
||||
>;
|
||||
|
||||
template<bool Rotating>
|
||||
using RotatingBase =
|
||||
std::conditional_t<
|
||||
Rotating,
|
||||
RenderElement2DRotating,
|
||||
EmptyRotatingBase
|
||||
>;
|
||||
|
||||
struct RenderingElement2DBase : Transform2D {
|
||||
std::vector<Vector<std::uint8_t, 4>> buffer;
|
||||
OpaqueType opaque;
|
||||
RenderingElement2DBase(Anchor2D anchor) : Transform2D(anchor) {
|
||||
scaled.size.x = 0;
|
||||
}
|
||||
RenderingElement2DBase(Anchor2D anchor, OpaqueType opaque) : Transform2D(anchor), opaque(opaque) {
|
||||
scaled.size.x = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<bool Scaling, bool Owning, bool Rotating> requires ((!Rotating || Scaling) && (!Owning || Scaling))
|
||||
struct RenderingElement2D : RenderingElement2DBase, ScalingBase<Scaling, Owning>, RotatingBase<Rotating> {
|
||||
RenderingElement2D() = default;
|
||||
|
|
@ -210,7 +129,7 @@ export namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
void UpdatePosition(Rendertarget& renderer, ScaleData2D oldScale) {
|
||||
void UpdatePosition(RendertargetBase& renderer, ScaleData2D oldScale) {
|
||||
if constexpr(Scaling && !Rotating) {
|
||||
if(oldScale.size.x != scaled.size.x || oldScale.size.y != scaled.size.y) {
|
||||
buffer.resize(scaled.size.x * scaled.size.y);
|
||||
|
|
@ -260,7 +179,7 @@ export namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
void UpdatePosition(Rendertarget& window) override {
|
||||
void UpdatePosition(RendertargetBase& window) override {
|
||||
ScaleData2D oldScale = scaled;
|
||||
ScaleElement(window.transform);
|
||||
UpdatePosition(window, oldScale);
|
||||
|
|
@ -269,7 +188,7 @@ export namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
void UpdatePosition(Rendertarget& window, Transform2D& parent) override {
|
||||
void UpdatePosition(RendertargetBase& window, Transform2D& parent) override {
|
||||
ScaleData2D oldScale = scaled;
|
||||
ScaleElement(parent);
|
||||
UpdatePosition(window, oldScale);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue