diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a77431a..7105cb6 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -23,6 +23,7 @@ MainWindow::MainWindow() { simulation = new Simulation; simulation->moveToThread(simulationThread); simulationThread->start(); + QMetaObject::invokeMethod(simulation, &Simulation::initialize); masses = std::vector(MaxSegments); lengths = std::vector(MaxSegments); diff --git a/src/Simulation.cpp b/src/Simulation.cpp index dae7836..2a234e0 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -5,6 +5,9 @@ #include #include #include "FPS.h" +#include +#include +#include Simulation::Simulation() { ups = new FPS; @@ -16,6 +19,36 @@ Simulation::Simulation() { timer->start(); }; +void Simulation::initialize() { + + // OpenGL Offscreen functions + { + auto context = new QOpenGLContext(this); + context->setFormat(QSurfaceFormat::defaultFormat()); + context->create(); + auto surface = new QOffscreenSurface(nullptr, this); + surface->setFormat(context->format()); + surface->create(); + context->makeCurrent(surface); + initializeOpenGLFunctions(); + } + + int maxWorkGroupCount[3]; + int maxWorkGroupSize[3]; + int maxWorkGroupInvocations; + for (int i = 0; i < 3; i++){ + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, i, maxWorkGroupCount + i); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, i, maxWorkGroupSize + i); + } + glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &maxWorkGroupInvocations); + + + printf("Max work group count: (%d, %d, %d)\n", maxWorkGroupCount[0], maxWorkGroupCount[1], maxWorkGroupCount[2]); + printf("Max work group size: (%d, %d, %d)\n", maxWorkGroupSize[0], maxWorkGroupSize[1], maxWorkGroupSize[2]); + printf("Max work group invocations (x * y * z): %d\n", maxWorkGroupInvocations); + +} + void Simulation::update() { if (!isPlaying) return; diff --git a/src/Simulation.h b/src/Simulation.h index 5781abf..c106e13 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -4,11 +4,12 @@ #include #include "Pendulum.h" #include +#include class QTimer; class FPS; -class Simulation : public QObject { +class Simulation : public QObject, protected QOpenGLFunctions_4_3_Core { Q_OBJECT public: explicit Simulation(); @@ -28,6 +29,7 @@ public: std::binary_semaphore semaphore = std::binary_semaphore(1); FPS * ups; + void initialize(); void updateEnergy(); signals: void layoutChanged();