KUserFeedback

openglinfosource.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "openglinfosource.h"
8#include "openglinfosource_p.h"
9
10#include <QVariant>
11#ifndef QT_NO_OPENGL
12#include <QOpenGLContext>
13#include <QOpenGLFunctions>
14#include <QSurfaceFormat>
15#include <QWindow>
16#include "logging_p.h"
17#endif
18
19using namespace KUserFeedback;
20
21OpenGLInfoSource::OpenGLInfoSource()
22 : AbstractDataSource(QStringLiteral("opengl"), Provider::DetailedSystemInformation)
23{
24}
25
27{
28 return tr("Information about type, version and vendor of the OpenGL stack.");
29}
30
32{
33 QVariantMap m;
34
35#ifndef QT_NO_OPENGL
36 QOpenGLContext context;
37 if (context.create()) {
38 QWindow window;
40 window.create();
41 if (!context.makeCurrent(&window)) {
42 qCWarning(Log) << "Could not make OpenGL context current";
43 m.insert(QStringLiteral("type"), QStringLiteral("none"));
44 return m;
45 }
46 QOpenGLFunctions functions(&context);
47 m.insert(QStringLiteral("vendor"), OpenGLInfoSourcePrivate::normalizeVendor(reinterpret_cast<const char*>(functions.glGetString(GL_VENDOR))));
48 m.insert(QStringLiteral("renderer"), OpenGLInfoSourcePrivate::normalizeRenderer(reinterpret_cast<const char*>(functions.glGetString(GL_RENDERER))));
49
50 switch (context.openGLModuleType()) {
52 {
53 m.insert(QStringLiteral("type"), QStringLiteral("GL"));
54
55#if defined(GL_MAJOR_VERSION) && defined(GL_MINOR_VERSION)
56 int major = 0, minor = 0;
57 functions.glGetIntegerv(GL_MAJOR_VERSION, &major);
58 functions.glGetIntegerv(GL_MINOR_VERSION, &minor);
59 // e.g. macOS legacy profiles return 0.0 here...
60 if (major > 0)
61 m.insert(QStringLiteral("version"), QString(QString::number(major) + QLatin1Char('.') + QString::number(minor)));
62#endif
63
64 OpenGLInfoSourcePrivate::parseGLVersion(reinterpret_cast<const char*>(functions.glGetString(GL_VERSION)), m);
65 OpenGLInfoSourcePrivate::parseGLSLVersion(reinterpret_cast<const char*>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION)), m);
66 break;
67 }
69 {
70 m.insert(QStringLiteral("type"), QStringLiteral("GLES"));
71 OpenGLInfoSourcePrivate::parseGLESVersion(reinterpret_cast<const char*>(functions.glGetString(GL_VERSION)), m);
72 OpenGLInfoSourcePrivate::parseESGLSLVersion(reinterpret_cast<const char*>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION)), m);
73 break;
74 }
75 }
76
77 switch (context.format().profile()) {
79 break;
81 m.insert(QStringLiteral("profile"), QStringLiteral("core"));
82 break;
84 m.insert(QStringLiteral("profile"), QStringLiteral("compat"));
85 break;
86 }
87
88 return m;
89 }
90#endif
91
92 m.insert(QStringLiteral("type"), QStringLiteral("none"));
93 return m;
94}
95
97{
98 return tr("OpenGL information");
99}
Base class for data sources for telemetry data.
QString description() const override
Returns a human-readable, translated description of what this source provides.
QString name() const override
Returns a short name of this data source.
QVariant data() override
Returns the data gathered by this source.
The central object managing data sources and transmitting feedback to the server.
Definition provider.h:32
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
QSurfaceFormat format() const const
bool makeCurrent(QSurface *surface)
OpenGLModuleType openGLModuleType()
void glGetIntegerv(GLenum pname, GLint *params)
const GLubyte * glGetString(GLenum name)
QString number(double n, char format, int precision)
OpenGLContextProfile profile() const const
void create()
void setSurfaceType(SurfaceType surfaceType)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.