From b7e8d7d04437e536d3fb2f9a79cfd2ac5d4ff788 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 01:04:17 -0600 Subject: [PATCH 01/14] Fix -nomouse --- src/sdl/i_video.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a59db26c..fd24c430 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -818,30 +818,33 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) event_t event; int wwidth, wheight; - SDL_GetWindowSize(window, &wwidth, &wheight); - - if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) + if (USE_MOUSEINPUT) { - SDLdoUngrabMouse(); - return; - } + SDL_GetWindowSize(window, &wwidth, &wheight); - if ((evt.x == realwidth/2) && (evt.y == realheight/2)) - { - return; - } - else - { - event.data2 = (evt.xrel) * (wwidth / realwidth); - event.data3 = -evt.yrel * (wheight / realheight); - } + if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) + { + SDLdoUngrabMouse(); + return; + } - event.type = ev_mouse; + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) + { + return; + } + else + { + event.data2 = (int)round((evt.xrel) * ((float)wwidth / (float)realwidth)); + event.data3 = (int)round(-evt.yrel * ((float)wheight / (float)realheight)); + } - if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) - { - D_PostEvent(&event); - HalfWarpMouse(wwidth, wheight); + event.type = ev_mouse; + + if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) + { + D_PostEvent(&event); + HalfWarpMouse(wwidth, wheight); + } } } From 4c55b5db2086df2861b7d24ced5109110230cd19 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 01:36:06 -0600 Subject: [PATCH 02/14] Center only on display 1. No more multimonitor span. --- src/sdl/i_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index fd24c430..6be2ede1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -198,13 +198,13 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) glfallbackresolution = SDL_FALSE; SDL_SetWindowFullscreen(window, 0); SDL_SetWindowSize(window, width, height); - SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED_DISPLAY(1), SDL_WINDOWPOS_CENTERED_DISPLAY(1)); } else if (!wasfullscreen) { // Reposition window only in windowed mode SDL_SetWindowSize(window, width, height); - SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED_DISPLAY(1), SDL_WINDOWPOS_CENTERED_DISPLAY(1)); } } else From b82f64dea51d2ec6236565b0fc1ea935f7a8b41c Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 01:51:29 -0600 Subject: [PATCH 03/14] Display error window on crash --- src/sdl/i_system.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index d3793b6d..23da092f 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -301,37 +301,38 @@ SDL_bool framebuffer = SDL_FALSE; UINT8 keyboard_started = false; -#if 0 static void signal_handler(INT32 num) { //static char msg[] = "oh no! back to reality!\r\n"; char * sigmsg; char sigdef[32]; + D_QuitNetGame(); // Fix server freezes + switch (num) { case SIGINT: - sigmsg = "interrupt"; + sigmsg = "SIGINT - interrupted"; break; case SIGILL: - sigmsg = "illegal instruction - invalid function image"; + sigmsg = "SIGILL - illegal instruction - invalid function image"; break; case SIGFPE: - sigmsg = "floating point exception"; + sigmsg = "SIGFPE - floating point exception"; break; case SIGSEGV: - sigmsg = "segment violation"; + sigmsg = "SIGSEGV - segment violation"; break; case SIGTERM: - sigmsg = "Software termination signal from kill"; + sigmsg = "SIGTERM - Software termination signal from kill"; break; #if !(defined (__unix_) || defined (UNIXCOMMON)) case SIGBREAK: - sigmsg = "Ctrl-Break sequence"; + sigmsg = "SIGBREAK - Ctrl-Break sequence"; break; #endif case SIGABRT: - sigmsg = "abnormal termination triggered by abort call"; + sigmsg = "SIGABRT - abnormal termination triggered by abort call"; break; default: sprintf(sigdef,"signal number %d", num); @@ -339,11 +340,15 @@ static void signal_handler(INT32 num) } I_OutputMsg("signal_handler() error: %s\n", sigmsg); + + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + "Signal caught", + sigmsg, NULL); + I_ShutdownSystem(); signal(num, SIG_DFL); //default signal action raise(num); I_Quit(); } -#endif #if defined (NDEBUG) && !defined (DC) && !defined (_WIN32_WCE) FUNCNORETURN static ATTRNORETURN void quit_handler(int num) @@ -739,19 +744,19 @@ void I_StartupKeyboard (void) { #if defined (NDEBUG) && !defined (DC) #ifdef SIGILL -// signal(SIGILL , signal_handler); + signal(SIGILL , signal_handler); #endif #ifdef SIGINT signal(SIGINT , quit_handler); #endif #ifdef SIGSEGV -// signal(SIGSEGV , signal_handler); + signal(SIGSEGV , signal_handler); #endif #ifdef SIGBREAK signal(SIGBREAK , quit_handler); #endif #ifdef SIGABRT -// signal(SIGABRT , signal_handler); + signal(SIGABRT , signal_handler); #endif #ifdef SIGTERM signal(SIGTERM , quit_handler); From 0913bd44af597940bc1e8e66cd60b4c1b396eea8 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 03:51:33 -0600 Subject: [PATCH 04/14] Fix mouse warping In some cases, the warp back to center was being detected as a mouse motion, causing all sorts of silliness with the mouse. The workaround is by only using the first motion event and ignoring every event after that, until the next call to I_GetEvent. --- src/sdl/i_video.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6be2ede1..b592d3bc 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -987,6 +987,9 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) void I_GetEvent(void) { SDL_Event evt; + // We only want the first motion event, + // otherwise we'll end up catching the warp back to center. + int mouseMotionOnce = 0; if (!graphics_started) { @@ -1005,7 +1008,8 @@ void I_GetEvent(void) Impl_HandleKeyboardEvent(evt.key, evt.type); break; case SDL_MOUSEMOTION: - Impl_HandleMouseMotionEvent(evt.motion); + if (!mouseMotionOnce) Impl_HandleMouseMotionEvent(evt.motion); + mouseMotionOnce = 1; break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: From 80891e916d9f5163874ba1d7e918d47922883ae6 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 15:19:39 -0600 Subject: [PATCH 05/14] Use scancodes instead of keycodes for locale independence. ONLY US KEYBOARDS SUPPORTED! THAT'S HOW WE DO IT IN AMURRICA --- src/sdl/i_video.c | 153 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b592d3bc..ceb13ffe 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -278,8 +278,157 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) } } +static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) +{ + if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) + { + // get lowercase ASCII + return code - SDL_SCANCODE_A + 'a'; + } + if (code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9) + { + return code - SDL_SCANCODE_1 + '1'; + } + else if (code == SDL_SCANCODE_0) + { + return '0'; + } + if (code >= SDL_SCANCODE_F1 && code <= SDL_SCANCODE_F12) + { + return KEY_F1 + (code - SDL_SCANCODE_F1); + } + switch (code) + { + case SDL_SCANCODE_KP_0: + return KEY_KEYPAD0; + case SDL_SCANCODE_KP_1: + return KEY_KEYPAD1; + case SDL_SCANCODE_KP_2: + return KEY_KEYPAD2; + case SDL_SCANCODE_KP_3: + return KEY_KEYPAD3; + case SDL_SCANCODE_KP_4: + return KEY_KEYPAD4; + case SDL_SCANCODE_KP_5: + return KEY_KEYPAD5; + case SDL_SCANCODE_KP_6: + return KEY_KEYPAD6; + case SDL_SCANCODE_KP_7: + return KEY_KEYPAD7; + case SDL_SCANCODE_KP_8: + return KEY_KEYPAD8; + case SDL_SCANCODE_KP_9: + return KEY_KEYPAD9; + + case SDL_SCANCODE_RETURN: + return KEY_ENTER; + case SDL_SCANCODE_ESCAPE: + return KEY_ESCAPE; + case SDL_SCANCODE_BACKSPACE: + return KEY_BACKSPACE; + case SDL_SCANCODE_TAB: + return KEY_TAB; + case SDL_SCANCODE_SPACE: + return KEY_SPACE; + case SDL_SCANCODE_MINUS: + return KEY_MINUS; + case SDL_SCANCODE_EQUALS: + return KEY_EQUALS; + case SDL_SCANCODE_LEFTBRACKET: + return '['; + case SDL_SCANCODE_RIGHTBRACKET: + return ']'; + case SDL_SCANCODE_BACKSLASH: + return '\\'; + case SDL_SCANCODE_NONUSHASH: + return '#'; + case SDL_SCANCODE_SEMICOLON: + return ';'; + case SDL_SCANCODE_APOSTROPHE: + return '\''; + case SDL_SCANCODE_GRAVE: + return '`'; + case SDL_SCANCODE_COMMA: + return ','; + case SDL_SCANCODE_PERIOD: + return '.'; + case SDL_SCANCODE_SLASH: + return '/'; + case SDL_SCANCODE_CAPSLOCK: + return KEY_CAPSLOCK; + case SDL_SCANCODE_PRINTSCREEN: + return 0; // undefined? + case SDL_SCANCODE_SCROLLLOCK: + return KEY_SCROLLLOCK; + case SDL_SCANCODE_PAUSE: + return KEY_PAUSE; + case SDL_SCANCODE_INSERT: + return KEY_INS; + case SDL_SCANCODE_HOME: + return KEY_HOME; + case SDL_SCANCODE_PAGEUP: + return KEY_PGUP; + case SDL_SCANCODE_DELETE: + return KEY_DEL; + case SDL_SCANCODE_END: + return KEY_END; + case SDL_SCANCODE_PAGEDOWN: + return KEY_PGDN; + case SDL_SCANCODE_RIGHT: + return KEY_RIGHTARROW; + case SDL_SCANCODE_LEFT: + return KEY_LEFTARROW; + case SDL_SCANCODE_DOWN: + return KEY_DOWNARROW; + case SDL_SCANCODE_UP: + return KEY_UPARROW; + case SDL_SCANCODE_NUMLOCKCLEAR: + return KEY_NUMLOCK; + case SDL_SCANCODE_KP_DIVIDE: + return KEY_KPADSLASH; + case SDL_SCANCODE_KP_MULTIPLY: + return '*'; // undefined? + case SDL_SCANCODE_KP_MINUS: + return KEY_MINUSPAD; + case SDL_SCANCODE_KP_PLUS: + return KEY_PLUSPAD; + case SDL_SCANCODE_KP_ENTER: + return KEY_ENTER; + case SDL_SCANCODE_KP_PERIOD: + return KEY_KPADDEL; + case SDL_SCANCODE_NONUSBACKSLASH: + return '\\'; + + case SDL_SCANCODE_LSHIFT: + return KEY_LSHIFT; + case SDL_SCANCODE_RSHIFT: + return KEY_RSHIFT; + case SDL_SCANCODE_LCTRL: + return KEY_LCTRL; + case SDL_SCANCODE_RCTRL: + return KEY_RCTRL; + case SDL_SCANCODE_LALT: + return KEY_LALT; + case SDL_SCANCODE_RALT: + return KEY_RALT; + case SDL_SCANCODE_LGUI: + return KEY_LEFTWIN; + case SDL_SCANCODE_RGUI: + return KEY_RIGHTWIN; + default: + break; + } + DBG_Printf("Unknown incoming scancode: %d, represented %c\n", + code, + SDL_GetKeyName(SDL_GetKeyFromScancode(code))); + return 0; +} + // -// Translates the SDL key into SRB2 key +// Translates the SDL scancode into SRB2 key +// +// Deprecated: keycodes in SDL2 are not scancode based. +// They do not work with non-US keyboards anymore. // static INT32 SDLatekey(SDL_Keycode sym) @@ -809,7 +958,7 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) { return; } - event.data1 = SDLatekey(evt.keysym.sym); + event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym.scancode); if (event.data1) D_PostEvent(&event); } From 5d0eafb26a020239e3d84b10a01d505a8ec7c1df Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 15:31:32 -0600 Subject: [PATCH 06/14] Fix MOUSE4/MOUSE5 MOUSE6-8 will not be supported on SDL2 as there is no interface for them. --- src/sdl/i_video.c | 228 +--------------------------------------------- 1 file changed, 5 insertions(+), 223 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ceb13ffe..566fb5b9 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -424,226 +424,6 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) return 0; } -// -// Translates the SDL scancode into SRB2 key -// -// Deprecated: keycodes in SDL2 are not scancode based. -// They do not work with non-US keyboards anymore. -// - -static INT32 SDLatekey(SDL_Keycode sym) -{ - INT32 rc = sym + 0x80; - - switch (sym) - { - case SDLK_LEFT: - rc = KEY_LEFTARROW; - break; - case SDLK_RIGHT: - rc = KEY_RIGHTARROW; - break; - case SDLK_DOWN: - rc = KEY_DOWNARROW; - break; - case SDLK_UP: - rc = KEY_UPARROW; - break; - - case SDLK_ESCAPE: - rc = KEY_ESCAPE; - break; - case SDLK_SPACE: - rc = KEY_SPACE; - break; - case SDLK_RETURN: - case SDLK_KP_ENTER: - rc = KEY_ENTER; - break; - case SDLK_TAB: - rc = KEY_TAB; - break; - case SDLK_F1: - rc = KEY_F1; - break; - case SDLK_F2: - rc = KEY_F2; - break; - case SDLK_F3: - rc = KEY_F3; - break; - case SDLK_F4: - rc = KEY_F4; - break; - case SDLK_F5: - rc = KEY_F5; - break; - case SDLK_F6: - rc = KEY_F6; - break; - case SDLK_F7: - rc = KEY_F7; - break; - case SDLK_F8: - rc = KEY_F8; - break; - case SDLK_F9: - rc = KEY_F9; - break; - case SDLK_F10: - rc = KEY_F10; - break; - case SDLK_F11: - rc = KEY_F11; - break; - case SDLK_F12: - rc = KEY_F12; - break; - - case SDLK_BACKSPACE: - rc = KEY_BACKSPACE; - break; - case SDLK_DELETE: - rc = KEY_DEL; - break; - - case SDLK_KP_EQUALS: //Alam & Logan: WTF? Mac KB haves one! XD - case SDLK_PAUSE: - rc = KEY_PAUSE; - break; - - case SDLK_EQUALS: - case SDLK_PLUS: - rc = KEY_EQUALS; - break; - - case SDLK_MINUS: - rc = KEY_MINUS; - break; - - case SDLK_LSHIFT: - rc = KEY_LSHIFT; - break; - - case SDLK_RSHIFT: - rc = KEY_RSHIFT; - break; - - case SDLK_CAPSLOCK: - rc = KEY_CAPSLOCK; - break; - - case SDLK_LCTRL: - rc = KEY_LCTRL; - break; - case SDLK_RCTRL: - rc = KEY_RCTRL; - break; - - case SDLK_LALT: - rc = KEY_LALT; - break; - case SDLK_RALT: - rc = KEY_RALT; - break; - - case SDLK_NUMLOCKCLEAR: - rc = KEY_NUMLOCK; - break; - case SDLK_SCROLLLOCK: - rc = KEY_SCROLLLOCK; - break; - - case SDLK_PAGEUP: - rc = KEY_PGUP; - break; - case SDLK_PAGEDOWN: - rc = KEY_PGDN; - break; - case SDLK_END: - rc = KEY_END; - break; - case SDLK_HOME: - rc = KEY_HOME; - break; - case SDLK_INSERT: - rc = KEY_INS; - break; - - case SDLK_KP_0: - rc = KEY_KEYPAD0; - break; - case SDLK_KP_1: - rc = KEY_KEYPAD1; - break; - case SDLK_KP_2: - rc = KEY_KEYPAD2; - break; - case SDLK_KP_3: - rc = KEY_KEYPAD3; - break; - case SDLK_KP_4: - rc = KEY_KEYPAD4; - break; - case SDLK_KP_5: - rc = KEY_KEYPAD5; - break; - case SDLK_KP_6: - rc = KEY_KEYPAD6; - break; - case SDLK_KP_7: - rc = KEY_KEYPAD7; - break; - case SDLK_KP_8: - rc = KEY_KEYPAD8; - break; - case SDLK_KP_9: - rc = KEY_KEYPAD9; - break; - - case SDLK_KP_PERIOD: - rc = KEY_KPADDEL; - break; - case SDLK_KP_DIVIDE: - rc = KEY_KPADSLASH; - break; - case SDLK_KP_MULTIPLY: - rc = '*'; - break; - case SDLK_KP_MINUS: - rc = KEY_MINUSPAD; - break; - case SDLK_KP_PLUS: - rc = KEY_PLUSPAD; - break; - - case SDLK_LMETA: - rc = KEY_LEFTWIN; - break; - case SDLK_RMETA: - rc = KEY_RIGHTWIN; - break; - - case SDLK_MENU: - rc = KEY_MENU; - break; - - default: - if (sym >= SDLK_SPACE && sym <= SDLK_DELETE) - rc = sym - SDLK_SPACE + ' '; - else if (sym >= 'A' && sym <= 'Z') - rc = sym - 'A' + 'a'; - else if (sym) - { - I_OutputMsg("Unknown Keycode %i, Name: %s\n",sym, SDL_GetKeyName( sym )); - } - else if (!sym) rc = 0; - break; - } - - return rc; -} - static void SDLdoUngrabMouse(void) { SDL_SetWindowGrab(window, SDL_FALSE); @@ -1020,9 +800,11 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) else if (evt.button == SDL_BUTTON_RIGHT) event.data1 = KEY_MOUSE1+1; else if (evt.button == SDL_BUTTON_LEFT) - event.data1= KEY_MOUSE1; - else if (evt.button <= MOUSEBUTTONS) - event.data1 = KEY_MOUSE1 + evt.which - SDL_BUTTON_LEFT; + event.data1 = KEY_MOUSE1; + else if (evt.button == SDL_BUTTON_X1) + event.data1 = KEY_MOUSE1+3; + else if (evt.button == SDL_BUTTON_X2) + event.data1 = KEY_MOUSE1+4; if (event.type == ev_keyup || event.type == ev_keydown) { D_PostEvent(&event); From d8484a86e04705e3bfce104b7df687499f962423 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 18:06:38 -0600 Subject: [PATCH 07/14] Virtual resolutions in OpenGL Also made fades use core functions if they are available. --- src/hardware/hw_drv.h | 4 ++ src/hardware/hw_main.c | 10 +++ src/hardware/hw_main.h | 2 + src/hardware/r_opengl/r_opengl.c | 112 ++++++++++++++++++++++++++++++- src/sdl/hwsym_sdl.c | 2 + src/sdl/i_video.c | 26 ++----- src/sdl/ogl_sdl.c | 9 +++ src/sdl/ogl_sdl.h | 2 + 8 files changed, 142 insertions(+), 25 deletions(-) diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 76fce5e4..e0c2f327 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -84,6 +84,8 @@ EXPORT void HWRAPI(EndScreenWipe) (void); EXPORT void HWRAPI(DoScreenWipe) (float alpha); EXPORT void HWRAPI(DrawIntermissionBG) (void); EXPORT void HWRAPI(MakeScreenTexture) (void); +EXPORT void HWRAPI(MakeScreenFinalTexture) (void); +EXPORT void HWRAPI(DrawScreenFinalTexture) (int width, int height); // ========================================================================== // HWR DRIVER OBJECT, FOR CLIENT PROGRAM // ========================================================================== @@ -127,6 +129,8 @@ struct hwdriver_s DoScreenWipe pfnDoScreenWipe; DrawIntermissionBG pfnDrawIntermissionBG; MakeScreenTexture pfnMakeScreenTexture; + MakeScreenFinalTexture pfnMakeScreenFinalTexture; + DrawScreenFinalTexture pfnDrawScreenFinalTexture; }; extern struct hwdriver_s hwdriver; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0ae24585..04175d50 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5936,4 +5936,14 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) HWRWipeCounter = 1.0f; } +void HWR_MakeScreenFinalTexture(void) +{ + HWD.pfnMakeScreenFinalTexture(); +} + +void HWR_DrawScreenFinalTexture(int width, int height) +{ + HWD.pfnDrawScreenFinalTexture(width, height); +} + #endif // HWRENDER diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 96994644..af7d821b 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -65,6 +65,8 @@ void HWR_StartScreenWipe(void); void HWR_EndScreenWipe(void); void HWR_DrawIntermissionBG(void); void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum); +void HWR_MakeScreenFinalTexture(void); +void HWR_DrawScreenFinalTexture(int width, int height); // This stuff is put here so MD2's can use them UINT32 HWR_Lighting(INT32 light, UINT32 color, UINT32 fadecolor, boolean fogblockpoly, boolean plane); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 631bb665..6b37a666 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -110,6 +110,7 @@ static GLint viewport[4]; static GLuint screentexture = 60000; static GLuint startScreenWipe = 60001; static GLuint endScreenWipe = 60002; +static GLuint finalScreenTexture = 60003; #if 0 GLuint screentexture = FIRST_TEX_AVAIL; #endif @@ -269,8 +270,8 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #endif #ifndef MINI_GL_COMPATIBILITY /* 1.3 functions for multitexturing */ -#define pglActiveTexture, glActiveTexture; -#define pglMultiTexCoord2f, glMultiTexCoord2f; +#define pglActiveTexture glActiveTexture +#define pglMultiTexCoord2f glMultiTexCoord2f #endif #else //!STATIC_OPENGL @@ -520,13 +521,40 @@ boolean SetupGLfunc(void) // This has to be done after the context is created so the version number can be obtained boolean SetupGLFunc13(void) { + const GLubyte *version = pglGetString(GL_VERSION); + int glmajor, glminor; + + gl13 = false; #ifdef MINI_GL_COMPATIBILITY return false; #else #ifdef STATIC_OPENGL gl13 = true; #else - if (isExtAvailable("GL_ARB_multitexture", gl_extensions)) + + // Parse the GL version + if (version != NULL) + { + if (sscanf(version, "%d.%d", &glmajor, &glminor) == 2) + { + // Look, we gotta prepare for the inevitable arrival of GL 2.0 code... + switch (glmajor) + { + case 1: + if (glminor == 3) gl13 = true; + break; + default: + break; + } + } + } + + if (gl13) + { + pglActiveTexture = GetGLFunc("glActiveTexture"); + pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); + } + else if (isExtAvailable("GL_ARB_multitexture", gl_extensions)) { // Get the functions pglActiveTexture = GetGLFunc("glActiveTextureARB"); @@ -2245,6 +2273,7 @@ EXPORT void HWRAPI(DoScreenWipe)(float alpha) pglActiveTexture(GL_TEXTURE0); pglEnable(GL_TEXTURE_2D); pglBindTexture(GL_TEXTURE_2D, endScreenWipe); + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); pglActiveTexture(GL_TEXTURE1); pglEnable(GL_TEXTURE_2D); @@ -2339,4 +2368,81 @@ EXPORT void HWRAPI(MakeScreenTexture) (void) tex_downloaded = 0; // 0 so it knows it doesn't have any of the cached patches downloaded right now } +EXPORT void HWRAPI(MakeScreenFinalTexture) (void) +{ + INT32 texsize = 2048; + + // Use a power of two texture, dammit + if(screen_width <= 512) + texsize = 512; + else if(screen_width <= 1024) + texsize = 1024; + + // Create screen texture + pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); +#ifdef KOS_GL_COMPATIBILITY + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_FILTER_NONE); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_FILTER_NONE); +#else + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); +#endif + Clamp2D(GL_TEXTURE_WRAP_S); + Clamp2D(GL_TEXTURE_WRAP_T); +#ifndef KOS_GL_COMPATIBILITY + pglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, texsize, texsize, 0); +#endif + + tex_downloaded = 0; // 0 so it knows it doesn't have any of the cached patches downloaded right now + +} + +EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) +{ + float xfix, yfix; + int lmaxx, lmaxy; + INT32 texsize = 2048; + + lmaxx = width < screen_width ? screen_width : width; + lmaxy = height < screen_height ? screen_height : height; + + if(screen_width <= 1024) + texsize = 1024; + if(screen_width <= 512) + texsize = 512; + + xfix = 1/((float)(texsize)/((float)((screen_width)))); + yfix = 1/((float)(texsize)/((float)((screen_height)))); + + //pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + pglViewport(0, 0, width, height); + + pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); + pglBegin(GL_QUADS); + + pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); + // Bottom left + pglTexCoord2f(0.0f, 0.0f); + pglVertex3f(-1, -1, 1.0f); + + // Top left + pglTexCoord2f(0.0f, yfix); + pglVertex3f(-1, 1, 1.0f); + + // Top right + pglTexCoord2f(xfix, yfix); + pglVertex3f(1, 1, 1.0f); + + // Bottom right + pglTexCoord2f(xfix, 0.0f); + pglVertex3f(1, -1, 1.0f); + + pglEnd(); + + SetModelView(screen_width, screen_height); + SetStates(); + + tex_downloaded = 0; // 0 so it knows it doesn't have any of the cached patches downloaded right now +} + #endif //HWRENDER diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 44ddf830..54f5da3a 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -105,6 +105,8 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(DoScreenWipe); GETFUNC(DrawIntermissionBG); GETFUNC(MakeScreenTexture); + GETFUNC(MakeScreenFinalTexture); + GETFUNC(DrawScreenFinalTexture); #else //HWRENDER if (0 == strcmp("FinishUpdate", funcName)) return funcPointer; //&FinishUpdate; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 566fb5b9..433ce17f 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -124,8 +124,8 @@ static SDL_Color localPalette[256]; static SDL_Rect **modeList = NULL; static Uint8 BitsPerPixel = 16; #endif -static Uint16 realwidth = BASEVIDWIDTH; -static Uint16 realheight = BASEVIDHEIGHT; +Uint16 realwidth = BASEVIDWIDTH; +Uint16 realheight = BASEVIDHEIGHT; static const Uint32 surfaceFlagsW = 0/*|SDL_RESIZABLE*/; static const Uint32 surfaceFlagsF = 0; static SDL_bool mousegrabok = SDL_TRUE; @@ -221,26 +221,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) if (rendermode == render_opengl) { - int sdlw, sdlh; - SDL_GetWindowSize(window, &sdlw, &sdlh); - // Logical fullscreen is not implemented yet for OpenGL, so... - // Special case handling - if (glfallbackresolution == SDL_FALSE && fullscreen && width != sdlw && height != sdlh) - { - if (VID_GetModeForSize(sdlw, sdlh) != -1) - { - wasfullscreen = SDL_TRUE; - VID_SetMode(VID_GetModeForSize(sdlw, sdlh)); - return; - } - else - { - wasfullscreen = SDL_TRUE; - glfallbackresolution = SDL_TRUE; - VID_SetMode(-1); - return; - } - } OglSdlSurface(vid.width, vid.height); } @@ -1779,6 +1759,8 @@ void I_StartupGraphics(void) HWD.pfnDoScreenWipe = hwSym("DoScreenWipe",NULL); HWD.pfnDrawIntermissionBG=hwSym("DrawIntermissionBG",NULL); HWD.pfnMakeScreenTexture= hwSym("MakeScreenTexture",NULL); + HWD.pfnMakeScreenFinalTexture=hwSym("MakeScreenFinalTexture",NULL); + HWD.pfnDrawScreenFinalTexture=hwSym("DrawScreenFinalTexture",NULL); // check gl renderer lib if (HWD.pfnGetRenderVersion() != VERSION) I_Error("%s", M_GetText("The version of the renderer doesn't match the version of the executable\nBe sure you have installed SRB2 properly.\n")); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 6cbecaf3..ba7e6517 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -201,13 +201,22 @@ boolean OglSdlSurface(INT32 w, INT32 h) void OglSdlFinishUpdate(boolean waitvbl) { static boolean oldwaitvbl = false; + int sdlw, sdlh; if (oldwaitvbl != waitvbl) { SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); } + oldwaitvbl = waitvbl; + SDL_GetWindowSize(window, &sdlw, &sdlh); + + HWR_MakeScreenFinalTexture(); + HWR_DrawScreenFinalTexture(sdlw, sdlh); SDL_GL_SwapWindow(window); + + SetModelView(realwidth, realheight); + SetStates(); } EXPORT void HWRAPI( OglSdlSetPalette) (RGBA_t *palette, RGBA_t *pgamma) diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 72f130a5..7e144644 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -27,6 +27,8 @@ void OglSdlFinishUpdate(boolean vidwait); extern SDL_Window *window; extern SDL_Renderer *renderer; extern SDL_GLContext sdlglcontext; +extern Uint16 realwidth; +extern Uint16 realheight; #ifdef _CREATE_DLL_ EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma); From d056e82b3b271952e17bc99a8a35d34ca979718e Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 18:20:32 -0600 Subject: [PATCH 08/14] Parse GL version correctly. --- src/hardware/r_opengl/r_opengl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 6b37a666..028bc988 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -535,7 +535,7 @@ boolean SetupGLFunc13(void) // Parse the GL version if (version != NULL) { - if (sscanf(version, "%d.%d", &glmajor, &glminor) == 2) + if (sscanf((const char*)version, "%d.%d", &glmajor, &glminor) == 2) { // Look, we gotta prepare for the inevitable arrival of GL 2.0 code... switch (glmajor) @@ -543,6 +543,10 @@ boolean SetupGLFunc13(void) case 1: if (glminor == 3) gl13 = true; break; + case 2: + case 3: + case 4: + gl13 = true; default: break; } @@ -2400,12 +2404,8 @@ EXPORT void HWRAPI(MakeScreenFinalTexture) (void) EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) { float xfix, yfix; - int lmaxx, lmaxy; INT32 texsize = 2048; - lmaxx = width < screen_width ? screen_width : width; - lmaxy = height < screen_height ? screen_height : height; - if(screen_width <= 1024) texsize = 1024; if(screen_width <= 512) From 869c4241eb9e201f668289e3d0010247c21fdba4 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 19:18:24 -0600 Subject: [PATCH 09/14] Restrict mouse to window when in focus --- src/sdl/i_video.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 433ce17f..322b9573 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -752,6 +752,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { D_PostEvent(&event); + SDL_SetWindowGrab(window, SDL_TRUE); HalfWarpMouse(wwidth, wheight); } } From be1565fce35cb3cbe173d3f294db8f2b32b94c79 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 22:34:09 -0600 Subject: [PATCH 10/14] Add support for new HWR functions in win32 and sdl12 --- src/sdl12/hwsym_sdl.c | 2 ++ src/win32/win_dll.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/sdl12/hwsym_sdl.c b/src/sdl12/hwsym_sdl.c index 44ddf830..54f5da3a 100644 --- a/src/sdl12/hwsym_sdl.c +++ b/src/sdl12/hwsym_sdl.c @@ -105,6 +105,8 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(DoScreenWipe); GETFUNC(DrawIntermissionBG); GETFUNC(MakeScreenTexture); + GETFUNC(MakeScreenFinalTexture); + GETFUNC(DrawScreenFinalTexture); #else //HWRENDER if (0 == strcmp("FinishUpdate", funcName)) return funcPointer; //&FinishUpdate; diff --git a/src/win32/win_dll.c b/src/win32/win_dll.c index c6ea016f..30c4d7f7 100644 --- a/src/win32/win_dll.c +++ b/src/win32/win_dll.c @@ -122,6 +122,8 @@ static loadfunc_t hwdFuncTable[] = { {"DoScreenWipe@4", &hwdriver.pfnDoScreenWipe}, {"DrawIntermissionBG@0",&hwdriver.pfnDrawIntermissionBG}, {"MakeScreenTexture@0", &hwdriver.pfnMakeScreenTexture}, + {"MakeScreenFinalTexture@0", &hwdriver.pfnMakeScreenFinalTexture}, + {"DrawScreenFinalTexture@8", &hwdriver.pfnDrawScreenFinalTexture} #else {"Init", &hwdriver.pfnInit}, {"Shutdown", &hwdriver.pfnShutdown}, @@ -150,6 +152,8 @@ static loadfunc_t hwdFuncTable[] = { {"DoScreenWipe", &hwdriver.pfnDoScreenWipe}, {"DrawIntermissionBG", &hwdriver.pfnDrawIntermissionBG}, {"MakeScreenTexture", &hwdriver.pfnMakeScreenTexture}, + {"MakeScreenFinalTexture", &hwdriver.pfnMakeScreenFinalTexture}, + {"DrawScreenFinalTexture", &hwdriver.pfnDrawScreenFinalTexture} #endif {NULL,NULL} }; From 2feda0b560afbd63f25143734d38e66a5f76401e Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 22:34:47 -0600 Subject: [PATCH 11/14] Fix second joystick in sdl --- src/sdl/i_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 322b9573..64675b53 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -827,7 +827,7 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt) // Determine the Joystick IDs for each current open joystick joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); - joyid[1] = SDL_JoystickInstanceID(JoyInfo.dev); + joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); evt.axis++; event.data1 = event.data2 = event.data3 = INT32_MAX; @@ -866,7 +866,7 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) // Determine the Joystick IDs for each current open joystick joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); - joyid[1] = SDL_JoystickInstanceID(JoyInfo.dev); + joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); if (evt.which == joyid[0]) { From 3eafca0dc1e09989e977135d63745839b5844b9c Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 22:58:08 -0600 Subject: [PATCH 12/14] Fix compile errors on win32, warnings elsewhere --- src/sdl/i_system.c | 2 +- src/sdl/i_video.c | 6 ++---- src/win32/win_dll.c | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 23da092f..3eb52bc5 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -304,7 +304,7 @@ UINT8 keyboard_started = false; static void signal_handler(INT32 num) { //static char msg[] = "oh no! back to reality!\r\n"; - char * sigmsg; + const char * sigmsg; char sigdef[32]; D_QuitNetGame(); // Fix server freezes diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 64675b53..9229b6ea 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -174,7 +174,6 @@ static void Impl_SetWindowIcon(void); static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { static SDL_bool wasfullscreen = SDL_FALSE; - static SDL_bool glfallbackresolution = SDL_FALSE; Uint32 rmask; Uint32 gmask; Uint32 bmask; @@ -195,7 +194,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) else if (!fullscreen && wasfullscreen) { wasfullscreen = SDL_FALSE; - glfallbackresolution = SDL_FALSE; SDL_SetWindowFullscreen(window, 0); SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED_DISPLAY(1), SDL_WINDOWPOS_CENTERED_DISPLAY(1)); @@ -743,8 +741,8 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) } else { - event.data2 = (int)round((evt.xrel) * ((float)wwidth / (float)realwidth)); - event.data3 = (int)round(-evt.yrel * ((float)wheight / (float)realheight)); + event.data2 = (INT32)round((evt.xrel) * ((float)wwidth / (float)realwidth)); + event.data3 = (INT32)round(-evt.yrel * ((float)wheight / (float)realheight)); } event.type = ev_mouse; diff --git a/src/win32/win_dll.c b/src/win32/win_dll.c index 30c4d7f7..8fa4d17f 100644 --- a/src/win32/win_dll.c +++ b/src/win32/win_dll.c @@ -123,7 +123,7 @@ static loadfunc_t hwdFuncTable[] = { {"DrawIntermissionBG@0",&hwdriver.pfnDrawIntermissionBG}, {"MakeScreenTexture@0", &hwdriver.pfnMakeScreenTexture}, {"MakeScreenFinalTexture@0", &hwdriver.pfnMakeScreenFinalTexture}, - {"DrawScreenFinalTexture@8", &hwdriver.pfnDrawScreenFinalTexture} + {"DrawScreenFinalTexture@8", &hwdriver.pfnDrawScreenFinalTexture}, #else {"Init", &hwdriver.pfnInit}, {"Shutdown", &hwdriver.pfnShutdown}, @@ -153,7 +153,7 @@ static loadfunc_t hwdFuncTable[] = { {"DrawIntermissionBG", &hwdriver.pfnDrawIntermissionBG}, {"MakeScreenTexture", &hwdriver.pfnMakeScreenTexture}, {"MakeScreenFinalTexture", &hwdriver.pfnMakeScreenFinalTexture}, - {"DrawScreenFinalTexture", &hwdriver.pfnDrawScreenFinalTexture} + {"DrawScreenFinalTexture", &hwdriver.pfnDrawScreenFinalTexture}, #endif {NULL,NULL} }; From 98c3c3a3ae1dd2a627a83375750a791842d5d870 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 13 Nov 2014 23:09:57 -0600 Subject: [PATCH 13/14] More warning squashing --- src/sdl/i_system.c | 2 +- src/sdl/i_video.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 3eb52bc5..c0f6801a 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -742,7 +742,7 @@ static inline void I_ShutdownConsole(void){} // void I_StartupKeyboard (void) { -#if defined (NDEBUG) && !defined (DC) +#if !defined (DC) #ifdef SIGILL signal(SIGILL , signal_handler); #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9229b6ea..660263b3 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -741,8 +741,8 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) } else { - event.data2 = (INT32)round((evt.xrel) * ((float)wwidth / (float)realwidth)); - event.data3 = (INT32)round(-evt.yrel * ((float)wheight / (float)realheight)); + event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth)); + event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); } event.type = ev_mouse; From 3fd2a705ee9812c3ab3cd0f98d4a91e18d796dfe Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Fri, 14 Nov 2014 00:04:54 -0600 Subject: [PATCH 14/14] Maybe this is the last warning related commit? --- src/sdl/i_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index c0f6801a..a1e91ec7 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -301,7 +301,7 @@ SDL_bool framebuffer = SDL_FALSE; UINT8 keyboard_started = false; -static void signal_handler(INT32 num) +FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { //static char msg[] = "oh no! back to reality!\r\n"; const char * sigmsg; @@ -350,7 +350,7 @@ static void signal_handler(INT32 num) I_Quit(); } -#if defined (NDEBUG) && !defined (DC) && !defined (_WIN32_WCE) +#if !defined (DC) FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { signal(num, SIG_DFL); //default signal action