UPDATE
Posting my top level render code. Basically I have a loop that calls all my individual renderers sequentially, all on the same thread and on the same context.
Top level render code:
// ...
render_fbo_->bind();
// Clear
context_->functions()->glClearColor(0.039f, 0.055f, 0.10f, 1.0f);
context_->functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render only the faces closest to you
context_->functions()->glEnable(GL_DEPTH_TEST);
context_->functions()->glDepthMask(GL_TRUE);
{
// Configure out viewport (x,y, width, height)
unsigned int i = 0;
foreach (const auto v, scene_graph_->viewports())
{
// Make sure that the viewports cameras are updated
v->camera()->calculatePosition();
auto vs = v->paddedRect();
context_->versionFunctions<QOpenGLFunctions_4_3_Core>()->glViewportIndexedf(i, vs.x(), vs.y(), vs.width(), vs.height());
i++;
}
}
foreach (const auto model, scene_graph_->models())
{
if (model->isDirty())
{
model->renderer()->synchronize(model);
model->dataSynced();
}
model->renderer()->render();
}
// Reset OpenGL state
context_->functions()->glDisable(GL_DEPTH_TEST);
// We need to flush the contents to the FBO before posting
// the texture to the other thread, otherwise, we might
// get unexpected results.
context_->functions()->glFlush();
// FPS
recalculateFPS();
render_fbo_->bindDefault();
render_fbo_.swap(display_fbo_);
emit textureReady(display_fbo_->texture(), size_);
When I include glFlush
glFinish()
after model->renderer()->render()
, I can see that some of my renders, specially my GroundRenderer
is taking waay too much time (the black line represents the amx time for 1 frame):
So, my goal now is to figure out why GroundRenderer
takes so much time. It basically just writes to a large circular buffer. I'm not experienced enough yet though to know what "large" is, but I haven't really observed a sensitivity to the specific size of the buffer (I cut it's size by a few orders of magnitude, and didn't see any real difference.)