Blob Blame History Raw
From 6183ad6916ce411c83abd71a89b9da45e3e09498 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
Date: Fri, 25 Nov 2016 20:25:27 +0000
Subject: [PATCH] change from glew to epoxy

cause that works under wayland out of the box and gtk3 uses it already

Change-Id: Iefaac31e325534a81a5389f752804af917c1baef
---
 Makefile.fetch                                     |   2 +-
 RepositoryExternal.mk                              |  44 ++---
 avmedia/Library_avmedia.mk                         |   2 +-
 avmedia/Library_avmediaogl.mk                      |   2 +-
 bin/lo-all-static-libs                             |   2 +-
 canvas/Library_oglcanvas.mk                        |   3 +-
 canvas/source/opengl/ogl_buffercontext.hxx         |   2 +-
 canvas/source/opengl/ogl_canvascustomsprite.cxx    |   2 +-
 canvas/source/opengl/ogl_canvashelper.cxx          |   2 +-
 canvas/source/opengl/ogl_canvastools.cxx           |   2 +-
 canvas/source/opengl/ogl_texturecache.cxx          |   2 +-
 canvas/source/opengl/ogl_tools.hxx                 |   3 +-
 chart2/Library_chartcore.mk                        |   2 +-
 chart2/Library_chartopengl.mk                      |   2 +-
 chart2/inc/pch/precompiled_chartcore.hxx           |   2 +-
 chart2/source/view/charttypes/GL3DBarChart.cxx     |   2 +-
 chart2/source/view/main/GL3DRenderer.cxx           |   8 +-
 chart2/source/view/main/OpenGLRender.cxx           |   2 +-
 config_host.mk.in                                  |   6 +-
 config_host/config_opengl.h.in                     |  10 --
 configure.ac                                       |  20 +--
 cui/Library_cui.mk                                 |   2 +-
 distro-configs/LibreOfficeFlatpak.conf             |   1 -
 download.lst                                       |   3 +-
 external/Module_external.mk                        |   2 +-
 external/epoxy/Library_epoxy.mk                    |  63 +++++++
 external/{glew => epoxy}/Makefile                  |   0
 .../{glew/Module_glew.mk => epoxy/Module_epoxy.mk} |   9 +-
 external/epoxy/README                              |   5 +
 external/epoxy/UnpackedTarball_epoxy.mk            |  20 +++
 external/epoxy/epoxy.windows.api.patch             |  90 ++++++++++
 external/glew/ExternalPackage_glew.mk              |  33 ----
 external/glew/ExternalProject_glew.mk              |  36 ----
 external/glew/README                               |   6 -
 external/glew/UnpackedTarball_glew.mk              |  48 ------
 external/glew/glew-macosx-install-name.patch.1     |  13 --
 external/glew/glew-msvc-disable-sse2.patch.1       |  10 --
 external/glew/glew-static-only.patch.1             |  12 --
 external/glew/glew-tmpdir.patch.1                  |  13 --
 external/glew/glew_use_CC_variable.patch.1         |  24 ---
 external/libgltf/ExternalProject_libgltf.mk        |  10 +-
 external/libgltf/UnpackedTarball_libgltf.mk        |   1 +
 external/libgltf/libgltf-msvc-x64.patch.1          |   4 +-
 external/libgltf/libgltf.epoxy.patch.1             | 192 +++++++++++++++++++++
 include/vcl/opengl/OpenGLContext.hxx               |   6 +-
 include/vcl/opengl/OpenGLHelper.hxx                |   2 +-
 include/vcl/opengl/OpenGLWrapper.hxx               |   2 +-
 slideshow/Library_OGLTrans.mk                      |   3 +-
 slideshow/Library_slideshow.mk                     |   2 +-
 .../OGLTrans/generic/OGLTrans_TransitionImpl.cxx   |   1 -
 .../OGLTrans/generic/OGLTrans_TransitionImpl.hxx   |   2 -
 .../OGLTrans/generic/OGLTrans_TransitionerImpl.cxx |   2 +-
 svx/Library_svxcore.mk                             |   2 +-
 toolkit/Library_tk.mk                              |   2 +-
 vcl/CppunitTest_vcl_bitmap_test.mk                 |   2 +-
 vcl/Executable_icontest.mk                         |   2 +-
 vcl/Executable_vcldemo.mk                          |   2 +-
 vcl/Library_vcl.mk                                 |   2 +-
 vcl/Library_vclplug_gen.mk                         |   2 +-
 vcl/Library_vclplug_gtk.mk                         |   2 +-
 vcl/Library_vclplug_gtk3.mk                        |   2 +-
 vcl/Library_vclplug_kde4.mk                        |   2 +-
 vcl/inc/opengl/framebuffer.hxx                     |   1 -
 vcl/inc/opengl/program.hxx                         |   1 -
 vcl/inc/opengl/texture.hxx                         |   2 +-
 vcl/inc/pch/precompiled_vcl.hxx                    |   2 +-
 vcl/inc/unx/saldisp.hxx                            |   2 +-
 vcl/opengl/win/gdiimpl.cxx                         |   6 +-
 vcl/opengl/x11/gdiimpl.cxx                         |  19 +-
 vcl/osx/salobj.cxx                                 |   4 +-
 vcl/source/opengl/OpenGLContext.cxx                |  34 +---
 vcl/source/opengl/OpenGLHelper.cxx                 |   8 +-
 vcl/unx/generic/app/saldisp.cxx                    |   1 -
 vcl/workben/icontest.cxx                           |   2 -
 74 files changed, 475 insertions(+), 366 deletions(-)
 delete mode 100644 config_host/config_opengl.h.in
 create mode 100644 external/epoxy/Library_epoxy.mk
 rename external/{glew => epoxy}/Makefile (100%)
 rename external/{glew/Module_glew.mk => epoxy/Module_epoxy.mk} (69%)
 create mode 100644 external/epoxy/README
 create mode 100644 external/epoxy/UnpackedTarball_epoxy.mk
 create mode 100644 external/epoxy/epoxy.windows.api.patch
 delete mode 100644 external/glew/ExternalPackage_glew.mk
 delete mode 100644 external/glew/ExternalProject_glew.mk
 delete mode 100644 external/glew/README
 delete mode 100644 external/glew/UnpackedTarball_glew.mk
 delete mode 100644 external/glew/glew-macosx-install-name.patch.1
 delete mode 100644 external/glew/glew-msvc-disable-sse2.patch.1
 delete mode 100644 external/glew/glew-static-only.patch.1
 delete mode 100644 external/glew/glew-tmpdir.patch.1
 delete mode 100644 external/glew/glew_use_CC_variable.patch.1
 create mode 100644 external/libgltf/libgltf.epoxy.patch.1

diff --git a/Makefile.fetch b/Makefile.fetch
index 3884f7f..c0c61033 100644
--- a/Makefile.fetch
+++ b/Makefile.fetch
@@ -129,7 +129,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk $(SRCDIR)/download.lst $(SRCDIR)
 		$(call fetch_Optional,FONTCONFIG,FONTCONFIG_TARBALL) \
 		$(call fetch_Optional,FREEHAND,FREEHAND_TARBALL) \
 		$(call fetch_Optional,FREETYPE,FREETYPE_TARBALL) \
-		$(call fetch_Optional,GLEW,GLEW_TARBALL) \
+		$(call fetch_Optional,EPOXY,EPOXY_TARBALL) \
 		$(call fetch_Optional,GLM,GLM_TARBALL) \
 		$(call fetch_Optional,GLYPHY,GLYPHY_TARBALL) \
 		$(call fetch_Optional_pack,GOOGLE_DOCS_EXTENSION_PACK) \
diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk
index 24bbab7..bd2fce4 100644
--- a/RepositoryExternal.mk
+++ b/RepositoryExternal.mk
@@ -184,51 +184,43 @@ endef
 endif # SYSTEM_CPPUNIT
 
 ifneq ($(ENABLE_OPENGL)$(ENABLE_OPENGL_CANVAS)$(if $(filter ANDROID,$(OS)),TRUE),)
-ifneq ($(SYSTEM_GLEW),)
+ifneq ($(SYSTEM_EPOXY),)
 
-define gb_LinkTarget__use_glew
+define gb_LinkTarget__use_epoxy
 $(call gb_LinkTarget_set_include,$(1),\
 	$$(INCLUDE) \
-    $(GLEW_CFLAGS) \
+    $(EPOXY_CFLAGS) \
 )
-$(call gb_LinkTarget_add_libs,$(1),$(GLEW_LIBS))
+$(call gb_LinkTarget_add_libs,$(1),$(EPOXY_LIBS))
 
 endef
 
-gb_ExternalProject__use_glew :=
+gb_ExternalProject__use_epoxy :=
 
-else # !SYSTEM_GLEW
+else # !SYSTEM_EPOXY
 
-$(eval $(call gb_Helper_register_packages_for_install,ooo,\
-	glew \
-))
-
-define gb_LinkTarget__use_glew
-$(call gb_LinkTarget_use_package,$(1),glew)
+define gb_LinkTarget__use_epoxy
 $(call gb_LinkTarget_set_include,$(1),\
-	-I$(call gb_UnpackedTarball_get_dir,glew/include) \
-	-DGLEW_NO_GLU \
-	$$(INCLUDE) \
+       -I$(call gb_UnpackedTarball_get_dir,epoxy/include) \
+       $$(INCLUDE) \
 )
 
-ifeq ($(COM),MSC)
-$(call gb_LinkTarget_add_libs,$(1),\
-	$(call gb_UnpackedTarball_get_dir,glew)/lib/$(if $(MSVC_USE_DEBUG_RUNTIME),Debug/$(wnt_arch_subdir_mandatory)/glew32d.lib,Release/$(wnt_arch_subdir_mandatory)/glew32.lib) \
-)
-else
-$(call gb_LinkTarget_add_libs,$(1),\
-	-L$(call gb_UnpackedTarball_get_dir,glew)/lib/ -lGLEW \
+$(call gb_LinkTarget_use_libraries,$(1),\
+    epoxy \
 )
-endif
 
 endef
 
-define gb_ExternalProject__use_glew
-$(call gb_ExternalProject_use_external_project,$(1),glew)
+$(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo,\
+	epoxy \
+))
+
+define gb_ExternalProject__use_epoxy
+$(call gb_ExternalProject_use_external_project,$(1),epoxy)
 
 endef
 
