moving to sdl2, input is broken, build is broken; do not use

This commit is contained in:
Sebastian Wick 2014-06-29 19:07:46 +02:00
parent e7f1a8ab79
commit 8e8b1516e2
12 changed files with 103 additions and 103 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ scripts/work/
/SDL.dll
/freetype.dll
/autoexec.cfg
*~

View file

@ -9,10 +9,10 @@ SDL = {
option.use_winlib = 0
option.lib_path = nil
if ExecuteSilent("pkg-config sdl") == 0 then
if ExecuteSilent("pkg-config sdl2") == 0 then
option.value = true
option.use_pkgconfig = true
elseif ExecuteSilent("sdl-config") > 0 and ExecuteSilent("sdl-config --cflags") == 0 then
elseif ExecuteSilent("sdl2-config") > 0 and ExecuteSilent("sdl2-config --cflags") == 0 then
option.value = true
option.use_sdlconfig = true
end
@ -28,11 +28,11 @@ SDL = {
local apply = function(option, settings)
if option.use_pkgconfig == true then
settings.cc.flags:Add("`pkg-config --cflags sdl`")
settings.link.flags:Add("`pkg-config --libs sdl`")
settings.cc.flags:Add("`pkg-config --cflags sdl2`")
settings.link.flags:Add("`pkg-config --libs sdl2`")
elseif option.use_sdlconfig == true then
settings.cc.flags:Add("`sdl-config --cflags`")
settings.link.flags:Add("`sdl-config --libs`")
settings.cc.flags:Add("`sdl2-config --cflags`")
settings.link.flags:Add("`sdl2-config --libs`")
elseif option.use_winlib > 0 then
settings.cc.includes:Add(SDL.basepath .. "/include")
if option.use_winlib == 32 then
@ -55,7 +55,7 @@ SDL = {
local display = function(option)
if option.value == true then
if option.use_pkgconfig == true then return "using pkg-config" end
if option.use_sdlconfig == true then return "using sdl-config" end
if option.use_sdlconfig == true then return "using sdl2-config" end
if option.use_winlib == 32 then return "using supplied win32 libraries" end
if option.use_winlib == 64 then return "using supplied win64 libraries" end
return "using unknown method"

View file

@ -1,6 +1,8 @@
#include "SDL.h"
#include "SDL_opengl.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <base/tl/threading.h>
@ -474,8 +476,8 @@ bool CCommandProcessorFragment_OpenGL::RunCommand(const CCommandBuffer::SCommand
void CCommandProcessorFragment_SDL::Cmd_Init(const SCommand_Init *pCommand)
{
m_GLContext = pCommand->m_Context;
GL_MakeCurrent(m_GLContext);
m_GLContext = pCommand->m_GLContext;
SDL_GL_MakeCurrent(m_pWindow, m_GLContext);
// set some default settings
glEnable(GL_BLEND);
@ -491,12 +493,12 @@ void CCommandProcessorFragment_SDL::Cmd_Init(const SCommand_Init *pCommand)
void CCommandProcessorFragment_SDL::Cmd_Shutdown(const SCommand_Shutdown *pCommand)
{
GL_ReleaseContext(m_GLContext);
SDL_GL_MakeCurrent(NULL, NULL);
}
void CCommandProcessorFragment_SDL::Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand)
{
GL_SwapBuffers(m_GLContext);
SDL_GL_SwapWindow(m_pWindow);
if(pCommand->m_Finish)
glFinish();
@ -504,35 +506,38 @@ void CCommandProcessorFragment_SDL::Cmd_Swap(const CCommandBuffer::SCommand_Swap
void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand)
{
// TODO: fix this code on osx or windows
SDL_Rect **ppModes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN);
if(ppModes == NULL)
SDL_DisplayMode mode;
int maxModes = SDL_GetNumDisplayModes(pCommand->m_Screen),
numModes = 0;
for(int i = 0; i < maxModes; i++)
{
// no modes
*pCommand->m_pNumModes = 0;
}
else if(ppModes == (SDL_Rect**)-1)
{
// no modes
*pCommand->m_pNumModes = 0;
}
else
{
int NumModes = 0;
for(int i = 0; ppModes[i]; ++i)
if(SDL_GetDisplayMode(pCommand->m_Screen, i, &mode) < 0)
{
if(NumModes == pCommand->m_MaxModes)
break;
pCommand->m_pModes[NumModes].m_Width = ppModes[i]->w;
pCommand->m_pModes[NumModes].m_Height = ppModes[i]->h;
pCommand->m_pModes[NumModes].m_Red = 8;
pCommand->m_pModes[NumModes].m_Green = 8;
pCommand->m_pModes[NumModes].m_Blue = 8;
NumModes++;
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
continue;
}
*pCommand->m_pNumModes = NumModes;
bool alreadyFound = false;
for(int j = 0; j < numModes; j++)
{
if(pCommand->m_pModes[j].m_Width == mode.w && pCommand->m_pModes[j].m_Height == mode.h)
{
alreadyFound = true;
break;
}
}
if(alreadyFound)
continue;
pCommand->m_pModes[numModes].m_Width = mode.w;
pCommand->m_pModes[numModes].m_Height = mode.h;
pCommand->m_pModes[numModes].m_Red = 8;
pCommand->m_pModes[numModes].m_Green = 8;
pCommand->m_pModes[numModes].m_Blue = 8;
numModes++;
}
*pCommand->m_pNumModes = numModes;
}
CCommandProcessorFragment_SDL::CCommandProcessorFragment_SDL()
@ -579,7 +584,7 @@ void CCommandProcessor_SDL_OpenGL::RunBuffer(CCommandBuffer *pBuffer)
// ------------ CGraphicsBackend_SDL_OpenGL
int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight)
int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Screen, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight)
{
if(!SDL_WasInit(SDL_INIT_VIDEO))
{
@ -595,42 +600,36 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height
#endif
}
const SDL_VideoInfo *pInfo = SDL_GetVideoInfo();
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows
SDL_Rect ScreenBounds;
if(SDL_GetDisplayBounds(Screen, &ScreenBounds) < 0)
{
dbg_msg("gfx", "unable to get current screen bounds: %s", SDL_GetError());
return -1;
}
// use current resolution as default
if(*Width == 0 || *Height == 0)
{
*Width = pInfo->current_w;
*Height = pInfo->current_h;
*Width = ScreenBounds.w;
*Height = ScreenBounds.h;
}
// store desktop resolution for settings reset button
*pDesktopWidth = pInfo->current_w;
*pDesktopHeight = pInfo->current_h;
// set flags
int SdlFlags = SDL_OPENGL;
if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE)
SdlFlags |= SDL_RESIZABLE;
if(pInfo->hw_available) // ignore_convention
SdlFlags |= SDL_HWSURFACE;
else
SdlFlags |= SDL_SWSURFACE;
if(pInfo->blit_hw) // ignore_convention
SdlFlags |= SDL_HWACCEL;
*pDesktopWidth = ScreenBounds.w;
*pDesktopHeight = ScreenBounds.h;
dbg_assert(!(Flags&IGraphicsBackend::INITFLAG_BORDERLESS)
|| !(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN),
"only one of borderless and fullscreen may be activated at the same time");
// set flags
int SdlFlags = SDL_WINDOW_OPENGL;
if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE)
SdlFlags |= SDL_WINDOW_RESIZABLE;
if(Flags&IGraphicsBackend::INITFLAG_BORDERLESS)
SdlFlags |= SDL_NOFRAME;
SdlFlags |= SDL_WINDOW_BORDERLESS;
if(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN)
SdlFlags |= SDL_FULLSCREEN;
SdlFlags |= SDL_WINDOW_FULLSCREEN;
// set gl attributes
if(FsaaSamples)
@ -645,34 +644,29 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Flags&IGraphicsBackend::INITFLAG_VSYNC ? 1 : 0);
SDL_GL_SetSwapInterval(Flags&IGraphicsBackend::INITFLAG_VSYNC ? 1 : 0);
// set caption
SDL_WM_SetCaption(pName, pName);
m_pWindow = SDL_CreateWindow(
pName,
SDL_WINDOWPOS_UNDEFINED_DISPLAY(0),
SDL_WINDOWPOS_UNDEFINED_DISPLAY(0),
*Width,
*Height,
SdlFlags);
// create window
m_pScreenSurface = SDL_SetVideoMode(*Width, *Height, 0, SdlFlags);
if(!m_pScreenSurface)
if(m_pWindow == NULL)
{
dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError());
//*pCommand->m_pResult = -1;
dbg_msg("gfx", "unable to create window: %s", SDL_GetError());
return -1;
}
#if defined(CONF_FAMILY_WINDOWS)
glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D");
if(glTexImage3D == 0)
{
dbg_msg("gfx", "glTexImage3D not supported");
return -1;
}
#endif
m_GLContext = SDL_GL_CreateContext(m_pWindow);
SDL_ShowCursor(0);
// fetch gl contexts and release the context from this thread
m_GLContext = GL_GetCurrentContext();
GL_ReleaseContext(m_GLContext);
if(m_GLContext == NULL)
{
dbg_msg("gfx", "unable to create renderer: %s", SDL_GetError());
return -1;
}
// start the command processor
m_pProcessor = new CCommandProcessor_SDL_OpenGL;
@ -684,7 +678,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height
CmdOpenGL.m_pTextureMemoryUsage = &m_TextureMemoryUsage;
CmdBuffer.AddCommand(CmdOpenGL);
CCommandProcessorFragment_SDL::SCommand_Init CmdSDL;
CmdSDL.m_Context = m_GLContext;
CmdSDL.m_GLContext = m_GLContext;
CmdBuffer.AddCommand(CmdSDL);
RunBuffer(&CmdBuffer);
WaitForIdle();
@ -718,7 +712,7 @@ int CGraphicsBackend_SDL_OpenGL::MemoryUsage() const
void CGraphicsBackend_SDL_OpenGL::Minimize()
{
SDL_WM_IconifyWindow();
SDL_MinimizeWindow(m_pWindow);
}
void CGraphicsBackend_SDL_OpenGL::Maximize()
@ -728,12 +722,12 @@ void CGraphicsBackend_SDL_OpenGL::Maximize()
int CGraphicsBackend_SDL_OpenGL::WindowActive()
{
return SDL_GetAppState()&SDL_APPINPUTFOCUS;
return SDL_GetWindowFlags(m_pWindow)&SDL_WINDOW_INPUT_FOCUS;
}
int CGraphicsBackend_SDL_OpenGL::WindowOpen()
{
return SDL_GetAppState()&SDL_APPACTIVE;
return SDL_GetWindowFlags(m_pWindow)&SDL_WINDOW_SHOWN;
}

