From 2480ea4cc668ff99007dd6fb8b44911eea5d5287 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 22 Aug 2013 11:59:38 +0300 Subject: store window size into rectangle. --- src/compoundsprite.cpp | 2 +- src/graphics.cpp | 5 +++++ src/graphics.h | 9 +++++++-- src/mobileopenglgraphics.cpp | 20 ++++++++++---------- src/normalopenglgraphics.cpp | 23 +++++++++++++---------- src/resources/atlasmanager.cpp | 6 ++++-- src/safeopenglgraphics.cpp | 16 ++++++++-------- src/sdl2graphics.cpp | 6 ++++-- src/sdlgraphics.cpp | 6 ++++-- 9 files changed, 56 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index b65d238d4..24e8306c3 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -338,7 +338,7 @@ void CompoundSprite::redraw() const SDLGraphics *graphics = new SDLGraphics(); graphics->setBlitMode(SDLGraphics::BLIT_GFX); - graphics->setWindow(surface); + graphics->setWindow(surface, BUFFER_WIDTH, BUFFER_HEIGHT); graphics->_beginDraw(); int tileX = 32 / 2; diff --git a/src/graphics.cpp b/src/graphics.cpp index ac219bc9a..d1d5a9590 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -148,9 +148,14 @@ bool Graphics::setOpenGLMode() if (!(mWindow = graphicsManager.createWindow(mWidth, mHeight, mBpp, getOpenGLFlags()))) { + mRect.w = 0; + mRect.h = 0; return false; } + mRect.w = static_cast(mWindow->w); + mRect.h = static_cast(mWindow->h); + #ifdef __APPLE__ if (mSync) { diff --git a/src/graphics.h b/src/graphics.h index cdd5b2e71..04234d415 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -105,8 +105,13 @@ class Graphics : public gcn::Graphics */ virtual ~Graphics(); - void setWindow(SDL_Window *const window) - { mWindow = window; } + void setWindow(SDL_Window *const window, + const int width, const int height) + { + mWindow = window; + mRect.w = width; + mRect.h = height; + } SDL_Window *getWindow() const { return mWindow; } diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp index 2aec87498..e2991eddc 100644 --- a/src/mobileopenglgraphics.cpp +++ b/src/mobileopenglgraphics.cpp @@ -845,11 +845,11 @@ void MobileOpenGLGraphics::_beginDraw() glLoadIdentity(); #ifdef ANDROID - glOrthof(0.0, static_cast(mWindow->w), - static_cast(mWindow->h), 0.0, -1.0, 1.0); + glOrthof(0.0, static_cast(mRect.w), + static_cast(mRect.h), 0.0, -1.0, 1.0); #else - glOrtho(0.0, static_cast(mWindow->w), - static_cast(mWindow->h), 0.0, -1.0, 1.0); + glOrtho(0.0, static_cast(mRect.w), + static_cast(mRect.h), 0.0, -1.0, 1.0); #endif glMatrixMode(GL_MODELVIEW); @@ -883,7 +883,7 @@ void MobileOpenGLGraphics::_beginDraw() // glScalef(0.5f, 0.5f, 0.5f); - pushClipArea(gcn::Rectangle(0, 0, mWindow->w, mWindow->h)); + pushClipArea(gcn::Rectangle(0, 0, mRect.w, mRect.h)); } void MobileOpenGLGraphics::_endDraw() @@ -894,13 +894,13 @@ void MobileOpenGLGraphics::_endDraw() void MobileOpenGLGraphics::prepareScreenshot() { if (config.getBoolValue("usefbo")) - graphicsManager.createFBO(mWindow->w, mWindow->h, &mFbo); + graphicsManager.createFBO(mRect.w, mRect.h, &mFbo); } SDL_Surface* MobileOpenGLGraphics::getScreenshot() { - const int h = mWindow->h; - const int w = mWindow->w - (mWindow->w % 4); + const int h = mRect.h; + const int w = mRect.w - (mRect.w % 4); GLint pack = 1; SDL_Surface *const screenshot = SDL_CreateRGBSurface( @@ -971,7 +971,7 @@ bool MobileOpenGLGraphics::pushClipArea(gcn::Rectangle area) glTranslatef(static_cast(transX), static_cast(transY), 0); } - glScissor(clipArea.x, mWindow->h - clipArea.y - clipArea.height, + glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); return result; @@ -986,7 +986,7 @@ void MobileOpenGLGraphics::popClipArea() glPopMatrix(); const gcn::ClipRectangle &clipArea = mClipStack.top(); - glScissor(clipArea.x, mWindow->h - clipArea.y - clipArea.height, + glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); } diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index ac933a6ac..089077224 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -1052,12 +1052,15 @@ void NormalOpenGLGraphics::_beginDraw() glMatrixMode(GL_PROJECTION); glLoadIdentity(); + const int w = mRect.w; + const int h = mRect.h; + #ifdef ANDROID - glOrthof(0.0, static_cast(mWindow->w), - static_cast(mWindow->h), 0.0, -1.0, 1.0); + glOrthof(0.0, static_cast(w), static_cast(h), + 0.0, -1.0, 1.0); #else - glOrtho(0.0, static_cast(mWindow->w), - static_cast(mWindow->h), 0.0, -1.0, 1.0); + glOrtho(0.0, static_cast(w), static_cast(h), + 0.0, -1.0, 1.0); #endif glMatrixMode(GL_MODELVIEW); @@ -1092,7 +1095,7 @@ void NormalOpenGLGraphics::_beginDraw() // glScalef(0.5f, 0.5f, 0.5f); - pushClipArea(gcn::Rectangle(0, 0, mWindow->w, mWindow->h)); + pushClipArea(gcn::Rectangle(0, 0, w, h)); } void NormalOpenGLGraphics::_endDraw() @@ -1103,13 +1106,13 @@ void NormalOpenGLGraphics::_endDraw() void NormalOpenGLGraphics::prepareScreenshot() { if (config.getBoolValue("usefbo")) - graphicsManager.createFBO(mWindow->w, mWindow->h, &mFbo); + graphicsManager.createFBO(mRect.w, mRect.h, &mFbo); } SDL_Surface* NormalOpenGLGraphics::getScreenshot() { - const int h = mWindow->h; - const int w = mWindow->w - (mWindow->w % 4); + const int h = mRect.h; + const int w = mRect.w - (mRect.w % 4); GLint pack = 1; SDL_Surface *const screenshot = SDL_CreateRGBSurface( @@ -1181,7 +1184,7 @@ bool NormalOpenGLGraphics::pushClipArea(gcn::Rectangle area) glTranslatef(static_cast(transX), static_cast(transY), 0); } - glScissor(clipArea.x, mWindow->h - clipArea.y - clipArea.height, + glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); return result; @@ -1196,7 +1199,7 @@ void NormalOpenGLGraphics::popClipArea() glPopMatrix(); const gcn::ClipRectangle &clipArea = mClipStack.top(); - glScissor(clipArea.x, mWindow->h - clipArea.y - clipArea.height, + glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); } diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp index f6cd23de4..2388856c1 100644 --- a/src/resources/atlasmanager.cpp +++ b/src/resources/atlasmanager.cpp @@ -224,14 +224,16 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *const atlas) atlas->width = powerOfTwo(atlas->width); atlas->height = powerOfTwo(atlas->height); + const int width = atlas->width; + const int height = atlas->height; // temp SDL surface for atlas SDL_Surface *const surface = SDL_CreateRGBSurface(SDL_SWSURFACE, - atlas->width, atlas->height, 32, rmask, gmask, bmask, amask); + width, height, 32, rmask, gmask, bmask, amask); if (!surface) return nullptr; SDLGraphics *const graphics = new SDLGraphics(); - graphics->setWindow(surface); + graphics->setWindow(surface, width, height); graphics->_beginDraw(); // drawing SDL images to surface diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp index f04ffb3bc..fcb97a398 100644 --- a/src/safeopenglgraphics.cpp +++ b/src/safeopenglgraphics.cpp @@ -401,8 +401,8 @@ void SafeOpenGLGraphics::_beginDraw() glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0, static_cast(mWindow->w), - static_cast(mWindow->h), 0.0, -1.0, 1.0); + glOrtho(0.0, static_cast(mRect.w), + static_cast(mRect.h), 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -420,7 +420,7 @@ void SafeOpenGLGraphics::_beginDraw() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - pushClipArea(gcn::Rectangle(0, 0, mWindow->w, mWindow->h)); + pushClipArea(gcn::Rectangle(0, 0, mRect.w, mRect.h)); } void SafeOpenGLGraphics::_endDraw() @@ -431,13 +431,13 @@ void SafeOpenGLGraphics::_endDraw() void SafeOpenGLGraphics::prepareScreenshot() { if (config.getBoolValue("usefbo")) - graphicsManager.createFBO(mWindow->w, mWindow->h, &mFbo); + graphicsManager.createFBO(mRect.w, mRect.h, &mFbo); } SDL_Surface* SafeOpenGLGraphics::getScreenshot() { - const int h = mWindow->h; - const int w = mWindow->w - (mWindow->w % 4); + const int h = mRect.h; + const int w = mRect.w - (mRect.w % 4); GLint pack = 1; SDL_Surface *const screenshot = SDL_CreateRGBSurface( @@ -504,7 +504,7 @@ bool SafeOpenGLGraphics::pushClipArea(gcn::Rectangle area) glPushMatrix(); glTranslatef(static_cast(transX), static_cast(transY), 0); - glScissor(clipArea.x, mWindow->h - clipArea.y - clipArea.height, + glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); return result; @@ -519,7 +519,7 @@ void SafeOpenGLGraphics::popClipArea() glPopMatrix(); const gcn::ClipRectangle &clipArea = mClipStack.top(); - glScissor(clipArea.x, mWindow->h - clipArea.y - clipArea.height, + glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); } diff --git a/src/sdl2graphics.cpp b/src/sdl2graphics.cpp index 99f022bcb..a2fc010f6 100644 --- a/src/sdl2graphics.cpp +++ b/src/sdl2graphics.cpp @@ -434,7 +434,7 @@ SDL_Surface *SDLGraphics::getScreenshot() const int amask = 0x00000000; SDL_Surface *const screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, - mWindow->w, mWindow->h, 24, rmask, gmask, bmask, amask); + mRect.w, mRect.h, 24, rmask, gmask, bmask, amask); if (screenshot) SDL_BlitSurface(mWindow, nullptr, screenshot, nullptr); @@ -782,7 +782,7 @@ void SDLGraphics::fillRectangle(const gcn::Rectangle& rectangle) void SDLGraphics::_beginDraw() { - pushClipArea(gcn::Rectangle(0, 0, mWindow->w, mWindow->h)); + pushClipArea(gcn::Rectangle(0, 0, mRect.w, mRect.h)); } void SDLGraphics::_endDraw() @@ -1141,6 +1141,8 @@ bool SDLGraphics::setVideoMode(const int w, const int h, const int bpp, if (!(mWindow = graphicsManager.createWindow(w, h, bpp, getSoftwareFlags()))) { + mRect.w = 0; + mRect.h = 0; return false; } diff --git a/src/sdlgraphics.cpp b/src/sdlgraphics.cpp index 6bc196cd9..38984593c 100644 --- a/src/sdlgraphics.cpp +++ b/src/sdlgraphics.cpp @@ -434,7 +434,7 @@ SDL_Surface *SDLGraphics::getScreenshot() const int amask = 0x00000000; SDL_Surface *const screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, - mWindow->w, mWindow->h, 24, rmask, gmask, bmask, amask); + mRect.w, mRect.h, 24, rmask, gmask, bmask, amask); if (screenshot) SDL_BlitSurface(mWindow, nullptr, screenshot, nullptr); @@ -782,7 +782,7 @@ void SDLGraphics::fillRectangle(const gcn::Rectangle& rectangle) void SDLGraphics::_beginDraw() { - pushClipArea(gcn::Rectangle(0, 0, mWindow->w, mWindow->h)); + pushClipArea(gcn::Rectangle(0, 0, mRect.w, mRect.h)); } void SDLGraphics::_endDraw() @@ -1141,6 +1141,8 @@ bool SDLGraphics::setVideoMode(const int w, const int h, const int bpp, if (!(mWindow = graphicsManager.createWindow(w, h, bpp, getSoftwareFlags()))) { + mRect.w = 0; + mRect.h = 0; return false; } -- cgit v1.2.3-60-g2f50