-endif # SYSTEM_GLEW
+endif # SYSTEM_EPOXY
 endif # ENABLE_OPENGL
 
 ifneq ($(SYSTEM_GLYPHY),)
diff --git a/avmedia/Library_avmedia.mk b/avmedia/Library_avmedia.mk
index 6a0c35b..d56a50d 100644
--- a/avmedia/Library_avmedia.mk
+++ b/avmedia/Library_avmedia.mk
@@ -29,7 +29,7 @@ $(eval $(call gb_Library_use_externals,avmedia,\
 
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Library_use_externals,avmedia,\
-    glew \
+    epoxy \
 ))
 endif
 
diff --git a/avmedia/Library_avmediaogl.mk b/avmedia/Library_avmediaogl.mk
index b7498bf..33c571f 100644
--- a/avmedia/Library_avmediaogl.mk
+++ b/avmedia/Library_avmediaogl.mk
@@ -16,7 +16,7 @@ $(eval $(call gb_Library_use_sdk_api,avmediaogl))
 $(eval $(call gb_Library_use_externals,avmediaogl, \
     boost_headers \
     libgltf \
-    glew \
+    epoxy \
     glm_headers \
 ))
 
diff --git a/bin/lo-all-static-libs b/bin/lo-all-static-libs
index 813241e..9faa042 100755
--- a/bin/lo-all-static-libs
+++ b/bin/lo-all-static-libs
@@ -63,7 +63,7 @@ echo $INSTDIR/$LIBO_LIB_FOLDER/lib*.a \
      $WORKDIR/UnpackedTarball/coinmp/CoinMP/src/.libs/*.a \
      $WORKDIR/UnpackedTarball/coinmp/CoinUtils/src/.libs/*.a \
      $WORKDIR/UnpackedTarball/coinmp/Osi/src/Osi/.libs/*.a \
-     $WORKDIR/UnpackedTarball/glew/lib/*.a \
+     $WORKDIR/UnpackedTarball/epoxy/lib/*.a \
      $WORKDIR/UnpackedTarball/icu/source/lib/*.a \
      $WORKDIR/UnpackedTarball/langtag/liblangtag/.libs/*.a \
      $WORKDIR/UnpackedTarball/lcms2/src/.libs/*.a \
diff --git a/canvas/Library_oglcanvas.mk b/canvas/Library_oglcanvas.mk
index 0118eb1..ea26705 100644
--- a/canvas/Library_oglcanvas.mk
+++ b/canvas/Library_oglcanvas.mk
@@ -42,7 +42,7 @@ $(eval $(call gb_Library_add_exception_objects,oglcanvas,\
 
 $(eval $(call gb_Library_use_externals,oglcanvas,\
 	boost_headers \
-	glew \
+	epoxy \
 ))
 
 ifeq ($(strip $(OS)),MACOSX)
@@ -61,7 +61,6 @@ $(eval $(call gb_Library_use_system_win32_libs,oglcanvas,\
 else
 $(eval $(call gb_Library_add_libs,oglcanvas,\
     -lGL \
-    -lX11 \
 ))
 endif
 
diff --git a/canvas/source/opengl/ogl_buffercontext.hxx b/canvas/source/opengl/ogl_buffercontext.hxx
index 202e063..7f2066a 100644
--- a/canvas/source/opengl/ogl_buffercontext.hxx
+++ b/canvas/source/opengl/ogl_buffercontext.hxx
@@ -10,7 +10,7 @@
 #ifndef INCLUDED_CANVAS_SOURCE_OPENGL_OGL_BUFFERCONTEXT_HXX
 #define INCLUDED_CANVAS_SOURCE_OPENGL_OGL_BUFFERCONTEXT_HXX
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <sal/config.h>
 #include <memory>
diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx
index 8d38177..6b23d45 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.cxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx
@@ -9,7 +9,7 @@
 
 #include <sal/config.h>
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <basegfx/point/b2dpoint.hxx>
diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx
index 84a96ce..175a02b 100644
--- a/canvas/source/opengl/ogl_canvashelper.cxx
+++ b/canvas/source/opengl/ogl_canvashelper.cxx
@@ -11,7 +11,7 @@
 
 #include <memory>
 #include <functional>
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx
index 657a220..3d9448b 100644
--- a/canvas/source/opengl/ogl_canvastools.cxx
+++ b/canvas/source/opengl/ogl_canvastools.cxx
@@ -9,7 +9,7 @@
 
 #include <sal/config.h>
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
diff --git a/canvas/source/opengl/ogl_texturecache.cxx b/canvas/source/opengl/ogl_texturecache.cxx
index 08cdd2f..43fb7d8 100644
--- a/canvas/source/opengl/ogl_texturecache.cxx
+++ b/canvas/source/opengl/ogl_texturecache.cxx
@@ -9,7 +9,7 @@
 
 #include <sal/config.h>
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <com/sun/star/geometry/IntegerSize2D.hpp>
 
diff --git a/canvas/source/opengl/ogl_tools.hxx b/canvas/source/opengl/ogl_tools.hxx
index 8133212..469a5be 100644
--- a/canvas/source/opengl/ogl_tools.hxx
+++ b/canvas/source/opengl/ogl_tools.hxx
@@ -11,8 +11,7 @@
 #define INCLUDED_CANVAS_SOURCE_OPENGL_OGL_TOOLS_HXX
 
 #include <sal/config.h>
-#include <GL/glew.h>
-
+#include <epoxy/gl.h>
 
 namespace oglcanvas
 {
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index 7040ade..b26cb3d 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -32,7 +32,7 @@ $(eval $(call gb_Library_use_externals,chartcore,\
 
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Library_use_externals,chartcore,\
-    glew \
+    epoxy \
 ))
 endif
 
diff --git a/chart2/Library_chartopengl.mk b/chart2/Library_chartopengl.mk
index 95ea58d..52be4a5 100644
--- a/chart2/Library_chartopengl.mk
+++ b/chart2/Library_chartopengl.mk
@@ -22,7 +22,7 @@ $(eval $(call gb_Library_set_precompiled_header,chartopengl,$(SRCDIR)/chart2/inc
 $(eval $(call gb_Library_use_externals,chartopengl,\
 	boost_headers \
 	glm_headers \
-	glew \
+	epoxy \
 ))
 
 $(eval $(call gb_Library_use_sdk_api,chartopengl))
diff --git a/chart2/inc/pch/precompiled_chartcore.hxx b/chart2/inc/pch/precompiled_chartcore.hxx
index 8d02451..908d7ac 100644
--- a/chart2/inc/pch/precompiled_chartcore.hxx
+++ b/chart2/inc/pch/precompiled_chartcore.hxx
@@ -73,7 +73,6 @@
 #include <vcl/virdev.hxx>
 #include <vcl/wall.hxx>
 #include <ChartModel.hxx>
-#include <GL/glew.h>
 #include <basegfx/basegfxdllapi.h>
 #include <basegfx/matrix/b3dhommatrix.hxx>
 #include <basegfx/numeric/ftools.hxx>
@@ -169,6 +168,7 @@
 #include <cppuhelper/weak.hxx>
 #include <editeng/editengdllapi.h>
 #include <editeng/unoprnms.hxx>
+#include <epoxy/gl.h>
 #include <i18nlangtag/i18nlangtagdllapi.h>
 #include <i18nlangtag/lang.h>
 #include <i18nlangtag/languagetag.hxx>
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 521054a..907e612 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -9,7 +9,7 @@
 
 #include <GL3DBarChart.hxx>
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <glm/glm.hpp>
 #include <glm/gtx/transform.hpp>
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 61916f9..995e414 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include "GL3DRenderer.hxx"
 
@@ -213,7 +213,7 @@ OpenGL3DRenderer::ShaderResources::~ShaderResources()
 
 void OpenGL3DRenderer::CheckGLSLVersion()
 {
-    maResources.m_b330Support = GLEW_VERSION_3_3;
+    maResources.m_b330Support = epoxy_gl_version() >= 33;
 }
 
 void OpenGL3DRenderer::ShaderResources::LoadShaders()
@@ -249,8 +249,8 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
         m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace");
         m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor");
 #if !defined MACOSX
-        //check whether the texture array is support
-        mbTexBatchSupport = GLEW_EXT_texture_array;
+        //check whether the texture array is supported
+        mbTexBatchSupport = epoxy_has_gl_extension("GL_EXT_texture_array");
 #endif
         CHECK_GL_ERROR();
         if (mbTexBatchSupport)
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 3182e66..91a3763 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <vector>
 #include "OpenGLRender.hxx"
 #include <vcl/graph.hxx>
diff --git a/config_host.mk.in b/config_host.mk.in
index 04fc400..e1fe93b 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -204,8 +204,8 @@ export GIO_LIBS=$(gb_SPACE)@GIO_LIBS@
 export GIT_REFERENCE_SRC=@GIT_REFERENCE_SRC@
 export GIT_LINK_SRC=@GIT_LINK_SRC@
 export GIT_NEEDED_SUBMODULES=@GIT_NEEDED_SUBMODULES@
-export GLEW_CFLAGS=$(gb_SPACE)@GLEW_CFLAGS@
-export GLEW_LIBS=$(gb_SPACE)@GLEW_LIBS@
+export EPOXY_CFLAGS=$(gb_SPACE)@EPOXY_CFLAGS@
+export EPOXY_LIBS=$(gb_SPACE)@EPOXY_LIBS@
 export GLM_CFLAGS=$(gb_SPACE)@GLM_CFLAGS@
 export GLYPHY_CFLAGS=$(gb_SPACE)@GLYPHY_CFLAGS@
 export GLYPHY_LIBS=$(gb_SPACE)@GLYPHY_LIBS@
@@ -530,7 +530,7 @@ export SYSTEM_FIREBIRD=@SYSTEM_FIREBIRD@
 export SYSTEM_GENBRK=@SYSTEM_GENBRK@
 export SYSTEM_GENCCODE=@SYSTEM_GENCCODE@
 export SYSTEM_GENCMN=@SYSTEM_GENCMN@
-export SYSTEM_GLEW=@SYSTEM_GLEW@
+export SYSTEM_EPOXY=@SYSTEM_EPOXY@
 export SYSTEM_GLM=@SYSTEM_GLM@
 export SYSTEM_GLYPHY=@SYSTEM_GLYPHY@
 export SYSTEM_GRAPHITE=@SYSTEM_GRAPHITE@
diff --git a/config_host/config_opengl.h.in b/config_host/config_opengl.h.in
deleted file mode 100644
index 67b9e47..0000000
--- a/config_host/config_opengl.h.in
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
-Settings for OpenGL
-*/
-
-#ifndef CONFIG_OPENGL_H
-#define CONFIG_OPENGL_H
-
-#define HAVE_GLEW_1_12 0
-
-#endif
diff --git a/configure.ac b/configure.ac
index d08c259..fcb95d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1647,6 +1647,11 @@ AC_ARG_WITH(system-cairo,
         [Use cairo libraries already on system.  Happens automatically for
          (implicit) --enable-gtk and for --enable-gtk3.]))
 
