should_use_software() {
  if ! command -v glxinfo >/dev/null 2>&1; then
    echo "glxinfo missing → assuming software fallback needed"
    return 0
  fi

  local direct core_ver

  direct=$(glxinfo | grep -i '^direct rendering:' | awk '{print $3}' || echo "No")
  if [[ "$direct" != "Yes" ]]; then
    echo "No direct rendering → force software"
    return 0
  fi

  # Prefer core profile version string (most reliable)
  core_ver=$(glxinfo | grep -i "OpenGL core profile version string" | grep -oE '[0-9]+\.[0-9]+' | head -n1)
  if [[ -z "$core_ver" ]]; then
    # Fallback to max core profile line if present
    core_ver=$(glxinfo | grep -i "Max core profile" | grep -oE '[0-9]+\.[0-9]+' | head -n1)
  fi

  echo "Detected OpenGL core: ${core_ver:-unknown}"

  if [[ "$core_ver" =~ ^(3\.[3-9]|[4-9]\.) ]]; then
    echo "Hardware OK (≥3.3 core)"
    return 1
  fi

  # Optional GLES fallback check (as you had)
  if command -v eglinfo >/dev/null 2>&1; then
    local es_ver=$(eglinfo | grep -oE 'OpenGL ES [0-9]+\.[0-9]+' | grep -oE '[0-9]+\.[0-9]+' | head -n1)
    if [[ "$es_ver" =~ ^[3-9]\. ]]; then
      echo "GLES ${es_ver} fallback OK"
      return 1
    fi
  fi

  echo "Insufficient OpenGL → force software"
  return 0
}
