142 bool adjustGlobalState)
144 const QSurfaceFormat &format = rendererConfig.
format;
149 QScopedPointer<AppAttributeSetter> sharedContextSetter;
150 QScopedPointer<AppAttributeSetter> glSetter;
151 QScopedPointer<AppAttributeSetter> glesSetter;
152 QScopedPointer<SurfaceFormatSetter> formatSetter;
153 QScopedPointer<EnvironmentSetter> rendererSetter;
154 QScopedPointer<EnvironmentSetter> portalSetter;
155 QScopedPointer<QGuiApplication> application;
158 QByteArray probeAppName(
"krita");
159 char *argv = probeAppName.data();
162 if (adjustGlobalState) {
163 sharedContextSetter.reset(
new AppAttributeSetter(Qt::AA_ShareOpenGLContexts,
false));
165 if (format.renderableType() != QSurfaceFormat::DefaultRenderableType) {
166 glSetter.reset(
new AppAttributeSetter(Qt::AA_UseDesktopOpenGL, format.renderableType() != QSurfaceFormat::OpenGLES));
167 glesSetter.reset(
new AppAttributeSetter(Qt::AA_UseOpenGLES, format.renderableType() == QSurfaceFormat::OpenGLES));
170 if (!qEnvironmentVariableIsSet(
"QT_ANGLE_PLATFORM")) {
173 portalSetter.reset(
new EnvironmentSetter(QLatin1String(
"QT_NO_XDG_DESKTOP_PORTAL"), QLatin1String(
"1")));
174 formatSetter.reset(
new SurfaceFormatSetter(format));
178 const bool runningInKDE = qEnvironmentVariableIsSet(
"KDE_FULL_SESSION");
179 const bool isInAppimage = qEnvironmentVariableIsSet(
"APPIMAGE");
181 if (runningInKDE && !isInAppimage) {
182 QGuiApplication::setDesktopSettingsAware(
false);
185 application.reset(
new QGuiApplication(argc, &argv));
187 if (runningInKDE && !isInAppimage) {
188 QGuiApplication::setDesktopSettingsAware(
true);
194 surface.setFormat(format);
195 surface.setSurfaceType(QSurface::OpenGLSurface);
197 QOpenGLContext context;
198 context.setFormat(format);
201 if (!context.create()) {
202 dbgOpenGL <<
"OpenGL context cannot be created";
205 if (!context.isValid()) {
206 dbgOpenGL <<
"OpenGL context is not valid while checking Qt's OpenGL status";
209 if (!context.makeCurrent(&surface)) {
210 dbgOpenGL <<
"OpenGL context cannot be made current";
218 dbgOpenGL <<
"Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() <<
"Actual:" << context.format().colorSpace();
222 if (format.redBufferSize() > 0 && format.greenBufferSize() > 0 && format.blueBufferSize() > 0
223 && (context.format().redBufferSize() != format.redBufferSize()
224 || context.format().greenBufferSize() != format.greenBufferSize()
225 || context.format().blueBufferSize() != format.blueBufferSize())) {
227 dbgOpenGL <<
"Failed to create an OpenGL context with requested bit depth. Requested:" << format.redBufferSize()
228 <<
"Actual:" << context.format().redBufferSize();
249 QSurfaceFormat *format)
257 format->setRedBufferSize(10);
258 format->setGreenBufferSize(10);
259 format->setBlueBufferSize(10);
260 format->setAlphaBufferSize(2);
264 format->setRedBufferSize(16);
265 format->setGreenBufferSize(16);
266 format->setBlueBufferSize(16);
267 format->setAlphaBufferSize(16);
271 format->setRedBufferSize(8);
272 format->setGreenBufferSize(8);
273 format->setBlueBufferSize(8);
274 format->setAlphaBufferSize(8);
284 qWarning() <<
"WARNING: Bt.2020 PQ surface type is not supported by this build of Krita";
287 qWarning() <<
"WARNING: scRGB surface type is not supported by this build of Krita";
293 if (rootSurfaceFormat.second == 10) {
294 format->setRedBufferSize(10);
295 format->setGreenBufferSize(10);
296 format->setBlueBufferSize(10);
297 format->setAlphaBufferSize(2);
301 format->setRedBufferSize(8);
302 format->setGreenBufferSize(8);
303 format->setBlueBufferSize(8);
304 format->setAlphaBufferSize(8);
318 format.redBufferSize() == 10 &&
319 format.greenBufferSize() == 10 &&
320 format.blueBufferSize() == 10 &&
321 format.alphaBufferSize() == 2;
325 format.redBufferSize() == 16 &&
326 format.greenBufferSize() == 16 &&
327 format.blueBufferSize() == 16 &&
328 format.alphaBufferSize() == 16;
330 return isBt2020PQ || isBt709G10;
359 if (!context.isValid()) {
363 QOpenGLFunctions *funcs = context.functions();
367 m_vendorString = QString(
reinterpret_cast<const char *
>(funcs->glGetString(GL_VENDOR)));
368 m_shadingLanguageString = QString(
reinterpret_cast<const char *
>(funcs->glGetString(GL_SHADING_LANGUAGE_VERSION)));
374 m_supportsFBO = context.functions()->hasOpenGLFeature(QOpenGLFunctions::Framebuffers);
378 context.hasExtension(
"GL_OES_mapbuffer") ||
379 context.hasExtension(
"GL_EXT_map_buffer_range") ||
380 context.hasExtension(
"GL_ARB_map_buffer_range");
384 context.hasExtension(
"GL_ARB_invalidate_subdata"));
385 m_supportsLod = context.format().majorVersion() >= 3 || (
m_isOpenGLES && context.hasExtension(
"GL_EXT_shader_texture_lod"));
388 if (QApplication::platformName() ==
"xcb") {
389 QPlatformNativeInterface *native = qApp->platformNativeInterface();
390 if (native->nativeResourceFunctionForContext(
"eglcontext")) {
392 }
else if (native->nativeResourceFunctionForContext(
"glxcontext")) {
395 qWarning() <<
"WARNING: Failed to detect QXcbGlIntegration type!";