+AC_ARG_WITH(system-epoxy,
+    AS_HELP_STRING([--with-system-epoxy],
+        [Use epoxy libraries already on system.  Happens automatically for
+         --enable-gtk3.]))
+
 AC_ARG_WITH(myspell-dicts,
     AS_HELP_STRING([--with-myspell-dicts],
         [Adds myspell dictionaries to the LibreOffice installation set]),
@@ -8883,14 +8888,6 @@ AC_SUBST([GLM_CFLAGS])
 AC_SUBST([SYSTEM_GLM])
 
 dnl ===================================================================
-dnl Check for system glew
-dnl ===================================================================
-libo_CHECK_SYSTEM_MODULE([glew], [GLEW], [glew >= 1.10.0])
-AS_IF([test "$with_system_glew" = "yes"],
-    [PKG_CHECK_EXISTS([glew >= 1.12.0], [AC_DEFINE([HAVE_GLEW_1_12])])],
-    [AC_DEFINE([HAVE_GLEW_1_12])])
-
-dnl ===================================================================
 dnl Check for system glyphy
 dnl ===================================================================
 dnl We currently use GLyphy only on Windows
@@ -8898,7 +8895,6 @@ if test $_os = WINNT; then
     libo_CHECK_SYSTEM_MODULE([glyphy], [GLYPHY], [glyphy >= 0.12.0], ["-I${WORKDIR}/UnpackedTarball/glyphy/src"])
 fi
 
-dnl ===================================================================
 dnl Check for system odbc
 dnl ===================================================================
 AC_MSG_CHECKING([which odbc headers to use])
@@ -11792,6 +11788,11 @@ AC_SUBST(CAIRO_CFLAGS)
 AC_SUBST(CAIRO_LIBS)
 
 dnl ===================================================================
+dnl Check for system epoxy
+dnl ===================================================================
+libo_CHECK_SYSTEM_MODULE([epoxy], [EPOXY], [epoxy >= 1.3.1], ["-I${WORKDIR}/UnpackedTarball/epoxy/include"])
+
+dnl ===================================================================
 dnl Test whether to use avahi
 dnl ===================================================================
 if test "$_os" = "WINNT"; then
@@ -12953,7 +12954,6 @@ AC_CONFIG_HEADERS([config_host/config_mpl.h])
 AC_CONFIG_HEADERS([config_host/config_orcus.h])
 AC_CONFIG_HEADERS([config_host/config_kde4.h])
 AC_CONFIG_HEADERS([config_host/config_oox.h])
-AC_CONFIG_HEADERS([config_host/config_opengl.h])
 AC_CONFIG_HEADERS([config_host/config_options.h])
 AC_CONFIG_HEADERS([config_host/config_test.h])
 AC_CONFIG_HEADERS([config_host/config_telepathy.h])
diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk
index 7bb181d..50c4fec 100644
--- a/cui/Library_cui.mk
+++ b/cui/Library_cui.mk
@@ -72,7 +72,7 @@ $(eval $(call gb_Library_use_externals,cui,\
 ))
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Library_use_externals,cui,\
-     glew \
+     epoxy \
  ))
 endif
 
diff --git a/distro-configs/LibreOfficeFlatpak.conf b/distro-configs/LibreOfficeFlatpak.conf
index d5d6686..121d198 100644
--- a/distro-configs/LibreOfficeFlatpak.conf
+++ b/distro-configs/LibreOfficeFlatpak.conf
@@ -11,7 +11,6 @@
 --without-system-coinmp
 --without-system-cppunit
 --without-system-firebird
---without-system-glew
 --without-system-glm
 --without-system-libabw
 --without-system-libcdr
diff --git a/download.lst b/download.lst
index 700c4dd..71b2451 100644
--- a/download.lst
+++ b/download.lst
@@ -29,6 +29,8 @@ export CURL_TARBALL := curl-7.51.0.tar.gz
 export DBGHELP_DLL := 13fbc2e8b37ddf28181dd6d8081c2b8e-dbghelp.dll
 export EBOOK_MD5SUM := 6b48eda57914e6343efebc9381027b78
 export EBOOK_TARBALL := libe-book-0.1.2.tar.bz2
+export EPOXY_MD5SUM := 96f6620a9b005a503e7b44b0b528287d
+export EPOXY_TARBALL := libepoxy-1.3.1.tar.bz2
 export EPM_TARBALL := 3ade8cfe7e59ca8e65052644fed9fca4-epm-3.7.tar.gz
 export ETONYEK_MD5SUM := 77ff46936dcc83670557274e7dd2aa33
 export ETONYEK_VERSION_MICRO := 6
@@ -54,7 +56,6 @@ export FONT_SOURCESANS_TARBALL := edc4d741888bc0d38e32dbaa17149596-source-sans-p
 export FREEHAND_MD5SUM := 8cf70c5dc4d24d2dc4a107f509d2d6d7
 export FREEHAND_TARBALL := libfreehand-0.1.1.tar.bz2
 export FREETYPE_TARBALL := dbf2caca1d3afd410a29217a9809d397-freetype-2.4.8.tar.bz2
-export GLEW_TARBALL := 3941e9cab2f4f9d8faee3e8d57ae7664-glew-1.12.0.zip
 export GLM_TARBALL := bae83fa5dc7f081768daace6e199adc3-glm-0.9.4.6-libreoffice.zip
 export GLYPHY_TARBALL := 5d303fb955beb9bf112267316ca9d021-glyphy-0.2.0.tar.bz2
 export GRAPHITE_TARBALL := 4311dd9ace498b57c85f611e0670df64-graphite2-minimal-1.3.8.tgz
diff --git a/external/Module_external.mk b/external/Module_external.mk
index 44280e3..55fce1f 100644
--- a/external/Module_external.mk
+++ b/external/Module_external.mk
@@ -39,13 +39,13 @@ $(eval $(call gb_Module_add_moduledirs,external,\
 	$(call gb_Helper_optional,CURL,curl) \
 	$(call gb_Helper_optional,EBOOK,libebook) \
 	$(call gb_Helper_optional,EPM,epm) \
+	$(call gb_Helper_optional,EPOXY,epoxy) \
 	$(call gb_Helper_optional,ETONYEK,libetonyek) \
 	$(call gb_Helper_optional,EXPAT,expat) \
 	$(call gb_Helper_optional,FIREBIRD,firebird) \
 	$(call gb_Helper_optional,FONTCONFIG,fontconfig) \
 	$(call gb_Helper_optional,FREEHAND,libfreehand) \
 	$(call gb_Helper_optional,FREETYPE,freetype) \
-	$(call gb_Helper_optional,GLEW,glew) \
 	$(call gb_Helper_optional,GLM,glm) \
 	$(call gb_Helper_optional,GLYPHY,glyphy) \
 	$(call gb_Helper_optional,GRAPHITE,graphite) \
diff --git a/external/epoxy/Library_epoxy.mk b/external/epoxy/Library_epoxy.mk
new file mode 100644
index 0000000..28f9dab
--- /dev/null
+++ b/external/epoxy/Library_epoxy.mk
@@ -0,0 +1,63 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,epoxy))
+
+$(eval $(call gb_Library_use_unpacked,epoxy,epoxy))
+
+$(eval $(call gb_Library_set_warnings_not_errors,epoxy))
+
+$(eval $(call gb_Library_set_include,epoxy,\
+	-I$(WORKDIR)/UnpackedTarball/epoxy/include \
+	-I$(WORKDIR)/UnpackedTarball/epoxy/src \
+	$$(INCLUDE) \
+))
+
+# epoxy is riddled with warnings... let's spare use
+# the pointless spamming
+$(eval $(call gb_Library_add_cxxflags,epoxy,\
+	-w \
+))
+$(eval $(call gb_Library_add_cflags,epoxy,\
+	-w \
+))
+
+ifeq ($(OS),LINUX)
+$(eval $(call gb_Library_add_libs,epoxy,\
+	-ldl \
+))
+endif
+
+$(eval $(call gb_Library_add_generated_cobjects,epoxy,\
+	UnpackedTarball/epoxy/src/dispatch_common \
+	UnpackedTarball/epoxy/src/gl_generated_dispatch \
+))
+
+ifeq ($(OS),WNT)
+$(eval $(call gb_Library_add_generated_cobjects,epoxy,\
+	UnpackedTarball/epoxy/src/dispatch_wgl \
+	UnpackedTarball/epoxy/src/wgl_generated_dispatch \
+))
+else ifeq ($(OS),MACOSX)
+# nothing
+else ifeq ($(OS),ANDROID)
+$(eval $(call gb_Library_add_generated_cobjects,epoxy,\
+	UnpackedTarball/epoxy/src/dispatch_egl \
+	UnpackedTarball/epoxy/src/egl_generated_dispatch \
+))
+else
+$(eval $(call gb_Library_add_generated_cobjects,epoxy,\
+	UnpackedTarball/epoxy/src/dispatch_glx \
+	UnpackedTarball/epoxy/src/glx_generated_dispatch \
+	UnpackedTarball/epoxy/src/dispatch_egl \
+	UnpackedTarball/epoxy/src/egl_generated_dispatch \
+))
+endif
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/glew/Makefile b/external/epoxy/Makefile
similarity index 100%
rename from external/glew/Makefile
rename to external/epoxy/Makefile
diff --git a/external/glew/Module_glew.mk b/external/epoxy/Module_epoxy.mk
similarity index 69%
rename from external/glew/Module_glew.mk
rename to external/epoxy/Module_epoxy.mk
index 1d1b9a7..ea65176 100644
--- a/external/glew/Module_glew.mk
+++ b/external/epoxy/Module_epoxy.mk
@@ -7,12 +7,11 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
 
