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 7cc9bfa
Show file tree
Hide file tree
Showing 88 changed files with 1,085 additions and 1,151 deletions.
9 changes: 8 additions & 1 deletion 3rdparty/box2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ project(${lib_name})

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

add_library(${target_name} STATIC ${box2d_sources})
add_library(${target_name} ${box2d_sources})

if (MSVC)
if (BUILD_SHARED_LIBS)
# this is needed by DLL users to import Box2D symbols
target_compile_definitions(box2d INTERFACE BOX2D_DLL)
endif()
endif()

# Atomics are still considered experimental in Visual Studio 17.8
if (FULL_MSVC)
Expand Down
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
4 changes: 2 additions & 2 deletions core/2d/FastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void FastTMXLayer::updateTiles(const Rect& culledRect)

void FastTMXLayer::updateVertexBuffer()
{
unsigned int vertexBufferSize = (unsigned int)(sizeof(V3F_C4B_T2F) * _totalQuads.size() * 4);
unsigned int vertexBufferSize = (unsigned int)(sizeof(V3F_C4F_T2F) * _totalQuads.size() * 4);
if (!_vertexBuffer)
{
_vertexBuffer = backend::DriverBase::getInstance()->newBuffer(vertexBufferSize, backend::BufferType::VERTEX, backend::BufferUsage::STATIC);
Expand Down Expand Up @@ -503,7 +503,7 @@ void FastTMXLayer::updateTotalQuads()
_tileToQuadIndex.resize(int(_layerSize.width * _layerSize.height), -1);
_indicesVertexZOffsets.clear();

auto color = Color4B::WHITE;
auto color = Color::WHITE;
color.a = getDisplayedOpacity();

if (_texture->hasPremultipliedAlpha())
Expand Down
2 changes: 1 addition & 1 deletion core/2d/FastTMXLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class AX_DLL FastTMXLayer : public Node
float _cameraZoomDirty;

std::vector<int> _tileToQuadIndex;
std::vector<V3F_C4B_T2F_Quad> _totalQuads;
std::vector<V3F_C4F_T2F_Quad> _totalQuads;
#ifdef AX_FAST_TILEMAP_32_BIT_INDICES
std::vector<unsigned int> _indices;
#else
Expand Down
2 changes: 1 addition & 1 deletion core/2d/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class AX_DLL GridBase : public Object
Director::Projection _directorProjection = Director::Projection::_2D;
Rect _gridRect;

Color4F _clearColor = {0, 0, 0, 0};
Color _clearColor = {0, 0, 0, 0};

CustomCommand _drawCommand;
//CallbackCommand _beforeDrawCommand;
Expand Down
48 changes: 24 additions & 24 deletions core/2d/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,18 @@ class LabelLetter : public Sprite
{
displayedOpacity = 0.0f;
}
Color4B color4(_displayedColor.r, _displayedColor.g, _displayedColor.b, displayedOpacity);
Color color(_displayedColor, displayedOpacity);
// special opacity for premultiplied textures
if (_opacityModifyRGB)
{
color4.r *= displayedOpacity / 255.0f;
color4.g *= displayedOpacity / 255.0f;
color4.b *= displayedOpacity / 255.0f;
color.r *= displayedOpacity / 255.0f;
color.g *= displayedOpacity / 255.0f;
color.b *= displayedOpacity / 255.0f;
}
_quad.bl.colors = color4;
_quad.br.colors = color4;
_quad.tl.colors = color4;
_quad.tr.colors = color4;
_quad.bl.colors = color;
_quad.br.colors = color;
_quad.tl.colors = color;
_quad.tr.colors = color;

_textureAtlas->updateQuad(_quad, _atlasIndex);
}
Expand Down Expand Up @@ -619,9 +619,9 @@ void Label::reset()
_hAlignment = TextHAlignment::LEFT;
_vAlignment = TextVAlignment::TOP;

_effectColorF = Color4F::BLACK;
_effectColorF = Color::BLACK;
_textColor = Color4B::WHITE;
_textColorF = Color4F::WHITE;
_textColorF = Color::WHITE;
setColor(Color3B::WHITE);

_shadowDirty = false;
Expand Down Expand Up @@ -1714,7 +1714,7 @@ void Label::updateContent()
// Github issue #15214. Uses _displayedColor instead of _textColor for the underline.
// This is to have the same behavior of SystemFonts.
_underlineNode->drawLine(Vec2(_linesOffsetX[i], y), Vec2(_linesWidth[i] + _linesOffsetX[i], y),
Color4F(_displayedColor), charheight / 6);
Color(_displayedColor), charheight / 6);
}
}
else if (_textSprite)
Expand All @@ -1729,7 +1729,7 @@ void Label::updateContent()
y += spriteSize.height / 2;
// FIXME: Might not work with different vertical alignments
_underlineNode->drawLine(Vec2(0.0f, y), Vec2(spriteSize.width, y),
Color4F(_textSprite->getDisplayedColor()), spriteSize.height / 6);
Color(_textSprite->getDisplayedColor()), spriteSize.height / 6);
}
}

