From 182a02fcf4731c704d38a6ba47415ba6fcddc4a7 Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Wed, 3 Feb 2016 12:38:58 +0100
Subject: [PATCH] Force re-generating the textures for color cycled graphics in
 opengl mode.

---
 src/include/video.h   | 2 +-
 src/video/graphic.cpp | 8 ++++++--
 src/video/video.cpp   | 3 +++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/include/video.h b/src/include/video.h
index 568f0be7f..881cca807 100644
--- a/src/include/video.h
+++ b/src/include/video.h
@@ -439,7 +439,7 @@ extern int LoadGraphicPNG(CGraphic *g);
 #if defined(USE_OPENGL) || defined(USE_GLES)
 
 /// Make an OpenGL texture
-extern void MakeTexture(CGraphic *graphic);
+extern void MakeTexture(CGraphic *graphic, bool force = false);
 /// Make an OpenGL texture of the player color pixels only.
 extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player);
 
diff --git a/src/video/graphic.cpp b/src/video/graphic.cpp
index dfb2edb9a..fdc8711d6 100644
--- a/src/video/graphic.cpp
+++ b/src/video/graphic.cpp
@@ -1201,10 +1201,14 @@ static void MakeTextures(CGraphic *g, int player, CUnitColors *colors)
 **
 **  @param g  The graphic object.
 */
-void MakeTexture(CGraphic *g)
+void MakeTexture(CGraphic *g, bool force)
 {
 	if (g->Textures) {
-		return;
+		if (force) {
+			glDeleteTextures(g->NumTextures, g->Textures);
+		} else {
+			return;
+		}
 	}
 
 	MakeTextures(g, 0, NULL);
diff --git a/src/video/video.cpp b/src/video/video.cpp
index bce783855..876f0122d 100644
--- a/src/video/video.cpp
+++ b/src/video/video.cpp
@@ -471,6 +471,9 @@ void ColorCycle()
 	} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
 		++colorCycling.cycleCount;
 		ColorCycleSurface(*Map.TileGraphic->Surface);
+#if defined(USE_OPENGL) || defined(USE_GLES)
+		MakeTexture(Map.TileGraphic, true);
+#endif
 	}
 }