bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.62k stars 1.92k forks source link

windowless offscreen rendering #1285

Open dbacchet opened 6 years ago

dbacchet commented 6 years ago

Question Hi, is there any way to use bgfx for offscreen/windowless rendering? I'm interested in running (mainly OpenGL in my case) applications on servers that don't always have the X system available. Creating a window on those systems will return a NULL handle, but it's usually possible to create a context for example using EGL (or CGL on mac...).

thanks for releasing bgfx to the community!

bkaradzic commented 6 years ago

Yes and no. Servers or service apps usually don't have access to GPU, and it causes initialization to fail even if you have ability to create window. On Windows in one case I did work around by exposing software rasterizer, but I never dealt with OpenGL. Modern APIs actually allow this windowless rendering. Anyhow if you know examples of windowless OpenGL context post link with example here.

dbacchet commented 6 years ago

this is a decent article about how to use EGL in linux: https://devblogs.nvidia.com/parallelforall/egl-eye-opengl-visualization-without-x-server/ A very similar concept applies to macOS, with CGL: http://renderingpipeline.com/2012/05/windowless-opengl-on-macos-x/ (a little old) and the corresponding API explanation is at: https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html No idea about Windows, honestly...

thanks for looking into this!

adminradio commented 6 years ago

Hi, I'm also interested in a windowless render solution (GLSL). Do you know 'Spout2' - a open source inter process communication library for OpenGL and DirectX? They do a lot of headless FBO transfers between CPU and GPU. Maybe it's worth a look: https://github.com/leadedge/Spout2

I'm in need of a backbuffer renderer (or a service daemon) for image manipulation with GLSL. Which I want to control with a JavaFX/JDK1.9 backend (via fragmentshader preprocessing and uniform variable manipulating. Transferspeed does not really matter, but processing and analyzing speed. :)

RicoP commented 6 years ago

If you just want to run the application without a window on a Linux machine without doing anything with the pixel output you can just run Xvfb and initialize bgfx with the bgfx::RendererType::Noop flag.

Just run those commands before you start your bgfx app.

export DISPLAY=':99.0' Xvfb :99 -screen 0 1280x720x24 > /dev/null 2>/tmp/xvfb.err &

bkaradzic commented 6 years ago

@RicoP They need GPU support without window. Noop provides no GPU support.

PyryM commented 6 years ago

You can use the Mesa llvmpipe driver alongside Xvfb to do headless on a machine without a graphics card: https://github.com/OKaluza/LavaVu/wiki/Headless-rendering. According to the stats posted for the drawstress example, bgfx can run with llvmpipe: https://bkaradzic.github.io/bgfx/examples.html#drawstress.