138 bool adjustGlobalState)
140 const QSurfaceFormat &format = rendererConfig.
format;
145 QScopedPointer<AppAttributeSetter> sharedContextSetter;
146 QScopedPointer<AppAttributeSetter> glSetter;
147 QScopedPointer<AppAttributeSetter> glesSetter;
148 QScopedPointer<SurfaceFormatSetter> formatSetter;
149 QScopedPointer<EnvironmentSetter> rendererSetter;
150 QScopedPointer<EnvironmentSetter> portalSetter;
151 QScopedPointer<QGuiApplication> application;
154 QByteArray probeAppName(
"krita");
155 char *argv = probeAppName.data();
158 if (adjustGlobalState) {
159 sharedContextSetter.reset(
new AppAttributeSetter(Qt::AA_ShareOpenGLContexts,
false));
161 if (format.renderableType() != QSurfaceFormat::DefaultRenderableType) {
162 glSetter.reset(
new AppAttributeSetter(Qt::AA_UseDesktopOpenGL, format.renderableType() != QSurfaceFormat::OpenGLES));
163 glesSetter.reset(
new AppAttributeSetter(Qt::AA_UseOpenGLES, format.renderableType() == QSurfaceFormat::OpenGLES));
166 if (!qEnvironmentVariableIsSet(
"QT_ANGLE_PLATFORM")) {
169 portalSetter.reset(
new EnvironmentSetter(QLatin1String(
"QT_NO_XDG_DESKTOP_PORTAL"), QLatin1String(
"1")));
170 formatSetter.reset(
new SurfaceFormatSetter(format));
174 const bool runningInKDE = qEnvironmentVariableIsSet(
"KDE_FULL_SESSION");
175 const bool isInAppimage = qEnvironmentVariableIsSet(
"APPIMAGE");
177 if (runningInKDE && !isInAppimage) {
178 QGuiApplication::setDesktopSettingsAware(
false);
181 application.reset(
new QGuiApplication(argc, &argv));
183 if (runningInKDE && !isInAppimage) {
184 QGuiApplication::setDesktopSettingsAware(
true);
190 surface.setFormat(format);
191 surface.setSurfaceType(QSurface::OpenGLSurface);
193 QOpenGLContext context;
194 context.setFormat(format);
197 if (!context.create()) {
198 dbgOpenGL <<
"OpenGL context cannot be created";
201 if (!context.isValid()) {
202 dbgOpenGL <<
"OpenGL context is not valid while checking Qt's OpenGL status";
205 if (!context.makeCurrent(&surface)) {
206 dbgOpenGL <<
"OpenGL context cannot be made current";
214 dbgOpenGL <<
"Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() <<
"Actual:" << context.format().colorSpace();
218 if (format.redBufferSize() > 0 && format.greenBufferSize() > 0 && format.blueBufferSize() > 0
219 && (context.format().redBufferSize() != format.redBufferSize()
220 || context.format().greenBufferSize() != format.greenBufferSize()
221 || context.format().blueBufferSize() != format.blueBufferSize())) {
223 dbgOpenGL <<
"Failed to create an OpenGL context with requested bit depth. Requested:" << format.redBufferSize()
224 <<
"Actual:" << context.format().redBufferSize();
245 QSurfaceFormat *format)
253 format->setRedBufferSize(10);
254 format->setGreenBufferSize(10);
255 format->setBlueBufferSize(10);
256 format->setAlphaBufferSize(2);
260 format->setRedBufferSize(16);
261 format->setGreenBufferSize(16);
262 format->setBlueBufferSize(16);
263 format->setAlphaBufferSize(16);
267 format->setRedBufferSize(8);
268 format->setGreenBufferSize(8);
269 format->setBlueBufferSize(8);
270 format->setAlphaBufferSize(8);
280 qWarning() <<
"WARNING: Bt.2020 PQ surface type is not supported by this build of Krita";
283 qWarning() <<
"WARNING: scRGB surface type is not supported by this build of Krita";
289 if (rootSurfaceFormat.second == 10) {
290 format->setRedBufferSize(10);
291 format->setGreenBufferSize(10);
292 format->setBlueBufferSize(10);
293 format->setAlphaBufferSize(2);
297 format->setRedBufferSize(8);
298 format->setGreenBufferSize(8);
299 format->setBlueBufferSize(8);
300 format->setAlphaBufferSize(8);
314 format.redBufferSize() == 10 &&
315 format.greenBufferSize() == 10 &&
316 format.blueBufferSize() == 10 &&
317 format.alphaBufferSize() == 2;
321 format.redBufferSize() == 16 &&
322 format.greenBufferSize() == 16 &&
323 format.blueBufferSize() == 16 &&
324 format.alphaBufferSize() == 16;
326 return isBt2020PQ || isBt709G10;
355 if (!context.isValid()) {
359 QOpenGLFunctions *funcs = context.functions();
363 m_vendorString = QString(
reinterpret_cast<const char *
>(funcs->glGetString(GL_VENDOR)));
364 m_shadingLanguageString = QString(
reinterpret_cast<const char *
>(funcs->glGetString(GL_SHADING_LANGUAGE_VERSION)));
370 m_supportsFBO = context.functions()->hasOpenGLFeature(QOpenGLFunctions::Framebuffers);
374 context.hasExtension(
"GL_OES_mapbuffer") ||
375 context.hasExtension(
"GL_EXT_map_buffer_range") ||
376 context.hasExtension(
"GL_ARB_map_buffer_range");
380 context.hasExtension(
"GL_ARB_invalidate_subdata"));
381 m_supportsLod = context.format().majorVersion() >= 3 || (
m_isOpenGLES && context.hasExtension(
"GL_EXT_shader_texture_lod"));