From 716aa1f33a5f921ea3b0458bcfcae7bbbcf08d09 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 24 Jul 2014 02:51:46 -0500 Subject: [PATCH 1/5] sdl2: fix mouse motion (remove -mousewarp) --- src/sdl2/i_video.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 8731c2d8..43485540 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -129,7 +129,6 @@ static Uint16 realheight = BASEVIDHEIGHT; static const Uint32 surfaceFlagsW = 0/*|SDL_RESIZABLE*/; static const Uint32 surfaceFlagsF = 0; static SDL_bool mousegrabok = SDL_TRUE; -static SDL_bool mousewarp = SDL_FALSE; #define HalfWarpMouse(x,y) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) static SDL_bool videoblitok = SDL_FALSE; static SDL_bool exposevideo = SDL_FALSE; @@ -760,6 +759,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_FOCUS_GAINED: kbfocus = SDL_TRUE; + mousefocus = SDL_TRUE; break; case SDL_WINDOWEVENT_FOCUS_LOST: kbfocus = SDL_FALSE; @@ -800,7 +800,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (MOUSE_MENU) { SDLdoUngrabMouse(); - return; } } @@ -832,43 +831,26 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) SDL_GetWindowSize(window, &wwidth, &wheight); - if (MOUSE_MENU) + if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) { SDLdoUngrabMouse(); return; } - if (mousewarp && (evt.x == wwidth/2) && (evt.y == wheight/2)) + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } else { - event.data2 = +evt.xrel; - event.data3 = -evt.yrel; + event.data2 = (evt.xrel) * (wwidth / realwidth) * 2; + event.data3 = -evt.yrel * (wheight / realheight) * 2; } event.type = ev_mouse; D_PostEvent(&event); - if (mousewarp) - { - // Warp the pointer back to the middle of the window - // or we cannot move any further if it's at a border. - if ((evt.x < (wwidth/2 )-(wwidth/4 )) || - (evt.y < (wheight/2)-(wheight/4)) || - (evt.x > (wwidth/2 )+(wwidth/4 )) || - (evt.y > (wheight/2)+(wheight/4) ) ) - { - HalfWarpMouse(wwidth, wheight); - } - } - else - { - SDL_SetWindowGrab(window, mousegrabok); - SDL_SetRelativeMouseMode(SDL_TRUE); - } - + HalfWarpMouse(wwidth, wheight); } static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) @@ -1902,8 +1884,6 @@ void I_StartupGraphics(void) if (M_CheckParm("-nomousegrab")) mousegrabok = SDL_FALSE; - else if (M_CheckParm("-mousewarp") || SDL_SetRelativeMouseMode(SDL_TRUE) == -1) - mousewarp = SDL_TRUE; #if 0 // defined (_DEBUG) else { From 39603487ecd714f47b8650112bd27479c530b11c Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 24 Jul 2014 03:01:16 -0500 Subject: [PATCH 2/5] sdl2: restore anisotropic filtering support in gl --- src/sdl2/ogl_sdl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sdl2/ogl_sdl.c b/src/sdl2/ogl_sdl.c index 562eaf2a..d4211927 100644 --- a/src/sdl2/ogl_sdl.c +++ b/src/sdl2/ogl_sdl.c @@ -171,7 +171,10 @@ boolean OglSdlSurface(INT32 w, INT32 h) DBG_Printf("Extensions : %s\n", gl_extensions); oglflags = 0; - maximumAnisotropy = 0; + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + else + maximumAnisotropy = 0; granisotropicmode_cons_t[1].value = maximumAnisotropy; From 88907222234dceb8015c61b9d9665235f7a3fb08 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 24 Jul 2014 03:03:41 -0500 Subject: [PATCH 3/5] sdl2: handle no AF support correctly (1, not 0) GL_EXT_texture_filter_anisotropic is cool I guess --- src/sdl2/ogl_sdl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl2/ogl_sdl.c b/src/sdl2/ogl_sdl.c index d4211927..b03d8e20 100644 --- a/src/sdl2/ogl_sdl.c +++ b/src/sdl2/ogl_sdl.c @@ -174,7 +174,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); else - maximumAnisotropy = 0; + maximumAnisotropy = 1; granisotropicmode_cons_t[1].value = maximumAnisotropy; From 005b502756bee819bdff794c6a40c57fbd21bc16 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 24 Jul 2014 03:15:35 -0500 Subject: [PATCH 4/5] sdl2: limit fullscreen resolution in OpenGL --- src/sdl2/i_video.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 43485540..3a23d5f0 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -185,14 +185,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { wasfullscreen = SDL_TRUE; SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); - // Logical fullscreen is not implemented yet for OpenGL, so... - // Special case handling - if (rendermode == render_opengl) - { - int sdlw, sdlh; - SDL_GetWindowSize(window, &sdlw, &sdlh); - VID_SetMode(VID_GetModeForSize(sdlw, sdlh)); - } } else if (!fullscreen && wasfullscreen) { @@ -217,6 +209,15 @@ 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 (USE_FULLSCREEN && width != sdlw && height != sdlh) + { + VID_SetMode(VID_GetModeForSize(sdlw, sdlh)); + return; + } OglSdlSurface(vid.width, vid.height); } From 8b0f374bfe3b5ee41ce8e1295d86d731a4300c97 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 24 Jul 2014 19:13:06 -0500 Subject: [PATCH 5/5] sdl2: potential huge perf. boost to software SDL_UpdateTexture is apparently not good for streaming textures. So instead, I did SDL_LockTexture/Unlock. --- src/sdl2/i_video.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 3a23d5f0..8faff69b 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -1381,8 +1381,25 @@ void I_FinishUpdate(void) } if (bufSurface) //Alam: New Way to send video data { + void *pixels; + int pitch; + SDL_BlitSurface(bufSurface, NULL, vidSurface, &rect); - SDL_UpdateTexture(texture, NULL, vidSurface->pixels, realwidth * 4); + // Fury -- streaming textures are bad on UpdateTexture + SDL_LockSurface(vidSurface); + SDL_LockTexture(texture, &rect, &pixels, &pitch); + if (pitch == vidSurface->pitch) + { + M_Memcpy(pixels, vidSurface->pixels, (pitch * vid.height)); + } + else + { + SDL_UnlockTexture(texture); + SDL_UnlockSurface(vidSurface); + I_Error("The intermediate buffer and final texture types are not the same.\n"); + } + SDL_UnlockTexture(texture); + SDL_UnlockSurface(vidSurface); } // Blit buffer to texture SDL_RenderCopy(renderer, texture, NULL, NULL);