Add Nee Backend Structure

Use TexAddress instead of Texture::Ref in Cmds
Add a .clang-format??
This commit is contained in:
2026-01-25 00:04:40 +01:00
parent da79db223f
commit d2806b2061
8 changed files with 594 additions and 44 deletions

334
.clang-format Normal file
View File

@@ -0,0 +1,334 @@
---
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: true
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseArrows: false
AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AttributeMacros:
- __capability
- absl_nonnull
- absl_nullable
- absl_nullability_unknown
BinPackArguments: true
BinPackLongBracedList: true
BinPackParameters: BinPack
BitFieldColonSpacing: Both
BracedInitializerIndentWidth: -1
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTemplateCloser: false
BreakBeforeTernaryOperators: true
BreakBinaryOperations: Never
BreakConstructorInitializers: BeforeColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: Yes
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
EnumTrailingComma: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExportBlock: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: true
KeepFormFeed: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
OneLineFormatOffRegex: ''
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakBeforeMemberAccess: 150
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: Always
RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes:
Enabled: true
IgnoreCase: false
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterOperatorKeyword: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterNot: false
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
ExceptDoubleParentheses: false
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TableGenBreakInsideDAGArg: DontBreak
TabWidth: 8
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
WrapNamespaceBodyWithEmptyLines: Leave
...

View File

@@ -59,4 +59,32 @@ class GfxGL2 : public GfxDriver {
GLuint pLocAlfa;
GLuint VBO, IBO, VAO; // vao is only used in > 3.3
};
class GfxGL3 : public GfxDriver2 {
public:
GfxGL3() : GfxDriver2("OpenGL3") {}
~GfxGL3() = default;
PD_SHARED(GfxGL3);
void Init() override;
void Deinit() override;
// void NewFrame() override;
void TexBind(PD::Li::TexAddress addr) override;
void Draw(const Li::CmdPool& pool) override;
PD::Li::TexAddress TexLoad(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter =
PD::Li::Texture::Filter::LINEAR) override;
void TexDelete(PD::Li::TexAddress tex) override;
std::vector<Li::Vertex> VertexBuffer;
std::vector<PD::u16> IndexBuffer;
GLuint Shader;
GLuint pLocProjection;
GLuint pLocTex;
GLuint pLocAlfa;
GLuint VBO, IBO, VAO; // vao is only used in > 3.3
};
} // namespace PD

View File

@@ -253,7 +253,7 @@ void GfxGL2::BindTex(PD::Li::TexAddress addr) {
void GfxGL2::RenderDrawData(const Li::CmdPool& Commands) {
size_t index = 0;
while (index < Commands.Size()) {
PD::Li::Texture::Ref Tex = Commands.GetCmd(index)->Tex;
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
if (!Tex) {
index++;
continue;
@@ -281,7 +281,7 @@ void GfxGL2::RenderDrawData(const Li::CmdPool& Commands) {
} else {
glDisable(GL_SCISSOR_TEST);
}
BindTex(Tex->Address);
BindTex(Tex);
#if PD_OPENGL >= 33
glBindVertexArray(VAO);
@@ -340,4 +340,161 @@ PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
return res;
}
void GfxGL3::Init() {
VertexBuffer.resize(4 * 8192);
IndexBuffer.resize(6 * 8192);
Shader = createShaderProgram(vertex_shader, frag_shader);
glUseProgram(Shader);
#if PD_OPENGL >= 33
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
#endif
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
#if PD_OPENGL < 33
SetupShaderAttribs(Shader); // GL 2.1
#else
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Pos));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, UV));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
(void*)offsetof(PD::Li::Vertex, Color));
#endif
glGenBuffers(1, &IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
pLocTex = glGetUniformLocation(Shader, "tex");
pLocAlfa = glGetUniformLocation(Shader, "alfa");
pLocProjection = glGetUniformLocation(Shader, "projection");
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#if PD_OPENGL >= 33
glBindVertexArray(0);
#endif
}
void GfxGL3::Deinit() {
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &IBO);
#if PD_OPENGL >= 33
glDeleteBuffers(1, &VAO);
#endif
}
// void NewFrame() {
//}
void GfxGL3::TexBind(PD::Li::TexAddress addr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
glUniform1i(pLocTex, 0);
GLint fmt = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
}
void GfxGL3::Draw(const Li::CmdPool& pool) {
size_t index = 0;
while (index < pool.Size()) {
PD::Li::TexAddress Tex = pool.GetCmd(index)->Tex;
if (Tex == 0) {
index++;
continue;
}
size_t StartIndex = CurrentIndex;
bool ScissorOn = pool.GetCmd(index)->ScissorOn;
ivec4 ScissorRect = pool.GetCmd(index)->ScissorRect;
while (index < pool.Size() && pool.GetCmd(index)->Tex == Tex &&
pool.GetCmd(index)->ScissorOn == ScissorOn &&
pool.GetCmd(index)->ScissorRect == ScissorRect) {
auto c = pool.GetCmd(index);
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
}
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
}
index++;
}
if (ScissorOn) {
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
ScissorRect.z, ScissorRect.w);
glEnable(GL_SCISSOR_TEST);
} else {
glDisable(GL_SCISSOR_TEST);
}
TexBind(Tex);
#if PD_OPENGL >= 33
glBindVertexArray(VAO);
#endif
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
&VertexBuffer[0], GL_DYNAMIC_DRAW);
#if PD_OPENGL < 33
// For some reason we need to set these every frame for every buffer
// Found that out when creating My 3d Engine
SetupShaderAttribs(Shader);
#endif
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
&IndexBuffer[0], GL_DYNAMIC_DRAW);
glDrawElements(GL_TRIANGLES, CurrentIndex - StartIndex, GL_UNSIGNED_SHORT,
(void*)(StartIndex * sizeof(PD::u16)));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
TexBind(0);
#if PD_OPENGL >= 33
glBindVertexArray(0);
#endif
}
}
PD::Li::TexAddress GfxGL3::TexLoad(const std::vector<PD::u8>& pixels, int w,
int h, PD::Li::Texture::Type type,
PD::Li::Texture::Filter filter) {
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
// Set base format (Always using RGBA as base)
GLenum fmt = GL_RGBA;
if (type == PD::Li::Texture::Type::RGB24) {
fmt = GL_RGB;
} else if (type == PD::Li::Texture::Type::A8) {
fmt = GL_ALPHA;
}
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
pixels.data());
if (filter == PD::Li::Texture::Filter::LINEAR) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glBindTexture(GL_TEXTURE_2D, 0);
return texID;
}
void GfxGL3::TexDelete(PD::Li::TexAddress tex) {
GLuint tex_ = tex;
glDeleteTextures(1, &tex_);
}
} // namespace PD

