|
|
@@ -11,6 +11,8 @@
|
|
|
#include <QLibrary>
|
|
|
#include <QDebug>
|
|
|
|
|
|
+#include "LHQLogAPI.h"
|
|
|
+
|
|
|
|
|
|
|
|
|
void test();
|
|
|
@@ -18,17 +20,19 @@ void test();
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
- // 可选:强制走桌面 OpenGL(避免走 OpenGLES)
|
|
|
- // QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
|
|
|
-
|
|
|
+ // Windows 下优先强制走桌面 OpenGL(避免 Qt 走 ANGLE/OpenGLES 导致拿不到 3.3 Core 函数表)
|
|
|
+ // 注意:必须在 QApplication 构造之前设置。
|
|
|
+#if defined(Q_OS_WIN)
|
|
|
+ QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
|
|
|
+#endif
|
|
|
QSurfaceFormat fmt;
|
|
|
fmt.setRenderableType(QSurfaceFormat::OpenGL);
|
|
|
fmt.setVersion(3, 3);
|
|
|
- fmt.setProfile(QSurfaceFormat::CoreProfile); // 或 CompatibilityProfile
|
|
|
+ // Windows 驱动对 CoreProfile 的支持差异更大;兼容性 Profile 更容易创建成功。
|
|
|
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
|
|
|
fmt.setDepthBufferSize(24);
|
|
|
fmt.setStencilBufferSize(8);
|
|
|
// fmt.setSamples(4); // 需要抗锯齿就打开
|
|
|
-
|
|
|
QSurfaceFormat::setDefaultFormat(fmt);
|
|
|
|
|
|
QApplication a(argc, argv);
|
|
|
@@ -39,23 +43,21 @@ int main(int argc, char *argv[])
|
|
|
// 打印“请求的版本”(defaultFormat)
|
|
|
{
|
|
|
const QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
|
|
|
- qDebug() << "Requested Qt SurfaceFormat: renderable=" << fmt.renderableType()
|
|
|
- << "version=" << fmt.majorVersion() << "." << fmt.minorVersion()
|
|
|
- << "profile=" << fmt.profile();
|
|
|
+ LH_WRITE_LOG(QString("Requested Qt SurfaceFormat: renderable=%1 version=%2.%3 profile=%4")
|
|
|
+ .arg(fmt.renderableType() == QSurfaceFormat::OpenGL ? "OpenGL" :
|
|
|
+ fmt.renderableType() == QSurfaceFormat::OpenGLES ? "OpenGLES" : "Default")
|
|
|
+ .arg(fmt.majorVersion())
|
|
|
+ .arg(fmt.minorVersion())
|
|
|
+ .arg(fmt.profile() == QSurfaceFormat::CoreProfile ? "Core" :
|
|
|
+ fmt.profile() == QSurfaceFormat::CompatibilityProfile ? "Compatibility" : "NoProfile"));
|
|
|
}
|
|
|
|
|
|
widget w;
|
|
|
w.show();
|
|
|
|
|
|
- // 打印“实际创建到的版本”(创建 widget 后上下文通常已可用;更精确的实际值也会在 PlayerGLWidget::initializeGL() 中打印)
|
|
|
- if (QOpenGLContext::currentContext()) {
|
|
|
- const QSurfaceFormat fmt = QOpenGLContext::currentContext()->format();
|
|
|
- qDebug() << "Current Qt OpenGLContext: isOpenGLES=" << QOpenGLContext::currentContext()->isOpenGLES()
|
|
|
- << "version=" << fmt.majorVersion() << "." << fmt.minorVersion()
|
|
|
- << "profile=" << fmt.profile();
|
|
|
- } else {
|
|
|
- qDebug() << "Current Qt OpenGLContext: (null at main)";
|
|
|
- }
|
|
|
+ // 说明:在 main() 里通常不会有 current OpenGL context(要等 QOpenGLWidget::initializeGL/painGL)。
|
|
|
+ // 实际创建到的上下文与版本会在 PlayerGLWidget::initializeGL() 的日志中打印。
|
|
|
+ LH_WRITE_LOG("Current Qt OpenGLContext: (expected null at main; created when QOpenGLWidget initializes)");
|
|
|
|
|
|
return a.exec();
|
|
|
}
|