-$(eval $(call gb_Module_Module,glew))
+$(eval $(call gb_Module_Module,epoxy))
 
-$(eval $(call gb_Module_add_targets,glew,\
-	ExternalProject_glew \
-	UnpackedTarball_glew \
-	ExternalPackage_glew \
+$(eval $(call gb_Module_add_targets,epoxy,\
+	Library_epoxy \
+	UnpackedTarball_epoxy \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/epoxy/README b/external/epoxy/README
new file mode 100644
index 0000000..8bd467a
--- /dev/null
+++ b/external/epoxy/README
@@ -0,0 +1,5 @@
+Epoxy is an OpenGL Extension Wrangler
+
+Epoxy is a library for handling OpenGL function pointer management for you
+
+https://github.com/anholt/libepoxy
diff --git a/external/epoxy/UnpackedTarball_epoxy.mk b/external/epoxy/UnpackedTarball_epoxy.mk
new file mode 100644
index 0000000..76c0fdf
--- /dev/null
+++ b/external/epoxy/UnpackedTarball_epoxy.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_UnpackedTarball_UnpackedTarball,epoxy))
+
+$(eval $(call gb_UnpackedTarball_set_tarball,epoxy,$(EPOXY_TARBALL)))
+
+$(eval $(call gb_UnpackedTarball_set_patchlevel,epoxy,0))
+
+$(eval $(call gb_UnpackedTarball_add_patches,epoxy, \
+    external/epoxy/epoxy.windows.api.patch \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/epoxy/epoxy.windows.api.patch b/external/epoxy/epoxy.windows.api.patch
new file mode 100644
index 0000000..12d2afb
--- /dev/null
+++ b/external/epoxy/epoxy.windows.api.patch
@@ -0,0 +1,90 @@
+--- include/epoxy/gl.h
++++ include/epoxy/gl.h
+@@ -59,7 +59,8 @@
+ 
+ #else
+ #ifndef APIENTRY
+-#define APIENTRY __stdcall
++#define WINAPI __stdcall
++#define APIENTRY WINAPI
+ #endif
+ 
+ #ifndef GLAPIENTRY
+--- src/egl_generated_dispatch.c
++++ src/egl_generated_dispatch.c
+@@ -128,7 +128,11 @@
+ };
+ 
+ #if USING_DISPATCH_TABLE
++#if defined (_MSC_VER)
++static __inline struct dispatch_table *
++#else
+ static inline struct dispatch_table *
++#endif
+ get_dispatch_table(void);
+ 
+ #endif
+@@ -1642,7 +1646,11 @@
+ uint32_t egl_tls_index;
+ uint32_t egl_tls_size = sizeof(struct dispatch_table);
+ 
++#if defined (_MSC_VER)
++static __inline struct dispatch_table *
++#else
+ static inline struct dispatch_table *
++#endif
+ get_dispatch_table(void)
+ {
+ 	return TlsGetValue(egl_tls_index);
+--- src/gl_generated_dispatch.c
++++ src/gl_generated_dispatch.c
+@@ -3122,7 +3122,11 @@
+ };
+ 
+ #if USING_DISPATCH_TABLE
++#if defined (_MSC_VER)
++static __inline struct dispatch_table *
++#else
+ static inline struct dispatch_table *
++#endif
+ get_dispatch_table(void);
+ 
+ #endif
+@@ -51507,7 +51511,11 @@
+ uint32_t gl_tls_index;
+ uint32_t gl_tls_size = sizeof(struct dispatch_table);
+ 
++#if defined (_MSC_VER)
++static __inline struct dispatch_table *
++#else
+ static inline struct dispatch_table *
++#endif
+ get_dispatch_table(void)
+ {
+ 	return TlsGetValue(gl_tls_index);
+--- src/wgl_generated_dispatch.c
++++ src/wgl_generated_dispatch.c
+@@ -157,7 +157,11 @@
+ };
+ 
+ #if USING_DISPATCH_TABLE
++#if defined (_MSC_VER)
++static __inline struct dispatch_table *
++#else
+ static inline struct dispatch_table *
++#endif
+ get_dispatch_table(void);
+ 
+ #endif
+@@ -1701,7 +1705,11 @@
+ uint32_t wgl_tls_index;
+ uint32_t wgl_tls_size = sizeof(struct dispatch_table);
+ 
++#if defined (_MSC_VER)
++static __inline struct dispatch_table *
++#else
+ static inline struct dispatch_table *
++#endif
+ get_dispatch_table(void)
+ {
+ 	return TlsGetValue(wgl_tls_index);
diff --git a/external/glew/ExternalPackage_glew.mk b/external/glew/ExternalPackage_glew.mk
deleted file mode 100644
index e6adc8b..0000000
--- a/external/glew/ExternalPackage_glew.mk
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
-#
-# This file is part of the LibreOffice project.
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-
-$(eval $(call gb_ExternalPackage_ExternalPackage,glew,glew))
-
-$(eval $(call gb_ExternalPackage_use_external_project,glew,glew))
-
-ifeq ($(OS)-$(COM),WNT-MSC)
-ifeq ($(CPUNAME),INTEL)
-glew_arch_subdir=Win32
-else ifeq ($(CPUNAME),X86_64)
-glew_arch_subdir=x64
-endif
-endif
-
-ifeq ($(OS),MACOSX)
-$(eval $(call gb_ExternalPackage_add_file,glew,$(LIBO_LIB_FOLDER)/libGLEW.1.12.0.dylib,lib/libGLEW.1.12.0.dylib))
-else ifeq ($(OS)-$(COM),WNT-GCC)
-else ifeq ($(COM),MSC)
-$(eval $(call gb_ExternalPackage_add_files,glew,$(LIBO_LIB_FOLDER), \
-	bin/$(if $(MSVC_USE_DEBUG_RUNTIME),Debug/$(glew_arch_subdir)/glew32d.dll,Release/$(glew_arch_subdir)/glew32.dll) \
-))
-else ifeq ($(DISABLE_DYNLOADING),)
-$(eval $(call gb_ExternalPackage_add_file,glew,$(LIBO_LIB_FOLDER)/libGLEW.so.1.12,lib/libGLEW.so.1.12.0))
-endif
-
-# vim: set noet sw=4 ts=4:
diff --git a/external/glew/ExternalProject_glew.mk b/external/glew/ExternalProject_glew.mk
deleted file mode 100644
index 0d80cd0..0000000
--- a/external/glew/ExternalProject_glew.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
-#
-# This file is part of the LibreOffice project.
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-
-$(eval $(call gb_ExternalProject_ExternalProject,glew))
-
-$(eval $(call gb_ExternalProject_register_targets,glew,\
-	build \
-))
-
-ifeq ($(COM),MSC)
-$(call gb_ExternalProject_get_state_target,glew,build) :
-	$(call gb_ExternalProject_run,build,\
-		$(if $(filter 140,$(VCVER)),$(DEVENV) /Upgrade glew.sln,echo up-to-date) && \
-		msbuild.exe glew_shared.vcxproj /p:Platform=$(if $(filter INTEL,$(CPUNAME)),Win32,x64) /p:Configuration=$(if $(MSVC_USE_DEBUG_RUNTIME),Debug,Release) $(if $(filter 140,$(VCVER)),/p:PlatformToolset=v140,/p:PlatformToolset=v120) \
-	,build/vc12) \
-	$(call gb_ExternalProject_run,build,\
-		msbuild.exe glewinfo.vcxproj /p:Platform=$(if $(filter INTEL,$(CPUNAME)),Win32,x64) /p:Configuration=Release $(if $(filter 140,$(VCVER)),/p:PlatformToolset=v140,/p:PlatformToolset=v120) \
-	,build/vc12)
-
-else
-
-$(call gb_ExternalProject_get_state_target,glew,build) :
-	$(call gb_ExternalProject_run,glew,\
-		$(if $(ENABLE_DEBUG),STRIP=) LD="$(CC)" \
-			$(MAKE) STRIP= glew.lib $(if $(filter DESKTOP,$(BUILD_TYPE)),$(if $(ENABLE_DEBUG),debug)) \
-	)
-
-endif
-
-# vim: set noet sw=4 ts=4:
diff --git a/external/glew/README b/external/glew/README
deleted file mode 100644
index 34b2d24..0000000
--- a/external/glew/README
+++ /dev/null
@@ -1,6 +0,0 @@
-GLEW is the OpenGL Extension Wrangler
-
-GLEW provides efficient run-time mechanisms for determining which OpenGL
-extensions are supported on the target platform.
-
-http://glew.sourceforge.net/
diff --git a/external/glew/UnpackedTarball_glew.mk b/external/glew/UnpackedTarball_glew.mk
deleted file mode 100644
index c47b7a0..0000000
--- a/external/glew/UnpackedTarball_glew.mk
+++ /dev/null
@@ -1,48 +0,0 @@
-# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
-#
-# This file is part of the LibreOffice project.
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-
-$(eval $(call gb_UnpackedTarball_UnpackedTarball,glew))
-
-$(eval $(call gb_UnpackedTarball_set_tarball,glew,$(GLEW_TARBALL)))
-
-$(eval $(call gb_UnpackedTarball_set_patchlevel,glew,0))
-
-$(eval $(call gb_UnpackedTarball_fix_end_of_line,glew,\
-	Makefile \
-	include/GL/glew.h \
-))
-
-ifeq ($(OS)$(COM),WNTMSC)
-$(eval $(call gb_UnpackedTarball_set_patchflags,glew,--binary))
-$(eval $(call gb_UnpackedTarball_add_patches,glew,\
-	external/glew/glew-msvc-disable-sse2.patch.1 \
-))
-else
-$(eval $(call gb_UnpackedTarball_add_patches,glew,\
-	external/glew/glew_use_CC_variable.patch.1 \
-))
-endif
-
-ifeq ($(OS),MACOSX)
-$(eval $(call gb_UnpackedTarball_add_patches,glew,\
-	external/glew/glew-macosx-install-name.patch.1 \
-))
-endif
-
-ifeq ($(DISABLE_DYNLOADING),TRUE)
-$(eval $(call gb_UnpackedTarball_add_patches,glew,\
-	external/glew/glew-static-only.patch.1 \
-))
-endif
-
-$(eval $(call gb_UnpackedTarball_add_patches,glew,\
-	external/glew/glew-tmpdir.patch.1 \
-))
-
-# vim: set noet sw=4 ts=4:
diff --git a/external/glew/glew-macosx-install-name.patch.1 b/external/glew/glew-macosx-install-name.patch.1
deleted file mode 100644
index 75e8e7f..0000000
--- a/external/glew/glew-macosx-install-name.patch.1
+++ /dev/null
@@ -1,13 +0,0 @@
--*- Mode:Diff -*-
-diff -ur glew.org/build/glew.rc glew/build/glew.rc
---- glew/config/Makefile.darwin
-+++ glew/config/Makefile.darwin
-@@ -20,7 +20,7 @@
- LIB.DEVLNK    = lib$(NAME).dylib
- LIB.SHARED    = lib$(NAME).$(SO_VERSION).dylib
- LIB.STATIC    = lib$(NAME).a
--LDFLAGS.SO    = -dynamiclib -install_name $(GLEW_DEST)/lib/$(LIB.SHARED) -current_version $(SO_VERSION) -compatibility_version $(SO_MAJOR)
-+LDFLAGS.SO    = -dynamiclib -install_name @__________________________________________________OOO/$(LIB.SHARED) -current_version $(SO_VERSION) -compatibility_version $(SO_MAJOR)
- LIB.SONAME.MX = lib$(NAME)mx.$(SO_MAJOR).dylib
- LIB.DEVLNK.MX = lib$(NAME)mx.dylib
- LIB.SHARED.MX = lib$(NAME)mx.$(SO_VERSION).dylib
diff --git a/external/glew/glew-msvc-disable-sse2.patch.1 b/external/glew/glew-msvc-disable-sse2.patch.1
deleted file mode 100644
index 6b07044..0000000
--- a/external/glew/glew-msvc-disable-sse2.patch.1
+++ /dev/null
@@ -1,10 +0,0 @@
---- glew/build//vc10/common.props.orig	2014-10-02 15:06:57.027060664 +0200
-+++ glew/build//vc10/common.props	2014-10-02 15:06:59.026060509 +0200
-@@ -10,6 +10,7 @@
-   <ItemDefinitionGroup>
-     <ClCompile>
-       <AdditionalIncludeDirectories>$(INCLUDE_DIR)</AdditionalIncludeDirectories>
-+      <EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
-     </ClCompile>
-   </ItemDefinitionGroup>
-   <ItemGroup>
diff --git a/external/glew/glew-static-only.patch.1 b/external/glew/glew-static-only.patch.1
deleted file mode 100644
index 14ccff2..0000000
--- a/external/glew/glew-static-only.patch.1
+++ /dev/null
@@ -1,12 +0,0 @@
--*- Mode:Diff -*-
---- glew/Makefile
-+++ glew/Makefile
-@@ -93,7 +93,7 @@
- LIB.SOBJS.MX       := $(addprefix tmp/$(SYSTEM)/mx/shared/,$(LIB.SRCS.NAMES))
- LIB.SOBJS.MX       := $(LIB.SOBJS.MX:.c=.o)
- 
--glew.lib: lib lib/$(LIB.SHARED) lib/$(LIB.STATIC) glew.pc
-+glew.lib: lib lib/$(LIB.STATIC)
- 
- lib:
- 	mkdir lib
diff --git a/external/glew/glew-tmpdir.patch.1 b/external/glew/glew-tmpdir.patch.1
deleted file mode 100644
index 9a2847b..0000000
--- a/external/glew/glew-tmpdir.patch.1
+++ /dev/null
@@ -1,13 +0,0 @@
-diff -ur glew.org/Makefile glew/Makefile
---- glew.org/Makefile	2016-05-02 06:25:53.521291677 +0200
-+++ glew/Makefile	2016-05-02 06:31:10.325035494 +0200
-@@ -55,7 +55,8 @@
- DIST_SRC_TGZ ?= $(shell pwd)/$(DIST_NAME).tgz
- DIST_WIN32   ?= $(shell pwd)/$(DIST_NAME)-win32.zip
- 
--DIST_DIR := $(shell mktemp -d /tmp/glew.XXXXXX)/$(DIST_NAME)
-+TMPDIR ?= /tmp
-+DIST_DIR := $(shell mktemp -d $(TMPDIR)/glew.XXXXXX)/$(DIST_NAME)
- 
- # To disable stripping of binaries either:
- #   - use STRIP= on gmake command-line
diff --git a/external/glew/glew_use_CC_variable.patch.1 b/external/glew/glew_use_CC_variable.patch.1
deleted file mode 100644
index 56e9903..0000000
--- a/external/glew/glew_use_CC_variable.patch.1
+++ /dev/null
@@ -1,24 +0,0 @@
-Use CC variable from environment, don't hardcode "cc".
-
---- glew/config/Makefile.linux.orig	2014-01-29 15:39:43.364972925 +0100
-+++ glew/config/Makefile.linux	2014-01-29 15:44:45.621000941 +0100
-@@ -1,6 +1,6 @@
- NAME = $(GLEW_NAME)
--CC = cc
--LD = cc
-+CC ?= cc
-+LD ?= $(CC)
- M_ARCH ?= $(shell uname -m)
- ARCH64 = false
- ifeq (x86_64,${M_ARCH})
---- glew/config/Makefile.darwin.orig	2014-01-29 15:44:39.541000377 +0100
-+++ glew/config/Makefile.darwin	2014-01-29 15:44:47.548001120 +0100
-@@ -1,6 +1,6 @@
- NAME = $(GLEW_NAME)
--CC = cc
--LD = cc
-+CC ?= cc
-+LD ?= $(CC)
- CFLAGS.EXTRA = -dynamic -fno-common
- #CFLAGS.EXTRA += -no-cpp-precomp
- LDFLAGS.EXTRA =
diff --git a/external/libgltf/ExternalProject_libgltf.mk b/external/libgltf/ExternalProject_libgltf.mk
index fcc82af..28f0ab1 100644
--- a/external/libgltf/ExternalProject_libgltf.mk
+++ b/external/libgltf/ExternalProject_libgltf.mk
@@ -17,7 +17,7 @@ $(eval $(call gb_ExternalProject_register_targets,libgltf,\
 
 $(eval $(call gb_ExternalProject_use_externals,libgltf,\
 	boost_headers \
-	glew \
+	epoxy \
 	glm_headers \
 ))
 
@@ -30,8 +30,8 @@ ifeq ($(SYSTEM_BOOST),)
 libgltf_AdditionalIncludes += "$(call gb_UnpackedTarball_get_dir,boost)"
 endif
 
-ifeq ($(SYSTEM_GLEW),)
-libgltf_AdditionalIncludes += "$(call gb_UnpackedTarball_get_dir,glew)/include"
+ifeq ($(SYSTEM_EPOXY),)
+libgltf_AdditionalIncludes += "$(call gb_UnpackedTarball_get_dir,epoxy)/include"
 endif
 
 ifeq ($(SYSTEM_GLM),)
@@ -45,7 +45,7 @@ $(call gb_ExternalProject_get_state_target,libgltf,build) :
 			$(if $(filter 120,$(VCVER)),/p:PlatformToolset=v120 /p:VisualStudioVersion=12.0 /ToolsVersion:12.0) \
 			$(if $(filter 140,$(VCVER)),/p:PlatformToolset=v140 /p:VisualStudioVersion=14.0 /ToolsVersion:14.0) \
 			'/p:AdditionalIncludeDirectories=$(subst $(WHITESPACE),;,$(subst /,\,$(strip $(libgltf_AdditionalIncludes))))' \
-			/p:AdditionalLibraryDirectories=$(if $(SYSTEM_GLEW),,"$(subst /,\,$(call gb_UnpackedTarball_get_dir,glew))\lib\$(if $(MSVC_USE_DEBUG_RUNTIME),Debug,Release)\Win32") \
+			/p:AdditionalLibraryDirectories=$(if $(SYSTEM_EPOXY),,"$(subst /,\,$(call gb_UnpackedTarball_get_dir,epoxy))\lib\$(if $(MSVC_USE_DEBUG_RUNTIME),Debug,Release)\Win32") \
 	,build/win32)
 
 else # !ifeq($(COM),MSC)
@@ -67,7 +67,7 @@ $(call gb_ExternalProject_get_state_target,libgltf,build) :
 			$(if $(ENABLE_DEBUG),--enable-debug,--disable-debug) \
 			--disable-werror \
 			BOOST_CFLAGS="$(if $(SYSTEM_BOOST),$(BOOST_CPPFLAGS),-I$(call gb_UnpackedTarball_get_dir,boost))" \
-			GLEW_CFLAGS="$(if $(SYSTEM_GLEW),$(GLEW_CFLAGS),-I$(call gb_UnpackedTarball_get_dir,glew)/include) -DGLEW_NO_GLU" \
+			GLEW_CFLAGS="$(if $(SYSTEM_EPOXY),$(EPOXY_CFLAGS),-I$(call gb_UnpackedTarball_get_dir,epoxy)/include)" \
 			GLM_CFLAGS="$(if $(SYSTEM_GLM),$(GLM_CFLAGS),-I$(call gb_UnpackedTarball_get_dir,glm))" \
 			$(if $(libgltf_CPPFLAGS),CPPFLAGS='$(libgltf_CPPFLAGS)') \
 		&& $(MAKE) \
diff --git a/external/libgltf/UnpackedTarball_libgltf.mk b/external/libgltf/UnpackedTarball_libgltf.mk
index 89a06da..574c701 100644
--- a/external/libgltf/UnpackedTarball_libgltf.mk
+++ b/external/libgltf/UnpackedTarball_libgltf.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_UnpackedTarball_set_patchlevel,libgltf,1))
 $(eval $(call gb_UnpackedTarball_add_patches,libgltf,\
 	external/libgltf/libgltf-msvc-disable-sse2.patch.1 \
 	external/libgltf/libgltf-msvc-x64.patch.1 \
+	external/libgltf/libgltf.epoxy.patch.1 \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/libgltf/libgltf-msvc-x64.patch.1 b/external/libgltf/libgltf-msvc-x64.patch.1
index 86417a7..b3f72b5 100644
--- a/external/libgltf/libgltf-msvc-x64.patch.1
+++ b/external/libgltf/libgltf-msvc-x64.patch.1
@@ -76,7 +76,7 @@ diff -ur libgltf.org/build/win32/libgltf.vcxproj libgltf/build/win32/libgltf.vcx
 +    <Link>
 +      <GenerateDebugInformation>true</GenerateDebugInformation>
 +      <AdditionalLibraryDirectories>$(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-+      <AdditionalDependencies>opengl32.lib;glew32.lib;$(AdditionalDependencies)</AdditionalDependencies>
++      <AdditionalDependencies>opengl32.lib;epoxy32.lib;$(AdditionalDependencies)</AdditionalDependencies>
 +    </Link>
 +  </ItemDefinitionGroup>
    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -101,7 +101,7 @@ diff -ur libgltf.org/build/win32/libgltf.vcxproj libgltf/build/win32/libgltf.vcx
 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
 +      <OptimizeReferences>true</OptimizeReferences>
 +      <AdditionalLibraryDirectories>$(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-+      <AdditionalDependencies>opengl32.lib;glew32.lib;$(AdditionalDependencies)</AdditionalDependencies>
++      <AdditionalDependencies>opengl32.lib;epoxy32.lib;$(AdditionalDependencies)</AdditionalDependencies>
 +      <SubSystem>Windows</SubSystem>
 +    </Link>
 +  </ItemDefinitionGroup>
diff --git a/external/libgltf/libgltf.epoxy.patch.1 b/external/libgltf/libgltf.epoxy.patch.1
new file mode 100644
index 0000000..c4deb5a
--- /dev/null
+++ b/external/libgltf/libgltf.epoxy.patch.1
@@ -0,0 +1,192 @@
+--- libgltf/inc/libgltf.h	2016-11-26 21:09:12.412551045 +0000
++++ libgltf/inc/libgltf.h	2016-11-26 21:11:06.459102534 +0000
+@@ -12,7 +12,7 @@
+ 
+ #include <stddef.h>
+ #include "types.h"
+-#include <GL/glew.h>
++#include <epoxy/gl.h>
+ #include <glm/glm.hpp>
+ #include <string>
+ #include <vector>
+--- libgltf/src/Camera.h	2016-11-26 21:09:12.451549182 +0000
++++ libgltf/src/Camera.h	2016-11-26 21:12:15.079824217 +0000
+@@ -10,7 +10,7 @@
+ #ifndef CAMERA_H
+ #define CAMERA_H
+ 
+-#include <GL/glew.h>
++#include <epoxy/gl.h>
+ #include <glm/glm.hpp>
+ 
+ namespace libgltf
+--- libgltf/src/Common.h	2016-11-26 21:09:12.452549134 +0000
++++ libgltf/src/Common.h	2016-11-26 21:12:06.515233386 +0000
+@@ -9,7 +9,7 @@
+ 
+ #ifndef COMMON_H
+ #define COMMON_H
+-#include <GL/glew.h>
++#include <epoxy/gl.h>
+ #include <glm/glm.hpp>
+ #include <string>
+ #include <vector>
+--- libgltf/src/Font.cpp	2016-11-26 21:09:12.450549230 +0000
++++ libgltf/src/Font.cpp	2016-11-26 21:12:11.168011102 +0000
+@@ -9,7 +9,7 @@
+ 
+ #include "Font.h"
+ 
+-#include <GL/glew.h>
++#include <epoxy/gl.h>
+ #include <glm/gtc/matrix_transform.hpp>
+ #include <cstdio>
+ 
+--- libgltf/src/RenderScene.cpp	2016-11-26 21:09:12.456548943 +0000
++++ libgltf/src/RenderScene.cpp	2016-11-26 21:15:45.021794354 +0000
+@@ -1084,7 +1084,7 @@
+ 
+ int RenderScene::initRender(const std::vector<glTFFile>& inputFiles)
+ {
+-    if( !glewIsSupported("GL_VERSION_3_0") )
++    if( epoxy_gl_version() < 30 )
+     {
+         return LIBGLTF_UNKNOWN_ERROR;
+     }
+--- libgltf/src/Shaders.cpp	2016-11-26 21:09:12.451549182 +0000
++++ libgltf/src/Shaders.cpp	2016-11-26 21:12:41.591557634 +0000
+@@ -9,7 +9,7 @@
+ 
+ #include "Shaders.h"
+ 
+-#include <GL/glew.h>
++#include <epoxy/gl.h>
+ #include <cstdio>
+ #include <cstring>
+ 
+--- libgltf/src/Texture.h	2016-11-26 21:09:12.454549039 +0000
++++ libgltf/src/Texture.h	2016-11-26 21:12:38.592700902 +0000
+@@ -10,7 +10,7 @@
+ #ifndef TEXTURE_H
+ #define TEXTURE_H
+ 
+-#include <GL/glew.h>
++#include <epoxy/gl.h>
+ 
+ namespace libgltf
+ {
+--- libgltf/configure	2016-11-28 10:15:59.782223873 +0000
++++ libgltf/configure	2016-11-28 10:16:08.191824453 +0000
+@@ -15534,112 +15534,6 @@
+ CPPFLAGS=$save_CPPFLAGS
+ 
+ 
+-# =========
+-# Find glew
+-# =========
+-save_CPPFLAGS=$CPPFLAGS
+-CPPFLAGS="$CPPFLAGS $GLEW_CFLAGS"
+-
+-pkg_failed=no
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLEW" >&5
+-$as_echo_n "checking for GLEW... " >&6; }
+-
+-if test -n "$GLEW_CFLAGS"; then
+-    pkg_cv_GLEW_CFLAGS="$GLEW_CFLAGS"
+- elif test -n "$PKG_CONFIG"; then
+-    if test -n "$PKG_CONFIG" && \
+-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glew >= 1.8.0\""; } >&5
+-  ($PKG_CONFIG --exists --print-errors "glew >= 1.8.0") 2>&5
+-  ac_status=$?
+-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+-  test $ac_status = 0; }; then
+-  pkg_cv_GLEW_CFLAGS=`$PKG_CONFIG --cflags "glew >= 1.8.0" 2>/dev/null`
+-		      test "x$?" != "x0" && pkg_failed=yes
+-else
+-  pkg_failed=yes
+-fi
+- else
+-    pkg_failed=untried
+-fi
+-if test -n "$GLEW_LIBS"; then
+-    pkg_cv_GLEW_LIBS="$GLEW_LIBS"
+- elif test -n "$PKG_CONFIG"; then
+-    if test -n "$PKG_CONFIG" && \
+-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glew >= 1.8.0\""; } >&5
+-  ($PKG_CONFIG --exists --print-errors "glew >= 1.8.0") 2>&5
+-  ac_status=$?
+-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+-  test $ac_status = 0; }; then
+-  pkg_cv_GLEW_LIBS=`$PKG_CONFIG --libs "glew >= 1.8.0" 2>/dev/null`
+-		      test "x$?" != "x0" && pkg_failed=yes
+-else
+-  pkg_failed=yes
+-fi
+- else
+-    pkg_failed=untried
+-fi
+-
+-
+-
+-if test $pkg_failed = yes; then
+-   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+-$as_echo "no" >&6; }
+-
+-if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+-        _pkg_short_errors_supported=yes
+-else
+-        _pkg_short_errors_supported=no
+-fi
+-        if test $_pkg_short_errors_supported = yes; then
+-	        GLEW_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "glew >= 1.8.0" 2>&1`
+-        else
+-	        GLEW_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "glew >= 1.8.0" 2>&1`
+-        fi
+-	# Put the nasty error message in config.log where it belongs
+-	echo "$GLEW_PKG_ERRORS" >&5
+-
+-	as_fn_error $? "Package requirements (glew >= 1.8.0) were not met:
+-
+-$GLEW_PKG_ERRORS
+-
+-Consider adjusting the PKG_CONFIG_PATH environment variable if you
+-installed software in a non-standard prefix.
+-
+-Alternatively, you may set the environment variables GLEW_CFLAGS
+-and GLEW_LIBS to avoid the need to call pkg-config.
+-See the pkg-config man page for more details." "$LINENO" 5
+-elif test $pkg_failed = untried; then
+-     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+-$as_echo "no" >&6; }
+-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
+-is in your PATH or set the PKG_CONFIG environment variable to the full
+-path to pkg-config.
+-
+-Alternatively, you may set the environment variables GLEW_CFLAGS
+-and GLEW_LIBS to avoid the need to call pkg-config.
+-See the pkg-config man page for more details.
+-
+-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+-See \`config.log' for more details" "$LINENO" 5; }
+-else
+-	GLEW_CFLAGS=$pkg_cv_GLEW_CFLAGS
+-	GLEW_LIBS=$pkg_cv_GLEW_LIBS
+-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+-$as_echo "yes" >&6; }
+-
+- ac_fn_cxx_check_header_mongrel "$LINENO" "GL/glew.h" "ac_cv_header_GL_glew_h" "$ac_includes_default"
+-if test "x$ac_cv_header_GL_glew_h" = xyes; then :
+-
+-else
+-  as_fn_error $? "GL/glew.h not found. install glew" "$LINENO" 5
+-fi
+-
+-
+-
+-fi
+-CPPFLAGS=$save_CPPFLAGS
+ 
+ 
+ 
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx
index a7cc2d6..7cd6954 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -12,7 +12,7 @@
 
 #include <string.h>
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 
 #include <vcl/dllapi.h>
 #include <vcl/window.hxx>
@@ -158,8 +158,8 @@ private:
     virtual void destroyCurrentContext();
 
 protected:
-    bool InitGLEW();
-    void InitGLEWDebugging();
+    bool InitGL();
+    void InitGLDebugging();
     static void InitChildWindow(SystemChildWindow *pChildWindow);
     static void BuffersSwapped();
     virtual GLWindow& getModifiableOpenGLWindow() = 0;
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index b2989b8..e0fc74e 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -10,7 +10,7 @@
 #ifndef INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
 #define INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <sal/log.hxx>
 #include <vcl/dllapi.h>
 #include <vcl/bitmapex.hxx>
diff --git a/include/vcl/opengl/OpenGLWrapper.hxx b/include/vcl/opengl/OpenGLWrapper.hxx
index 3b7f6a7..e9fb967 100644
--- a/include/vcl/opengl/OpenGLWrapper.hxx
+++ b/include/vcl/opengl/OpenGLWrapper.hxx
@@ -7,7 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-// Fully wrapped methods that have no exotic GL / GLEW header deps.
+// Fully wrapped methods that have no exotic GL header deps.
 
 #ifndef INCLUDED_VCL_OPENGL_OPENGLWRAPPER_HXX
 #define INCLUDED_VCL_OPENGL_OPENGLWRAPPER_HXX
diff --git a/slideshow/Library_OGLTrans.mk b/slideshow/Library_OGLTrans.mk
index 032a88c..e5effbe 100644
--- a/slideshow/Library_OGLTrans.mk
+++ b/slideshow/Library_OGLTrans.mk
@@ -34,7 +34,7 @@ $(eval $(call gb_Library_use_libraries,OGLTrans,\
 
 $(eval $(call gb_Library_use_externals,OGLTrans,\
 	boost_headers \
-	glew \
+	epoxy \
 	glm_headers \
 ))
 
@@ -76,7 +76,6 @@ $(eval $(call gb_Library_add_exception_objects,OGLTrans,\
 
 $(eval $(call gb_Library_add_libs,OGLTrans,\
 	-lGL \
-	-lX11 \
 ))
 endif
 
diff --git a/slideshow/Library_slideshow.mk b/slideshow/Library_slideshow.mk
index 3834dfd..90ddd70 100644
--- a/slideshow/Library_slideshow.mk
+++ b/slideshow/Library_slideshow.mk
@@ -31,7 +31,7 @@ $(eval $(call gb_Library_use_externals,slideshow,\
 ))
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Library_use_externals,slideshow,\
-     glew \
+     epoxy \
  ))
 endif
 
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index 9eb1e51..94b2217 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -26,7 +26,6 @@
  *
  ************************************************************************/
 
-#include <GL/glew.h>
 #include <glm/gtc/matrix_transform.hpp>
 #include <glm/gtc/type_ptr.hpp>
 #include <vcl/opengl/OpenGLHelper.hxx>
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
index 2a7c472..fe6a1c5 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
@@ -31,8 +31,6 @@
 #include <config_lgpl.h>
 #include <glm/gtc/type_ptr.hpp>
 
-#include <GL/glew.h>
-
 #include <memory>
 #include <vector>
 
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
index a428e99..266228c 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
@@ -817,7 +817,7 @@ void buildMipmaps(
     GLint internalFormat, GLsizei width, GLsizei height, GLenum format,
     GLenum type, const void * data)
 {
-    if (GLEW_ARB_framebuffer_object) {
+    if (epoxy_has_gl_extension("GL_ARB_framebuffer_object")) {
         glTexImage2D(
             GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type,
             data);
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 40db407..ce9fd0f 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -88,7 +88,7 @@ $(eval $(call gb_Library_use_externals,svxcore,\
 ))
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Library_use_externals,svxcore,\
-     glew \
+     epoxy \
  ))
 endif
 
diff --git a/toolkit/Library_tk.mk b/toolkit/Library_tk.mk
index ecb376e..efb8e34 100644
--- a/toolkit/Library_tk.mk
+++ b/toolkit/Library_tk.mk
@@ -27,7 +27,7 @@ $(eval $(call gb_Library_use_externals,tk,\
 
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Library_use_externals,tk,\
-    glew \
+    epoxy \
 ))
 endif
 $(eval $(call gb_Library_set_include,tk,\
diff --git a/vcl/CppunitTest_vcl_bitmap_test.mk b/vcl/CppunitTest_vcl_bitmap_test.mk
index 1104181..7acfeb4 100644
--- a/vcl/CppunitTest_vcl_bitmap_test.mk
+++ b/vcl/CppunitTest_vcl_bitmap_test.mk
@@ -19,7 +19,7 @@ $(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
 ))
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
-     glew \
+     epoxy \
  ))
 endif
 
diff --git a/vcl/Executable_icontest.mk b/vcl/Executable_icontest.mk
index 58efd05..db3be4f 100644
--- a/vcl/Executable_icontest.mk
+++ b/vcl/Executable_icontest.mk
@@ -15,7 +15,7 @@ $(eval $(call gb_Executable_use_externals,icontest,\
 ))
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Executable_use_externals,icontest,\
-    glew \
+    epoxy \
 ))
 endif
 
diff --git a/vcl/Executable_vcldemo.mk b/vcl/Executable_vcldemo.mk
index 6003ecd..1685fda 100644
--- a/vcl/Executable_vcldemo.mk
+++ b/vcl/Executable_vcldemo.mk
@@ -21,7 +21,7 @@ $(eval $(call gb_Executable_use_externals,vcldemo,\
 ))
 ifeq ($(ENABLE_OPENGL),TRUE)
 $(eval $(call gb_Executable_use_externals,vcldemo,\
-    glew \
+    epoxy \
 ))
 endif
 
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 761fcbe..1de8921 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -123,7 +123,7 @@ $(eval $(call gb_Library_use_externals,vcl,\
 ))
 ifneq ($(ENABLE_OPENGL)$(if $(filter ANDROID,$(OS)),TRUE),)
 $(eval $(call gb_Library_use_externals,vcl,\
-     glew \
+     epoxy \
  ))
 endif
 
diff --git a/vcl/Library_vclplug_gen.mk b/vcl/Library_vclplug_gen.mk
index 859bc98..34f6b92 100644
--- a/vcl/Library_vclplug_gen.mk
+++ b/vcl/Library_vclplug_gen.mk
@@ -51,7 +51,7 @@ $(eval $(call gb_Library_use_externals,vclplug_gen,\
 	boost_headers \
 	cairo \
 	graphite \
-	glew \
+	epoxy \
 	harfbuzz \
 	icuuc \
 	valgrind \
diff --git a/vcl/Library_vclplug_gtk.mk b/vcl/Library_vclplug_gtk.mk
index c32a127..67247b7 100644
--- a/vcl/Library_vclplug_gtk.mk
+++ b/vcl/Library_vclplug_gtk.mk
@@ -59,7 +59,7 @@ $(eval $(call gb_Library_use_externals,vclplug_gtk,\
 	cairo \
 	dbus \
 	gio \
-	glew \
+	epoxy \
 	gtk \
 	gthread \
 	icuuc \
diff --git a/vcl/Library_vclplug_gtk3.mk b/vcl/Library_vclplug_gtk3.mk
index 8d013d9..1457c1a 100644
--- a/vcl/Library_vclplug_gtk3.mk
+++ b/vcl/Library_vclplug_gtk3.mk
@@ -75,7 +75,7 @@ $(eval $(call gb_Library_use_libraries,vclplug_gtk3,\
 
 $(eval $(call gb_Library_use_externals,vclplug_gtk3,\
 	boost_headers \
-	glew \
+	epoxy \
 	dbus \
 ))
 
diff --git a/vcl/Library_vclplug_kde4.mk b/vcl/Library_vclplug_kde4.mk
index 645d6c9..e63acb7 100644
--- a/vcl/Library_vclplug_kde4.mk
+++ b/vcl/Library_vclplug_kde4.mk
@@ -54,7 +54,7 @@ $(eval $(call gb_Library_use_externals,vclplug_kde4,\
 	boost_headers \
 	icuuc \
 	kde4 \
-	glew \
+	epoxy \
 ))
 
 $(eval $(call gb_Library_add_libs,vclplug_kde4,\
diff --git a/vcl/inc/opengl/framebuffer.hxx b/vcl/inc/opengl/framebuffer.hxx
index 9f94a8f..3a9fbfe 100644
--- a/vcl/inc/opengl/framebuffer.hxx
+++ b/vcl/inc/opengl/framebuffer.hxx
@@ -10,7 +10,6 @@
 #ifndef INCLUDED_VCL_INC_OPENGL_FRAMEBUFFER_H
 #define INCLUDED_VCL_INC_OPENGL_FRAMEBUFFER_H
 
-#include <GL/glew.h>
 #include <vcl/dllapi.h>
 
 #include <opengl/texture.hxx>
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 3c194d8..68fb525 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -14,7 +14,6 @@
 
 #include <list>
 
-#include <GL/glew.h>
 #include <vcl/dllapi.h>
 
 #include <basegfx/point/b2dpoint.hxx>
diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
index 055ba21..5ff7e99 100644
--- a/vcl/inc/opengl/texture.hxx
+++ b/vcl/inc/opengl/texture.hxx
@@ -20,7 +20,7 @@
 #ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_H
 #define INCLUDED_VCL_INC_OPENGL_TEXTURE_H
 
-#include <GL/glew.h>
+#include <epoxy/gl.h>
 #include <vcl/dllapi.h>
 #include <vcl/salgtype.hxx>
 #include <rtl/ustring.hxx>
diff --git a/vcl/inc/pch/precompiled_vcl.hxx b/vcl/inc/pch/precompiled_vcl.hxx
index 833d73e..fc4098c 100644
--- a/vcl/inc/pch/precompiled_vcl.hxx
+++ b/vcl/inc/pch/precompiled_vcl.hxx
@@ -58,6 +58,7 @@
 #include <boost/multi_array.hpp>
 #include <boost/optional.hpp>
 #include <boost/shared_array.hpp>
+#include <epoxy/gl.h>
 #include <osl/conditn.hxx>
 #include <osl/diagnose.h>
 #include <osl/diagnose.hxx>
@@ -186,7 +187,6 @@
 #include <vcl/virdev.hxx>
 #include <vcl/window.hxx>
 #include <vcl/wrkwin.hxx>
-#include <GL/glew.h>
 #include <PhysicalFontCollection.hxx>
 #include <PhysicalFontFace.hxx>
 #include <PhysicalFontFamily.hxx>
diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx
index 91cbad7..61dde19 100644
--- a/vcl/inc/unx/saldisp.hxx
+++ b/vcl/inc/unx/saldisp.hxx
@@ -28,7 +28,7 @@ class   SalXLib;
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/extensions/Xrender.h>
-#include "GL/glxew.h"
+#include <epoxy/glx.h>
 
 #include <unx/salunx.h>
 #include <unx/saltype.h>
diff --git a/vcl/opengl/win/gdiimpl.cxx b/vcl/opengl/win/gdiimpl.cxx
index 8d1fbea..c29b39a 100644
--- a/vcl/opengl/win/gdiimpl.cxx
+++ b/vcl/opengl/win/gdiimpl.cxx
@@ -15,7 +15,7 @@
 #include <win/saldata.hxx>
 #include <win/salframe.h>
 #include <win/salinst.h>
-#include <GL/wglew.h>
+#include <epoxy/wgl.h>
 
 static std::vector<HGLRC> g_vShareList;
 
@@ -551,7 +551,7 @@ bool WinOpenGLContext::ImplInit()
         return false;
     }
 
-    if (!InitGLEW())
+    if (!InitGL())
     {
         if (bFirstCall)
             disableOpenGLAndTerminateForRestart();
@@ -618,7 +618,7 @@ bool WinOpenGLContext::ImplInit()
         return false;
     }
 
-    InitGLEWDebugging();
+    InitGLDebugging();
 
     g_vShareList.push_back(m_aGLWin.hRC);
 
diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx
index 00ab62d..46ee552 100644
--- a/vcl/opengl/x11/gdiimpl.cxx
+++ b/vcl/opengl/x11/gdiimpl.cxx
@@ -184,23 +184,10 @@ namespace
         return pFBC;
     }
 
-    // we need them before glew can initialize them
-    // glew needs an OpenGL context so we need to get the address manually
-    void initOpenGLFunctionPointers()
-    {
-        glXChooseFBConfig = reinterpret_cast<GLXFBConfig*(*)(Display *dpy, int screen, const int *attrib_list, int *nelements)>(glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXChooseFBConfig")));
-        glXGetVisualFromFBConfig = reinterpret_cast<XVisualInfo*(*)(Display *dpy, GLXFBConfig config)>(glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXGetVisualFromFBConfig")));    // try to find a visual for the current set of attributes
-        glXGetFBConfigAttrib = reinterpret_cast<int(*)(Display *dpy, GLXFBConfig config, int attribute, int* value)>(glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXGetFBConfigAttrib")));
-        glXCreateContextAttribsARB = reinterpret_cast<GLXContext(*)(Display*, GLXFBConfig, GLXContext, Bool, const int*)>(glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("glXCreateContextAttribsARB")));
-        glXCreatePixmap = reinterpret_cast<GLXPixmap(*)(Display*, GLXFBConfig, Pixmap, const int*)>(glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("glXCreatePixmap")));
-    }
-
     Visual* getVisual(Display* dpy, Window win)
     {
         OpenGLZone aZone;
 
-        initOpenGLFunctionPointers();
-
         XWindowAttributes xattr;
         if( !XGetWindowAttributes( dpy, win, &xattr ) )
         {
@@ -266,8 +253,6 @@ SystemWindowData X11OpenGLContext::generateWinData(vcl::Window* pParent, bool /*
     if( dpy == nullptr || !glXQueryExtension( dpy, nullptr, nullptr ) )
         return aWinData;
 
-    initOpenGLFunctionPointers();
-
     int best_fbc = -1;
     GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc, true, false);
 
@@ -400,8 +385,8 @@ bool X11OpenGLContext::ImplInit()
         }
     }
 
-    bool bRet = InitGLEW();
-    InitGLEWDebugging();
+    bool bRet = InitGL();
+    InitGLDebugging();
 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
diff --git a/vcl/osx/salobj.cxx b/vcl/osx/salobj.cxx
index c75f2a7..9e6e746 100644
--- a/vcl/osx/salobj.cxx
+++ b/vcl/osx/salobj.cxx
@@ -321,8 +321,8 @@ bool AquaOpenGLContext::ImplInit()
     NSOpenGLView* pView = getOpenGLView();
     [[pView openGLContext] makeCurrentContext];
 
-    bool bRet = InitGLEW();
-    InitGLEWDebugging();
+    bool bRet = InitGL();
+    InitGLDebugging();
     return bRet;
 }
 
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index ffe5f36..2412191 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -7,7 +7,6 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <config_opengl.h>
 #include <chrono>
 
 #include <vcl/opengl/OpenGLContext.hxx>
@@ -205,13 +204,8 @@ extern "C" void
 APIENTRY
 #endif
 debug_callback(GLenum source, GLenum type, GLuint id,
-        GLenum severity, GLsizei , const GLchar* message,
-#if HAVE_GLEW_1_12
-        const GLvoid*
-#else
-        GLvoid*
-#endif
-        )
+               GLenum severity, GLsizei , const GLchar* message,
+               const GLvoid*)
 {
     // ignore Nvidia's : "Program/shader state performance warning: Fragment Shader is going to be recompiled because the shader key based on GL state mismatches."
     // the GLSL compiler is a bit too aggressive in optimizing the state based on the current OpenGL state
@@ -264,29 +258,13 @@ bool OpenGLContext::ImplInit()
     return false;
 }
 
-bool OpenGLContext::InitGLEW()
+bool OpenGLContext::InitGL()
 {
-    static bool bGlewInit = false;
-    if(!bGlewInit)
-    {
-        OpenGLZone aZone;
-
-        glewExperimental = GL_TRUE;
-        GLenum err = glewInit();
-        if (err != GLEW_OK)
-        {
-            SAL_WARN("vcl.opengl", "Failed to initialize GLEW: " << glewGetErrorString(err));
-            return false;
-        }
-        else
-            bGlewInit = true;
-    }
-
     VCL_GL_INFO("OpenGLContext::ImplInit----end, GL version: " << OpenGLHelper::getGLVersion());
     mbInitialized = true;
 
     // I think we need at least GL 3.0
-    if (!GLEW_VERSION_3_0)
+    if (epoxy_gl_version() < 30)
     {
         SAL_WARN("vcl.opengl", "We don't have at least OpenGL 3.0");
         return false;
@@ -302,11 +280,11 @@ bool OpenGLContext::InitGLEW()
     return true;
 }
 
-void OpenGLContext::InitGLEWDebugging()
+void OpenGLContext::InitGLDebugging()
 {
 #ifdef DBG_UTIL
     // only enable debug output in dbgutil build
-    if( GLEW_ARB_debug_output)
+    if (epoxy_has_gl_extension("GL_ARB_debug_output"))
     {
         OpenGLZone aZone;
 
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 12f6151..61af553 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -401,7 +401,7 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,
         aGeometryShaderSource = getShaderSource(rGeometryShaderName);
 
     GLint bBinaryResult = GL_FALSE;
-    if( GLEW_ARB_get_program_binary && !rDigest.isEmpty() )
+    if (epoxy_has_gl_extension("GL_ARB_get_program_binary") && !rDigest.isEmpty())
     {
         OString aFileName =
                 createFileName(rVertexShaderName, rFragmentShaderName, rGeometryShaderName, rDigest);
@@ -473,7 +473,7 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,
     if (bHasGeometryShader)
         glAttachShader(ProgramID, GeometryShaderID);
 
-    if( GLEW_ARB_get_program_binary && !rDigest.isEmpty() )
+    if (epoxy_has_gl_extension("GL_ARB_get_program_binary") && !rDigest.isEmpty())
     {
         glProgramParameteri(ProgramID, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
         glLinkProgram(ProgramID);
@@ -1059,14 +1059,14 @@ void OpenGLHelper::debugMsgPrint(const char *pFormat, ...)
     {
         OpenGLZone aZone;
 
-        if (GLEW_KHR_debug)
+        if (epoxy_has_gl_extension("GL_KHR_debug"))
             glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION,
                                  GL_DEBUG_TYPE_OTHER,
                                  1, // one[sic] id is as good as another ?
                                  // GL_DEBUG_SEVERITY_NOTIFICATION for >= GL4.3 ?
                                  GL_DEBUG_SEVERITY_LOW,
                                  strlen(pStr), pStr);
-        else if (GLEW_AMD_debug_output)
+        else if (epoxy_has_gl_extension("GL_AMD_debug_output"))
             glDebugMessageInsertAMD(GL_DEBUG_CATEGORY_APPLICATION_AMD,
                                     GL_DEBUG_SEVERITY_LOW_AMD,
                                     1, // one[sic] id is as good as another ?
diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx
index ec53250..283ae94 100644
--- a/vcl/unx/generic/app/saldisp.cxx
+++ b/vcl/unx/generic/app/saldisp.cxx
@@ -47,7 +47,6 @@
 #include <X11/extensions/Xinerama.h>
 #endif
 
-#include "GL/glxew.h"
 #include <opengl/zone.hxx>
 
 #include <vcl/svapp.hxx>
diff --git a/vcl/workben/icontest.cxx b/vcl/workben/icontest.cxx
index f5028b9..6461855 100644
--- a/vcl/workben/icontest.cxx
+++ b/vcl/workben/icontest.cxx
@@ -20,8 +20,6 @@
 
 #include <math.h>
 
-#include <GL/glew.h>
-
 #include <glm/gtx/bit.hpp>
 
 #include <com/sun/star/lang/XComponent.hpp>
-- 
2.9.3