1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-18 02:34:57 +00:00

Some more opengl setup cleanup and fullscreen switching improvement

This commit is contained in:
fgenesis 2016-11-14 03:13:34 +01:00
parent fe7c6ee048
commit e92b76cf40
6 changed files with 97 additions and 155 deletions

View file

@ -92,8 +92,6 @@ void BitBlotLogo::applyState()
dsq->jiggleCursor();
dsq->forceInputGrabOff();
if (dsq->user.demo.shortLogos)
{
skipLogo();

View file

@ -143,8 +143,6 @@ const bool isReleaseCandidate = false;
const bool isFinalCandidate = false;
const bool isGoldMaster = true;
int setInpGrab = -1;
Vector savesz;
/// WARNING: this is just to init, the actual value is set from user settings!
@ -244,13 +242,6 @@ void DSQ::onSwitchScreenMode()
toggleFullscreen();
}
void DSQ::forceInputGrabOff()
{
toggleInputGrabPlat(false);
setInpGrab = 0;
SDL_ShowCursor(SDL_DISABLE);
}
void DSQ::rumble(float leftMotor, float rightMotor, float time, int source)
{
if (this->inputMode == INPUT_JOYSTICK)
@ -941,7 +932,6 @@ This build is not yet final, and as such there are a couple things lacking. They
debugLog("OK");
setInputGrab(0);
dsq->forceInputGrabOff();
debugLog("Init Sound Library...");
initSoundLibrary(user.audio.deviceName);
@ -1395,11 +1385,8 @@ This build is not yet final, and as such there are a couple things lacking. They
else
core->afterEffectManager = 0;
setInputGrab(1);
bindInput();
setInputGrab(1);
// Go directly to the title in dev mode
if(isDeveloperKeys())
@ -1565,10 +1552,6 @@ void DSQ::toggleBlackBars(bool on, float t)
}
}
void DSQ::toggleInputGrabPlat(bool on)
{
}
int DSQ::getEntityLayerToLayer(int lcode)
{
if (lcode == -4)
@ -4034,43 +4017,10 @@ void DSQ::onUpdate(float dt)
}
}
static int lastWidth = 0;
static int lastHeight = 0;
if (lastWidth != width || lastHeight != height) {
setInpGrab = -1;
}
lastWidth = width;
lastHeight = height;
static bool lastfullscreen = false;
if (lastfullscreen != _fullscreen)
{
setInpGrab = -1;
}
lastfullscreen = _fullscreen;
if (game && game->avatar && game->avatar->isInputEnabled() && !game->isPaused() && !game->isInGameMenu())
{
if (setInpGrab != 1)
{
toggleInputGrabPlat(true);
setInpGrab = 1;
}
}
else
{
if (setInpGrab != 0)
{
toggleInputGrabPlat(false);
setInpGrab = 0;
}
}
updatepecue(dt);
Network::update();

View file

@ -186,8 +186,6 @@ public:
void init();
void shutdown();
void toggleInputGrabPlat(bool on);
void toggleBlackBars(bool on, float t=0);
void setCursor(CursorType type);
@ -468,8 +466,6 @@ public:
void bindInput();
void forceInputGrabOff();
int weird;
void setCutscene(bool on, bool canSkip=false);

View file

@ -3212,8 +3212,6 @@ void Game::applyState()
dsq->toggleCursor(true, 0.5);
}
dsq->forceInputGrabOff();
debugLog("Game::applyState Done");
}

View file

