Skip to content

Commit

Permalink
Tidy vertex format
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Oct 5, 2024
1 parent 8d50295 commit c05b010
Show file tree
Hide file tree
Showing 102 changed files with 1,213 additions and 1,373 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/box2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(target_name ${lib_name})

project(${lib_name})

FILE(GLOB_RECURSE box2d_sources *.h;*.c)
file(GLOB_RECURSE box2d_sources *.h;*.c)

add_library(${target_name} ${box2d_sources})

Expand Down
8 changes: 4 additions & 4 deletions core/2d/AnchoredSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ void AnchoredSprite::setVertexCoords(const Rect& rect, V3F_C4F_T2F_Quad* outQuad
const float y2 = y1 + rect.size.height;

// Don't update Z.
outQuad->bl.vertices.set(x1, y1, 0.0f);
outQuad->br.vertices.set(x2, y1, 0.0f);
outQuad->tl.vertices.set(x1, y2, 0.0f);
outQuad->tr.vertices.set(x2, y2, 0.0f);
outQuad->bl.position.set(x1, y1, 0.0f);
outQuad->br.position.set(x2, y1, 0.0f);
outQuad->tl.position.set(x1, y2, 0.0f);
outQuad->tr.position.set(x2, y2, 0.0f);
}
}

Expand Down
36 changes: 17 additions & 19 deletions core/2d/AutoPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PolygonInfo::PolygonInfo(const PolygonInfo& other) : triangles(), _isVertsOwner(
_filename = other._filename;
_isVertsOwner = true;
_rect = other._rect;
triangles.verts = new V3F_C4F_T2F[other.triangles.vertCount];
triangles.verts = new V3F_T2F_C4F[other.triangles.vertCount];
triangles.indices = new unsigned short[other.triangles.indexCount];
AXASSERT(triangles.verts && triangles.indices, "not enough memory");
triangles.vertCount = other.triangles.vertCount;
Expand All @@ -80,7 +80,7 @@ PolygonInfo& PolygonInfo::operator=(const PolygonInfo& other)
_filename = other._filename;
_isVertsOwner = true;
_rect = other._rect;
triangles.verts = new V3F_C4F_T2F[other.triangles.vertCount];
triangles.verts = new V3F_T2F_C4F[other.triangles.vertCount];
triangles.indices = new unsigned short[other.triangles.indexCount];
AXASSERT(triangles.verts && triangles.indices, "not enough memory");
triangles.vertCount = other.triangles.vertCount;
Expand All @@ -104,7 +104,7 @@ void PolygonInfo::setQuad(V3F_C4F_T2F_Quad* quad)
triangles.indices = quadIndices9;
triangles.vertCount = 4;
triangles.indexCount = 6;
triangles.verts = (V3F_C4F_T2F*)quad;
triangles.verts = (V3F_T2F_C4F*)quad;
}

void PolygonInfo::setQuads(V3F_C4F_T2F_Quad* quad, int numberOfQuads)
Expand All @@ -116,7 +116,7 @@ void PolygonInfo::setQuads(V3F_C4F_T2F_Quad* quad, int numberOfQuads)
triangles.indices = quadIndices9;
triangles.vertCount = 4 * numberOfQuads;
triangles.indexCount = 6 * numberOfQuads;
triangles.verts = (V3F_C4F_T2F*)quad;
triangles.verts = (V3F_T2F_C4F*)quad;
}

void PolygonInfo::setTriangles(const TrianglesCommand::Triangles& other)
Expand Down Expand Up @@ -159,13 +159,13 @@ unsigned int PolygonInfo::getTrianglesCount() const
float PolygonInfo::getArea() const
{
float area = 0;
V3F_C4F_T2F* verts = triangles.verts;
V3F_T2F_C4F* verts = triangles.verts;
unsigned short* indices = triangles.indices;
for (unsigned int i = 0; i < triangles.indexCount; i += 3)
{
auto A = verts[indices[i]].vertices;
auto B = verts[indices[i + 1]].vertices;
auto C = verts[indices[i + 2]].vertices;
auto A = verts[indices[i]].position;
auto B = verts[indices[i + 1]].position;
auto C = verts[indices[i + 2]].position;
area += (A.x * (B.y - C.y) + B.x * (C.y - A.y) + C.x * (A.y - B.y)) / 2;
}
return area;
Expand Down Expand Up @@ -610,7 +610,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
std::vector<p2t::Triangle*> tris = cdt.GetTriangles();

axstd::pod_vector<unsigned short> indices(tris.size() * 3);
axstd::pod_vector<V3F_C4F_T2F> verts;
axstd::pod_vector<V3F_T2F_C4F> verts;
verts.reserve(indices.size() / 2); // we won't know the size of verts until we process all of the triangles!

unsigned short idx = 0;
Expand All @@ -627,7 +627,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
auto length = vdx;
for (j = 0; j < length; j++)
{
if (verts[j].vertices == v3)
if (verts[j].position == v3)
{
found = true;
break;
Expand All @@ -640,10 +640,8 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
}
else
{
// vert does not exist yet, so we need to create a new one,
auto c = Color::WHITE;
auto t2f = Tex2F(0, 0); // don't worry about tex coords now, we calculate that later
verts.push_back(V3F_C4F_T2F{v3, c, t2f});
// vert does not exist yet, so we need to create a new one
verts.emplace_back(v3, Vec2::ZERO, Color::WHITE);
indices[idx++] = vdx++;;
}
}
Expand All @@ -656,7 +654,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
return triangles;
}

