Skip to content

Commit

Permalink
Change underlaying color type to Color4F aka ax::Color
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Oct 5, 2024
1 parent 4176cc4 commit 6357d75
Show file tree
Hide file tree
Showing 87 changed files with 970 additions and 1,058 deletions.
2 changes: 1 addition & 1 deletion core/2d/AnchoredSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ AnchoredSprite* AnchoredSprite::create()
return nullptr;
}

void AnchoredSprite::setVertexCoords(const Rect& rect, V3F_C4B_T2F_Quad* outQuad)
void AnchoredSprite::setVertexCoords(const Rect& rect, V3F_C4F_T2F_Quad* outQuad)
{
float relativeOffsetX = _unflippedOffsetPositionFromCenter.x - getContentSize().x * _spriteVertexAnchor.x;
float relativeOffsetY = _unflippedOffsetPositionFromCenter.y - getContentSize().y * _spriteVertexAnchor.y;
Expand Down
2 changes: 1 addition & 1 deletion core/2d/AnchoredSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class AX_DLL AnchoredSprite : public Sprite
virtual Rect getTouchRect();

protected:
virtual void setVertexCoords(const Rect& rect, V3F_C4B_T2F_Quad* outQuad) override;
virtual void setVertexCoords(const Rect& rect, V3F_C4F_T2F_Quad* outQuad) override;
Vec2 _spriteVertexAnchor = Vec2::ANCHOR_MIDDLE;
};

