Use GLEW instead of QOpenGLFunctions

This commit is contained in:
Dan Paulat 2025-07-07 22:44:01 -05:00
parent 4bd749d976
commit 331b2d855f
33 changed files with 788 additions and 959 deletions

View file

@ -130,7 +130,7 @@ public:
PlacefilePolygons::PlacefilePolygons(
const std::shared_ptr<GlContext>& context) :
DrawItem(context->gl()), p(std::make_unique<Impl>(context))
DrawItem(), p(std::make_unique<Impl>(context))
{
}
PlacefilePolygons::~PlacefilePolygons() = default;
@ -152,8 +152,6 @@ void PlacefilePolygons::set_thresholded(bool thresholded)
void PlacefilePolygons::Initialize()
{
gl::OpenGLFunctions& gl = p->context_->gl();
p->shaderProgram_ = p->context_->GetShaderProgram(
{{GL_VERTEX_SHADER, ":/gl/map_color.vert"},
{GL_GEOMETRY_SHADER, ":/gl/threshold.geom"},
@ -168,58 +166,58 @@ void PlacefilePolygons::Initialize()
p->uSelectedTimeLocation_ =
p->shaderProgram_->GetUniformLocation("uSelectedTime");
gl.glGenVertexArrays(1, &p->vao_);
gl.glGenBuffers(2, p->vbo_.data());
glGenVertexArrays(1, &p->vao_);
glGenBuffers(2, 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);
// aScreenCoord
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);
// aColor
gl.glVertexAttribPointer(2,
4,
GL_FLOAT,
GL_FALSE,
kPointsPerVertex * sizeof(float),
reinterpret_cast<void*>(4 * sizeof(float)));
gl.glEnableVertexAttribArray(2);
glVertexAttribPointer(2,
4,
GL_FLOAT,
GL_FALSE,
kPointsPerVertex * sizeof(float),
reinterpret_cast<void*>(4 * sizeof(float)));
glEnableVertexAttribArray(2);
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);
// aThreshold
gl.glVertexAttribIPointer(3, //
1,
GL_INT,
kIntegersPerVertex_ * sizeof(GLint),
static_cast<void*>(0));
gl.glEnableVertexAttribArray(3);
glVertexAttribIPointer(3, //
1,
GL_INT,
kIntegersPerVertex_ * sizeof(GLint),
static_cast<void*>(0));
glEnableVertexAttribArray(3);
// aTimeRange
gl.glVertexAttribIPointer(4, //
2,
GL_INT,
kIntegersPerVertex_ * sizeof(GLint),
reinterpret_cast<void*>(1 * sizeof(GLint)));
gl.glEnableVertexAttribArray(4);
glVertexAttribIPointer(4, //
2,
GL_INT,
kIntegersPerVertex_ * sizeof(GLint),
reinterpret_cast<void*>(1 * sizeof(GLint)));
glEnableVertexAttribArray(4);
p->dirty_ = true;
}
@ -229,9 +227,7 @@ void PlacefilePolygons::Render(
{
if (!p->currentBuffer_.empty())
{
gl::OpenGLFunctions& gl = p->context_->gl();
gl.glBindVertexArray(p->vao_);
glBindVertexArray(p->vao_);
p->Update();
p->shaderProgram_->Use();
@ -244,12 +240,12 @@ void PlacefilePolygons::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
@ -257,23 +253,21 @@ void PlacefilePolygons::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()));
// Draw icons
gl.glDrawArrays(GL_TRIANGLES, 0, p->numVertices_);
glDrawArrays(GL_TRIANGLES, 0, p->numVertices_);
}
}
void PlacefilePolygons::Deinitialize()
{
gl::OpenGLFunctions& gl = p->context_->gl();
gl.glDeleteVertexArrays(1, &p->vao_);
gl.glDeleteBuffers(2, p->vbo_.data());
glDeleteVertexArrays(1, &p->vao_);
glDeleteBuffers(2, p->vbo_.data());
std::unique_lock lock {p->bufferMutex_};
@ -318,23 +312,21 @@ void PlacefilePolygons::Impl::Update()
{
if (dirty_)
{
gl::OpenGLFunctions& gl = context_->gl();
std::unique_lock lock {bufferMutex_};
// Buffer vertex data
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]);
gl.glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * currentBuffer_.size(),
currentBuffer_.data(),
GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]);
glBufferData(GL_ARRAY_BUFFER,
sizeof(GLfloat) * currentBuffer_.size(),
currentBuffer_.data(),
GL_DYNAMIC_DRAW);
// Buffer threshold data
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]);
gl.glBufferData(GL_ARRAY_BUFFER,
sizeof(GLint) * currentIntegerBuffer_.size(),
currentIntegerBuffer_.data(),
GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]);
glBufferData(GL_ARRAY_BUFFER,
sizeof(GLint) * currentIntegerBuffer_.size(),
currentIntegerBuffer_.data(),
GL_DYNAMIC_DRAW);
numVertices_ =
static_cast<GLsizei>(currentBuffer_.size() / kPointsPerVertex);