void AutoPolygon::calculateUV(const Rect& rect, V3F_C4F_T2F* verts, ssize_t count)
void AutoPolygon::calculateUV(const Rect& rect, V3F_T2F_C4F* verts, ssize_t count)
{
/*
whole texture UV coordination
Expand All @@ -683,10 +681,10 @@ void AutoPolygon::calculateUV(const Rect& rect, V3F_C4F_T2F* verts, ssize_t coun
for (auto i = verts; i != end; ++i)
{
// for every point, offset with the center point
float u = (i->vertices.x * _scaleFactor + rect.origin.x) / texWidth;
float v = (rect.origin.y + rect.size.height - i->vertices.y * _scaleFactor) / texHeight;
i->texCoords.u = u;
i->texCoords.v = v;
float u = (i->position.x * _scaleFactor + rect.origin.x) / texWidth;
float v = (rect.origin.y + rect.size.height - i->position.y * _scaleFactor) / texHeight;
i->texCoord.u = u;
i->texCoord.v = v;
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/2d/AutoPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class AX_DLL AutoPolygon
* ap.calculateUV(rect, myPolygons.verts, 20);
* @endcode
*/
void calculateUV(const Rect& rect, V3F_C4F_T2F* verts, ssize_t count);
void calculateUV(const Rect& rect, V3F_T2F_C4F* verts, ssize_t count);

/**
* a helper function, packing trace, reduce, expand, triangulate and calculate uv in one function
Expand Down
20 changes: 10 additions & 10 deletions core/2d/CameraBackgroundBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ bool CameraBackgroundDepthBrush::init()
pipelineDescriptor.programState = _programState;

_vertices.resize(4);
_vertices[0].vertices = Vec3(-1, -1, 0);
_vertices[1].vertices = Vec3(1, -1, 0);
_vertices[2].vertices = Vec3(1, 1, 0);
_vertices[3].vertices = Vec3(-1, 1, 0);
_vertices[0].position = Vec3(-1, -1, 0);
_vertices[1].position = Vec3(1, -1, 0);
_vertices[2].position = Vec3(1, 1, 0);
_vertices[3].position = Vec3(-1, 1, 0);

_vertices[0].colors = _vertices[1].colors = _vertices[2].colors = _vertices[3].colors = Color(0, 0, 0, 1);
_vertices[0].color = _vertices[1].color = _vertices[2].color = _vertices[3].color = Color(0, 0, 0, 1);

_vertices[0].texCoords = Tex2F(0, 0);
_vertices[1].texCoords = Tex2F(1, 0);
_vertices[2].texCoords = Tex2F(1, 1);
_vertices[3].texCoords = Tex2F(0, 1);
_vertices[0].texCoord = Tex2F(0, 0);
_vertices[1].texCoord = Tex2F(1, 0);
_vertices[2].texCoord = Tex2F(1, 1);
_vertices[3].texCoord = Tex2F(0, 1);

_customCommand.setBeforeCallback(AX_CALLBACK_0(CameraBackgroundDepthBrush::onBeforeDraw, this));
_customCommand.setAfterCallback(AX_CALLBACK_0(CameraBackgroundDepthBrush::onAfterDraw, this));
Expand Down Expand Up @@ -235,7 +235,7 @@ void CameraBackgroundColorBrush::setColor(const Color& color)
{
for (auto&& vert : _vertices)
{
vert.colors = color;
vert.color = color;
}
_customCommand.updateVertexBuffer(_vertices.data(), sizeof(_vertices[0]) * _vertices.size());
}
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CameraBackgroundBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class AX_DLL CameraBackgroundDepthBrush : public CameraBackgroundBrush
CustomCommand _customCommand;

bool _clearColor;
std::vector<V3F_C4F_T2F> _vertices;
std::vector<V3F_T2F_C4F> _vertices;
struct
{
uint32_t stencilWriteMask = 0;
Expand Down
Loading

0 comments on commit c05b010

Please sign in to comment.