具有单个上下文的OpenTK多个GLControl [英] OpenTK multiple GLControl with a single Context

查看:373
本文介绍了具有单个上下文的OpenTK多个GLControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I m working on a program which should have multiple views of a model. I would like to use multiple GLControls`.

Im working on a program which should have multiple views of a model. I would like to use multipleGLControls` for that.

是否有可能创建使用相同GraphicsContext的多个GLControl?

Is there any possibility to create multiple GLControl which use the same GraphicsContext?

我在多线程环境中成功创建了该环境,但是当时不共享上下文.所以我必须为每个上下文加载模型,这很糟糕.

I successfully created this on a multithreaded enviroment, but the contexts are not shared then. So I have to load the model for each context, which is bad.

我在单线程环境中的伪代码如下:

My pseudocode for a single threaded enviroment looks something like this:

glControl1.MakeCurrent();
// Render here
glControl1.SwapBuffers();
glControl2.MakeCurrent();
// Render here too
glControl2.SwapBuffers();

我通过在线程上创建多个上下文来尝试此操作,但是它崩溃了

I tried this by creating multiple contexts on the thread but it crashed with

错误:170"位于"MakeCurrent()

Error: 170" at "MakeCurrent()

glControl2

. (即使glControl2.Context.MakeCurrent(null)在切换上下文之前也无效)

of glControl2. (Even glControl2.Context.MakeCurrent(null) before switching the context didn`t work)

也许您有一些提示可以对我有所帮助.

Maybe you have some hints which can help me.

推荐答案

在我发布此问题后,我立即找到了解决方案.

Right after I posted this question I found the solution.

我在要渲染我的东西的线程上创建了一个新的GraphicsContext.

I created a new GraphicsContext on the thread I want to render my stuff.

//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();
}

如您所见,我没有使用glControl2.MakeCurrent().相反,我创建了这个新上下文control2Context.

As you can see, I'm not using glControl2.MakeCurrent(). Instead I created this new context control2Context.

也许这可以帮助面临相同问题的人.

Maybe this can help someone who is facing the same problem.

这篇关于具有单个上下文的OpenTK多个GLControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