0

I'm trying to develop an Apache2 module that utilizes OpenGL to perform off-screen rendering and dynamically generate images that I can then send back to the client.

Apache2 is running on an Ubuntu 12.04 machine and I created a test module that renders a quad and stores the frame as an image to disk using OpenGL/GLX. But when the module receives a client request, it crashes at XOpenDisplay(0) with a segmentation fault. Any ideas what could be going wrong?

Edit: All the examples I have seen talk about using a pixel buffer (PBuffer). As far as I know, these are deprecated and FBOs should be used instead. Can someone explain how to create a context and use FBOs to perform off-screen rendering?

1 Answer 1

4

While technically it's perfectly possible to do windowless, display server less off-screen GPU accelerated rendering with OpenGL, practically it's impossible these days because you need a display environment to actually get access to the GPU. Fortunately the structure of graphics systems is changing these days (Hybrid graphics, display compositors). Already Mesa provides an off-screen context creation mode (OSMesa), but it's far from being feature complete.

So right now, you'll need some kind of display server drawable to work with on which you can bind a context. X11 offers two kinds of GPU accelerated drawables: Windows and PBuffers. You can use FBOs with either (PBuffers are technically Windows that can not be mapped to the root window and have an off-screen canvas). The easiest way to go is to create a regular window on an X server but not showing it; you can still create an OpenGL context on it and create FBOs, like shown in numerous tutorials. But for OpenGL to work the X server you use must be active hold the console and be configured to use the GPU (theoretically with newer Hybrid graphics capable X servers and drivers it should be possible to configure the X server to use a dummy display device and configure the GPU as a secondary device for accelerated rendering, but I never tried that, so far).

Sign up to request clarification or add additional context in comments.

8 Comments

This is indeed very helpful. But can you elaborate on this part: "for OpenGL to work the X server you use must be active hold the console and be configured to use the GPU". The main problem I'm facing is not being able to open a display since XOpenDisplay() always fails. I tried passing NULL to get the number from the environment variable, but it still fails. I tested by starting Apache2 from the command line as a single process so that I can monitor the output on the console.
@informer2000: First make sure that there's actually a X server running. If so you must provide clients with the DISPLAY number and the path to the authorization info. When starting the X server use the -auth … option to specify the path where to place the authorization data (somewhere in /var/run or so) and make it readable by the webserver process. Set the XAUTHORITY environment variable to that path then.
Thanks datenwolf. But I don't see what I'm doing differently from what you mentioned. I checked the DISPLAY variable from my code and it does get the correct value (:0.0). So I guess XOpenDisplay() is called with that value. The client app for the X server would be my module (or basically Apache). XAUTHORITY points to the .Xauthority file in my user's home. Since I am launching Apache from the command line as a single process, my user is probably the one owning the process.
The only thing I can think of is that perhaps the owner of the child process is say www-data which doesn't have access to the .Xauthority file!
@informer2000: The frame probably came back, because the X servver you were using was not the one holding the terminal at the moment of doing the OpenGL rendering. For OpenGL to work with current X servers, the X server used must be one, that is currently producing output on a display connector. If you start a second X server on your machine, but then switch back to your session, the other X server can not product OpenGL output (with current drivers).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.