Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwinglutils_funcs.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | 20 | | |||
21 | #include "kwinglutils.h" | 21 | #include "kwinglutils.h" | ||
22 | #include "kwinglplatform.h" | 22 | #include "kwinglplatform.h" | ||
23 | 23 | | |||
24 | #include <dlfcn.h> | | |||
25 | #if HAVE_EPOXY_GLX | | |||
26 | #include <epoxy/glx.h> | | |||
27 | #endif | | |||
28 | | ||||
29 | 24 | | |||
30 | // Resolves given function, using getProcAddress | 25 | // Resolves given function, using getProcAddress | ||
31 | #define GL_RESOLVE( function ) \ | | |||
32 | if (platformInterface == GlxPlatformInterface) \ | | |||
33 | function = (function ## _func)getProcAddress( #function ); \ | | |||
34 | else if (platformInterface == EglPlatformInterface) \ | | |||
35 | function = (function ## _func)eglGetProcAddress( #function ); | | |||
36 | // Same as above but tries to use function "symbolName" | | |||
37 | // Useful when functionality is defined in an extension with a different name | 26 | // Useful when functionality is defined in an extension with a different name | ||
broulik: There's nothing above anymore | |||||
38 | #define GL_RESOLVE_WITH_EXT( function, symbolName ) \ | 27 | #define GL_RESOLVE_WITH_EXT( function, symbolName ) \ | ||
39 | if (platformInterface == GlxPlatformInterface) { \ | 28 | function = (function ## _func)resolveFunction( #symbolName ); | ||
40 | function = (function ## _func)getProcAddress( #symbolName ); \ | | |||
41 | } else if (platformInterface == EglPlatformInterface) { \ | | |||
42 | function = (function ## _func)eglGetProcAddress( #symbolName ); \ | | |||
43 | } | | |||
44 | 29 | | |||
45 | namespace KWin | 30 | namespace KWin | ||
46 | { | 31 | { | ||
47 | 32 | | |||
48 | static GLenum GetGraphicsResetStatus(); | 33 | static GLenum GetGraphicsResetStatus(); | ||
49 | static void ReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, | 34 | static void ReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, | ||
50 | GLenum type, GLsizei bufSize, GLvoid *data); | 35 | GLenum type, GLsizei bufSize, GLvoid *data); | ||
51 | static void GetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params); | 36 | static void GetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params); | ||
52 | 37 | | |||
53 | // GL_ARB_robustness / GL_EXT_robustness | 38 | // GL_ARB_robustness / GL_EXT_robustness | ||
54 | glGetGraphicsResetStatus_func glGetGraphicsResetStatus; | 39 | glGetGraphicsResetStatus_func glGetGraphicsResetStatus; | ||
55 | glReadnPixels_func glReadnPixels; | 40 | glReadnPixels_func glReadnPixels; | ||
56 | glGetnUniformfv_func glGetnUniformfv; | 41 | glGetnUniformfv_func glGetnUniformfv; | ||
57 | 42 | | |||
58 | typedef void (*glXFuncPtr)(); | | |||
59 | | ||||
60 | static glXFuncPtr getProcAddress(const char* name) | | |||
61 | { | | |||
62 | glXFuncPtr ret = nullptr; | | |||
63 | #if HAVE_EPOXY_GLX | | |||
64 | ret = glXGetProcAddress((const GLubyte*) name); | | |||
65 | #endif | | |||
66 | if (ret == nullptr) | | |||
67 | ret = (glXFuncPtr) dlsym(RTLD_DEFAULT, name); | | |||
68 | return ret; | | |||
69 | } | | |||
70 | | ||||
71 | void eglResolveFunctions() | 43 | void eglResolveFunctions() | ||
72 | { | 44 | { | ||
73 | } | 45 | } | ||
74 | 46 | | |||
75 | void glResolveFunctions(OpenGLPlatformInterface platformInterface) | 47 | void glResolveFunctions(std::function<resolveFuncPtr(const char*)> resolveFunction) | ||
76 | { | 48 | { | ||
77 | const bool haveArbRobustness = hasGLExtension(QByteArrayLiteral("GL_ARB_robustness")); | 49 | const bool haveArbRobustness = hasGLExtension(QByteArrayLiteral("GL_ARB_robustness")); | ||
78 | const bool haveExtRobustness = hasGLExtension(QByteArrayLiteral("GL_EXT_robustness")); | 50 | const bool haveExtRobustness = hasGLExtension(QByteArrayLiteral("GL_EXT_robustness")); | ||
79 | bool robustContext = false; | 51 | bool robustContext = false; | ||
80 | if (GLPlatform::instance()->isGLES()) { | 52 | if (GLPlatform::instance()->isGLES()) { | ||
81 | if (haveExtRobustness) { | 53 | if (haveExtRobustness) { | ||
82 | GLint value = 0; | 54 | GLint value = 0; | ||
83 | glGetIntegerv(GL_CONTEXT_ROBUST_ACCESS_EXT, &value); | 55 | glGetIntegerv(GL_CONTEXT_ROBUST_ACCESS_EXT, &value); | ||
Show All 14 Lines | |||||
98 | } | 70 | } | ||
99 | if (robustContext && haveArbRobustness) { | 71 | if (robustContext && haveArbRobustness) { | ||
100 | // See http://www.opengl.org/registry/specs/ARB/robustness.txt | 72 | // See http://www.opengl.org/registry/specs/ARB/robustness.txt | ||
101 | GL_RESOLVE_WITH_EXT(glGetGraphicsResetStatus, glGetGraphicsResetStatusARB); | 73 | GL_RESOLVE_WITH_EXT(glGetGraphicsResetStatus, glGetGraphicsResetStatusARB); | ||
102 | GL_RESOLVE_WITH_EXT(glReadnPixels, glReadnPixelsARB); | 74 | GL_RESOLVE_WITH_EXT(glReadnPixels, glReadnPixelsARB); | ||
103 | GL_RESOLVE_WITH_EXT(glGetnUniformfv, glGetnUniformfvARB); | 75 | GL_RESOLVE_WITH_EXT(glGetnUniformfv, glGetnUniformfvARB); | ||
104 | } else if (robustContext && haveExtRobustness) { | 76 | } else if (robustContext && haveExtRobustness) { | ||
105 | // See http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt | 77 | // See http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt | ||
106 | glGetGraphicsResetStatus = (glGetGraphicsResetStatus_func) eglGetProcAddress("glGetGraphicsResetStatusEXT"); | 78 | glGetGraphicsResetStatus = (glGetGraphicsResetStatus_func) resolveFunction("glGetGraphicsResetStatusEXT"); | ||
107 | glReadnPixels = (glReadnPixels_func) eglGetProcAddress("glReadnPixelsEXT"); | 79 | glReadnPixels = (glReadnPixels_func) resolveFunction("glReadnPixelsEXT"); | ||
108 | glGetnUniformfv = (glGetnUniformfv_func) eglGetProcAddress("glGetnUniformfvEXT"); | 80 | glGetnUniformfv = (glGetnUniformfv_func) resolveFunction("glGetnUniformfvEXT"); | ||
109 | } else { | 81 | } else { | ||
110 | glGetGraphicsResetStatus = KWin::GetGraphicsResetStatus; | 82 | glGetGraphicsResetStatus = KWin::GetGraphicsResetStatus; | ||
111 | glReadnPixels = KWin::ReadnPixels; | 83 | glReadnPixels = KWin::ReadnPixels; | ||
112 | glGetnUniformfv = KWin::GetnUniformfv; | 84 | glGetnUniformfv = KWin::GetnUniformfv; | ||
113 | } | 85 | } | ||
114 | } | 86 | } | ||
115 | 87 | | |||
116 | static GLenum GetGraphicsResetStatus() | 88 | static GLenum GetGraphicsResetStatus() | ||
Show All 18 Lines |
There's nothing above anymore