|
|
@ -13,7 +13,7 @@ GLWidget::GLWidget(Simulation * simulation) : simulation(simulation) { |
|
|
|
startTimer(1000 / 144); |
|
|
|
startTimer(1000 / 144); |
|
|
|
fps = new FPS; |
|
|
|
fps = new FPS; |
|
|
|
fps->setUpdateInterval(500); |
|
|
|
fps->setUpdateInterval(500); |
|
|
|
connect(simulation, &Simulation::layoutChanged, this, &GLWidget::initGPUMemory); |
|
|
|
connect(simulation, &Simulation::layoutChanged, this, &GLWidget::uploadStaticDataToGPU); |
|
|
|
connect(simulation, &Simulation::positionChanged, this, &GLWidget::changePosition); |
|
|
|
connect(simulation, &Simulation::positionChanged, this, &GLWidget::changePosition); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -41,13 +41,10 @@ void GLWidget::initializeGL() { |
|
|
|
glClearColor(.15, .15, .15, 1); |
|
|
|
glClearColor(.15, .15, .15, 1); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Pendulum*> empty; |
|
|
|
std::vector<Pendulum*> empty; |
|
|
|
initGPUMemory(&empty); |
|
|
|
uploadStaticDataToGPU(&empty); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GLWidget::paintGL() { |
|
|
|
void GLWidget::paintGL() { |
|
|
|
QPixmap img(size()); |
|
|
|
|
|
|
|
auto p = new QPainter(&img); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Native OpenGL
|
|
|
|
// Native OpenGL
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
@ -76,6 +73,8 @@ void GLWidget::paintGL() { |
|
|
|
glBindVertexArray(0); |
|
|
|
glBindVertexArray(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap img(size()); |
|
|
|
|
|
|
|
auto p = new QPainter(&img); |
|
|
|
// FPS
|
|
|
|
// FPS
|
|
|
|
{ |
|
|
|
{ |
|
|
|
p->setPen(Qt::white); |
|
|
|
p->setPen(Qt::white); |
|
|
@ -102,7 +101,7 @@ bool GLWidget::AnyDialogOpen() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
void GLWidget::uploadStaticDataToGPU(const std::vector<Pendulum *> *pendula) { |
|
|
|
|
|
|
|
|
|
|
|
int pointCount = std::transform_reduce(pendula->begin(), pendula->end(), 0, [](int prev, int curr){ |
|
|
|
int pointCount = std::transform_reduce(pendula->begin(), pendula->end(), 0, [](int prev, int curr){ |
|
|
|
return prev + curr + 1; |
|
|
|
return prev + curr + 1; |
|
|
@ -183,16 +182,12 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
|
|
|
|
|
|
|
|
glBindVertexArray(0); |
|
|
|
glBindVertexArray(0); |
|
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simulation->pendulaMutex.unlock(); |
|
|
|
simulation->pendulaMutex.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GLWidget::changePosition(const std::vector<Pendulum *> *pendula) { |
|
|
|
void GLWidget::changePosition(const std::vector<Pendulum *> *pendula) { |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, positionVBO); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, positionVBO); |
|
|
|
auto positions = (GLfloat*) glMapBufferRange(GL_ARRAY_BUFFER, 0, GLsizeiptr(positionCount * sizeof(float)), GL_MAP_WRITE_BIT); |
|
|
|
auto positions = (GLfloat*) glMapBufferRange(GL_ARRAY_BUFFER, 0, GLsizeiptr(positionCount * sizeof(float)), GL_MAP_WRITE_BIT); |
|
|
|
if (positions){ |
|
|
|
|
|
|
|
size_t index = 0; |
|
|
|
size_t index = 0; |
|
|
|
for (const auto p : *pendula){ |
|
|
|
for (const auto p : *pendula){ |
|
|
|
index += 3; |
|
|
|
index += 3; |
|
|
@ -202,10 +197,8 @@ void GLWidget::changePosition(const std::vector<Pendulum *> *pendula) { |
|
|
|
index++; |
|
|
|
index++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
simulation->pendulaMutex.unlock(); |
|
|
|
|
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER); |
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
simulation->pendulaMutex.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GLWidget::resizeGL(int w, int h) { |
|
|
|
void GLWidget::resizeGL(int w, int h) { |
|
|
|