summaryrefslogtreecommitdiff
path: root/pcr/reicast-multilib-git/sdl-opengl.patch
blob: 372ec9a52fee9ad7c9303e1c2c3e7695603d77a6 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
diff -Nur a/core/khronos/GL3/gl3w.c b/core/khronos/GL3/gl3w.c
--- a/core/khronos/GL3/gl3w.c	2015-10-06 21:43:53.040336386 -0300
+++ b/core/khronos/GL3/gl3w.c	2015-10-06 22:04:39.682388782 -0300
@@ -1,6 +1,25 @@
 #include <GL3/gl3w.h>
 
-#ifdef _WIN32
+#if defined(USE_SDL2)
+	#include <SDL2/SDL.h>
+	static void open_libgl(void)
+	{
+		SDL_GL_LoadLibrary(NULL);
+	}
+
+	static void close_libgl(void)
+	{
+		SDL_GL_UnloadLibrary();
+	}
+
+	static void *get_proc(const char *proc)
+	{
+		void *res = NULL;
+		res = (void*)SDL_GL_GetProcAddress(proc);
+		return res;
+	}
+
+#elif defined(_WIN32)
 #define WIN32_LEAN_AND_MEAN 1
 #include <windows.h>
 
diff -Nur a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp
--- a/core/sdl/sdl.cpp	2015-10-06 21:43:53.048336444 -0300
+++ b/core/sdl/sdl.cpp	2015-10-06 22:04:39.683388790 -0300
@@ -5,6 +5,18 @@
 #include "sdl/sdl.h"
 #ifdef GLES
 	#include <EGL/egl.h>
+#else
+	#ifndef USE_SDL2
+		#error "Our SDL1.2 implementation only supports GLES. You need SDL2 for OpenGL 3 support!"
+	#endif
+	#include "khronos/GL3/gl3w.h"
+#endif
+
+#ifdef USE_SDL2
+	static SDL_Window* window = NULL;
+	static SDL_GLContext glcontext;
+#else
+	SDL_Surface *screen = NULL;
 #endif
 
 #ifdef TARGET_PANDORA
@@ -14,8 +26,6 @@
 #endif
 #define WINDOW_HEIGHT  480
 
-SDL_Surface *screen = NULL;
-
 static SDL_Joystick *JoySDL = 0;
 
 extern bool FrameSkipping;
@@ -80,11 +90,15 @@
 
 		AxisCount = SDL_JoystickNumAxes(JoySDL);
 		ButtonCount = SDL_JoystickNumButtons(JoySDL);
-		Name = SDL_JoystickName(0);
-		
+		#ifdef USE_SDL2
+			Name = SDL_JoystickName(JoySDL);
+		#else
+			Name = SDL_JoystickName(0);
+		#endif
+
 		printf("SDK: Found '%s' joystick with %d axes and %d buttons\n", Name, AxisCount, ButtonCount);
 
-		if (strcmp(Name,"Microsoft X-Box 360 pad")==0)
+		if (Name != NULL && strcmp(Name,"Microsoft X-Box 360 pad")==0)
 		{
 			sdl_map_btn  = sdl_map_btn_xbox360;
 			sdl_map_axis = sdl_map_axis_xbox360;
@@ -113,12 +127,16 @@
 		}
 	#endif
 	
-	SDL_ShowCursor(0);
+	#ifndef USE_SDL2
+		SDL_ShowCursor(0);
 
-	if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
-	{
-		printf("SDK: Error while grabbing mouse\n");
-	}
+		if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
+		{
+			printf("SDL: Error while grabbing mouse\n");
+		}
+	#else
+		SDL_SetRelativeMouseMode(SDL_TRUE);
+	#endif
 }
 
 void input_sdl_handle(u32 port)
@@ -397,7 +415,14 @@
 	#ifdef TARGET_PANDORA
 		strncpy(OSD_Counters, text, 256);
 	#else
-		SDL_WM_SetCaption(text, NULL);    // *TODO*  Set Icon also...
+		#ifdef USE_SDL2
+			if(window)
+			{
+				SDL_SetWindowTitle(window, text);    // *TODO*  Set Icon also...
+			}
+		#else
+			SDL_WM_SetCaption(text, NULL);
+		#endif
 	#endif
 }
 
