start compute shader

main
Benjamin Kraft 1 year ago
parent 50b63c59aa
commit e2bf29bf75
  1. 1
      src/MainWindow.cpp
  2. 33
      src/Simulation.cpp
  3. 4
      src/Simulation.h

@ -23,6 +23,7 @@ MainWindow::MainWindow() {
simulation = new Simulation; simulation = new Simulation;
simulation->moveToThread(simulationThread); simulation->moveToThread(simulationThread);
simulationThread->start(); simulationThread->start();
QMetaObject::invokeMethod(simulation, &Simulation::initialize);
masses = std::vector<double>(MaxSegments); masses = std::vector<double>(MaxSegments);
lengths = std::vector<double>(MaxSegments); lengths = std::vector<double>(MaxSegments);

@ -5,6 +5,9 @@
#include <omp.h> #include <omp.h>
#include <iostream> #include <iostream>
#include "FPS.h" #include "FPS.h"
#include <QOpenGLContext>
#include <QOpenGLShaderProgram>
#include <QOffscreenSurface>
Simulation::Simulation() { Simulation::Simulation() {
ups = new FPS; ups = new FPS;
@ -16,6 +19,36 @@ Simulation::Simulation() {
timer->start(); 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() { void Simulation::update() {
if (!isPlaying) if (!isPlaying)
return; return;

@ -4,11 +4,12 @@
#include <chrono> #include <chrono>
#include "Pendulum.h" #include "Pendulum.h"
#include <semaphore> #include <semaphore>
#include <QOpenGLFunctions_4_3_Core>
class QTimer; class QTimer;
class FPS; class FPS;
class Simulation : public QObject { class Simulation : public QObject, protected QOpenGLFunctions_4_3_Core {
Q_OBJECT Q_OBJECT
public: public:
explicit Simulation(); explicit Simulation();
@ -28,6 +29,7 @@ public:
std::binary_semaphore semaphore = std::binary_semaphore(1); std::binary_semaphore semaphore = std::binary_semaphore(1);
FPS * ups; FPS * ups;
void initialize();
void updateEnergy(); void updateEnergy();
signals: signals:
void layoutChanged(); void layoutChanged();

Loading…
Cancel
Save