#!/bin/bash # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2026 Open-IOV contributors # gzdoom_pbuf_run.sh - in-guest GZDoom run recipe for the offscreen SDL2 # GLX-pbuffer harness. Run this inside the guest after push_gl_tools.sh has # placed the shims in /tmp. It prints the exact command line, runs GZDoom # under timeout, and leaves the output in $GZLOG. # # Environment (all overridable): # GZDOOM_BIN default /opt/gzdoom/gzdoom # WAD default /usr/share/games/doom/freedoom2.wad # GZCAP default /tmp/gzframes.bin (sdl_cap.so capture file) # GZPBUF_W/H default 640/480 (gz_pbuf.so pbuffer size) # GZLOG default /tmp/gzdoom-pbuf.log # TIMEOUT default 300 seconds # GZ_ARGS extra GZDoom args appended after the base set # GZ_DETACH default 0; set 1 to setsid/nohup the run and return # DISPLAY default :0 # # The base args are windowed GL: +set vid_fullscreen 0, 640x480, OpenGL # backend 0, +vid_rendermode 4 (GL mode), MAP01. The preload order matters: # sdl_cap.so first (captures SDL_GL_SwapWindow), gz_pbuf.so second (turns the # SDL GL context into a GLX pbuffer and the swap into glFinish). set -u GZDOOM_BIN="${GZDOOM_BIN:-/opt/gzdoom/gzdoom}" WAD="${WAD:-/usr/share/games/doom/freedoom2.wad}" GZCAP="${GZCAP:-/tmp/gzframes.bin}" GZPBUF_W="${GZPBUF_W:-640}" GZPBUF_H="${GZPBUF_H:-480}" GZLOG="${GZLOG:-/tmp/gzdoom-pbuf.log}" TIMEOUT="${TIMEOUT:-300}" GZ_ARGS="${GZ_ARGS:-}" GZ_DETACH="${GZ_DETACH:-0}" DISPLAY="${DISPLAY:-:0}" SDL_VIDEODRIVER="${SDL_VIDEODRIVER:-offscreen}" LD_PRELOAD="${LD_PRELOAD:-/tmp/sdl_cap.so /tmp/gz_pbuf.so}" export DISPLAY SDL_VIDEODRIVER LD_PRELOAD GZCAP GZPBUF_W GZPBUF_H if [ ! -x "$GZDOOM_BIN" ]; then echo "gzdoom_pbuf_run: GZDOOM_BIN not executable: $GZDOOM_BIN" >&2 exit 2 fi if [ ! -f "$WAD" ]; then echo "gzdoom_pbuf_run: WAD not found: $WAD" >&2 exit 2 fi for so in /tmp/sdl_cap.so /tmp/gz_pbuf.so; do if [ ! -f "$so" ]; then echo "gzdoom_pbuf_run: shim missing: $so" >&2 exit 2 fi done CMD=( "$GZDOOM_BIN" -iwad "$WAD" +set vid_fullscreen 0 +set vid_defwidth "$GZPBUF_W" +set vid_defheight "$GZPBUF_H" +set vid_preferbackend 0 +vid_rendermode 4 -nosound -nomusic +vid_activeinbackground 1 +vid_maxfps 60 +map MAP01 ) if [ -n "$GZ_ARGS" ]; then read -r -a GZ_EXTRA <<< "$GZ_ARGS" CMD+=("${GZ_EXTRA[@]}") fi echo "gzdoom_pbuf_run: DISPLAY=$DISPLAY SDL_VIDEODRIVER=$SDL_VIDEODRIVER" echo "gzdoom_pbuf_run: LD_PRELOAD=$LD_PRELOAD" echo "gzdoom_pbuf_run: GZCAP=$GZCAP GZPBUF_W=$GZPBUF_W GZPBUF_H=$GZPBUF_H" echo "gzdoom_pbuf_run: LOG=$GZLOG TIMEOUT=$TIMEOUT DETACH=$GZ_DETACH" printf 'CMD:' printf ' %q' "${CMD[@]}" echo if [ "$GZ_DETACH" = "1" ]; then setsid nohup timeout "$TIMEOUT" "${CMD[@]}" > "$GZLOG" 2>&1 < /dev/null & echo "PID=$!" echo "LOG=$GZLOG" exit 0 fi timeout "$TIMEOUT" "${CMD[@]}" > "$GZLOG" 2>&1 rc=$? echo "RC=$rc" echo "LOG=$GZLOG" exit "$rc"