From a934d04b8c49c250e9be27581129c75bc058814a Mon Sep 17 00:00:00 2001
From: Simon Judd <sirjuddington@gmail.com>
Date: Mon, 9 Dec 2019 12:26:17 +1030
Subject: [PATCH] Always use wxGLCanvas as a base for OGLCanvas

Even if using SFML - this fixes the depth buffer not being created on linux
---

diff --git a/src/OpenGL/OpenGL.cpp b/src/OpenGL/OpenGL.cpp
index 7e506550..0a8d4236 100644
--- a/src/OpenGL/OpenGL.cpp
+++ b/src/OpenGL/OpenGL.cpp
@@ -38,14 +38,14 @@ CVAR(Bool, gl_tex_enable_np2, true, CVAR_SAVE)
 CVAR(Bool, gl_point_sprite, true, CVAR_SAVE)
 CVAR(Bool, gl_tweak_accuracy, true, CVAR_SAVE)
 CVAR(Bool, gl_vbo, true, CVAR_SAVE)
-CVAR(Int, gl_depth_buffer_size, 16, CVAR_SAVE)
+CVAR(Int, gl_depth_buffer_size, 24, CVAR_SAVE)
 
 namespace OpenGL
 {
 #ifndef USE_SFML_RENDERWINDOW
 	wxGLContext*	context = NULL;
-	int				wx_gl_attrib[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, WX_GL_STENCIL_SIZE, 8, 0 };
 #endif
+	int				wx_gl_attrib[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, WX_GL_STENCIL_SIZE, 8, 0 };
 	bool			initialised = false;
 	double			version = 0;
 	unsigned		max_tex_size = 128;
@@ -224,7 +224,6 @@ bool OpenGL::accuracyTweak()
 	return gl_tweak_accuracy;
 }
 
-#ifndef USE_SFML_RENDERWINDOW
 /* OpenGL::getWxGLAttribs
  * Returns the GL attributes array for use with wxGLCanvas
  *******************************************************************/
@@ -235,7 +234,6 @@ int* OpenGL::getWxGLAttribs()
 
 	return wx_gl_attrib;
 }
-#endif
 
 /* OpenGL::setColour
  * Sets the colour to [col], and changes the colour blend mode if
diff --git a/src/OpenGL/OpenGL.h b/src/OpenGL/OpenGL.h
index 1d5c9b9a..9082687c 100644
--- a/src/OpenGL/OpenGL.h
+++ b/src/OpenGL/OpenGL.h
@@ -20,10 +20,8 @@
 #include <GL/glu.h>
 #endif
 
-#ifndef USE_SFML_RENDERWINDOW
 #include <wx/glcanvas.h>
 #undef None // Why does <X11/X.h> #define this? Idiotic
-#endif
 
 #define BLEND_NORMAL	0
 #define BLEND_ADDITIVE	1
@@ -56,9 +54,7 @@ namespace OpenGL
 	unsigned		maxTextureSize();
 	bool			isInitialised();
 	bool			accuracyTweak();
-#ifndef USE_SFML_RENDERWINDOW
 	int*			getWxGLAttribs();
-#endif
 	void			setColour(rgba_t col, bool set_blend = true);
 	void			setColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255, int8_t blend = BLEND_IGNORE);
 	void			setBlend(int blend);
diff --git a/src/UI/Canvas/OGLCanvas.cpp b/src/UI/Canvas/OGLCanvas.cpp
index 4bba9f98..a48d9ac6 100644
--- a/src/UI/Canvas/OGLCanvas.cpp
+++ b/src/UI/Canvas/OGLCanvas.cpp
@@ -55,8 +55,9 @@ EXTERN_CVAR(Int, gl_depth_buffer_size)
 /* OGLCanvas::OGLCanvas
  * OGLCanvas class constructor, SFML implementation
  *******************************************************************/
-OGLCanvas::OGLCanvas(wxWindow* parent, int id, bool handle_timer, int timer_interval)
-	: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxWANTS_CHARS), timer(this)
+OGLCanvas::OGLCanvas(wxWindow* parent, int id, bool handle_timer, int timer_interval) :
+	wxGLCanvas(parent, id, OpenGL::getWxGLAttribs(), wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxWANTS_CHARS),
+	timer(this)
 {
 	init_done = false;
 	recreate = false;
diff --git a/src/UI/Canvas/OGLCanvas.h b/src/UI/Canvas/OGLCanvas.h
index 9b9b07db..128cb633 100644
--- a/src/UI/Canvas/OGLCanvas.h
+++ b/src/UI/Canvas/OGLCanvas.h
@@ -8,7 +8,7 @@
 
 class wxWindow;
 #ifdef USE_SFML_RENDERWINDOW
-class OGLCanvas : public wxControl, public sf::RenderWindow
+class OGLCanvas : public wxGLCanvas, public sf::RenderWindow
 {
 #else
 class OGLCanvas : public wxGLCanvas
@@ -38,7 +38,11 @@ public:
 	void			setup2D();
 
 #ifdef USE_SFML_RENDERWINDOW
-	void	SwapBuffers() { display(); }
+	bool SwapBuffers() override
+	{
+		display();
+		return true;
+	}
 #endif
 
 	void	onPaint(wxPaintEvent& e);