Expand Down
22 changes: 11 additions & 11 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_C4B_T2F[other.triangles.vertCount];
triangles.verts = new V3F_C4F_T2F[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_C4B_T2F[other.triangles.vertCount];
triangles.verts = new V3F_C4F_T2F[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 @@ -97,17 +97,17 @@ PolygonInfo::~PolygonInfo()
releaseVertsAndIndices();
}

void PolygonInfo::setQuad(V3F_C4B_T2F_Quad* quad)
void PolygonInfo::setQuad(V3F_C4F_T2F_Quad* quad)
{
releaseVertsAndIndices();
_isVertsOwner = false;
triangles.indices = quadIndices9;
triangles.vertCount = 4;
triangles.indexCount = 6;
triangles.verts = (V3F_C4B_T2F*)quad;
triangles.verts = (V3F_C4F_T2F*)quad;
}

void PolygonInfo::setQuads(V3F_C4B_T2F_Quad* quad, int numberOfQuads)
void PolygonInfo::setQuads(V3F_C4F_T2F_Quad* quad, int numberOfQuads)
{
AXASSERT(numberOfQuads >= 1 && numberOfQuads <= 9, "Invalid number of Quads");

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

void PolygonInfo::setTriangles(const TrianglesCommand::Triangles& other)
Expand Down Expand Up @@ -159,7 +159,7 @@ unsigned int PolygonInfo::getTrianglesCount() const
float PolygonInfo::getArea() const
{
float area = 0;
V3F_C4B_T2F* verts = triangles.verts;
V3F_C4F_T2F* verts = triangles.verts;
unsigned short* indices = triangles.indices;
for (unsigned int i = 0; i < triangles.indexCount; i += 3)
{
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_C4B_T2F> verts;
axstd::pod_vector<V3F_C4F_T2F> 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 Down Expand Up @@ -641,9 +641,9 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
else
{
// vert does not exist yet, so we need to create a new one,
auto c4b = Color4B::WHITE;
auto c = Color::WHITE;
auto t2f = Tex2F(0, 0); // don't worry about tex coords now, we calculate that later
verts.push_back(V3F_C4B_T2F{v3, c4b, t2f});
verts.push_back(V3F_C4F_T2F{v3, c, t2f});
indices[idx++] = vdx++;;
}
}
Expand All @@ -656,7 +656,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
return triangles;
}

void AutoPolygon::calculateUV(const Rect& rect, V3F_C4B_T2F* verts, ssize_t count)
void AutoPolygon::calculateUV(const Rect& rect, V3F_C4F_T2F* verts, ssize_t count)
{
/*
whole texture UV coordination
Expand Down
10 changes: 5 additions & 5 deletions core/2d/AutoPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ class AX_DLL PolygonInfo
* set the data to be a pointer to a quad
* the member verts will not be released when this PolygonInfo destructs
* as the verts memory are managed by other objects
* @param quad a pointer to the V3F_C4B_T2F_Quad object
* @param quad a pointer to the V3F_C4F_T2F_Quad object
*/
void setQuad(V3F_C4B_T2F_Quad* quad);
void setQuad(V3F_C4F_T2F_Quad* quad);

/**
* set the data to be a pointer to a number of Quads
* the member verts will not be released when this PolygonInfo destructs
* as the verts memory are managed by other objects
* @param quad a pointer to the V3F_C4B_T2F_Quad quads
* @param quad a pointer to the V3F_C4F_T2F_Quad quads
*/
void setQuads(V3F_C4B_T2F_Quad* quads, int numberOfQuads);
void setQuads(V3F_C4F_T2F_Quad* quads, int numberOfQuads);

/**
* set the data to be a pointer to a triangles
Expand Down Expand Up @@ -225,7 +225,7 @@ class AX_DLL AutoPolygon
* ap.calculateUV(rect, myPolygons.verts, 20);
* @endcode
*/
void calculateUV(const Rect& rect, V3F_C4B_T2F* verts, ssize_t count);
void calculateUV(const Rect& rect, V3F_C4F_T2F* verts, ssize_t count);

/**
* a helper function, packing trace, reduce, expand, triangulate and calculate uv in one function
Expand Down
10 changes: 5 additions & 5 deletions core/2d/CameraBackgroundBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ CameraBackgroundBrush* CameraBackgroundBrush::createNoneBrush()
return ret;
}

CameraBackgroundColorBrush* CameraBackgroundBrush::createColorBrush(const Color4F& color, float depth)
CameraBackgroundColorBrush* CameraBackgroundBrush::createColorBrush(const Color& color, float depth)
{
return CameraBackgroundColorBrush::create(color, depth);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ bool CameraBackgroundDepthBrush::init()
_vertices[2].vertices = Vec3(1, 1, 0);
_vertices[3].vertices = Vec3(-1, 1, 0);

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

_vertices[0].texCoords = Tex2F(0, 0);
_vertices[1].texCoords = Tex2F(1, 0);
Expand Down Expand Up @@ -231,16 +231,16 @@ void CameraBackgroundColorBrush::drawBackground(Camera* camera)
CameraBackgroundDepthBrush::drawBackground(camera);
}

void CameraBackgroundColorBrush::setColor(const Color4F& color)
void CameraBackgroundColorBrush::setColor(const Color& color)
{
for (auto&& vert : _vertices)
{
vert.colors = Color4B(color);
vert.colors = color;
}
_customCommand.updateVertexBuffer(_vertices.data(), sizeof(_vertices[0]) * _vertices.size());
}

CameraBackgroundColorBrush* CameraBackgroundColorBrush::create(const Color4F& color, float depth)
CameraBackgroundColorBrush* CameraBackgroundColorBrush::create(const Color& color, float depth)
{
auto ret = new CameraBackgroundColorBrush();

Expand Down
10 changes: 5 additions & 5 deletions core/2d/CameraBackgroundBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AX_DLL CameraBackgroundBrush : public Object
* @param depth Depth used to clear depth buffer
* @return Created brush
*/
static CameraBackgroundColorBrush* createColorBrush(const Color4F& color, float depth);
static CameraBackgroundColorBrush* createColorBrush(const Color& color, float depth);

/** Creates a Skybox brush with 6 textures.
@param positive_x texture for the right side of the texture cube face.
Expand Down Expand Up @@ -179,7 +179,7 @@ class AX_DLL CameraBackgroundDepthBrush : public CameraBackgroundBrush
CustomCommand _customCommand;

bool _clearColor;
std::vector<V3F_C4B_T2F> _vertices;
std::vector<V3F_C4F_T2F> _vertices;
struct
{
uint32_t stencilWriteMask = 0;
Expand All @@ -206,7 +206,7 @@ class AX_DLL CameraBackgroundColorBrush : public CameraBackgroundDepthBrush
* @param depth Depth used to clear the depth buffer
* @return Created brush
*/
static CameraBackgroundColorBrush* create(const Color4F& color, float depth);
static CameraBackgroundColorBrush* create(const Color& color, float depth);

/**
* Draw background
Expand All @@ -217,15 +217,15 @@ class AX_DLL CameraBackgroundColorBrush : public CameraBackgroundDepthBrush
* Set clear color
* @param color Color used to clear the color buffer
*/
void setColor(const Color4F& color);
void setColor(const Color& color);

CameraBackgroundColorBrush();
virtual ~CameraBackgroundColorBrush();

virtual bool init() override;

protected:
Color4F _color;
Color _color;
};

class TextureCube;
Expand Down
Loading

0 comments on commit 6357d75

Please sign in to comment.