View File

@@ -34,6 +34,31 @@ enum LiBackendFlags_ {
};
namespace PD {
// The backend api nobody asked for
class GfxDriver2 {
public:
GfxDriver2(const std::string& name = "NullGfx") : pName(name) {};
~GfxDriver2() = default;
virtual void Init() {}
virtual void Deinit() {}
virtual void Draw(const PD::Li::CmdPool& pool) {}
virtual void TexBind(PD::Li::TexAddress addr) {}
virtual PD::Li::TexAddress TexLoad(
const std::vector<PD::u8>& pixels, int w, int h,
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
PD::Li::Texture::Filter filter = PD::Li::Texture::Filter::LINEAR) {
return 0;
}
virtual void TexDelete(PD::Li::TexAddress tex) {}
protected:
const std::string pName;
LiBackendFlags pFlags = 0;
size_t CurrentIndex = 0;
size_t CurrentVertex = 0;
ivec2 ViewPort;
};
class GfxDriver {
public:
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};

View File

@@ -69,7 +69,7 @@ class Command {
bool ScissorOn = false;
int Layer = 0;
int Index = 0;
Texture::Ref Tex;
TexAddress Tex;
};
class PD_LITHIUM_API CmdPool {

View File

@@ -38,6 +38,8 @@ class Vertex {
}
~Vertex() {}
PD_RAW(Vertex);
// private:
/** Open Access Data Section */

View File

@@ -91,7 +91,7 @@ PD_LITHIUM_API void DrawList::Optimize() {
PD_LITHIUM_API Command::Ref DrawList::GetNewCmd() {
Command::Ref cmd = pPool.NewCmd();
cmd->Index = pPool.Size() - 1;
cmd->Tex = CurrentTex;
cmd->Tex = CurrentTex->Address;
pClipCmd(cmd);
return cmd;
}
@@ -103,7 +103,7 @@ PD_LITHIUM_API void DrawList::pClipCmd(Command::Ref cmd) {
}
}
PD_LITHIUM_API void DrawList::PathArcToN(const fvec2 &c, float radius,
PD_LITHIUM_API void DrawList::PathArcToN(const fvec2& c, float radius,
float a_min, float a_max,
int segments) {
// Path.push_back(c);
@@ -114,7 +114,7 @@ PD_LITHIUM_API void DrawList::PathArcToN(const fvec2 &c, float radius,
}
}
PD_LITHIUM_API void DrawList::PathFastArcToN(const fvec2 &c, float r,
PD_LITHIUM_API void DrawList::PathFastArcToN(const fvec2& c, float r,
float amin, float amax, int s) {
/**
* Funcion with less division overhead
@@ -210,19 +210,19 @@ PD_LITHIUM_API void DrawList::PathRectEx(fvec2 a, fvec2 b, float rounding,
}
}
PD_LITHIUM_API void DrawList::DrawRect(const fvec2 &pos, const fvec2 &size,
PD_LITHIUM_API void DrawList::DrawRect(const fvec2& pos, const fvec2& size,
u32 color, int thickness) {
PathRect(pos, pos + size);
// Flags is currently hardcoded (1 = close)
PathStroke(color, thickness, 1);
}
void DrawList::DrawRectFilled(const fvec2 &pos, const fvec2 &size, u32 color) {
void DrawList::DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color) {
PathRect(pos, pos + size);
PathFill(color);
}
PD_LITHIUM_API void DrawList::DrawTriangle(const fvec2 &a, const fvec2 &b,
const fvec2 &c, u32 color,
PD_LITHIUM_API void DrawList::DrawTriangle(const fvec2& a, const fvec2& b,
const fvec2& c, u32 color,
int thickness) {
PathAdd(a);
PathAdd(b);
@@ -230,15 +230,15 @@ PD_LITHIUM_API void DrawList::DrawTriangle(const fvec2 &a, const fvec2 &b,
PathStroke(color, thickness, 1);
}
PD_LITHIUM_API void DrawList::DrawTriangleFilled(const fvec2 &a, const fvec2 &b,
const fvec2 &c, u32 color) {
PD_LITHIUM_API void DrawList::DrawTriangleFilled(const fvec2& a, const fvec2& b,
const fvec2& c, u32 color) {
PathAdd(a);
PathAdd(b);
PathAdd(c);
PathFill(color);
}
PD_LITHIUM_API void DrawList::DrawCircle(const fvec2 &center, float rad,
PD_LITHIUM_API void DrawList::DrawCircle(const fvec2& center, float rad,
u32 color, int num_segments,
int thickness) {
if (num_segments <= 0) {
@@ -251,7 +251,7 @@ PD_LITHIUM_API void DrawList::DrawCircle(const fvec2 &center, float rad,
PathStroke(color, thickness, (1 << 0));
}
PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2 &center, float rad,
PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2& center, float rad,
u32 color, int num_segments) {
if (num_segments <= 0) {
// Auto Segment
@@ -263,7 +263,7 @@ PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2 &center, float rad,
}
// TODO: Don't render OOS
PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2> &points,
PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2>& points,
u32 clr, u32 flags, int thickness) {
if (points.size() < 2) {
return;
@@ -285,7 +285,7 @@ PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2> &points,
}
PD_LITHIUM_API void DrawList::DrawConvexPolyFilled(
const std::vector<fvec2> &points, u32 clr) {
const std::vector<fvec2>& points, u32 clr) {
if (points.size() < 3) {
return; // Need at least three points
}
@@ -293,24 +293,24 @@ PD_LITHIUM_API void DrawList::DrawConvexPolyFilled(
Renderer::CmdConvexPolyFilled(cmd, points, clr, CurrentTex);
}
PD_LITHIUM_API void DrawList::DrawText(const fvec2 &pos,
const std::string &text, u32 color) {
PD_LITHIUM_API void DrawList::DrawText(const fvec2& pos,
const std::string& text, u32 color) {
if (!pCurrentFont) {
return;
}
pCurrentFont->CmdTextEx(pPool, pos, color, pFontScale, text);
}
PD_LITHIUM_API void DrawList::DrawTextEx(const fvec2 &p,
const std::string &text, u32 color,
LiTextFlags flags, const fvec2 &box) {
PD_LITHIUM_API void DrawList::DrawTextEx(const fvec2& p,
const std::string& text, u32 color,
LiTextFlags flags, const fvec2& box) {
if (!pCurrentFont) {
return;
}
pCurrentFont->CmdTextEx(pPool, p, color, pFontScale, text, flags, box);
}
PD_LITHIUM_API void DrawList::DrawLine(const fvec2 &a, const fvec2 &b,
PD_LITHIUM_API void DrawList::DrawLine(const fvec2& a, const fvec2& b,
u32 color, int t) {
PathAdd(a);
PathAdd(b);

View File

@@ -49,7 +49,7 @@ PD_LITHIUM_API void Font::LoadDefaultFont(int id, int pixel_height) {
#endif
}
PD_LITHIUM_API void Font::LoadTTF(const std::string &path, int height) {
PD_LITHIUM_API void Font::LoadTTF(const std::string& path, int height) {
/**
* Just use LoadFile2Mem which looks way cleaner
* and helps not having the font loading code twice
@@ -60,7 +60,7 @@ PD_LITHIUM_API void Font::LoadTTF(const std::string &path, int height) {
LoadTTF(font, height);
}
PD_LITHIUM_API void Font::pMakeAtlas(bool final, std::vector<u8> &font_tex,
PD_LITHIUM_API void Font::pMakeAtlas(bool final, std::vector<u8>& font_tex,
int texszs, PD::Li::Texture::Ref tex) {
auto t =
Gfx::LoadTex(font_tex, texszs, texszs, Texture::RGBA32, Texture::LINEAR);
@@ -68,7 +68,7 @@ PD_LITHIUM_API void Font::pMakeAtlas(bool final, std::vector<u8> &font_tex,
Textures.push_back(tex);
}
PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8> &data, int height) {
PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8>& data, int height) {
/**
* Some additional Info:
* Removed the stbtt get bitmapbox as we dont need to place
@@ -107,7 +107,7 @@ PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8> &data, int height) {
if (stbtt_IsGlyphEmpty(&inf, gi)) continue;
int w = 0, h = 0, xo = 0, yo = 0;
unsigned char *bitmap =
unsigned char* bitmap =
stbtt_GetCodepointBitmap(&inf, scale, scale, ii, &w, &h, &xo, &yo);
if (!bitmap || w <= 0 || h <= 0) {
if (bitmap) free(bitmap);
@@ -184,7 +184,7 @@ PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8> &data, int height) {
}
}
PD_LITHIUM_API Font::Codepoint &Font::GetCodepoint(u32 cp) {
PD_LITHIUM_API Font::Codepoint& Font::GetCodepoint(u32 cp) {
// Check if codepoijt exist or return a static invalid one
auto res = CodeMap.find(cp);
if (res == CodeMap.end()) {
@@ -195,7 +195,7 @@ PD_LITHIUM_API Font::Codepoint &Font::GetCodepoint(u32 cp) {
return res->second;
}
PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string& text, float scale) {
u32 id = PD::FNV1A32(text);
if (pTMS.find(id) != pTMS.end()) {
pTMS[id].TimeStamp = PD::OS::GetTime();
@@ -210,7 +210,7 @@ PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
float cfs = (DefaultPixelHeight * scale) / (float)PixelHeight;
float lh = (float)PixelHeight * cfs;
size_t index = 0;
for (auto &it : wtext) {
for (auto& it : wtext) {
if (it == L'\0') {
break;
}
@@ -248,9 +248,9 @@ PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
return res;
}
PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
float scale, const std::string &text,
LiTextFlags flags, const fvec2 &box) {
PD_LITHIUM_API void Font::CmdTextEx(CmdPool& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text,
LiTextFlags flags, const fvec2& box) {
fvec2 off;
float cfs = (DefaultPixelHeight * scale) / (float)PixelHeight;
float lh = (float)PixelHeight * cfs;
@@ -278,7 +278,7 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
lines.push_back(tmp);
}
for (auto &it : lines) {
for (auto& it : lines) {
if (flags & LiTextFlags_NoOOS) {
if (rpos.y + off.y + lh < 0) {
off.y += lh;
@@ -295,8 +295,10 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
auto wline = Strings::MakeWstring(it);
auto cmd = cmds.NewCmd();
auto Tex = GetCodepoint(wline[0]).Tex;
cmd->Tex = Tex;
for (auto &jt : wline) {
if (Tex) {
cmd->Tex = Tex->Address;
}
for (auto& jt : wline) {
auto cp = GetCodepoint(jt);
if ((cp.pInvalid && jt != L' ' && jt != L'\n' && jt != L'\t') &&
jt != L'\r') {
@@ -305,7 +307,9 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
if (Tex != cp.Tex) {
cmd = cmds.NewCmd();
Tex = cp.Tex;
cmd->Tex = Tex;
if (Tex) {
cmd->Tex = Tex->Address;
}
}
if (jt == L'\t') {
off.x += 16 * cfs;
@@ -314,7 +318,7 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
if (flags & LiTextFlags_Shaddow) {
// Draw
Rect rec = Renderer::PrimRect(
rpos + vec2(off.x + 1, off.y + (cp.Offset * cfs)) + 1,
rpos + fvec2(off.x + 1, off.y + (cp.Offset * cfs)) + 1,
cp.Size * cfs, 0.f);
Renderer::CmdQuad(cmd, rec, cp.SimpleUV, 0xff111111);
}
@@ -333,9 +337,9 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
}
}
PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
PD_LITHIUM_API std::string Font::pWrapText(const std::string& txt, float scale,
const PD::fvec2& max,
PD::fvec2& dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
@@ -370,9 +374,9 @@ PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
return ret;
}
PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
PD_LITHIUM_API std::string Font::pShortText(const std::string& txt, float scale,
const PD::fvec2& max,
PD::fvec2& dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
@@ -398,7 +402,7 @@ PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
maxlen -= GetTextBounds(ext, scale).x;
maxlen -= GetTextBounds(ph, scale).x;
for (auto &it : tmp) {
for (auto& it : tmp) {
if (GetTextBounds(ret, scale).x > maxlen) {
ret += ph;
ret += ext;