Generate multiple texture atlases when first atlas is full

This commit is contained in:
Dan Paulat 2023-09-02 23:37:45 -05:00
parent 7198d1c7af
commit 9766e02f32
10 changed files with 205 additions and 141 deletions

View file

@ -23,7 +23,7 @@ static constexpr size_t kNumRectangles = 1;
static constexpr size_t kNumTriangles = kNumRectangles * 2;
static constexpr size_t kVerticesPerTriangle = 3;
static constexpr size_t kVerticesPerRectangle = kVerticesPerTriangle * 2;
static constexpr size_t kPointsPerVertex = 10;
static constexpr size_t kPointsPerVertex = 11;
static constexpr size_t kBufferLength =
kNumTriangles * kVerticesPerTriangle * kPointsPerVertex;
@ -147,7 +147,7 @@ void GeoLine::Initialize()
// aTexCoord
gl.glVertexAttribPointer(2,
2,
3,
GL_FLOAT,
GL_FALSE,
kPointsPerVertex * sizeof(float),
@ -160,7 +160,7 @@ void GeoLine::Initialize()
GL_FLOAT,
GL_FALSE,
kPointsPerVertex * sizeof(float),
reinterpret_cast<void*>(6 * sizeof(float)));
reinterpret_cast<void*>(7 * sizeof(float)));
gl.glEnableVertexAttribArray(3);
p->dirty_ = true;
@ -264,6 +264,8 @@ void GeoLine::Impl::Update()
const float oy = width_ * 0.5f * sinf(angle_);
// Texture coordinates
static constexpr float r = 0.0f;
const float ls = texture_.sLeft_;
const float rs = texture_.sRight_;
const float tt = texture_.tTop_;
@ -289,12 +291,12 @@ void GeoLine::Impl::Update()
{ //
// Line
{
{lx, by, -ox, -oy, ls, bt, mc0, mc1, mc2, mc3}, // BL
{lx, by, +ox, +oy, ls, tt, mc0, mc1, mc2, mc3}, // TL
{rx, ty, -ox, -oy, rs, bt, mc0, mc1, mc2, mc3}, // BR
{rx, ty, -ox, -oy, rs, bt, mc0, mc1, mc2, mc3}, // BR
{rx, ty, +ox, +oy, rs, tt, mc0, mc1, mc2, mc3}, // TR
{lx, by, +ox, +oy, ls, tt, mc0, mc1, mc2, mc3} // TL
{lx, by, -ox, -oy, ls, bt, r, mc0, mc1, mc2, mc3}, // BL
{lx, by, +ox, +oy, ls, tt, r, mc0, mc1, mc2, mc3}, // TL
{rx, ty, -ox, -oy, rs, bt, r, mc0, mc1, mc2, mc3}, // BR
{rx, ty, -ox, -oy, rs, bt, r, mc0, mc1, mc2, mc3}, // BR
{rx, ty, +ox, +oy, rs, tt, r, mc0, mc1, mc2, mc3}, // TR
{lx, by, +ox, +oy, ls, tt, r, mc0, mc1, mc2, mc3} // TL
}};
gl.glBufferData(GL_ARRAY_BUFFER,

View file

@ -26,7 +26,7 @@ static constexpr std::size_t kNumTriangles = kNumRectangles * 2;
static constexpr std::size_t kVerticesPerTriangle = 3;
static constexpr std::size_t kVerticesPerRectangle = kVerticesPerTriangle * 2;
static constexpr std::size_t kPointsPerVertex = 9;
static constexpr std::size_t kPointsPerTexCoord = 2;
static constexpr std::size_t kPointsPerTexCoord = 3;
static constexpr std::size_t kIconBufferLength =
kNumTriangles * kVerticesPerTriangle * kPointsPerVertex;
static constexpr std::size_t kTextureBufferLength =
@ -208,7 +208,7 @@ void PlacefileIcons::Initialize()
// aTexCoord
gl.glVertexAttribPointer(2,
2,
3,
GL_FLOAT,
GL_FALSE,
kPointsPerTexCoord * sizeof(float),
@ -508,12 +508,12 @@ void PlacefileIcons::Impl::UpdateTextureBuffer()
textureBuffer_.end(),
{
// Icon
0.0f, 0.0f, // BL
0.0f, 0.0f, // TL
0.0f, 0.0f, // BR
0.0f, 0.0f, // BR
0.0f, 0.0f, // TR
0.0f, 0.0f // TL
0.0f, 0.0f, 0.0f, // BL
0.0f, 0.0f, 0.0f, // TL
0.0f, 0.0f, 0.0f, // BR
0.0f, 0.0f, 0.0f, // BR
0.0f, 0.0f, 0.0f, // TR
0.0f, 0.0f, 0.0f // TL
});
// clang-format on
@ -536,12 +536,12 @@ void PlacefileIcons::Impl::UpdateTextureBuffer()
textureBuffer_.end(),
{
// Icon
0.0f, 0.0f, // BL
0.0f, 0.0f, // TL
0.0f, 0.0f, // BR
0.0f, 0.0f, // BR
0.0f, 0.0f, // TR
0.0f, 0.0f // TL
0.0f, 0.0f, 0.0f, // BL
0.0f, 0.0f, 0.0f, // TL
0.0f, 0.0f, 0.0f, // BR
0.0f, 0.0f, 0.0f, // BR
0.0f, 0.0f, 0.0f, // TR
0.0f, 0.0f, 0.0f // TL
});
// clang-format on
@ -559,18 +559,19 @@ void PlacefileIcons::Impl::UpdateTextureBuffer()
const float rs = ls + icon.scaledWidth_;
const float tt = icon.texture_.tTop_ + iconY;
const float bt = tt + icon.scaledHeight_;
const float r = static_cast<float>(icon.texture_.layerId_);
// clang-format off
textureBuffer_.insert(
textureBuffer_.end(),
{
// Icon
ls, bt, // BL
ls, tt, // TL
rs, bt, // BR
rs, bt, // BR
rs, tt, // TR
ls, tt // TL
ls, bt, r, // BL
ls, tt, r, // TL
rs, bt, r, // BR
rs, bt, r, // BR
rs, tt, r, // TR
ls, tt, r // TL
});
// clang-format on
}

