2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "kwinglutils.h"
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
2015-10-30 10:50:31 +00:00
|
|
|
#if HAVE_EPOXY_GLX
|
|
|
|
#include <epoxy/glx.h>
|
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Resolves given function, using getProcAddress
|
2012-09-29 11:19:35 +00:00
|
|
|
#define GL_RESOLVE( function ) \
|
|
|
|
if (platformInterface == GlxPlatformInterface) \
|
|
|
|
function = (function ## _func)getProcAddress( #function ); \
|
|
|
|
else if (platformInterface == EglPlatformInterface) \
|
|
|
|
function = (function ## _func)eglGetProcAddress( #function );
|
2012-10-03 07:32:25 +00:00
|
|
|
// Same as above but tries to use function "symbolName"
|
|
|
|
// Useful when functionality is defined in an extension with a different name
|
|
|
|
#define GL_RESOLVE_WITH_EXT( function, symbolName ) \
|
2012-09-29 11:19:35 +00:00
|
|
|
if (platformInterface == GlxPlatformInterface) { \
|
2012-10-03 07:32:25 +00:00
|
|
|
function = (function ## _func)getProcAddress( #symbolName ); \
|
2012-09-29 11:19:35 +00:00
|
|
|
} else if (platformInterface == EglPlatformInterface) { \
|
2012-10-03 07:32:25 +00:00
|
|
|
function = (function ## _func)eglGetProcAddress( #symbolName ); \
|
2012-09-29 11:19:35 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2013-05-19 14:14:47 +00:00
|
|
|
static GLenum GetGraphicsResetStatus();
|
|
|
|
static void ReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
|
|
|
GLenum type, GLsizei bufSize, GLvoid *data);
|
|
|
|
static void GetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
|
|
|
|
|
2014-02-11 18:57:06 +00:00
|
|
|
// GL_MESA_swap_control
|
2012-11-13 21:19:01 +00:00
|
|
|
glXSwapIntervalMESA_func glXSwapIntervalMESA;
|
2013-03-13 16:01:14 +00:00
|
|
|
|
2014-02-11 18:57:06 +00:00
|
|
|
// GL_ARB_robustness / GL_EXT_robustness
|
2013-05-19 14:14:47 +00:00
|
|
|
glGetGraphicsResetStatus_func glGetGraphicsResetStatus;
|
|
|
|
glReadnPixels_func glReadnPixels;
|
|
|
|
glGetnUniformfv_func glGetnUniformfv;
|
|
|
|
|
2014-02-11 18:57:06 +00:00
|
|
|
typedef void (*glXFuncPtr)();
|
2012-07-22 13:23:26 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static glXFuncPtr getProcAddress(const char* name)
|
|
|
|
{
|
2015-10-30 10:50:31 +00:00
|
|
|
glXFuncPtr ret = nullptr;
|
|
|
|
#if HAVE_EPOXY_GLX
|
|
|
|
ret = glXGetProcAddress((const GLubyte*) name);
|
|
|
|
#endif
|
2014-01-08 10:43:02 +00:00
|
|
|
if (ret == nullptr)
|
2011-01-30 14:34:42 +00:00
|
|
|
ret = (glXFuncPtr) dlsym(RTLD_DEFAULT, name);
|
2007-04-29 17:35:43 +00:00
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void glxResolveFunctions()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-02-11 18:35:54 +00:00
|
|
|
if (hasGLExtension(QByteArrayLiteral("GLX_MESA_swap_control")))
|
2012-11-13 21:19:01 +00:00
|
|
|
glXSwapIntervalMESA = (glXSwapIntervalMESA_func) getProcAddress("glXSwapIntervalMESA");
|
|
|
|
else
|
2014-01-08 10:43:02 +00:00
|
|
|
glXSwapIntervalMESA = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2013-05-19 14:17:41 +00:00
|
|
|
|
2012-09-29 11:19:35 +00:00
|
|
|
void eglResolveFunctions()
|
|
|
|
{
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2012-09-29 11:19:35 +00:00
|
|
|
void glResolveFunctions(OpenGLPlatformInterface platformInterface)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-02-11 18:35:54 +00:00
|
|
|
if (hasGLExtension(QByteArrayLiteral("GL_ARB_robustness"))) {
|
2013-05-19 14:14:47 +00:00
|
|
|
// See http://www.opengl.org/registry/specs/ARB/robustness.txt
|
|
|
|
GL_RESOLVE_WITH_EXT(glGetGraphicsResetStatus, glGetGraphicsResetStatusARB);
|
|
|
|
GL_RESOLVE_WITH_EXT(glReadnPixels, glReadnPixelsARB);
|
|
|
|
GL_RESOLVE_WITH_EXT(glGetnUniformfv, glGetnUniformfvARB);
|
2015-10-30 12:47:16 +00:00
|
|
|
} else if (hasGLExtension(QByteArrayLiteral("GL_EXT_robustness"))) {
|
2013-05-19 14:17:41 +00:00
|
|
|
// See http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt
|
|
|
|
glGetGraphicsResetStatus = (glGetGraphicsResetStatus_func) eglGetProcAddress("glGetGraphicsResetStatusEXT");
|
|
|
|
glReadnPixels = (glReadnPixels_func) eglGetProcAddress("glReadnPixelsEXT");
|
|
|
|
glGetnUniformfv = (glGetnUniformfv_func) eglGetProcAddress("glGetnUniformfvEXT");
|
|
|
|
} else {
|
|
|
|
glGetGraphicsResetStatus = KWin::GetGraphicsResetStatus;
|
|
|
|
glReadnPixels = KWin::ReadnPixels;
|
|
|
|
glGetnUniformfv = KWin::GetnUniformfv;
|
|
|
|
}
|
2010-12-05 11:35:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 14:14:47 +00:00
|
|
|
static GLenum GetGraphicsResetStatus()
|
|
|
|
{
|
|
|
|
return GL_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReadnPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
|
|
|
GLenum type, GLsizei bufSize, GLvoid *data)
|
|
|
|
{
|
|
|
|
Q_UNUSED(bufSize)
|
|
|
|
glReadPixels(x, y, width, height, format, type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GetnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
|
|
|
|
{
|
|
|
|
Q_UNUSED(bufSize)
|
|
|
|
glGetUniformfv(program, location, params);
|
|
|
|
}
|
|
|
|
|
2010-12-05 11:35:40 +00:00
|
|
|
} // namespace
|