@ -125,65 +125,31 @@ void Core::reloadDevice()
void Core::setup_opengl()
{
#ifdef BBGE_BUILD_SDL2
assert(gGLctx);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(gScreen);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(gScreen);
const char *name = SDL_GetCurrentVideoDriver();
SDL_SetWindowGrab(gScreen, SDL_TRUE);
#else
SDL_WM_GrabInput(grabInputOnReentry == 0 ? SDL_GRAB_OFF : SDL_GRAB_ON);
char name[256];
SDL_VideoDriverName((char*)name, 256);
#endif
glViewport(0, 0, width, height);
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
SDL_ShowCursor(SDL_DISABLE);
SDL_PumpEvents();
for(int i = 0; i < KEY_MAXARRAY; i++)
{
keys[i] = 0;
}
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0); // Depth Buffer Setup
glDisable(GL_CULL_FACE);
glLoadIdentity();
glFinish();
setClearColor(clearColor);
clearBuffers();
showBuffer();
lib_graphics = true;
_hasFocus = true;
enumerateScreenModes();
}
void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
{
assert(lib_graphics);
bool wasFullscreen = _fullscreen;
if (fullscreen == -1)
@ -201,6 +167,8 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
if (bpp == -1)
bpp = _bpp;
int oldw = width;
int oldh = height;
width = w;
height = h;
_vsync = vsync;
@ -216,53 +184,54 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
else
SDL_GL_SetSwapInterval(0);
SDL_SetWindowSize(gScreen, w, h);
int disp = SDL_GetWindowDisplayIndex(gScreen);
if(w != oldw|| h != oldh)
SDL_SetWindowSize(gScreen, w, h);
int screenflags = 0;
if(fullscreen)
if(!!fullscreen != wasFullscreen)
{
// Record window position so we can properly restore it when leaving fullscreen
if(!wasFullscreen)
SDL_GetWindowPosition(gScreen, &winPosX, &winPosY);
// Use desktop fullscreen if possible, but only if the resolution
// matches the actual desktop resolution.
// Else we'll get unused areas on the screen.
if(disp >= 0)
int screenflags = 0;
if(fullscreen)
{
SDL_Rect bounds;
SDL_DisplayMode desktop;
if(SDL_GetDisplayBounds(disp, &bounds) == 0
&& SDL_GetDesktopDisplayMode(disp, &desktop) == 0)
// Record window position so we can properly restore it when leaving fullscreen
if(!wasFullscreen)
SDL_GetWindowPosition(gScreen, &winPosX, &winPosY);
// Use desktop fullscreen if possible, but only if the resolution
// matches the actual desktop resolution.
// Else we'll get unused areas on the screen.
int disp = SDL_GetWindowDisplayIndex(gScreen);
if(disp >= 0)
{
//SDL_SetWindowPosition(gScreen, bounds.x, bounds.y);
if(w == desktop.w && h == desktop.h)
SDL_DisplayMode desktop;
if(SDL_GetDesktopDisplayMode(disp, &desktop) == 0)
{
screenflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
debugLog("Switching to desktop fullscreen");
if(w == desktop.w && h == desktop.h)
{
screenflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
debugLog("Switching to desktop fullscreen");
}
}
}
if(!screenflags)
{
screenflags = SDL_WINDOW_FULLSCREEN;
debugLog("Switching to fullscreen");
}
}
if(!screenflags)
SDL_SetWindowFullscreen(gScreen, screenflags);
if(!fullscreen)
{
screenflags = SDL_WINDOW_FULLSCREEN;
debugLog("Switching to fullscreen");
SDL_SetWindowSize(gScreen, w, h);
if(wasFullscreen)
{
// Need to do this; else the window ends up at (0, 0) with the title bar outside the screen area
SDL_SetWindowPosition(gScreen, winPosX, winPosY);
}
}
}
SDL_SetWindowFullscreen(gScreen, screenflags);
if(!fullscreen)
{
SDL_SetWindowSize(gScreen, w, h);
if(wasFullscreen)
{
// Need to do this; else the window ends up at (0, 0) with the title bar outside the screen area
SDL_SetWindowPosition(gScreen, winPosX, winPosY);
}
}
#else
# error FIXME: backport to support SDL 1.2
@ -276,6 +245,11 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
resetTimer();
}
void Core::onWindowResize(int w, int h)
{
initGraphics(w, h);
}
void Core::setFullscreen(bool full)
{
if(full == !!_fullscreen)
@ -590,11 +564,6 @@ Core::~Core()
core = 0;
}
bool Core::hasFocus()
{
return _hasFocus;
}
void Core::setInputGrab(bool on)
{
if (isWindowFocus())
@ -799,11 +768,6 @@ void Core::globalScaleChanged()
invGlobalScaleSqr = invGlobalScale * invGlobalScale;
}
Vector Core::getClearColor()
{
return clearColor;
}
void Core::setClearColor(const Vector &c)
{
clearColor = c;
@ -814,6 +778,8 @@ void Core::setClearColor(const Vector &c)
bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsync, int bpp)
{
assert(!gScreen);
_hasFocus = false;
#ifndef BBGE_BUILD_SDL2
@ -867,10 +833,13 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
exit(0);
}
debugLog("GL vendor, renderer & version:");
debugLog((const char*)glGetString(GL_VENDOR));
debugLog((const char*)glGetString(GL_RENDERER));
debugLog((const char*)glGetString(GL_VERSION));
{
const char *name = SDL_GetCurrentVideoDriver();
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
}
#else
Uint32 flags = 0;
flags = SDL_OPENGL;
@ -885,11 +854,30 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
SDL_Quit();
exit_error(os.str());
}
{
char name[256];
SDL_VideoDriverName((char*)name, 256);
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
}
#endif
}
debugLog("GL vendor, renderer & version:");
debugLog((const char*)glGetString(GL_VENDOR));
debugLog((const char*)glGetString(GL_RENDERER));
debugLog((const char*)glGetString(GL_VERSION));
lib_graphics = true;
enumerateScreenModes();
initGraphics(width, height, fullscreen, vsync, bpp);
_hasFocus = true;
// init success
return true;
}
@ -942,6 +930,10 @@ void Core::enumerateScreenModes()
}
}
#endif
std::ostringstream os;
os << "Screen modes available: " << screenModes.size();
debugLog(os.str());
}
void Core::shutdownSoundLibrary()
@ -1541,7 +1533,6 @@ void Core::pollEvents(float dt)
if ((event.key.keysym.sym == SDLK_g) && (event.key.keysym.mod & KMOD_CTRL))
{
grabInputOnReentry = (grabInputOnReentry)?0:-1;
setReentryInputGrab(1);
}
@ -1589,13 +1580,20 @@ void Core::pollEvents(float dt)
}
break;
#ifdef BBGE_BUILD_SDL2
#ifdef BBGE_BUILD_SDL2
case SDL_WINDOWEVENT:
{
if (event.window.event == SDL_WINDOWEVENT_CLOSE)
switch(event.window.event)
{
SDL_Quit();
_exit(0);
case SDL_WINDOWEVENT_CLOSE:
SDL_Quit();
_exit(0);
break;
/*case SDL_WINDOWEVENT_FOCUS_GAINED:
_hasFocus = true;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
_hasFocus = false;*/
}
}
break;
@ -1620,7 +1618,10 @@ void Core::pollEvents(float dt)
onJoystickRemoved(event.jdevice.which);
break;
#else
case SDL_WINDOWEVENT_RESIZED: // User resized window
onWindowResize(event.window.data1, event.window.data2);
#else
case SDL_MOUSEBUTTONDOWN:
{
if (_hasFocus && updateMouse)
@ -1654,7 +1655,7 @@ void Core::pollEvents(float dt)
}
}
break;
#endif
#endif
case SDL_QUIT:
SDL_Quit();

View file

@ -393,7 +393,6 @@ public:
void setup_opengl();
void setClearColor(const Vector &c);
Vector getClearColor();
int flipMouseButtons;
void initFrameBuffer();
FrameBuffer frameBuffer;
@ -410,8 +409,6 @@ public:
std::string secondaryTexturePath;
bool hasFocus();
float get_old_dt() { return old_dt; }
float get_current_dt() { return current_dt; }
@ -504,6 +501,8 @@ protected:
virtual void modifyDt(float &dt){}
void setPixelScale(int pixelScaleX, int pixelScaleY);
virtual void onWindowResize(int w, int h);
int virtualHeight, virtualWidth;