我正在尝试将 Cesium 嵌入到 QT 5.2 应用程序中,
我正在加载一个存储在 qrc 资源中的 html 文件,该文件创建一个 Cesium.Viewer 小部件并使用 stats.min.js 监视其 framePerSecond 性能。
查看器.html:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version (or Chrome Frame if pre-IE11). -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum- scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="Cesium/Cesium.js"></script>
<script src="stats.min.js"></script>
<style>
@import url(Cesium/Widgets/widgets.css);
#cesiumContainer {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
margin: 0;
overflow: hidden;
padding: 0;
font-family: sans-serif;
}
body {
padding: 0;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
var stats = new Stats();
// Align top-left
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
document.body.appendChild( stats.domElement );
setInterval( function () {
stats.update();
}, 1000 / 60 );
var widget = new Cesium.Viewer('cesiumContainer');
</script>
</body>
</html>
在 QT 方面,我有以下代码:
#include <QApplication>
#include <QWebView>
#include <QWebPage>
#include <QGraphicsView>
#include <QGraphicsWebView>
#include <QGLWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView *gview;
QGraphicsScene *scene;
QGraphicsWebView *web_view;
QWebSettings::globalSettings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, true);
gview = new QGraphicsView();
gview->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
gview->setViewport(new QGLWidget());
scene = new QGraphicsScene(gview);
web_view = new QGraphicsWebView();
scene->addItem(web_view);
gview->setScene(scene);
web_view->load(QUrl("qrc:/Resources/Viewer.html"));
web_view->resize(1500, 900);
gview->resize(1550, 950);
gview->show();
return a.exec();
}
我遇到了 framePerSecond 速率的问题,使用 QWebView 小部件,fps 值不超过 20 fps,使用 QGraphicsView,QGraphicsWebView(如上),fps 值更好但不超过 30 fps。如果我向查看器添加几何图形,则 fps 速率会减慢。
浏览器的 60 fps 速率似乎无法达到。我在 QT 设置上做错了吗?任何想法?。