View file

@ -218,7 +218,8 @@ public:
class CCommandProcessorFragment_SDL
{
// SDL stuff
SGLContext m_GLContext;
SDL_Window *m_pWindow;
SDL_GLContext m_GLContext;
public:
enum
{
@ -229,7 +230,8 @@ public:
struct SCommand_Init : public CCommandBuffer::SCommand
{
SCommand_Init() : SCommand(CMD_INIT) {}
SGLContext m_Context;
SDL_Window *m_pWindow;
SDL_GLContext m_GLContext;
};
struct SCommand_Shutdown : public CCommandBuffer::SCommand
@ -261,12 +263,12 @@ class CCommandProcessor_SDL_OpenGL : public CGraphicsBackend_Threaded::ICommandP
// graphics backend implemented with SDL and OpenGL
class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
{
SDL_Surface *m_pScreenSurface;
SDL_Window *m_pWindow;
SDL_GLContext m_GLContext;
ICommandProcessor *m_pProcessor;
SGLContext m_GLContext;
volatile int m_TextureMemoryUsage;
public:
virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight);
virtual int Init(const char *pName, int Screen, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight);
virtual int Shutdown();
virtual int MemoryUsage() const;

View file

@ -49,7 +49,7 @@
#include <windows.h>
#endif
#include "SDL.h"
#include "SDL2/SDL.h"
#ifdef main
#undef main
#endif

View file

@ -709,7 +709,7 @@ int CGraphics_Threaded::IssueInit()
if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC;
if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
return m_pBackend->Init("Teeworlds", &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight);
return m_pBackend->Init("Teeworlds", g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight);
}
int CGraphics_Threaded::InitWindow()
@ -898,7 +898,7 @@ void CGraphics_Threaded::WaitForIdle()
m_pBackend->WaitForIdle();
}
int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes)
int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen)
{
if(g_Config.m_GfxDisplayAllModes)
{
@ -914,7 +914,7 @@ int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes)
mem_zero(&Image, sizeof(Image));
int NumModes = 0;
CCommandBuffer::SCommand_VideoModes Cmd;
CCommandBuffer::SCommand_VideoModes Cmd(Screen);
Cmd.m_pModes = pModes;
Cmd.m_MaxModes = MaxModes;
Cmd.m_pNumModes = &NumModes;

View file

@ -193,11 +193,13 @@ public:
struct SCommand_VideoModes : public SCommand
{
SCommand_VideoModes() : SCommand(CMD_VIDEOMODES) {}
SCommand_VideoModes(int screen) : SCommand(CMD_VIDEOMODES),
m_Screen(screen) {}
CVideoMode *m_pModes; // processor will fill this in
int m_MaxModes; // maximum of modes the processor can write to the m_pModes
int *m_pNumModes; // processor will write to this pointer
int m_Screen;
};
struct SCommand_Swap : public SCommand
@ -305,7 +307,7 @@ public:
virtual ~IGraphicsBackend() {}
virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight) = 0;
virtual int Init(const char *pName, int Screen, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight) = 0;
virtual int Shutdown() = 0;
virtual int MemoryUsage() const = 0;
@ -437,7 +439,7 @@ public:
virtual void TakeScreenshot(const char *pFilename);
virtual void Swap();
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes);
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen);
virtual int GetDesktopScreenWidth() { return m_DesktopScreenWidth; }
virtual int GetDesktopScreenHeight() { return m_DesktopScreenHeight; }