View file

@ -23,7 +23,7 @@ static constexpr std::size_t kNumTriangles = kNumRectangles * 2;
static constexpr std::size_t kVerticesPerTriangle = 3;
static constexpr std::size_t kVerticesPerRectangle = kVerticesPerTriangle * 2;
static constexpr std::size_t kPointsPerVertex = 8;
static constexpr std::size_t kPointsPerTexCoord = 2;
static constexpr std::size_t kPointsPerTexCoord = 3;
static constexpr std::size_t kImageBufferLength =
kNumTriangles * kVerticesPerTriangle * kPointsPerVertex;
static constexpr std::size_t kTextureBufferLength =
@ -177,7 +177,7 @@ void PlacefileImages::Initialize()
// aTexCoord
gl.glVertexAttribPointer(2,
2,
3,
GL_FLOAT,
GL_FALSE,
kPointsPerTexCoord * sizeof(float),
@ -367,6 +367,8 @@ void PlacefileImages::Impl::UpdateTextureBuffer()
currentImageFiles_.cbegin()->second :
it->second;
const float r = static_cast<float>(image.texture_.layerId_);
// Limit processing to groups of 3 (triangles)
std::size_t numElements = di->elements_.size() - di->elements_.size() % 3;
for (std::size_t i = 0; i < numElements; ++i)
@ -379,7 +381,7 @@ void PlacefileImages::Impl::UpdateTextureBuffer()
const float t =
image.texture_.tTop_ + (image.scaledHeight_ * element.tv_);
textureBuffer_.insert(textureBuffer_.end(), {s, t});
textureBuffer_.insert(textureBuffer_.end(), {s, t, r});
}
}
}