共享OpenGL资源的策略 [英] Strategy for sharing OpenGL resources

查看:184
本文介绍了共享OpenGL资源的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个类似CAD的应用程序(基于Qt),它将是一个多文档界面,每个文档将包含大约5个视口(来自QGLWidget).因此,我需要在整个应用程序中共享平面着色器,然后在每个文档(即5个视口)之间共享3D资产(存储为VBO的模型).

I'm creating a CAD-like app (Qt-based), it will be a multiple document interface and each document will contain about 5 viewports (derived from QGLWidget). As such I need my flat shader to be shared across the entire application, and then the 3D assets (models stored as VBOs) to be shared across each document i.e. the 5 viewports.

我以为只要共享着色器程序和VBO GLuint地址,所有内容都可以自动工作-不能.我认为,因为每个视口/上下文在图形卡上都有其自己的地址空间,如果有人知道,请告知!

I thought as long as I shared around the shader program and VBO GLuint addresses all will automagickly work - it doesn't. I think because each viewport/context has it's own address space on the graphics card, if anyone knows better please inform!

我想在应用程序启动时编译着​​色器,但是事实证明这很困难,因为我需要有效的QGLWidget才能使OpenGL事先进入有效状态.但是,由于我需要共享QGLWidgets(通过它们的构造函数)以使它们共享资源,因此需要创建一个并显示,然后才能实例化另一个.但这是不切实际的,因为要同时向用户显示多个视图.

I would like to have the shader compiled on application start, but this is proving difficult as I need a valid QGLWidget to get OpenGL into a valid state beforehand. But as I need to share the QGLWidgets (through their constructor) to have them share resources, one needs to be created and shown before the others can be instantiated. But this is highly impractical as multiple views to be shown at once to the user.

这肯定比我讲的容易,因为它几乎不是开创性的东西,但是我真的很挣扎-有人能指出我正确的方向吗?

This must be easier than I'm making out because it's hardly groundbreaking stuff, but I am really struggling - can anyone point me in the right direction?

谢谢,凸轮

推荐答案

以下是通常的CAD/MDI应用程序正在做的事情:

Here's what usual CAD/MDI applications are doing:

  • 他们创建了一个共享上下文,可以很好地共享资源.

  • they create a shared context that serves for well, sharing resources.

在创建新的OpenGL渲染上下文以提供对共享上下文的资源ID的访问时使用wglShareLists.

they use wglShareLists when creating a new OpenGL rendering context for giving access to the resource ids of the shared context.

wglShareLists不仅可以用于显示列表,还可以用于共享VBO,纹理,着色器等(共享DL是旧用法,因此是函数名).

wglShareLists can be used for sharing VBOs, textures, shaders, etc, not only display lists (sharing DLs is the legacy usage, hence the function name).

我不记得您是否需要使用共享上下文创建资源,或者是否可以在任何上下文中创建资源.

I don't remember if you need to create resources with the shared context or if you can create them on any contexts.

如果您不在Windows上,请参见glXCreateContext.那应该使您步入正轨.

If you're not on windows, see glXCreateContext. That should put you on track.

我看过Qt,它看起来像是与成员QGLContext::create抽象的.

I've looked at Qt, it looks like it's abstracted with member QGLContext::create.

这篇关于共享OpenGL资源的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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