From 0d8a5c191ca94a657281ebd255952ddb9bda94eb Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 15 Nov 2016 13:00:30 +0100 Subject: [PATCH] More graphics init cleanup. Remove aspect ratio check. Fix screen transition effect that broke in prev. commits. --- Aquaria/DSQ.cpp | 22 +++++++--------------- Aquaria/DSQ.h | 1 + BBGE/AfterEffect.cpp | 30 ++++++++++++++++-------------- BBGE/AfterEffect.h | 2 ++ BBGE/Core.cpp | 10 +++------- BBGE/Core.h | 1 - BBGE/ScreenTransition.cpp | 31 +++++-------------------------- 7 files changed, 34 insertions(+), 63 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 3c23dae..ed75431 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -242,6 +242,12 @@ void DSQ::onSwitchScreenMode() toggleFullscreen(); } +void DSQ::onWindowResize(int w, int h) +{ + Core::onWindowResize(w, h); + screenTransition->reloadDevice(); +} + void DSQ::rumble(float leftMotor, float rightMotor, float time, int source) { if (this->inputMode == INPUT_JOYSTICK) @@ -873,16 +879,6 @@ This build is not yet final, and as such there are a couple things lacking. They particleManager->setSize(user.video.numParticles); fullscreen = user.video.full; - - float asp = float(user.video.resx)/float(user.video.resy); - - if(asp < 1.0f) - { - std::ostringstream os; - os << "Aspect ratio for resolution [" << user.video.resx << ", " << user.video.resy << "] not supported."; - exit_error(os.str()); - } - useFrameBuffer = user.video.fbuffer; if (isDeveloperKeys()) @@ -912,8 +908,6 @@ This build is not yet final, and as such there are a couple things lacking. They debugLog("Init Graphics Library..."); initGraphicsLibrary(user.video.resx, user.video.resy, fullscreen, user.video.vsync, user.video.bits); - core->enable2DWide(user.video.resx, user.video.resy); - core->initFrameBuffer(); debugLog("OK"); setInputGrab(0); @@ -924,7 +918,6 @@ This build is not yet final, and as such there are a couple things lacking. They sound->setVoiceFader(0.5); sound->event_playVoice.set(MakeFunctionEvent(DSQ, onPlayVoice)); sound->event_stopVoice.set(MakeFunctionEvent(DSQ, onStopVoice)); - debugLog("OK"); debugLog("Init Input Library..."); @@ -1261,8 +1254,6 @@ This build is not yet final, and as such there are a couple things lacking. They } addRenderObject(tfader, LR_TRANSITION); - screenTransition = 0; - screenTransition = new AquariaScreenTransition(); { screenTransition->position = Vector(400,300); @@ -4368,6 +4359,7 @@ void DSQ::updatepecue(float dt) void AquariaScreenTransition::capture() { + assert(screen_texture); this->alpha = 0; InterpolatedVector oldAlpha = dsq->cursor->alpha; dsq->cursor->alpha.x = 0; diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index c87b015..6aca505 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -508,6 +508,7 @@ protected: void reloadDevice(); void onSwitchScreenMode(); + virtual void onWindowResize(int w, int h); void onPlayVoice(); void onStopVoice(); diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index d373029..23bb30a 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -38,19 +38,11 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) bRenderGridPoints = true; shaderPipeline.resize(10, 0); - screenWidth = core->getWindowWidth(); - screenHeight = core->getWindowHeight(); - - this->xDivs = 0; - this->yDivs = 0; - drawGrid = 0; this->xDivs = xDivs; this->yDivs = yDivs; - reloadDevice(); - if (xDivs != 0 && yDivs != 0) { drawGrid = new Vector * [xDivs]; @@ -60,6 +52,8 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) } } + updateDevice(); + loadShaders(); } @@ -378,7 +372,7 @@ void AfterEffectManager::unloadDevice() unloadShaders(); } -void AfterEffectManager::reloadDevice() +void AfterEffectManager::_updateScreenSize() { screenWidth = core->getWindowWidth(); screenHeight = core->getWindowHeight(); @@ -395,11 +389,19 @@ void AfterEffectManager::reloadDevice() textureHeight = screenHeight; sizePowerOf2Texture(textureHeight); } +} - if(backupBuffer.isInited()) - backupBuffer.reloadDevice(); - else - backupBuffer.init(-1, -1, true); +void AfterEffectManager::updateDevice() +{ + _updateScreenSize(); + backupBuffer.init(-1, -1, true); +} + +void AfterEffectManager::reloadDevice() +{ + _updateScreenSize(); + + backupBuffer.reloadDevice(); for (size_t i = 0; i < loadedShaders.size(); ++i) { @@ -409,11 +411,11 @@ void AfterEffectManager::reloadDevice() if (!sh->isLoaded()) { debugLog("AfterEffect::reloadDevice(): Failed to reload shader"); - delete sh; loadedShaders[i] = 0; for(size_t j = 0; j < shaderPipeline.size(); ++j) if(sh == shaderPipeline[j]) shaderPipeline[j] = 0; + delete sh; } } } diff --git a/BBGE/AfterEffect.h b/BBGE/AfterEffect.h index 49e6931..24b2186 100644 --- a/BBGE/AfterEffect.h +++ b/BBGE/AfterEffect.h @@ -97,6 +97,7 @@ public: void unloadDevice(); void reloadDevice(); + void updateDevice(); std::vector effects; std::vector openSpots; @@ -121,6 +122,7 @@ public: void deleteShader(int handle); protected: + void _updateScreenSize(); int _insertShader(Shader *sh); std::vector shaderPipeline; // Shaders are applied in this order. Can contain the same pointer more than once. diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index c32a354..c007133 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -139,8 +139,9 @@ void Core::setup_opengl() setClearColor(clearColor); - clearBuffers(); - showBuffer(); + frameBuffer.init(-1, -1, true); + if(afterEffectManager) + afterEffectManager->updateDevice(); } @@ -1389,11 +1390,6 @@ void Core::setupGlobalResolutionScale() glScalef(globalResolutionScale.x, globalResolutionScale.y, globalResolutionScale.z); } -void Core::initFrameBuffer() -{ - frameBuffer.init(-1, -1, true); -} - void Core::setMouseConstraint(bool on) { diff --git a/BBGE/Core.h b/BBGE/Core.h index 67157cf..4760a06 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -390,7 +390,6 @@ public: void setup_opengl(); void setClearColor(const Vector &c); int flipMouseButtons; - void initFrameBuffer(); FrameBuffer frameBuffer; void updateRenderObjects(float dt); bool joystickAsMouse; diff --git a/BBGE/ScreenTransition.cpp b/BBGE/ScreenTransition.cpp index b826a97..89277c1 100644 --- a/BBGE/ScreenTransition.cpp +++ b/BBGE/ScreenTransition.cpp @@ -25,15 +25,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ScreenTransition::ScreenTransition() : RenderObject() { - createTexture(); - + screen_texture = 0; cull = false; followCamera = 1; alpha = 0; + createTexture(); } void ScreenTransition::createTexture() { + destroyTexture(); + width = core->getVirtualWidth(); height = core->getVirtualHeight(); @@ -46,20 +48,13 @@ void ScreenTransition::createTexture() sizePowerOf2Texture(textureWidth); sizePowerOf2Texture(textureHeight); - - //create our texture glGenTextures(1,&screen_texture); glBindTexture(GL_TEXTURE_2D, screen_texture); - //GL_NEAREST - // vs - //GL_LINEAR glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,3, textureWidth, textureHeight, 0 , GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D,0); - - } void ScreenTransition::destroyTexture() @@ -85,10 +80,9 @@ void ScreenTransition::reloadDevice() void ScreenTransition::capture() { + assert(screen_texture); core->render(); - - if (screen_texture) { glBindTexture(GL_TEXTURE_2D,screen_texture); @@ -127,24 +121,9 @@ void ScreenTransition::onRender() const float pw = float(windowWidth)/float(textureWidth); const float ph = float(windowHeight)/float(textureHeight); - - glBindTexture(GL_TEXTURE_2D, screen_texture); - - -#if 0 //def BBGE_BUILD_MACOSX - float aspect = float(core->width) / float(core->height); - float checkAspect = 16.0f/10.0f; - if (fabsf(aspect - checkAspect) < 0.01f) - { - glTranslatef(0.5f,0.0f,0.0f); - } -#endif - glBegin(GL_QUADS); - - glTexCoord2d(0, 0); glVertex3f(-width2, height2, 0.0); glTexCoord2d(pw, 0);