@@ -415,17 +440,79 @@
 
 	int window_width  = cfgLoadInt("x11","width", WINDOW_WIDTH);
 	int window_height = cfgLoadInt("x11","height", WINDOW_HEIGHT);
+
 	#ifdef TARGET_PANDORA
 		int flags = SDL_FULLSCREEN;
 	#else
 		int flags = SDL_SWSURFACE;
 	#endif
-	screen = SDL_SetVideoMode(window_width, window_height, 0, flags);
-	if (!screen)
-	{
-		die("error creating SDL screen");
-	}
-	x11_disp = EGL_DEFAULT_DISPLAY;
-	printf("Created SDL Windows (%ix%i) successfully\n", window_width, window_height);
+
+	#if !defined(GLES) && defined(USE_SDL2)
+		flags |= SDL_WINDOW_OPENGL;
+
+		SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
+		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+		SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+		window = SDL_CreateWindow("Reicast Emulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,	window_width, window_height, flags);
+		if (!window)
+		{
+			die("error creating SDL window");
+		}
+
+		glcontext = SDL_GL_CreateContext(window);
+		if (!glcontext)
+		{
+			die("Error creating SDL GL context");
+		}
+		SDL_GL_MakeCurrent(window, NULL);
+	#else
+		screen = SDL_SetVideoMode(window_width, window_height, 0, flags);
+		if (!screen)
+		{
+			die("error creating SDL screen");
+		}
+
+		x11_disp = EGL_DEFAULT_DISPLAY;
+	#endif
+
+	printf("Created SDL Window (%ix%i) and GL Context successfully\n", window_width, window_height);
 }
 #endif
+
+#if !defined(GLES) && defined(USE_SDL2)
+	extern int screen_width, screen_height;
+
+	bool gl_init(void* wind, void* disp)
+	{
+		SDL_GL_MakeCurrent(window, glcontext);
+		return gl3wInit() != -1 && gl3wIsSupported(3, 1);
+	}
+
+	void gl_swap()
+	{
+		SDL_GL_SwapWindow(window);
+
+		/* Check if drawable has been resized */
+		int new_width, new_height;
+		SDL_GL_GetDrawableSize(window, &new_width, &new_height);
+
+		if (new_width != screen_width || new_height != screen_height)
+		{
+			screen_width = new_width;
+			screen_height = new_height;
+		}
+	}
+
+	void gl_term()
+	{
+		SDL_GL_DeleteContext(glcontext);
+	}
+#endif
\ No newline at end of file
diff -Nur a/core/sdl/sdl.h b/core/sdl/sdl.h
--- a/core/sdl/sdl.h	2015-10-06 21:43:53.048336444 -0300
+++ b/core/sdl/sdl.h	2015-10-06 22:04:39.683388790 -0300
@@ -1,5 +1,9 @@
 #pragma once
-#include <SDL/SDL.h>
+#ifdef USE_SDL2
+	#include <SDL2/SDL.h>
+#else
+	#include <SDL/SDL.h>
+#endif
 extern void* sdl_glc;
 extern void input_sdl_init();
 extern void input_sdl_handle(u32 port);
diff -Nur a/shell/linux/Makefile b/shell/linux/Makefile
--- a/shell/linux/Makefile	2015-10-06 21:43:53.161337253 -0300
+++ b/shell/linux/Makefile	2015-10-06 22:04:39.683388790 -0300
@@ -175,6 +175,10 @@
     $(error Unknown platform)
 endif
 
+ifdef USE_SDL2
+    USE_SDL := 1
+endif
+
 RZDCY_SRC_DIR = ../../core
 include $(RZDCY_SRC_DIR)/core.mk
 
@@ -202,8 +206,14 @@
 endif
 
 ifdef USE_SDL
-    CXXFLAGS += `sdl-config --cflags` -D USE_SDL
-    LIBS += `sdl-config --libs`
+    CXXFLAGS += -D USE_SDL
+    ifdef USE_SDL2
+        CXXFLAGS += `sdl2-config --cflags` -D USE_SDL2
+        LIBS += `sdl2-config --libs`
+    else
+        CXXFLAGS += `sdl-config --cflags`
+        LIBS += `sdl-config --libs`
+    endif
 endif
 
 ifdef PGO_MAKE