faster rect command creation
This commit is contained in:
@@ -45,6 +45,8 @@ class PD_API Drawlist {
|
|||||||
|
|
||||||
/** Command Allocation */
|
/** Command Allocation */
|
||||||
Command& NewCommand();
|
Command& NewCommand();
|
||||||
|
bool HasCommands() { return pCommands.size() > 0; }
|
||||||
|
Command& GetLastCommand() { return pCommands[pCommands.size() - 1]; }
|
||||||
|
|
||||||
/** Path API */
|
/** Path API */
|
||||||
void PathAdd(const fvec2& point) { pPath.Push(point); }
|
void PathAdd(const fvec2& point) { pPath.Push(point); }
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ class Vertex {
|
|||||||
Vertex() {}
|
Vertex() {}
|
||||||
Vertex(const fvec2& pos, const fvec2& uv, u32 color)
|
Vertex(const fvec2& pos, const fvec2& uv, u32 color)
|
||||||
: pos(pos), uv(uv), color(color) {}
|
: pos(pos), uv(uv), color(color) {}
|
||||||
|
Vertex(float x, float y, float u, float v, u32 color)
|
||||||
|
: pos(x, y), uv(u, v), color(color) {}
|
||||||
~Vertex() {}
|
~Vertex() {}
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
|
|||||||
+25
-9
@@ -207,6 +207,17 @@ PD_API fvec2 Font::GetTextBounds(const char* text, float scale) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD_API void PrimTextQuad(Command& cmd, float x, float y, float w, float h,
|
||||||
|
const fvec4& uv, const PD::Color& color) {
|
||||||
|
cmd.Reserve(4, 6);
|
||||||
|
cmd.Add(2, 1, 0);
|
||||||
|
cmd.Add(3, 2, 0);
|
||||||
|
cmd.Add(Vertex(x, y, uv.x, uv.y, color));
|
||||||
|
cmd.Add(Vertex(x + w, y, uv.z, uv.y, color));
|
||||||
|
cmd.Add(Vertex(x + w, y + h, uv.z, uv.w, color));
|
||||||
|
cmd.Add(Vertex(x, y + h, uv.x, uv.w, color));
|
||||||
|
}
|
||||||
|
|
||||||
PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color,
|
PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color,
|
||||||
float scale, const char* text, LiTextFlags flags,
|
float scale, const char* text, LiTextFlags flags,
|
||||||
const fvec2& box) {
|
const fvec2& box) {
|
||||||
@@ -225,7 +236,7 @@ PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color,
|
|||||||
|
|
||||||
U8Iterator it(text);
|
U8Iterator it(text);
|
||||||
u32 c;
|
u32 c;
|
||||||
Command* cmd = nullptr;
|
Command* cmd = dl.HasCommands() ? &dl.GetLastCommand() : nullptr;
|
||||||
while (it.Decode32(c)) {
|
while (it.Decode32(c)) {
|
||||||
auto cp = GetCodepoint(c);
|
auto cp = GetCodepoint(c);
|
||||||
if ((cp.pInvalid && c != L'\n' && c != L'\t' && c != L' ') && c != L'\r')
|
if ((cp.pInvalid && c != L'\n' && c != L'\t' && c != L' ') && c != L'\r')
|
||||||
@@ -252,15 +263,20 @@ PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color,
|
|||||||
cmd->Tex = Textures[cp.Tex];
|
cmd->Tex = Textures[cp.Tex];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & LiTextFlags_Shaddow) {
|
// calculating once and using PrimTextQuad to directly push
|
||||||
Rect rec = Math::PrimRect(rpos + off + fvec2(1, cp.Offset * cfs + 1),
|
// saves ~42% on raw multiline text draw time 6.3 -> 3.7 ms
|
||||||
cp.Size * cfs, 0.f);
|
// and ~25% on the whole frametime 20.3 -> 15.2 ms
|
||||||
dl.PrimQuad(*cmd, rec, cp.SimpleUV, 0xff111111);
|
// tested with Craftus-Next 0.8.0 commit:
|
||||||
}
|
// 33298ccc276bf996d341710e69ecf05f99c57961
|
||||||
|
float cw = cp.Size.x * cfs;
|
||||||
|
float ch = cp.Size.y * cfs;
|
||||||
|
float cx = rpos.x + off.x;
|
||||||
|
float cy = rpos.y + off.y + (cp.Offset * cfs);
|
||||||
|
|
||||||
Rect rec = Math::PrimRect(rpos + off + fvec2(0, cp.Offset * cfs),
|
if (flags & LiTextFlags_Shaddow) {
|
||||||
cp.Size * cfs, 0.f);
|
PrimTextQuad(*cmd, cx + 1.f, cy + 1.f, cw, ch, cp.SimpleUV, 0xff111111);
|
||||||
dl.PrimQuad(*cmd, rec, cp.SimpleUV, color);
|
}
|
||||||
|
PrimTextQuad(*cmd, cx, cy, cw, ch, cp.SimpleUV, color);
|
||||||
|
|
||||||
off.x += cp.Size.x * cfs + 2 * cfs;
|
off.x += cp.Size.x * cfs + 2 * cfs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user