Large refactor of texture loading.

In this new implementation, everything is loaded on a separate thread,
but the textures are initialized on the main OpenGL thread.

This is all to work around the fact that you cannot create a separate
GL context in GLUT.
This commit is contained in:
2018-04-12 16:52:09 +02:00
parent 30aa25a09e
commit 265bc61b98
14 changed files with 158 additions and 53 deletions

View File

@@ -223,9 +223,7 @@ void RenderingState::loadSimulationData(const std::map<string, LayerInfo> &info,
void RenderingState::queueUpdate()
{
loadingFuture = std::async(std::launch::async, []() {
// Currently causes a segfault, due to threaded OpenGL.
// Possible solution: don't do GL things while loading.
//RenderingState::instance().updateVisualisers();
RenderingState::instance().updateVisualisers();
});
isLoading = true;
}
@@ -456,7 +454,7 @@ float RenderingState::layerAlpha() const
void RenderingState::idleFunc()
{
if (isLoading && loadingFuture.valid()) {
auto result = loadingFuture.wait_for(std::chrono::milliseconds(40));
auto result = loadingFuture.wait_for(std::chrono::milliseconds(16));
switch (result) {
case std::future_status::deferred:
LOG(ERROR) << "loading status was deferred, invalid state!";
@@ -468,7 +466,8 @@ void RenderingState::idleFunc()
case std::future_status::ready:
loadingFuture.get();
//isLoading = false;
loadGLItems();
isLoading = false;
break;
}
} else {
@@ -484,3 +483,9 @@ void RenderingState::idleFunc()
}
glutPostRedisplay();
}
void RenderingState::loadGLItems()
{
std::for_each(layerVisualisations.begin(), layerVisualisations.end(), [](auto& x) { x->glLoad(); });
std::for_each(interactionAnimations.begin(), interactionAnimations.end(), [](auto& x) { if (x) x->glLoad(); });
}