Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DrawNodeEx/DrawNodeExTest update #1914

Merged
merged 59 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
66ee110
Fix issue #1546 of UILayout(#1549) and small performance boost
aismann Dec 30, 2023
aad2280
add test
aismann Dec 30, 2023
6127ff4
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Dec 31, 2023
b5708b1
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Jan 2, 2024
cc6c569
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Jan 2, 2024
8650ebb
Update DrawPrimitivesTest.cpp (Smaller tester code)
aismann Jan 2, 2024
d4fead5
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Jan 3, 2024
5201e4f
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Jan 4, 2024
8fff9fb
Update DrawNodeEx.h
aismann Jan 4, 2024
5a65ad4
Update AXLinkHelpers.cmake
aismann Jan 4, 2024
29199fa
Merge branch 'axmolengine:dev' into dev
aismann Jan 4, 2024
93f1bfa
Merge branch 'axmolengine:dev' into dev
aismann Jan 5, 2024
d917585
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Jan 21, 2024
645193e
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Jan 24, 2024
9a20a39
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Feb 4, 2024
f9b4ca6
Merge remote-tracking branch 'upstream/2.1' into dev
aismann Feb 4, 2024
ad3767a
Update Console.cpp (removed the '\n' which creates an second (empty) …
aismann Mar 15, 2024
f8b772f
Merge branch 'axmolengine:dev' into dev
aismann Mar 15, 2024
03cfb8c
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Mar 15, 2024
d3573d9
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Mar 22, 2024
fa40de8
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Mar 30, 2024
14e7fb6
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Apr 4, 2024
bf54b54
Merge branch 'dev' of https://github.com/aismann/axmol into dev
aismann Apr 27, 2024
bfb43d9
Merge branch 'axmolengine:dev' into dev
aismann Apr 29, 2024
54249d7
Merge branch 'axmolengine:dev' into dev
aismann May 5, 2024
c0f5e8e
Merge branch 'axmolengine:dev' into dev
aismann May 7, 2024
cda1307
segment stuff
aismann May 7, 2024
588f091
.
aismann May 7, 2024
6068474
add some more tests
aismann May 8, 2024
c1f3a0b
Issue 1888
aismann May 8, 2024
6e38249
.
aismann May 8, 2024
ac10db1
add all DrawNode cocos2dx
aismann May 8, 2024
bcdf6ed
.
aismann May 8, 2024
56595bc
.
aismann May 8, 2024
b10e733
.
aismann May 13, 2024
2e78576
Merge branch 'axmolengine:dev' into dev
aismann May 13, 2024
5f600d2
Merge branch 'dev' into DrawNodeEx_Tester
aismann May 13, 2024
36ef5e7
add feature for drawing in correct order
aismann May 16, 2024
a77e4f0
.
aismann May 16, 2024
55d7ae6
Update DrawNodeEx.cpp
aismann May 16, 2024
f891cd2
.
aismann May 16, 2024
87562fd
Update DrawNodeEx.cpp
aismann May 16, 2024
62d7e17
DRAWNODE_TRIANGLE_ONLY
aismann May 16, 2024
b94a695
DRAWNODE_DRAW_LINE_POINT
aismann May 16, 2024
96ea980
.
aismann May 16, 2024
8ab29e4
Merge branch 'axmolengine:dev' into dev
aismann May 16, 2024
e96476d
Merge branch 'dev' into DrawNodeEx_Tester
aismann May 16, 2024
58a76b4
Update DrawNodeExTest.cpp
aismann May 16, 2024
ea46c35
Merge branch 'axmolengine:dev' into dev
aismann May 17, 2024
8443939
Merge branch 'dev' into DrawNodeEx_Tester
aismann May 17, 2024
def4c74
Update DrawNodeExTest.cpp
aismann May 17, 2024
1795e81
.
aismann May 21, 2024
03e99ff
Merge remote-tracking branch 'upstream/dev' into DrawNodeEx_Tester
aismann May 21, 2024
e23e273
Merge remote-tracking branch 'upstream/dev' into DrawNodeEx_Tester
aismann May 21, 2024
af41774
Merge remote-tracking branch 'upstream/dev' into DrawNodeEx_Tester
aismann May 22, 2024
cc42bb3
.
aismann May 22, 2024
4cfc920
Add round brackets
aismann May 22, 2024
1ad13df
commendet this both lines (check it in next version)
aismann May 22, 2024
1553f96
.
aismann May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 144 additions & 9 deletions extensions/DrawNodeEx/src/DrawNodeEx/DrawNodeEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

NS_AX_EXT_BEGIN



/** Is a polygon convex?
* @param verts A pointer to point coordinates.
* @param count The number of verts measured in points.
Expand Down Expand Up @@ -146,12 +148,17 @@ DrawNodeEx::DrawNodeEx(float lineWidth)
DrawNodeEx::~DrawNodeEx()
{
AX_SAFE_FREE(_bufferTriangle);

#if defined(DRAWNODE_DRAW_LINE_POINT)
AX_SAFE_FREE(_bufferPoint);
AX_SAFE_FREE(_bufferLine);
#endif

freeShaderInternal(_customCommandTriangle);
#if defined(DRAWNODE_DRAW_LINE_POINT)
freeShaderInternal(_customCommandPoint);
freeShaderInternal(_customCommandLine);
#endif
}

DrawNodeEx* DrawNodeEx::create(float defaultLineWidth)
Expand Down Expand Up @@ -184,6 +191,7 @@ void DrawNodeEx::ensureCapacityTriangle(int count)
}
}

#if defined(DRAWNODE_DRAW_LINE_POINT)
void DrawNodeEx::ensureCapacityPoint(int count)
{
AXASSERT(count >= 0, "capacity must be >= 0");
Expand Down Expand Up @@ -213,18 +221,21 @@ void DrawNodeEx::ensureCapacityLine(int count)
_customCommandLine.updateVertexBuffer(_bufferLine, _bufferCapacityLine * sizeof(V2F_C4B_T2F));
}
}
#endif

bool DrawNodeEx::init()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
updateShader();
ensureCapacityTriangle(512);
_dirtyTriangle = true;

#if defined(DRAWNODE_DRAW_LINE_POINT)
ensureCapacityPoint(64);
ensureCapacityLine(256);

_dirtyTriangle = true;
_dirtyLine = true;
_dirtyPoint = true;
#endif

return true;
}
Expand All @@ -233,12 +244,13 @@ void DrawNodeEx::updateShader()
{
updateShaderInternal(_customCommandTriangle, backend::ProgramType::POSITION_COLOR_LENGTH_TEXTURE,
CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::TRIANGLE);

#if defined(DRAWNODE_DRAW_LINE_POINT)
updateShaderInternal(_customCommandPoint, backend::ProgramType::POSITION_COLOR_TEXTURE_AS_POINTSIZE,
CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::POINT);

updateShaderInternal(_customCommandLine, backend::ProgramType::POSITION_COLOR_LENGTH_TEXTURE,
CustomCommand::DrawType::ARRAY, CustomCommand::PrimitiveType::LINE);
#endif
}

void DrawNodeEx::updateShaderInternal(CustomCommand& cmd,
Expand Down Expand Up @@ -312,7 +324,7 @@ void DrawNodeEx::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
_customCommandTriangle.init(_globalZOrder);
renderer->addCommand(&_customCommandTriangle);
}

#if defined(DRAWNODE_DRAW_LINE_POINT)
if (_bufferCountPoint)
{
updateBlendState(_customCommandPoint);
Expand All @@ -328,10 +340,21 @@ void DrawNodeEx::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
_customCommandLine.init(_globalZOrder);
renderer->addCommand(&_customCommandLine);
}
#endif
}

void DrawNodeEx::drawPoint(const Vec2& position, const float pointSize, const Color4B& color)
{
#if defined(DRAWNODE_DRAW_LINE_POINT)
if (_drawOrder == true)
{
#endif
drawSolidCircle(position, pointSize, 0.f, 12, 1.f, 1.f, color, 0.f, color);
#if defined(DRAWNODE_DRAW_LINE_POINT)
return;
}
#endif
#if defined(DRAWNODE_DRAW_LINE_POINT)
ensureCapacityPoint(1);

V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint;
Expand All @@ -341,6 +364,7 @@ void DrawNodeEx::drawPoint(const Vec2& position, const float pointSize, const Co
_bufferCountPoint += 1;
_dirtyPoint = true;
_customCommandPoint.setVertexDrawInfo(0, _bufferCountPoint);
#endif
}

void DrawNodeEx::drawPoints(const Vec2* position, unsigned int numberOfPoints, const Color4B& color)
Expand All @@ -353,6 +377,19 @@ void DrawNodeEx::drawPoints(const Vec2* position,
const float pointSize,
const Color4B& color)
{
#if defined(DRAWNODE_DRAW_LINE_POINT)
if (_drawOrder == true)
{
#endif
for (unsigned int i = 0; i < numberOfPoints; i++)
{
drawSolidCircle(position[i], pointSize, 0.f, 12, 1.f, 1.f, color, 0.f, color);
}
#if defined(DRAWNODE_DRAW_LINE_POINT)
return;
}
#endif
#if defined(DRAWNODE_DRAW_LINE_POINT)
ensureCapacityPoint(numberOfPoints);

V2F_C4B_T2F* point = _bufferPoint + _bufferCountPoint;
Expand All @@ -366,6 +403,7 @@ void DrawNodeEx::drawPoints(const Vec2* position,
_bufferCountPoint += numberOfPoints;
_dirtyPoint = true;
_customCommandPoint.setVertexDrawInfo(0, _bufferCountPoint);
#endif
}

void DrawNodeEx::drawLine(const Vec2& origin, const Vec2& destination, const Color4B& color, float thickness)
Expand All @@ -377,6 +415,16 @@ void DrawNodeEx::drawLine(const Vec2& origin, const Vec2& destination, const Col
}
else
{
#if defined(DRAWNODE_DRAW_LINE_POINT)
if (_drawOrder == true)
{
#endif
drawSegment(origin, destination, thickness / 3, color);
#if defined(DRAWNODE_DRAW_LINE_POINT)
return;
}
#endif
#if defined(DRAWNODE_DRAW_LINE_POINT)
Vec2 line[2] = { origin, destination };
Vec2* _vertices = transform(line, 2);

Expand All @@ -391,6 +439,7 @@ void DrawNodeEx::drawLine(const Vec2& origin, const Vec2& destination, const Col
_bufferCountLine += 2;
_dirtyLine = true;
_customCommandLine.setVertexDrawInfo(0, _bufferCountLine);
#endif
}
}

Expand Down Expand Up @@ -427,6 +476,16 @@ void DrawNodeEx::drawPoly(const Vec2* poli,
}
else
{
#if defined(DRAWNODE_DRAW_LINE_POINT)
if (_drawOrder == true)
{
#endif
_drawPolygon(poli, numberOfPoints, Color4B::TRANSPARENT, thickness / 3, color, closePolygon);
#if defined(DRAWNODE_DRAW_LINE_POINT)
return;
}
#endif
#if defined(DRAWNODE_DRAW_LINE_POINT)
Vec2* _vertices = transform(poli, numberOfPoints);

unsigned int vertex_count;
Expand Down Expand Up @@ -460,6 +519,7 @@ void DrawNodeEx::drawPoly(const Vec2* poli,
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountLine += vertex_count;
_customCommandLine.setVertexDrawInfo(0, _bufferCountLine);
#endif
}
}

Expand Down Expand Up @@ -1031,10 +1091,12 @@ void DrawNodeEx::clear()
{
_bufferCountTriangle = 0;
_dirtyTriangle = true;
#if defined(DRAWNODE_DRAW_LINE_POINT)
_bufferCountLine = 0;
_dirtyLine = true;
_bufferCountPoint = 0;
_dirtyPoint = true;
#endif
_lineWidth = _defaultLineWidth;
}

Expand Down Expand Up @@ -1163,7 +1225,39 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
extrude[i] = { offset, n2 };
}

for (unsigned int i = 0; i < count; i++)
int i = 0;
int j = (i + 1) % count;
Vec2 v0 = _vertices[i];
Vec2 v1 = _vertices[j];

Vec2 n0 = extrude[i].n;

Vec2 offset0 = extrude[i].offset;
Vec2 offset1 = extrude[j].offset;

Vec2 inner0 = v0 - offset0 * borderWidth;
Vec2 inner1 = v1 - offset1 * borderWidth;
Vec2 outer0 = v0 + offset0 * borderWidth;
Vec2 outer1 = v1 + offset1 * borderWidth;
borderColor = borderColo;
//if (i >= (count - 1) && !closedPolygon) // /-2 ??
//{
// borderColor = Color4B::TRANSPARENT;
//}

V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColor, Tex2F(-n0)},
{inner1, borderColor, Tex2F(-n0)},
{outer1, borderColor, Tex2F(n0)} };
*cursor++ = tmp1;

V2F_C4B_T2F_Triangle tmp2 = { {inner0, borderColor, Tex2F(-n0)},
{outer0, borderColor, Tex2F(n0)},
{outer1, borderColor, Tex2F(n0)} };
*cursor++ = tmp2;



for (unsigned int i = 1; i < (count - 1); i++)
{
int j = (i + 1) % count;
Vec2 v0 = _vertices[i];
Expand All @@ -1179,10 +1273,10 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
Vec2 outer0 = v0 + offset0 * borderWidth;
Vec2 outer1 = v1 + offset1 * borderWidth;
borderColor = borderColo;
if (i >= count - 1 && !closedPolygon) // /-2 ??
{
borderColor = Color4B::TRANSPARENT;
}
//if (i >= (count - 1) && !closedPolygon) // /-2 ??
//{
// borderColor = Color4B::TRANSPARENT;
//}

V2F_C4B_T2F_Triangle tmp1 = { {inner0, borderColor, Tex2F(-n0)},
{inner1, borderColor, Tex2F(-n0)},
Expand All @@ -1195,6 +1289,36 @@ void DrawNodeEx::_drawPolygon(const Vec2* verts,
*cursor++ = tmp2;
}

i = count - 1;
j = (i + 1) % count;
v0 = _vertices[i];
v1 = _vertices[j];

n0 = extrude[i].n;

offset0 = extrude[i].offset;
offset1 = extrude[j].offset;

inner0 = v0 - offset0 * borderWidth;
inner1 = v1 - offset1 * borderWidth;
outer0 = v0 + offset0 * borderWidth;
outer1 = v1 + offset1 * borderWidth;
borderColor = borderColo;
//if (i >= (count - 1) && !closedPolygon) // /-2 ??
//{
// borderColor = Color4B::TRANSPARENT;
//}

tmp1 = { {inner0, borderColor, Tex2F(-n0)},
{inner1, borderColor, Tex2F(-n0)},
{outer1, borderColor, Tex2F(n0)} };
*cursor++ = tmp1;

tmp2 = { {inner0, borderColor, Tex2F(-n0)},
{outer0, borderColor, Tex2F(n0)},
{outer1, borderColor, Tex2F(n0)} };
*cursor++ = tmp2;

free(extrude);
}

Expand Down Expand Up @@ -1227,6 +1351,16 @@ void DrawNodeEx::_drawPoly(const Vec2* poli,
}
else
{
#if defined(DRAWNODE_DRAW_LINE_POINT)
if (_drawOrder == true)
{
#endif
_drawPolygon(poli, numberOfPoints, Color4B::TRANSPARENT, thickness / 3, color, false);
#if defined(DRAWNODE_DRAW_LINE_POINT)
return;
}
#endif
#if defined(DRAWNODE_DRAW_LINE_POINT)
Vec2* _vertices = transform(poli, numberOfPoints);

unsigned int vertex_count;
Expand Down Expand Up @@ -1260,6 +1394,7 @@ void DrawNodeEx::_drawPoly(const Vec2* poli,
vertex_count * sizeof(V2F_C4B_T2F));
_bufferCountLine += vertex_count;
_customCommandLine.setVertexDrawInfo(0, _bufferCountLine);
#endif
}
}
NS_AX_EXT_END
Expand Down
Loading