mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:30:05 +00:00
Use GLEW instead of QOpenGLFunctions
This commit is contained in:
parent
4bd749d976
commit
331b2d855f
33 changed files with 788 additions and 959 deletions
|
|
@ -140,7 +140,7 @@ public:
|
|||
};
|
||||
|
||||
PlacefileIcons::PlacefileIcons(const std::shared_ptr<GlContext>& context) :
|
||||
DrawItem(context->gl()), p(std::make_unique<Impl>(context))
|
||||
DrawItem(), p(std::make_unique<Impl>(context))
|
||||
{
|
||||
}
|
||||
PlacefileIcons::~PlacefileIcons() = default;
|
||||
|
|
@ -161,12 +161,6 @@ void PlacefileIcons::set_thresholded(bool thresholded)
|
|||
|
||||
void PlacefileIcons::Initialize()
|
||||
{
|
||||
gl::OpenGLFunctions& gl = p->context_->gl();
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
auto& gl30 = p->context_->gl30();
|
||||
#endif
|
||||
|
||||
p->shaderProgram_ = p->context_->GetShaderProgram(
|
||||
{{GL_VERTEX_SHADER, ":/gl/geo_texture2d.vert"},
|
||||
{GL_GEOMETRY_SHADER, ":/gl/threshold.geom"},
|
||||
|
|
@ -181,86 +175,82 @@ void PlacefileIcons::Initialize()
|
|||
p->uSelectedTimeLocation_ =
|
||||
p->shaderProgram_->GetUniformLocation("uSelectedTime");
|
||||
|
||||
gl.glGenVertexArrays(1, &p->vao_);
|
||||
gl.glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
||||
glGenVertexArrays(1, &p->vao_);
|
||||
glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
||||
|
||||
gl.glBindVertexArray(p->vao_);
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[0]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW);
|
||||
glBindVertexArray(p->vao_);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
// aLatLong
|
||||
gl.glVertexAttribPointer(0,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
static_cast<void*>(0));
|
||||
gl.glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
static_cast<void*>(0));
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
// aXYOffset
|
||||
gl.glVertexAttribPointer(1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
reinterpret_cast<void*>(2 * sizeof(float)));
|
||||
gl.glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
reinterpret_cast<void*>(2 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
// aModulate
|
||||
gl.glVertexAttribPointer(3,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
reinterpret_cast<void*>(4 * sizeof(float)));
|
||||
gl.glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
reinterpret_cast<void*>(4 * sizeof(float)));
|
||||
glEnableVertexAttribArray(3);
|
||||
|
||||
// aAngle
|
||||
gl.glVertexAttribPointer(4,
|
||||
1,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
reinterpret_cast<void*>(8 * sizeof(float)));
|
||||
gl.glEnableVertexAttribArray(4);
|
||||
glVertexAttribPointer(4,
|
||||
1,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerVertex * sizeof(float),
|
||||
reinterpret_cast<void*>(8 * sizeof(float)));
|
||||
glEnableVertexAttribArray(4);
|
||||
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[1]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
// aTexCoord
|
||||
gl.glVertexAttribPointer(2,
|
||||
3,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerTexCoord * sizeof(float),
|
||||
static_cast<void*>(0));
|
||||
gl.glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2,
|
||||
3,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
kPointsPerTexCoord * sizeof(float),
|
||||
static_cast<void*>(0));
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[2]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, p->vbo_[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, 0u, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
// aThreshold
|
||||
gl.glVertexAttribIPointer(5, //
|
||||
1,
|
||||
GL_INT,
|
||||
0,
|
||||
static_cast<void*>(0));
|
||||
gl.glEnableVertexAttribArray(5);
|
||||
glVertexAttribIPointer(5, //
|
||||
1,
|
||||
GL_INT,
|
||||
0,
|
||||
static_cast<void*>(0));
|
||||
glEnableVertexAttribArray(5);
|
||||
|
||||
// aTimeRange
|
||||
gl.glVertexAttribIPointer(6, //
|
||||
2,
|
||||
GL_INT,
|
||||
kIntegersPerVertex_ * sizeof(GLint),
|
||||
reinterpret_cast<void*>(1 * sizeof(GLint)));
|
||||
gl.glEnableVertexAttribArray(6);
|
||||
glVertexAttribIPointer(6, //
|
||||
2,
|
||||
GL_INT,
|
||||
kIntegersPerVertex_ * sizeof(GLint),
|
||||
reinterpret_cast<void*>(1 * sizeof(GLint)));
|
||||
glEnableVertexAttribArray(6);
|
||||
|
||||
// aDisplayed
|
||||
#if !defined(__APPLE__)
|
||||
gl30.glVertexAttribI1i(7, 1);
|
||||
#else
|
||||
glVertexAttribI1i(7, 1);
|
||||
#endif
|
||||
|
||||
p->dirty_ = true;
|
||||
}
|
||||
|
|
@ -273,9 +263,7 @@ void PlacefileIcons::Render(
|
|||
|
||||
if (!p->currentIconList_.empty())
|
||||
{
|
||||
gl::OpenGLFunctions& gl = p->context_->gl();
|
||||
|
||||
gl.glBindVertexArray(p->vao_);
|
||||
glBindVertexArray(p->vao_);
|
||||
|
||||
p->Update(textureAtlasChanged);
|
||||
p->shaderProgram_->Use();
|
||||
|
|
@ -288,12 +276,12 @@ void PlacefileIcons::Render(
|
|||
// If thresholding is enabled, set the map distance
|
||||
units::length::nautical_miles<float> mapDistance =
|
||||
util::maplibre::GetMapDistance(params);
|
||||
gl.glUniform1f(p->uMapDistanceLocation_, mapDistance.value());
|
||||
glUniform1f(p->uMapDistanceLocation_, mapDistance.value());
|
||||
}
|
||||
else
|
||||
{
|
||||
// If thresholding is disabled, set the map distance to 0
|
||||
gl.glUniform1f(p->uMapDistanceLocation_, 0.0f);
|
||||
glUniform1f(p->uMapDistanceLocation_, 0.0f);
|
||||
}
|
||||
|
||||
// Selected time
|
||||
|
|
@ -301,27 +289,25 @@ void PlacefileIcons::Render(
|
|||
(p->selectedTime_ == std::chrono::system_clock::time_point {}) ?
|
||||
std::chrono::system_clock::now() :
|
||||
p->selectedTime_;
|
||||
gl.glUniform1i(
|
||||
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);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Draw icons
|
||||
gl.glDrawArrays(GL_TRIANGLES, 0, p->numVertices_);
|
||||
glDrawArrays(GL_TRIANGLES, 0, p->numVertices_);
|
||||
}
|
||||
}
|
||||
|
||||
void PlacefileIcons::Deinitialize()
|
||||
{
|
||||
gl::OpenGLFunctions& gl = p->context_->gl();
|
||||
|
||||
gl.glDeleteVertexArrays(1, &p->vao_);
|
||||
gl.glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
||||
glDeleteVertexArrays(1, &p->vao_);
|
||||
glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
||||
|
||||
std::unique_lock lock {p->iconMutex_};
|
||||
|
||||
|
|
@ -649,8 +635,6 @@ void PlacefileIcons::Impl::UpdateTextureBuffer()
|
|||
|
||||
void PlacefileIcons::Impl::Update(bool textureAtlasChanged)
|
||||
{
|
||||
gl::OpenGLFunctions& gl = context_->gl();
|
||||
|
||||
// If the texture atlas has changed
|
||||
if (dirty_ || textureAtlasChanged)
|
||||
{
|
||||
|
|
@ -664,29 +648,29 @@ void PlacefileIcons::Impl::Update(bool textureAtlasChanged)
|
|||
UpdateTextureBuffer();
|
||||
|
||||
// Buffer texture data
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(float) * textureBuffer_.size(),
|
||||
textureBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(float) * textureBuffer_.size(),
|
||||
textureBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
}
|
||||
|
||||
// If buffers need updating
|
||||
if (dirty_)
|
||||
{
|
||||
// Buffer vertex data
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(float) * currentIconBuffer_.size(),
|
||||
currentIconBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(float) * currentIconBuffer_.size(),
|
||||
currentIconBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
|
||||
// Buffer threshold data
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]);
|
||||
gl.glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(GLint) * currentIntegerBuffer_.size(),
|
||||
currentIntegerBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(GLint) * currentIntegerBuffer_.size(),
|
||||
currentIntegerBuffer_.data(),
|
||||
GL_DYNAMIC_DRAW);
|
||||
|
||||
numVertices_ =
|
||||
static_cast<GLsizei>(currentIconBuffer_.size() / kPointsPerVertex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue