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

查看:19
本文介绍了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.

如果没有其他方法只能通过集成的英特尔硬件,我想知道如何使用这些硬件就可以了.

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 渲染,您可以在任何您喜欢的地方对像素缓冲区表面进行 blit.这篇来自 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 核心.

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天全站免登陆