aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drone_controller.cc71
-rw-r--r--src/drone_controller.hh6
-rw-r--r--src/opengl_mesh.cc1
-rw-r--r--src/opengl_widget.cc2
-rw-r--r--src/opengl_widget.hh5
5 files changed, 45 insertions, 40 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index f1b4a48..cede63d 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -45,9 +45,9 @@ DroneController::DroneController(const QJsonObject &json)
}
-void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) const {
- OpenGLWidget::instance->getLineProgram()->bind();
- OpenGLWidget::instance->getLineProgram()->setUniformValue("color", 1, 0, .532);
+void DroneController::drawTrajectory(OpenGLWidget *glw, const Drone &d) const {
+ glw->getLineProgram()->bind();
+ glw->getLineProgram()->setUniformValue("color", 1, 0, .532);
size_t trajectory_len = 1;
for (const Waypoint &wp : d.getWaypoints()) {
if (wp.frame > frame) break;
@@ -65,25 +65,23 @@ void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) c
trajectory[i] = d.getPos().x();
trajectory[i + 1] = d.getPos().y();
trajectory[i + 2] = d.getPos().z();
- f->glEnableVertexAttribArray(0);
- f->glBindBuffer(GL_ARRAY_BUFFER, 0);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, trajectory);
+ glw->glEnableVertexAttribArray(0);
+ glw->glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, trajectory);
glLineWidth(2);
- f->glDisable(GL_CULL_FACE);
- f->glDrawArrays(GL_LINE_STRIP, 0, trajectory_len);
- f->glEnable(GL_CULL_FACE);
- OpenGLWidget::instance->getLineProgram()->release();
- OpenGLWidget::instance->getMainProgram()->bind();
+ glw->glDisable(GL_CULL_FACE);
+ glw->glDrawArrays(GL_LINE_STRIP, 0, trajectory_len);
+ glw->glEnable(GL_CULL_FACE);
+ glw->getLineProgram()->release();
+ glw->getMainProgram()->bind();
}
-void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const {
- OpenGLWidget *glw = OpenGLWidget::instance;
-
+void DroneController::drawGuide(OpenGLWidget *glw, const Drone &d) const {
glw->getLineProgram()->bind();
- f->glEnableVertexAttribArray(0);
- f->glBindBuffer(GL_ARRAY_BUFFER, 0);
- f->glDisable(GL_CULL_FACE);
+ glw->glEnableVertexAttribArray(0);
+ glw->glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glw->glDisable(GL_CULL_FACE);
QVector<GLfloat> support_line {
d.getPos().x(), 0, d.getPos().z(),
@@ -91,8 +89,8 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const
};
glLineWidth(2);
glw->getLineProgram()->setUniformValue("color", .2, .2, .4);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, support_line.constData());
- f->glDrawArrays(GL_LINES, 0, 2);
+ glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, support_line.constData());
+ glw->glDrawArrays(GL_LINES, 0, 2);
QVector<GLfloat> grid;
const int size = 100;
@@ -113,8 +111,8 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const
}
glLineWidth(1);
glw->getLineProgram()->setUniformValue("color", .2, .2, .2);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, grid.constData());
- f->glDrawArrays(GL_LINES, 0, grid.size() / 3);
+ glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, grid.constData());
+ glw->glDrawArrays(GL_LINES, 0, grid.size() / 3);
glDisable(GL_DEPTH_TEST); // pro-gamer move
QVector<GLfloat> axes {
@@ -124,17 +122,17 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const
};
glLineWidth(2);
glw->getLineProgram()->setUniformValue("color", 1, 0, 0);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData());
- f->glDrawArrays(GL_LINES, 0, 2);
+ glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData());
+ glw->glDrawArrays(GL_LINES, 0, 2);
glw->getLineProgram()->setUniformValue("color", 0, 1, 0);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 6);
- f->glDrawArrays(GL_LINES, 0, 2);
+ glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 6);
+ glw->glDrawArrays(GL_LINES, 0, 2);
glw->getLineProgram()->setUniformValue("color", 0, 0, 1);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 12);
- f->glDrawArrays(GL_LINES, 0, 2);
+ glw->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 12);
+ glw->glDrawArrays(GL_LINES, 0, 2);
glDisable(GL_DEPTH_TEST);
- f->glEnable(GL_CULL_FACE);
+ glw->glEnable(GL_CULL_FACE);
glw->getLineProgram()->release();
glw->getMainProgram()->bind();
@@ -154,27 +152,30 @@ void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const
}
-void DroneController::draw(QOpenGLExtraFunctions *f) const {
+void DroneController::draw(OpenGLWidget *glw) const {
const QVector<QPair<int, int>> &col = collisions[frame];
for (const Drone &d : drones) {
+ glw->getMainProgram()->bind();
QMatrix4x4 mat;
mat.translate(d.getPos());
for (const QPair<int, int> &p : col) {
if (d.getId() == p.first || d.getId() == p.second) {
- OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", true);
+ glw->getMainProgram()->setUniformValue("highlight", true);
}
}
- d.getMesh()->draw(f, mat);
+ d.getMesh()->draw(glw, mat);
if (draw_spheres) {
mat.scale(sphere_radius);
- sphere->draw(f, mat);
+ sphere->draw(glw, mat);
}
- OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", false);
+ glw->getMainProgram()->bind();
+ glw->getMainProgram()->setUniformValue("highlight", false);
+ glw->getMainProgram()->release();
if (draw_trajectories) {
- drawTrajectory(f, d);
+ drawTrajectory(glw, d);
}
if (draw_guides) {
- drawGuide(f, d);
+ drawGuide(glw, d);
}
}
}
diff --git a/src/drone_controller.hh b/src/drone_controller.hh
index 742677b..6099e08 100644
--- a/src/drone_controller.hh
+++ b/src/drone_controller.hh
@@ -31,13 +31,13 @@ class DroneController : public QObject, public Painter {
static bool collides(const Drone &a, const Drone &b, double radius);
- void drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) const;
- void drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const;
+ void drawTrajectory(OpenGLWidget *glw, const Drone &d) const;
+ void drawGuide(OpenGLWidget *glw, const Drone &d) const;
public:
DroneController(const QJsonObject &json);
int getDuration() const;
- void draw(QOpenGLExtraFunctions *f) const;
+ void draw(OpenGLWidget *glw) const;
signals:
void frameChanged(int frame);
diff --git a/src/opengl_mesh.cc b/src/opengl_mesh.cc
index 8ad3336..e54938d 100644
--- a/src/opengl_mesh.cc
+++ b/src/opengl_mesh.cc
@@ -33,4 +33,5 @@ void OpenGLMesh::draw(QOpenGLExtraFunctions *f, const QMatrix4x4 &mat) const {
f->glDrawArrays(GL_TRIANGLES, 0, nverts);
if (tex) tex->release();
f->glBindVertexArray(0);
+ program->release();
}
diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc
index a4d9c8c..582bf3e 100644
--- a/src/opengl_widget.cc
+++ b/src/opengl_widget.cc
@@ -211,8 +211,8 @@ void OpenGLWidget::paintGL() {
glPolygonOffset(1, 1);
ground->draw(this, QMatrix4x4());
glDisable(GL_POLYGON_OFFSET_FILL);
- if (painter) painter->draw(this);
main_program.release();
+ if (painter) painter->draw(this);
}
diff --git a/src/opengl_widget.hh b/src/opengl_widget.hh
index 39897be..abe226f 100644
--- a/src/opengl_widget.hh
+++ b/src/opengl_widget.hh
@@ -13,9 +13,12 @@
#define FOV 70
+class OpenGLWidget;
+
+
class Painter {
public:
- virtual void draw(QOpenGLExtraFunctions *f) const = 0;
+ virtual void draw(OpenGLWidget *glw) const = 0;
};