From ad4b40fad653b73ca8a79b13161ff43e159b3ef4 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 30 Sep 2021 06:14:25 -0400 Subject: [PATCH] [client] opengl: add gl_dynprocs module This is similar to egl_dynprocs, except for OpenGL functions. --- client/CMakeLists.txt | 1 + client/include/gl_dynprocs.h | 50 +++++++++++++++++++++++++++++++ client/src/gl_dynprocs.c | 58 ++++++++++++++++++++++++++++++++++++ client/src/main.c | 2 ++ 4 files changed, 111 insertions(+) create mode 100644 client/include/gl_dynprocs.h create mode 100644 client/src/gl_dynprocs.c diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 8f823038..498844d3 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -111,6 +111,7 @@ set(SOURCES src/util.c src/clipboard.c src/kb.c + src/gl_dynprocs.c src/egl_dynprocs.c src/eglutil.c src/overlay_utils.c diff --git a/client/include/gl_dynprocs.h b/client/include/gl_dynprocs.h new file mode 100644 index 00000000..27f3bbff --- /dev/null +++ b/client/include/gl_dynprocs.h @@ -0,0 +1,50 @@ +/** + * Looking Glass + * Copyright © 2017-2021 The Looking Glass Authors + * https://looking-glass.io + * + * 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, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _H_LG_GL_DYNPROCS_ +#define _H_LG_GL_DYNPROCS_ +#ifdef ENABLE_OPENGL + +#include +#include + +struct GLDynProcs +{ + PFNGLGENBUFFERSPROC glGenBuffers; + PFNGLBINDBUFFERPROC glBindBuffer; + PFNGLBUFFERDATAPROC glBufferData; + PFNGLBUFFERSUBDATAPROC glBufferSubData; + PFNGLDELETEBUFFERSPROC glDeleteBuffers; + PFNGLISSYNCPROC glIsSync; + PFNGLFENCESYNCPROC glFenceSync; + PFNGLCLIENTWAITSYNCPROC glClientWaitSync; + PFNGLDELETESYNCPROC glDeleteSync; + PFNGLGENERATEMIPMAPPROC glGenerateMipmap; +}; + +extern struct GLDynProcs g_gl_dynProcs; + +void gl_dynProcsInit(void); + +#else + #define gl_dynProcsInit(...) +#endif + +#endif // _H_LG_GL_DYNPROCS_ diff --git a/client/src/gl_dynprocs.c b/client/src/gl_dynprocs.c new file mode 100644 index 00000000..2fc7e64b --- /dev/null +++ b/client/src/gl_dynprocs.c @@ -0,0 +1,58 @@ +/** + * Looking Glass + * Copyright © 2017-2021 The Looking Glass Authors + * https://looking-glass.io + * + * 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, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef ENABLE_OPENGL + +#include "gl_dynprocs.h" +#include + +struct GLDynProcs g_gl_dynProcs = {0}; + + +static void * getProcAddressGL(const char * name) +{ + return (void *) glXGetProcAddressARB((const GLubyte *) name); +} + +static void * setProcAddressGL2(const char * name, const char * backup) +{ + void * func = getProcAddressGL(name); + return func ? func : getProcAddressGL(backup); +} + +void gl_dynProcsInit(void) +{ + g_gl_dynProcs.glGenBuffers = setProcAddressGL2("glGenBuffers", "glGenBuffersARB"); + g_gl_dynProcs.glBindBuffer = setProcAddressGL2("glBindBuffer", "glBindBufferARB"); + g_gl_dynProcs.glBufferData = setProcAddressGL2("glBufferData", "glBufferDataARB"); + g_gl_dynProcs.glBufferSubData = setProcAddressGL2("glBufferSubData", "glBufferSubDataARB"); + g_gl_dynProcs.glDeleteBuffers = setProcAddressGL2("glDeleteBuffers", "glDeleteBuffersARB"); + + g_gl_dynProcs.glIsSync = getProcAddressGL("glIsSync"); + g_gl_dynProcs.glFenceSync = getProcAddressGL("glFenceSync"); + g_gl_dynProcs.glClientWaitSync = getProcAddressGL("glClientWaitSync"); + g_gl_dynProcs.glDeleteSync = getProcAddressGL("glDeleteSync"); + + g_gl_dynProcs.glGenerateMipmap = getProcAddressGL("glGenerateMipmap"); + if (!g_gl_dynProcs.glGenerateMipmap) + g_gl_dynProcs.glGenerateMipmap = getProcAddressGL("glGenerateMipmapEXT"); +}; + +#endif diff --git a/client/src/main.c b/client/src/main.c index c26fec72..1e5e23ac 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -58,6 +58,7 @@ #include "kb.h" #include "ll.h" #include "egl_dynprocs.h" +#include "gl_dynprocs.h" #include "overlays.h" #include "overlay_utils.h" #include "util.h" @@ -1297,6 +1298,7 @@ int main(int argc, char * argv[]) config_init(); ivshmemOptionsInit(); egl_dynProcsInit(); + gl_dynProcsInit(); g_state.overlays = ll_new(); app_registerOverlay(&LGOverlayConfig, NULL);