summarylogtreecommitdiffstats
path: root/git-37321d1.patch
blob: f2f878f770b84c777dcf4a1975cca9a576137aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
From 37321d1d483cee0c01285774921fb861bd6f9c1e Mon Sep 17 00:00:00 2001
From: Edoardo Prezioso <edo88@email.it>
Date: Thu, 8 Jan 2015 00:23:14 +0100
Subject: [PATCH] - Implement SDL2 into GZDoom (needs improvements).

Make also minor fixes.
Now it compiles and runs fine for me, except for the invisible cursor in the menu (no idea why).
---
 src/posix/sdl/sdlglvideo.cpp | 67 ++++++++++++++++++++++++++------------------
 src/posix/sdl/sdlglvideo.h   |  9 +++---
 2 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp
index 649989e..9331c0f 100644
--- a/src/posix/sdl/sdlglvideo.cpp
+++ b/src/posix/sdl/sdlglvideo.cpp
@@ -1,8 +1,6 @@
 
 // HEADER FILES ------------------------------------------------------------
 
-#include <iostream>
-
 #include "doomtype.h"
 
 #include "templates.h"
@@ -48,6 +46,7 @@ extern IVideo *Video;
 // extern int vid_renderer;
 
 EXTERN_CVAR (Float, Gamma)
+EXTERN_CVAR (Int, vid_adapter)
 EXTERN_CVAR (Int, vid_displaybits)
 EXTERN_CVAR (Int, vid_renderer)
 
@@ -156,14 +155,19 @@ bool SDLGLVideo::NextMode (int *width, int *height, bool *letterbox)
 	}
 	else
 	{
-		SDL_Rect **modes = SDL_ListModes (NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
-		if (modes != NULL && modes[IteratorMode] != NULL)
+		SDL_DisplayMode mode = {}, oldmode = {};
+		if(IteratorMode != 0)
+			SDL_GetDisplayMode(vid_adapter, IteratorMode-1, &oldmode);
+		do
 		{
-			*width = modes[IteratorMode]->w;
-			*height = modes[IteratorMode]->h;
+			if (SDL_GetDisplayMode(vid_adapter, IteratorMode, &mode) != 0)
+				return false;
 			++IteratorMode;
-			return true;
-		}
+		} while(mode.w == oldmode.w && mode.h == oldmode.h);
+
+		*width = mode.w;
+		*height = mode.h;
+		return true;
 	}
 	return false;
 }
@@ -182,11 +186,11 @@ DFrameBuffer *SDLGLVideo::CreateFrameBuffer (int width, int height, bool fullscr
 		if (fb->Width == width &&
 			fb->Height == height)
 		{
-			bool fsnow = (fb->Screen->flags & SDL_FULLSCREEN) != 0;
+			bool fsnow = (SDL_GetWindowFlags (fb->Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
 	
 			if (fsnow != fullscreen)
 			{
-				SDL_WM_ToggleFullScreen (fb->Screen);
+				SDL_SetWindowFullscreen (fb->Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
 			}
 			return old;
 		}
@@ -336,30 +340,37 @@ SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen)
 		return;
 	}
 
-		
-	Screen = SDL_SetVideoMode (width, height,
-		32,
-		SDL_HWSURFACE|SDL_HWPALETTE|SDL_OPENGL | SDL_GL_DOUBLEBUFFER|SDL_ANYFORMAT|
-		(fullscreen ? SDL_FULLSCREEN : 0));
+	FString caption;
+	caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
+	Screen = SDL_CreateWindow (caption,
+		SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter),
+		width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)|SDL_WINDOW_OPENGL);
 
 	if (Screen == NULL)
 		return;
 
-	m_supportsGamma = -1 != SDL_GetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]);
-	
-#if defined(__APPLE__)
-	// Need to set title here because a window is not created yet when calling the same function from main()
-	char caption[100];
-	mysnprintf(caption, countof(caption), GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
-	SDL_WM_SetCaption(caption, NULL);
-#endif // __APPLE__
+	GLContext = SDL_GL_CreateContext(Screen);
+	if (GLContext == NULL)
+		return;
+
+	m_supportsGamma = -1 != SDL_GetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]);
 }
 
 SDLGLFB::~SDLGLFB ()
 {
-	if (m_supportsGamma) 
+	if (Screen)
 	{
-		SDL_SetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]);
+		if (m_supportsGamma)
+		{
+			SDL_SetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]);
+		}
+
+		if (GLContext)
+		{
+			SDL_GL_DeleteContext(GLContext);
+		}
+
+		SDL_DestroyWindow(Screen);
 	}
 }
 
@@ -386,7 +397,7 @@ bool SDLGLFB::CanUpdate ()
 
 void SDLGLFB::SetGammaTable(WORD *tbl)
 {
-	SDL_SetGammaRamp(&tbl[0], &tbl[256], &tbl[512]);
+	SDL_SetWindowGammaRamp(Screen, &tbl[0], &tbl[256], &tbl[512]);
 }
 
 bool SDLGLFB::Lock(bool buffered)
@@ -420,7 +431,7 @@ bool SDLGLFB::IsLocked ()
 
 bool SDLGLFB::IsFullscreen ()
 {
-	return (Screen->flags & SDL_FULLSCREEN) != 0;
+	return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
 }
 
 
@@ -443,6 +454,6 @@ void SDLGLFB::NewRefreshRate ()
 
 void SDLGLFB::SwapBuffers()
 {
-	SDL_GL_SwapBuffers ();
+	SDL_GL_SwapWindow (Screen);
 }
 
diff --git a/src/posix/sdl/sdlglvideo.h b/src/posix/sdl/sdlglvideo.h
index 205e416..3867be6 100644
--- a/src/posix/sdl/sdlglvideo.h
+++ b/src/posix/sdl/sdlglvideo.h
@@ -3,7 +3,6 @@
 
 #include "hardware.h"
 #include "v_video.h"
-#include <SDL.h>
 #include "gl/system/gl_system.h"
 
 EXTERN_CVAR (Float, dimamount)
@@ -70,9 +69,11 @@ protected:
 	SDLGLFB () {}
 	BYTE GammaTable[3][256];
 	bool UpdatePending;
-	
-	SDL_Surface *Screen;
-	
+
+	SDL_Window *Screen;
+
+	SDL_GLContext GLContext;
+
 	void UpdateColors ();
 
 	int m_Lock;
-- 
2.3.2