mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:30:05 +00:00
Placefile images looping
This commit is contained in:
parent
4feff1cb6e
commit
f158c4174c
1 changed files with 50 additions and 13 deletions
|
|
@ -29,6 +29,9 @@ static constexpr std::size_t kImageBufferLength =
|
|||
static constexpr std::size_t kTextureBufferLength =
|
||||
kNumTriangles * kVerticesPerTriangle * kPointsPerTexCoord;
|
||||
|
||||
// Threshold, start time, end time
|
||||
static constexpr std::size_t kIntegersPerVertex_ = 3;
|
||||
|
||||
struct PlacefileImageInfo
|
||||
{
|
||||
PlacefileImageInfo(const std::string& imageFile,
|
||||
|
|
@ -58,6 +61,7 @@ public:
|
|||
uMapMatrixLocation_(GL_INVALID_INDEX),
|
||||
uMapScreenCoordLocation_(GL_INVALID_INDEX),
|
||||
uMapDistanceLocation_(GL_INVALID_INDEX),
|
||||
uSelectedTimeLocation_(GL_INVALID_INDEX),
|
||||
vao_ {GL_INVALID_INDEX},
|
||||
vbo_ {GL_INVALID_INDEX},
|
||||
numVertices_ {0}
|
||||
|
|
@ -91,9 +95,9 @@ public:
|
|||
newImageList_ {};
|
||||
|
||||
std::vector<float> currentImageBuffer_ {};
|
||||
std::vector<GLint> currentThresholdBuffer_ {};
|
||||
std::vector<GLint> currentIntegerBuffer_ {};
|
||||
std::vector<float> newImageBuffer_ {};
|
||||
std::vector<GLint> newThresholdBuffer_ {};
|
||||
std::vector<GLint> newIntegerBuffer_ {};
|
||||
|
||||
std::vector<float> textureBuffer_ {};
|
||||
|
||||
|
|
@ -102,6 +106,7 @@ public:
|
|||
GLint uMapMatrixLocation_;
|
||||
GLint uMapScreenCoordLocation_;
|
||||
GLint uMapDistanceLocation_;
|
||||
GLint uSelectedTimeLocation_;
|
||||
|
||||
GLuint vao_;
|
||||
std::array<GLuint, 3> vbo_;
|
||||
|
|
@ -145,6 +150,8 @@ void PlacefileImages::Initialize()
|
|||
p->shaderProgram_->GetUniformLocation("uMapScreenCoord");
|
||||
p->uMapDistanceLocation_ =
|
||||
p->shaderProgram_->GetUniformLocation("uMapDistance");
|
||||
p->uSelectedTimeLocation_ =
|
||||
p->shaderProgram_->GetUniformLocation("uSelectedTime");
|
||||
|
||||
gl.glGenVertexArrays(1, &p->vao_);
|
||||
gl.glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
||||
|
|
@ -199,10 +206,18 @@ void PlacefileImages::Initialize()
|
|||
gl.glVertexAttribIPointer(5, //
|
||||
1,
|
||||
GL_INT,
|
||||
0,
|
||||
kIntegersPerVertex_ * sizeof(GLint),
|
||||
static_cast<void*>(0));
|
||||
gl.glEnableVertexAttribArray(5);
|
||||
|
||||
// aTimeRange
|
||||
gl.glVertexAttribIPointer(6, //
|
||||
2,
|
||||
GL_INT,
|
||||
kIntegersPerVertex_ * sizeof(GLint),
|
||||
reinterpret_cast<void*>(1 * sizeof(GLint)));
|
||||
gl.glEnableVertexAttribArray(6);
|
||||
|
||||
p->dirty_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -237,6 +252,17 @@ void PlacefileImages::Render(
|
|||
gl.glUniform1f(p->uMapDistanceLocation_, 0.0f);
|
||||
}
|
||||
|
||||
// Selected time
|
||||
std::chrono::system_clock::time_point selectedTime =
|
||||
(p->selectedTime_ == std::chrono::system_clock::time_point {}) ?
|
||||
std::chrono::system_clock::now() :
|
||||
p->selectedTime_;
|
||||
gl.glUniform1i(
|
||||
p->uSelectedTimeLocation_,
|
||||
static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>(
|
||||
selectedTime.time_since_epoch())
|
||||
.count()));
|
||||
|
||||
// Interpolate texture coordinates
|
||||
gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
|
@ -258,7 +284,7 @@ void PlacefileImages::Deinitialize()
|
|||
p->currentImageList_.clear();
|
||||
p->currentImageFiles_.clear();
|
||||
p->currentImageBuffer_.clear();
|
||||
p->currentThresholdBuffer_.clear();
|
||||
p->currentIntegerBuffer_.clear();
|
||||
p->textureBuffer_.clear();
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +304,7 @@ void PlacefileImages::StartImages(const std::string& baseUrl)
|
|||
p->newImageList_.clear();
|
||||
p->newImageFiles_.clear();
|
||||
p->newImageBuffer_.clear();
|
||||
p->newThresholdBuffer_.clear();
|
||||
p->newIntegerBuffer_.clear();
|
||||
}
|
||||
|
||||
void PlacefileImages::AddImage(
|
||||
|
|
@ -301,13 +327,13 @@ void PlacefileImages::FinishImages()
|
|||
p->currentImageList_.swap(p->newImageList_);
|
||||
p->currentImageFiles_.swap(p->newImageFiles_);
|
||||
p->currentImageBuffer_.swap(p->newImageBuffer_);
|
||||
p->currentThresholdBuffer_.swap(p->newThresholdBuffer_);
|
||||
p->currentIntegerBuffer_.swap(p->newIntegerBuffer_);
|
||||
|
||||
// Clear the new buffers
|
||||
p->newImageList_.clear();
|
||||
p->newImageFiles_.clear();
|
||||
p->newImageBuffer_.clear();
|
||||
p->newThresholdBuffer_.clear();
|
||||
p->newIntegerBuffer_.clear();
|
||||
|
||||
// Mark the draw item dirty
|
||||
p->dirty_ = true;
|
||||
|
|
@ -317,8 +343,9 @@ void PlacefileImages::Impl::UpdateBuffers()
|
|||
{
|
||||
newImageBuffer_.clear();
|
||||
newImageBuffer_.reserve(newImageList_.size() * kImageBufferLength);
|
||||
newThresholdBuffer_.clear();
|
||||
newThresholdBuffer_.reserve(newImageList_.size() * kVerticesPerRectangle);
|
||||
newIntegerBuffer_.clear();
|
||||
newIntegerBuffer_.reserve(newImageList_.size() * kVerticesPerRectangle *
|
||||
kIntegersPerVertex_);
|
||||
newImageFiles_.clear();
|
||||
|
||||
// Fixed modulate color
|
||||
|
|
@ -339,6 +366,16 @@ void PlacefileImages::Impl::UpdateBuffers()
|
|||
units::length::nautical_miles<double> threshold = di->threshold_;
|
||||
GLint thresholdValue = static_cast<GLint>(std::round(threshold.value()));
|
||||
|
||||
// Start and end time
|
||||
GLint startTime =
|
||||
static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>(
|
||||
di->startTime_.time_since_epoch())
|
||||
.count());
|
||||
GLint endTime =
|
||||
static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>(
|
||||
di->endTime_.time_since_epoch())
|
||||
.count());
|
||||
|
||||
// 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)
|
||||
|
|
@ -355,8 +392,8 @@ void PlacefileImages::Impl::UpdateBuffers()
|
|||
|
||||
newImageBuffer_.insert(newImageBuffer_.end(),
|
||||
{lat, lon, x, y, mc0, mc1, mc2, mc3});
|
||||
newThresholdBuffer_.insert(newThresholdBuffer_.end(),
|
||||
{thresholdValue});
|
||||
newIntegerBuffer_.insert(newIntegerBuffer_.end(),
|
||||
{thresholdValue, startTime, endTime});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -431,8 +468,8 @@ void PlacefileImages::Impl::Update(bool textureAtlasChanged)
|
|||
// Buffer threshold data
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(GLint) * currentThresholdBuffer_.size(),
|
||||
currentThresholdBuffer_.data(),
|
||||
sizeof(GLint) * currentIntegerBuffer_.size(),
|
||||
currentIntegerBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
|
||||
numVertices_ = static_cast<GLsizei>(currentImageBuffer_.size() /
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue