Skip to content

Commit

Permalink
Traktor: Cleanup in spark module.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 31, 2024
1 parent 41f1107 commit b8d8e62
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 238 deletions.
25 changes: 8 additions & 17 deletions code/Spark/Acc/AccBitmapRect.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,17 +10,15 @@

#include "Resource/Proxy.h"

namespace traktor
namespace traktor::render
{
namespace render
{

class ITexture;

}
}

namespace spark
{
namespace traktor::spark
{

/*!
* \ingroup Spark
Expand All @@ -29,17 +27,11 @@ class AccBitmapRect : public RefCountImpl< IRefCount >
{
public:
resource::Proxy< render::ITexture > texture;
float rect[4];
float rect[4] = { 0.0f, 0.0f, 0.0f, 0.0f };

AccBitmapRect()
{
rect[0] =
rect[1] =
rect[2] =
rect[3] = 0.0f;
}
AccBitmapRect() = default;

AccBitmapRect(
explicit AccBitmapRect(
const resource::Proxy< render::ITexture >& texture_,
float left,
float top,
Expand Down Expand Up @@ -72,5 +64,4 @@ class AccBitmapRect : public RefCountImpl< IRefCount >
}
};

}
}
20 changes: 8 additions & 12 deletions code/Spark/Acc/AccGlyph.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -12,17 +12,15 @@
#include "Core/Math/Matrix33.h"
#include "Resource/Proxy.h"

namespace traktor
namespace traktor::resource
{
namespace resource
{

class IResourceManager;

}
}

namespace render
{
namespace traktor::render
{

class Buffer;
class IRenderSystem;
Expand All @@ -31,10 +29,10 @@ class IVertexLayout;
class RenderPass;
class Shader;

}
}

namespace spark
{
namespace traktor::spark
{

class AccGlyph : public Object
{
Expand Down Expand Up @@ -79,6 +77,4 @@ class AccGlyph : public Object
uint32_t m_count = 0;
};

}
}

25 changes: 11 additions & 14 deletions code/Spark/Acc/AccGradientCache.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -15,12 +15,10 @@
#include "Spark/Acc/AccBitmapRect.h"
#include "Spark/Acc/AccGradientCache.h"

namespace traktor
namespace traktor::spark
{
namespace spark
namespace
{
namespace
{

const uint32_t c_gradientsSize = 32;
const uint32_t c_gradientsWidth = 1024;
Expand Down Expand Up @@ -53,7 +51,7 @@ Color4f interpolateGradient(const AlignedVector< FillStyle::ColorRecord >& color
return a.color * Scalar(1.0f - f) + b.color * Scalar(f);
}

}
}

AccGradientCache::AccGradientCache(render::IRenderSystem* renderSystem)
: m_renderSystem(renderSystem)
Expand Down Expand Up @@ -103,7 +101,7 @@ Ref< AccBitmapRect > AccGradientCache::getGradientTexture(const FillStyle& style
cs.feed(colorRecord);
cs.end();

uint64_t hash = cs.get();
const uint64_t hash = cs.get();
auto it = m_cache.find(hash);
if (it != m_cache.end())
return it->second;
Expand All @@ -127,8 +125,8 @@ Ref< AccBitmapRect > AccGradientCache::getGradientTexture(const FillStyle& style
int32_t x2 = int32_t(colorRecords[i].ratio * c_gradientsSize);
for (int32_t x = x1; x < x2; ++x)
{
float f = float(x - x1) / (x2 - x1);
Color4ub c = (colorRecords[i - 1].color * Scalar(1.0f - f) + colorRecords[i].color * Scalar(f)).toColor4ub();
const float f = float(x - x1) / (x2 - x1);
const Color4ub c = (colorRecords[i - 1].color * Scalar(1.0f - f) + colorRecords[i].color * Scalar(f)).toColor4ub();
gd[x * 4 + 0] = c.r;
gd[x * 4 + 1] = c.g;
gd[x * 4 + 2] = c.b;
Expand Down Expand Up @@ -177,11 +175,11 @@ Ref< AccBitmapRect > AccGradientCache::getGradientTexture(const FillStyle& style
{
for (int x = 0; x < c_gradientsSize; ++x)
{
float fx = x / s - 1.0f;
float fy = y / s - 1.0f;
float f = sqrtf(fx * fx + fy * fy);
const float fx = x / s - 1.0f;
const float fy = y / s - 1.0f;
const float f = sqrtf(fx * fx + fy * fy);

Color4ub c = interpolateGradient(colorRecords, f).toColor4ub();
const Color4ub c = interpolateGradient(colorRecords, f).toColor4ub();
gd[x * 4 + 0] = c.r;
gd[x * 4 + 1] = c.g;
gd[x * 4 + 2] = c.b;
Expand Down Expand Up @@ -226,5 +224,4 @@ void AccGradientCache::synchronize()
}
}

}
}
14 changes: 5 additions & 9 deletions code/Spark/Acc/AccGradientCache.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -12,18 +12,16 @@
#include "Core/Containers/SmallMap.h"
#include "Core/Misc/AutoPtr.h"

namespace traktor
namespace traktor::render
{
namespace render
{

class IRenderSystem;
class ITexture;

}
}

namespace spark
{
namespace traktor::spark
{

class AccBitmapRect;
class FillStyle;
Expand Down Expand Up @@ -56,6 +54,4 @@ class AccGradientCache : public Object
bool m_dirty = false;
};

}
}

11 changes: 4 additions & 7 deletions code/Spark/Acc/AccQuad.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -18,12 +18,10 @@
#include "Spark/ColorTransform.h"
#include "Spark/Acc/AccQuad.h"

namespace traktor
namespace traktor::spark
{
namespace spark
namespace
{
namespace
{

const resource::Id< render::Shader > c_idShaderSolid(Guid(L"{2EDC5E1B-562D-9F46-9E3C-474729FB078E}"));
const resource::Id< render::Shader > c_idShaderTextured(Guid(L"{98A59F6A-1D90-144C-B688-4CEF382453F2}"));
Expand All @@ -47,7 +45,7 @@ const render::Handle s_handleCxFormAdd(L"Spark_CxFormAdd");
const render::Handle s_handleTexture(L"Spark_Texture");
const render::Handle s_handleTextureOffset(L"Spark_TextureOffset");

}
}

bool AccQuad::create(
resource::IResourceManager* resourceManager,
Expand Down Expand Up @@ -204,5 +202,4 @@ void AccQuad::blit(
});
}

}
}
20 changes: 8 additions & 12 deletions code/Spark/Acc/AccQuad.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -13,17 +13,15 @@
#include "Core/Math/Matrix33.h"
#include "Resource/Proxy.h"

namespace traktor
namespace traktor::resource
{
namespace resource
{

class IResourceManager;

}
}

namespace render
{
namespace traktor::render
{

class Buffer;
class IRenderSystem;
Expand All @@ -32,10 +30,10 @@ class IVertexLayout;
class RenderPass;
class Shader;

}
}

namespace spark
{
namespace traktor::spark
{

class ColorTransform;

Expand Down Expand Up @@ -81,6 +79,4 @@ class AccQuad : public Object
Ref< render::Buffer > m_vertexBuffer;
};

}
}

14 changes: 7 additions & 7 deletions code/Spark/Acc/AccShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool AccShape::createFromTriangles(
for (int32_t it = 0; it < c_maxSubDivide; ++it)
{
int32_t nsub = 0;
int32_t size = clusters.size();
int32_t size = (int32_t)clusters.size();
for (int32_t i = 0; i < size; ++i)
{
if (clusters[i].lines.size() > c_maxLinesPerCluster)
Expand All @@ -204,14 +204,14 @@ bool AccShape::createFromTriangles(
for (int32_t ix = 0; ix < c_subSize; ++ix)
{
const Vector2 dxy(1.0f / float(c_subSize), 1.0f / float(c_subSize));
const Vector2 fxy = Vector2(ix, iy) * dxy;
const Vector2 fxy = Vector2(float(ix), float(iy)) * dxy;

Aabb2 cell;
cell.mn = clusters[i].bounds.mn + (clusters[i].bounds.mx - clusters[i].bounds.mn) * fxy;
cell.mx = clusters[i].bounds.mn + (clusters[i].bounds.mx - clusters[i].bounds.mn) * (fxy + dxy);

bool foundLine = false;
for (int32_t j = 0; j < clusters[i].lines.size(); ++j)
for (int32_t j = 0; j < (int32_t)clusters[i].lines.size(); ++j)
{
const Line& line = lines[clusters[i].lines[j]];

Expand Down Expand Up @@ -275,7 +275,7 @@ bool AccShape::createFromTriangles(

// Generate line batches from clusters.
Ref< render::Buffer > vertexRange;
if (!m_lineVertexPool->acquire(clusters.size() * 2 * 3, vertexRange))
if (!m_lineVertexPool->acquire(int32_t(clusters.size() * 2 * 3), vertexRange))
return false;

LineVertex* vertex = static_cast< LineVertex* >(vertexRange->lock());
Expand All @@ -285,7 +285,7 @@ bool AccShape::createFromTriangles(
// Calculate size of buffer.
int32_t lineDataSize = 0;
for (auto c : clusters)
lineDataSize += c.lines.size();
lineDataSize += (int32_t)c.lines.size();

Ref< render::Buffer > lineBuffer = m_renderSystem->createBuffer(render::BufferUsage::BuStructured, lineDataSize * sizeof(LineData), false);
if (!lineBuffer)
Expand All @@ -297,7 +297,7 @@ bool AccShape::createFromTriangles(
m_lineRenderBatches.push_back();
m_lineRenderBatches.back().vertexRange = vertexRange;
m_lineRenderBatches.back().lineBuffer = lineBuffer;
m_lineRenderBatches.back().primitives.setNonIndexed(render::PrimitiveType::Triangles, 0, clusters.size() * 2);
m_lineRenderBatches.back().primitives.setNonIndexed(render::PrimitiveType::Triangles, 0, uint32_t(clusters.size() * 2));
m_lineRenderBatches.back().color = lineStyle.getLineColor();
m_lineRenderBatches.back().width = width - 0.5f;

Expand Down Expand Up @@ -352,7 +352,7 @@ bool AccShape::createFromTriangles(
Ref< AccBitmapRect > texture;
bool textureClamp = false;

if (!m_fillVertexPool->acquire(triangles.size() * 3, m_fillVertexRange))
if (!m_fillVertexPool->acquire(int32_t(triangles.size() * 3), m_fillVertexRange))
return false;

FillVertex* vertex = static_cast< FillVertex* >(m_fillVertexRange->lock());
Expand Down
Loading

0 comments on commit b8d8e62

Please sign in to comment.