我m working on a program which should have multiple views of a model. I would like to use multiple为此GLControls`。
是否有可能创建使用相同GraphicsContext的多个GLControl?
我在多线程环境中成功创建了此环境,但是当时不共享上下文。所以我必须为每个上下文加载模型,这很糟糕。
我对单线程环境的伪代码如下所示:
glControl1.MakeCurrent();
// Render here
glControl1.SwapBuffers();
glControl2.MakeCurrent();
// Render here too
glControl2.SwapBuffers();
Run Code Online (Sandbox Code Playgroud)
我通过在线程上创建多个上下文来尝试此操作,但是它崩溃了
错误:170“”在“ MakeCurrent()
的glControl2。(即使glControl2.Context.MakeCurrent(null)在切换上下文之前也没有用)
也许您有一些提示可以帮助我。
在我发布此问题后,我立即找到了解决方案。
我在要渲染我的东西的线程上创建了一个新的GraphicsContext。
//Here does a new thread start->
IGraphicsContext control2Context = new GraphicsContext(GraphicsMode.Default,glControl2.WindowInfo);
while(true)
{
glControl1.MakeCurrent()
//render
GL.Flush();
glControl1.SwapBuffers();
control2Context.MakeCurrent(glControl2.WindowInfo);
//render
GL.Flush();
glControl2.SwapBuffers();
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我没有使用glControl2.MakeCurrent()。相反,我创建了这个新上下文control2Context。
也许这可以帮助面临相同问题的人。