View file

@ -8,7 +8,7 @@
#include <engine/shared/config.h>
#include "SDL.h"
#include <SDL2/SDL.h>
#include "sound.h"

View file

@ -158,7 +158,7 @@ public:
virtual void SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight) = 0;
virtual void TakeScreenshot(const char *pFilename) = 0;
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes) = 0;
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen) = 0;
virtual int GetDesktopScreenWidth() = 0;
virtual int GetDesktopScreenHeight() = 0;

View file

@ -57,6 +57,7 @@ MACRO_CONFIG_INT(SndDevice, snd_device, -1, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "
MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(GfxScreen, gfx_screen, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen index")
MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width")
MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height")
MACRO_CONFIG_INT(GfxBorderless, gfx_borderless, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Borderless window (not to be used with fullscreen)")

View file

@ -1482,7 +1482,7 @@ void CMenus::UpdatedFilteredVideoModes()
void CMenus::OnInit()
{
m_NumModes = Graphics()->GetVideoModes(m_aModes, MAX_RESOLUTIONS);
m_NumModes = Graphics()->GetVideoModes(m_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen);
UpdateVideoFormats();
bool Found = false;

View file

@ -1318,7 +1318,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
if(DoButton_CheckBox(&s_GfxDisplayAllModes, Localize("Show only supported"), g_Config.m_GfxDisplayAllModes^1, &Button))
{
g_Config.m_GfxDisplayAllModes ^= 1;
m_NumModes = Graphics()->GetVideoModes(m_aModes, MAX_RESOLUTIONS);
m_NumModes = Graphics()->GetVideoModes(m_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen);
UpdateVideoFormats();
bool Found = false;
@ -1444,7 +1444,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
if(g_Config.m_GfxDisplayAllModes)
{
g_Config.m_GfxDisplayAllModes = 0;
m_NumModes = Graphics()->GetVideoModes(m_aModes, MAX_RESOLUTIONS);
m_NumModes = Graphics()->GetVideoModes(m_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen);
UpdateVideoFormats();
bool Found = false;