Expand Down Expand Up @@ -1775,15 +1775,15 @@ void Label::updateBuffer(TextureAtlas* textureAtlas, CustomCommand& customComman
{
if (textureAtlas->getTotalQuads() > customCommand.getVertexCapacity())
{
customCommand.createVertexBuffer((unsigned int)sizeof(V3F_C4B_T2F_Quad),
customCommand.createVertexBuffer((unsigned int)sizeof(V3F_C4F_T2F_Quad),
(unsigned int)textureAtlas->getTotalQuads(),
CustomCommand::BufferUsage::DYNAMIC);
customCommand.createIndexBuffer(CustomCommand::IndexFormat::U_SHORT,
(unsigned int)textureAtlas->getTotalQuads() * 6,
CustomCommand::BufferUsage::DYNAMIC);
}
customCommand.updateVertexBuffer(textureAtlas->getQuads(),
(unsigned int)(textureAtlas->getTotalQuads() * sizeof(V3F_C4B_T2F_Quad)));
(unsigned int)(textureAtlas->getTotalQuads() * sizeof(V3F_C4F_T2F_Quad)));
customCommand.updateIndexBuffer(textureAtlas->getIndices(),
(unsigned int)(textureAtlas->getTotalQuads() * 6 * sizeof(unsigned short)));
customCommand.setIndexDrawInfo(0, (unsigned int)(textureAtlas->getTotalQuads() * 6));
Expand Down Expand Up @@ -1899,7 +1899,7 @@ void Label::updateEffectUniforms(BatchCommand& batch,
_displayedOpacity = _shadowColor4F.a * (oldOPacity / 255.0f) * 255;
setColor(Color3B(_shadowColor4F));
batch.shadowCommand.updateVertexBuffer(
textureAtlas->getQuads(), (unsigned int)(textureAtlas->getTotalQuads() * sizeof(V3F_C4B_T2F_Quad)));
textureAtlas->getQuads(), (unsigned int)(textureAtlas->getTotalQuads() * sizeof(V3F_C4F_T2F_Quad)));
batch.shadowCommand.init(_globalZOrder);
renderer->addCommand(&batch.shadowCommand);

Expand Down Expand Up @@ -2382,18 +2382,18 @@ void Label::updateColor()
return;
}

Color4B color4(_displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity);
Color color(_displayedColor, _displayedOpacity / 255.0f);

// special opacity for premultiplied textures
if (_isOpacityModifyRGB)
{
color4.r *= _displayedOpacity / 255.0f;
color4.g *= _displayedOpacity / 255.0f;
color4.b *= _displayedOpacity / 255.0f;
color.r *= _displayedOpacity / 255.0f;
color.g *= _displayedOpacity / 255.0f;
color.b *= _displayedOpacity / 255.0f;
}

ax::TextureAtlas* textureAtlas;
V3F_C4B_T2F_Quad* quads;
V3F_C4F_T2F_Quad* quads;
for (auto&& batchNode : _batchNodes)
{
textureAtlas = batchNode->getTextureAtlas();
Expand All @@ -2402,10 +2402,10 @@ void Label::updateColor()

for (int index = 0; index < count; ++index)
{
quads[index].bl.colors = color4;
quads[index].br.colors = color4;
quads[index].tl.colors = color4;
quads[index].tr.colors = color4;
quads[index].bl.colors = color;
quads[index].br.colors = color;
quads[index].tl.colors = color;
quads[index].tr.colors = color;
textureAtlas->updateQuad(quads[index], index);
}
}
Expand Down
Loading

0 comments on commit 7cc9bfa

Please sign in to comment.