在Linux中没有X.org的OpenGL [英] OpenGL without X.org in linux

查看:152
本文介绍了在Linux中没有X.org的OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Linux中打开不带X的OpenGL上下文.有什么办法吗?

I'd like to open an OpenGL context without X in Linux. Is there any way at all to do it?

我知道集成英特尔图形卡硬件是可能的,尽管大多数人的系统中都装有Nvidia卡.我想获得一种适用于Nvidia卡的解决方案.

I know it's possible for integrated Intel graphics card hardware, though most people have Nvidia cards in their system. I'd like to get a solution that works with Nvidia cards.

如果除了通过集成的Intel硬件之外别无选择,我想知道如何使用这些硬件是可以的.

If there's no other way than through integrated Intel hardware, I guess it'd be okay to know how it's done with those.

X11协议本身太大且太复杂.它提供的鼠标/键盘/平板电脑输入多路复用功能对于现代程序来说太浪费了.我认为这是阻止Linux桌面改进的最严重障碍,这就是为什么我要寻找替代方案的原因.

X11 protocol itself is too large and complex. Mouse/Keyboard/Tablet input multiplexing it provides is too watered-down for modern programs. I think it's the worst roadblock that prevents Linux desktop from improving, which is why I look for alternatives.

推荐答案

更新(2017年9月17日):

Update (Sep. 17, 2017):

NVIDIA最近发表了一篇文章详细介绍了如何在无头系统上使用OpenGL ,该问题与问题描述非常相似.

NVIDIA recently published an article detailing how to use OpenGL on headless systems, which is a very similar use case as the question describes.

总结:

  • 链接到libOpenGL.solibEGL.so而不是libGL.so. (因此,您的链接器选项应为-lOpenGL -lEGL
  • 呼叫eglGetDisplay,然后呼叫eglInitialize初始化EGL.
  • 使用配置属性EGL_SURFACE_TYPEEGL_PBUFFER_BIT调用eglChooseConfig.
  • 呼叫eglCreatePbufferSurface,然后呼叫eglBindApi(EGL_OPENGL_API);,然后呼叫eglCreateContexteglMakeCurrent.
  • Link to libOpenGL.so and libEGL.so instead of libGL.so. (Your linker options should therefore be -lOpenGL -lEGL
  • Call eglGetDisplay, then eglInitialize to initialize EGL.
  • Call eglChooseConfig with the config attribute EGL_SURFACE_TYPE followed with EGL_PBUFFER_BIT.
  • Call eglCreatePbufferSurface, then eglBindApi(EGL_OPENGL_API);, then eglCreateContext and eglMakeCurrent.

从那时起,像往常一样执行OpenGL渲染,然后可以随心所欲地涂抹像素缓冲区表面. NVIDIA的这篇补充文章包括一个基本内容示例和多个GPU的示例.根据应用程序的需要,也可以将PBuffer表面替换为窗口表面或像素图表面.

From that point on, do your OpenGL rendering as usual, and you can blit your pixel buffer surface wherever you like. This supplementary article from NVIDIA includes a basic example and an example for multiple GPUs. The PBuffer surface can also be replaced with a window surface or pixmap surface, according to the application needs.

很遗憾,我在以前的编辑中没有对此做更多的研究,但是很好.更好的答案就是更好的答案.

I regret not doing more research on this on my previous edit, but oh well. Better answers are better answers.

自从2010年我的回答以来,Linux图形领域发生了许多重大变化.因此,一个更新的答案:

Since my answer in 2010, there have been a number of major shakeups in the Linux graphics space. So, an updated answer:

如今,nouveau和其他DRI驱动程序已经成熟到OpenGL软件稳定并且总体上表现良好的地步.通过在Mesa中引入EGL API,现在甚至可以在Linux桌面上编写OpenGL和OpenGL ES应用程序.

Today, nouveau and the other DRI drivers have matured to the point where OpenGL software is stable and performs reasonably well in general. With the introduction of the EGL API in Mesa, it's now possible to write OpenGL and OpenGL ES applications on even Linux desktops.

您可以将应用程序编写为目标EGL,并且可以在没有窗口管理器甚至合成器的情况下运行它.为此,您可以调用eglGetDisplayeglInitialize,最后调用eglCreateContexteglMakeCurrent,而不是通常的glx调用.

You can write your application to target EGL, and it can be run without the presence of a window manager or even a compositor. To do so, you would call eglGetDisplay, eglInitialize, and ultimately eglCreateContext and eglMakeCurrent, instead of the usual glx calls to do the same.

我不知道在没有显示服务器的情况下工作的具体代码路径,但是EGL可以接受X11显示器和Wayland显示器,而且我知道EGL可以在没有显示器的情况下运行.您可以创建GL ES 1.1,ES 2.0,ES 3.0(如果您具有Mesa 9.1或更高版本)和OpenGL 3.1(Mesa 9.0或更高版本)上下文. Mesa尚未(截至2013年9月)尚未实现OpenGL 3.2 Core.

I do not know the specific code path for working without a display server, but EGL accepts both X11 displays and Wayland displays, and I do know it is possible for EGL to operate without one. You can create GL ES 1.1, ES 2.0, ES 3.0 (if you have Mesa 9.1 or later), and OpenGL 3.1 (Mesa 9.0 or later) contexts. Mesa has not (as of Sep. 2013) yet implemented OpenGL 3.2 Core.

值得注意的是,在Raspberry Pi和Android上,默认情况下默认支持EGL和GL ES 2.0(Android上<1.1的3.0).在Raspberry Pi上,我认为Wayland尚未运行(截至2013年9月),但是在不使用包含的二进制驱动程序的显示服务器的情况下,您确实获得了EGL.如果您感兴趣的话,您的EGL代码也应该可以移植到iOS上(只需进行最少的修改).

Notably, on the Raspberry Pi and on Android, EGL and GL ES 2.0 (1.1 on Android < 3.0) are supported by default. On the Raspberry Pi, I don't think Wayland yet works (as of Sep. 2013), but you do get EGL without a display server using the included binary drivers. Your EGL code should also be portable (with minimal modification) to iOS, if that interests you.

以下是过时的,先前接受的帖子:

我想在Linux中打开不带X的OpenGL上下文.有什么办法吗?

I'd like to open an OpenGL context without X in linux. Is there any way at all to do it?

我相信Mesa提供了一个帧缓冲目标.如果它完全提供了任何硬件加速,那么它将仅与那些具有适用于这种用途的开源驱动程序的硬件一起使用.

I believe Mesa provides a framebuffer target. If it provides any hardware acceleration at all, it will only be with hardware for which there are open source drivers that have been adapted to support such a use.

Gallium3D也不成熟,据我所知,甚至对此路线的支持也没有.

Gallium3D is also immature, and support for this isn't even on the roadmap, as far as I know.

我想获得一种适用于nvidia卡的解决方案.

I'd like to get a solution that works with nvidia cards.

没有一个.期间.

NVIDIA仅提供X驱动程序,而Nouveau项目仍不成熟,并且不支持您正在寻找的使用类型,因为它们目前仅专注于X11驱动程序.

NVIDIA only provides an X driver, and the Nouveau project is still immature, and doesn't support the kind of use that you're looking for, as they are currently focused only on the X11 driver.

这篇关于在Linux中没有X.org的OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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