OpenGL的:加载资源辅助线程? [英] OpenGL: secondary thread for loading resources?

查看:108
本文介绍了OpenGL的:加载资源辅助线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C和Win32的工作,我想知道如何实现加载资源辅助线程的OpenGL(纹理和维也纳组织)。

Working with C and Win32, I would like to know how to implement a secondary OpenGL thread for loading resources(textures and VBOs).

从我发现,这应该与wglShareLists()来完成,但我不知道如何设置二级螺纹:

From what I found, this should be done with wglShareLists(), but I am unsure about how to set up the secondary thread:

我是否需要一个新的设备上下文或只有一个新的渲染上下文?

Do I need a new device context or only a new rendering context?

什么WGL的功能,我需要打电话?

What wgl functions do I need to call?

推荐答案

您不需要一个新的环境,因为你可以重用第一个相同的设备上下文。顺便说一句,您可以指定其他设备上下文,但取决于你的平台上,你应该照顾它(在Windows上,设备contextes必须具有相同的像素格式),否则你可能会失败两个contextes间共享对象

You don't need a new context because you can reuse the same device context of the first one. Btw, you can specify another device context, but depending on your platform you should take care about it (on Windows, device contextes must have the same pixel format), otherwise you could fail to share objects between two contextes

创建主线程两个方面,第二个共享与第一个。然后,进行主线程第一个电流,同时使辅助线程上的另一个电流。
请注意,您可以与任何渲染方面:所有共享contextes看到相同的对象由它的名字,他们确实共享的对象名字空间的。两个不同的对象的名称空间(即,两个非共享contextes)可以定义相同的对象(即,纹理对象名称为1),但相同的名称实际上指向不同的对象根据当前的上下文

Create both context in the main thread, the second one sharing with the first one. Then, make the first one current on the main thread, while making the other one current on the secondary thread. Note that you can share with any render context: all sharing contextes "see" the same object by its name, indeed they share an object name space. Two different object name spaces (i.e. two non-sharing contextes) can have defined the same object (i.e. texture object name is 1), but the same name actually points to different object depending on the current context.

由辅助线程创建的对象是可见的同时,始终。然而,并非所有的对象可以跨contextes共享。请记住,有时候它发生在驱动程序支持意想不到的对象,其他时候碰巧驱动程序不支持正确的预期目标。

Objects created by the secondary thread are visible concurrently and consistently. However, not all objects can be shared across contextes. Keep in mind that sometimes it happens that the driver supports unexpected objects, and other times it happens that driver doesn't support correctly an expected object.

的OpenGL正在成为一种面向对象的语言。你可以看到特定的模式创建对象:

OpenGL is becoming an object oriented language. You can see a certain pattern for creating objects:


  • 生成的名称( GenTextures GenBuffers 的)

  • 定义对象( BindTexture BindBuffer 的)

  • 对象存在(的 IsTexture IsShader IsFramebuffer 的)

  • 删除名称(对象)

  • Generate name (GenTextures, GenBuffers)
  • Define object (BindTexture, BindBuffer)
  • Object existence (IsTexture, IsShader, IsFramebuffer)
  • Delete name (and object)

(注意,对象与创建的的程序只存在时,他们必然)

(Note that an object created with Gen routines exists only when they are bound)

对象类可能是


  • 显示列表

  • 纹理对象

  • 缓冲区对象

  • 着色对象和程序对象

  • 渲染对象

  • 帧缓冲区对象

  • 查询对象

  • 同步对象

  • 变换反馈对象

我会建议使用运行测试,如下所示:

I would suggest to use a "runtime" test, like the following:

private bool TestSharingObject(RenderContext rContextShare)
{
    uint texture = 0;

    // rContextShader is a context sharing with this RenderCOntext

    this.MakeCurrent(true);

    if (Caps.TextureObject.Supported == true) {
        // Generate texture name
        Gl.GenTextures(1, out texture);
        // Ensure existing texture object
        Gl.BindTexture(Gl.TEXTURE_2D, texture);
        Gl.BindTexture(Gl.TEXTURE_2D, 0);
        // Self test
        if (Gl.IsTexture(texture) == false)
            throw new NotSupportedException();
    }

    // Make current sharing context
    rContextShare.MakeCurrent(true);

    return ((texture != 0) && (Gl.IsTexture(texture) == true));
}

另一个建议是对是CPU密集型辅助线程操作运行,而不会直接影响绘图系统窗口的缓冲区。一个很好的例子将是一个着色器编译,因为编译CPU上运行一面;也请记住,驾驶者可以异步的操作,以及OpenGL实现可能的管道不同的操作。

Another suggestion would be to run on secondary thread operations that are CPU intensive, and not directly affecting drawing system windows buffers. A good example would be a shader compilation, since the compilation runs on CPU side; keep also in mind that the driver could async your operations, and that OpenGL implementations may pipeline different operations..

这篇关于OpenGL的:加载资源辅助线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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