I have an OpenGL application with two main parts (viewers) with a main outline:
int main(int argc, char* argv[])
{
gp::viewers::PatternViewer pViewer;
gp::viewers::MeshViewer mViewer;
while (!pViewer.shouldClose() && !mViewer.shouldClose())
{
pViewer.makeCurrent();
pViewer.mainLoop();
pViewer.swap();
mViewer.makeCurrent();
mViewer.mainLoop();
mViewer.swap();
glfwWaitEvents();
}
glfwTerminate();
return 0;
}
It happens that user interaction with one viewer must propagate the changes to another viewer. My gut instinct says to refresh the cycle as follows:
int main(int argc, char* argv[])
{
gp::viewers::PatternViewer pViewer;
gp::viewers::MeshViewer mViewer;
while (!pViewer.shouldClose() && !mViewer.shouldClose())
{
pViewer.makeCurrent();
pViewer.mainLoop();
pViewer.swap();
mViewer.makeCurrent();
mViewer.mainLoop();
mViewer.swap();
mViewer.update(pViewer);
pViewer.update(mViewer);
glfwWaitEvents();
}
glfwTerminate();
return 0;
}
But in this case, the PatternViewer needs to know about the MeshViewer, and the MeshViewer needs to know about the PatternViewer - a circular dependency. Moreover, it is unclear whether mViewer.update (pViewer) should update pViewer with any updates available from mViewer, or vice versa. It seems to me that it should be the first - mViewer should know what updates are distributed, not pViewer.
, PatternViewer MeshViewer Viewer.
? / ?