File indexing completed on 2024-11-10 04:56:55
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2007 Rivo Laks <rivolaks@hot.ee> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "opengl/glplatform.h" 0011 #include "opengl/glutils.h" 0012 0013 // Resolves given function, using getProcAddress 0014 // Useful when functionality is defined in an extension with a different name 0015 #define GL_RESOLVE_WITH_EXT(function, symbolName) \ 0016 function = (function##_func)resolveFunction(#symbolName); 0017 0018 namespace KWin 0019 { 0020 0021 static GLenum GetGraphicsResetStatus(); 0022 static void ReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, 0023 GLenum type, GLsizei bufSize, GLvoid *data); 0024 static void GetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params); 0025 0026 // GL_ARB_robustness / GL_EXT_robustness 0027 glGetGraphicsResetStatus_func glGetGraphicsResetStatus; 0028 glReadnPixels_func glReadnPixels; 0029 glGetnUniformfv_func glGetnUniformfv; 0030 0031 void glResolveFunctions(const std::function<resolveFuncPtr(const char *)> &resolveFunction) 0032 { 0033 const bool haveArbRobustness = hasGLExtension(QByteArrayLiteral("GL_ARB_robustness")); 0034 const bool haveExtRobustness = hasGLExtension(QByteArrayLiteral("GL_EXT_robustness")); 0035 bool robustContext = false; 0036 if (GLPlatform::instance()->isGLES()) { 0037 if (haveExtRobustness) { 0038 GLint value = 0; 0039 glGetIntegerv(GL_CONTEXT_ROBUST_ACCESS_EXT, &value); 0040 robustContext = (value != 0); 0041 } 0042 } else { 0043 if (haveArbRobustness) { 0044 if (hasGLVersion(3, 0)) { 0045 GLint value = 0; 0046 glGetIntegerv(GL_CONTEXT_FLAGS, &value); 0047 if (value & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB) { 0048 robustContext = true; 0049 } 0050 } else { 0051 robustContext = true; 0052 } 0053 } 0054 } 0055 if (robustContext && haveArbRobustness) { 0056 // See https://www.opengl.org/registry/specs/ARB/robustness.txt 0057 GL_RESOLVE_WITH_EXT(glGetGraphicsResetStatus, glGetGraphicsResetStatusARB); 0058 GL_RESOLVE_WITH_EXT(glReadnPixels, glReadnPixelsARB); 0059 GL_RESOLVE_WITH_EXT(glGetnUniformfv, glGetnUniformfvARB); 0060 } else if (robustContext && haveExtRobustness) { 0061 // See https://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt 0062 glGetGraphicsResetStatus = (glGetGraphicsResetStatus_func)resolveFunction("glGetGraphicsResetStatusEXT"); 0063 glReadnPixels = (glReadnPixels_func)resolveFunction("glReadnPixelsEXT"); 0064 glGetnUniformfv = (glGetnUniformfv_func)resolveFunction("glGetnUniformfvEXT"); 0065 } else { 0066 glGetGraphicsResetStatus = KWin::GetGraphicsResetStatus; 0067 glReadnPixels = KWin::ReadnPixels; 0068 glGetnUniformfv = KWin::GetnUniformfv; 0069 } 0070 } 0071 0072 static GLenum GetGraphicsResetStatus() 0073 { 0074 return GL_NO_ERROR; 0075 } 0076 0077 static void ReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, 0078 GLenum type, GLsizei bufSize, GLvoid *data) 0079 { 0080 glReadPixels(x, y, width, height, format, type, data); 0081 } 0082 0083 static void GetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params) 0084 { 0085 glGetUniformfv(program, location, params); 0086 } 0087 0088 } // namespace