diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-07-02 19:33:01 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-07-02 19:33:01 +0300 |
commit | eda234f5e156d376541044b351fd2e1e766700a3 (patch) | |
tree | 56ef425beb88fe84c280dea3a3ddeef676553589 | |
parent | 5ce62dae5b3848833765a19296ffd9fd7e9721d8 (diff) | |
download | manaplus-eda234f5e156d376541044b351fd2e1e766700a3.tar.gz manaplus-eda234f5e156d376541044b351fd2e1e766700a3.tar.bz2 manaplus-eda234f5e156d376541044b351fd2e1e766700a3.tar.xz manaplus-eda234f5e156d376541044b351fd2e1e766700a3.zip |
Fix resize in modernopengl with own context in SDL1.2 build.
-rw-r--r-- | src/render/graphics.cpp | 2 | ||||
-rw-r--r-- | src/render/graphics.h | 6 | ||||
-rw-r--r-- | src/render/modernopenglgraphics.cpp | 22 | ||||
-rw-r--r-- | src/render/modernopenglgraphics.h | 4 | ||||
-rw-r--r-- | src/utils/glxhelper.cpp | 9 | ||||
-rw-r--r-- | src/utils/glxhelper.h | 6 | ||||
-rw-r--r-- | src/utils/sdl2helper.cpp | 4 | ||||
-rw-r--r-- | src/utils/sdl2helper.h | 2 | ||||
-rw-r--r-- | src/utils/sdlhelper.cpp | 14 | ||||
-rw-r--r-- | src/utils/sdlhelper.h | 2 |
10 files changed, 63 insertions, 8 deletions
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp index a9dc968db..4c5d1d282 100644 --- a/src/render/graphics.cpp +++ b/src/render/graphics.cpp @@ -504,6 +504,7 @@ bool Graphics::resizeScreen(const int width, const int height) // +++ need impliment resize in soft mode #endif // USE_OPENGL + screenResized(); beginDraw(); return true; @@ -527,6 +528,7 @@ bool Graphics::resizeScreen(const int width, const int height) } } + screenResized(); beginDraw(); return success; diff --git a/src/render/graphics.h b/src/render/graphics.h index e05f23a84..3a051ed55 100644 --- a/src/render/graphics.h +++ b/src/render/graphics.h @@ -167,6 +167,9 @@ class Graphics notfinal */ virtual bool resizeScreen(const int width, const int height); + virtual void restoreContext() + { } + /** * Draws a resclaled version of the image */ @@ -468,6 +471,9 @@ class Graphics notfinal uint32_t *const arr A_UNUSED) { } + virtual void screenResized() + { } + int mWidth; int mHeight; int mActualWidth; diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp index 1fadba3c4..eb245e0de 100644 --- a/src/render/modernopenglgraphics.cpp +++ b/src/render/modernopenglgraphics.cpp @@ -117,6 +117,11 @@ ModernOpenGLGraphics::ModernOpenGLGraphics() : ModernOpenGLGraphics::~ModernOpenGLGraphics() { deleteArraysInternal(); + deleteGLObjects(); +} + +void ModernOpenGLGraphics::deleteGLObjects() +{ if (mProgram) mProgram->decRef(); if (mVbo) @@ -191,14 +196,18 @@ void ModernOpenGLGraphics::postInit() // mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0); mAttributesCached = mVbo; - screenResized(); + mglUniform2f(mScreenUniform, + static_cast<float>(mWidth) / 2.0f, + static_cast<float>(mHeight) / 2.0f); } void ModernOpenGLGraphics::screenResized() { - mglUniform2f(mScreenUniform, - static_cast<float>(mWidth) / 2.0f, - static_cast<float>(mHeight) / 2.0f); + deleteGLObjects(); + mVboCached = 0U; + mEboCached = 0U; + mAttributesCached = 0U; + postInit(); } void ModernOpenGLGraphics::deleteArrays() @@ -1261,7 +1270,10 @@ void ModernOpenGLGraphics::clearScreen() const void ModernOpenGLGraphics::createGLContext() { - mGLContext = SDL::createGLContext(mWindow, 3, 3); + if (mGLContext) + SDL::makeCurrentContext(mGLContext); + else + mGLContext = SDL::createGLContext(mWindow, 3, 3); } void ModernOpenGLGraphics::finalize(ImageCollection *const col) diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h index 2b27c621e..86e9f7bf1 100644 --- a/src/render/modernopenglgraphics.h +++ b/src/render/modernopenglgraphics.h @@ -64,7 +64,7 @@ class ModernOpenGLGraphics final : public Graphics void setColorAll(const Color &color, const Color &color2) override final; - void screenResized(); + void screenResized() override final; void finalize(ImageCollection *const col) override final; @@ -85,6 +85,8 @@ class ModernOpenGLGraphics final : public Graphics virtual void createGLContext() override final; private: + void deleteGLObjects(); + inline void drawQuad(const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, diff --git a/src/utils/glxhelper.cpp b/src/utils/glxhelper.cpp index 1fedeb9c6..1624b6309 100644 --- a/src/utils/glxhelper.cpp +++ b/src/utils/glxhelper.cpp @@ -36,7 +36,7 @@ static int ErrorHandler(Display *d A_UNUSED, XErrorEvent *e A_UNUSED) return 0; } -void *GlxHelper::createContext(unsigned int window, +void *GlxHelper::createContext(const unsigned int window, void *const display0, const int major, const int minor) @@ -117,4 +117,11 @@ void *GlxHelper::createContext(unsigned int window, return context2; } +bool GlxHelper::makeCurrent(const unsigned int window, + void *const display, + void *const context) +{ + return mglXMakeCurrent(static_cast<Display*>(display), window, context); +} + #endif // defined(USE_OPENGL) && defined(USE_X11) diff --git a/src/utils/glxhelper.h b/src/utils/glxhelper.h index 0378256d0..ce3a5568d 100644 --- a/src/utils/glxhelper.h +++ b/src/utils/glxhelper.h @@ -31,10 +31,14 @@ namespace GlxHelper { - void *createContext(unsigned int window, + void *createContext(const unsigned int window, void *const display, const int major, const int minor); + + bool makeCurrent(const unsigned int window, + void *const display, + void *const context); } // namespace Glx #endif // defined(USE_OPENGL) && defined(USE_X11) diff --git a/src/utils/sdl2helper.cpp b/src/utils/sdl2helper.cpp index 3b2b988a0..07f8d965c 100644 --- a/src/utils/sdl2helper.cpp +++ b/src/utils/sdl2helper.cpp @@ -126,4 +126,8 @@ void *SDL::createGLContext(SDL_Window *const window, return context; } +void SDL::makeCurrentContext(void *const context A_UNUSED) +{ +} + #endif // USE_SDL2 diff --git a/src/utils/sdl2helper.h b/src/utils/sdl2helper.h index 6f59b27a6..b7ab35d84 100644 --- a/src/utils/sdl2helper.h +++ b/src/utils/sdl2helper.h @@ -55,6 +55,8 @@ namespace SDL void *createGLContext(SDL_Window *const window, const int major, const int minor); + + void makeCurrentContext(void *const context); } // namespace SDL #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp index 19cffa0a6..b809fd76b 100644 --- a/src/utils/sdlhelper.cpp +++ b/src/utils/sdlhelper.cpp @@ -140,6 +140,16 @@ void *SDL::createGLContext(SDL_Surface *const window A_UNUSED, } return context; } + +void SDL::makeCurrentContext(void *const context) +{ + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWMInfo(&info); + GlxHelper::makeCurrent(info.info.x11.window, + info.info.x11.display, + context); +} #else void *SDL::createGLContext(SDL_Surface *const window A_UNUSED, const int major A_UNUSED, @@ -147,6 +157,10 @@ void *SDL::createGLContext(SDL_Surface *const window A_UNUSED, { return nullptr; } + +void SDL::makeCurrentContext(void *const context A_UNUSED) +{ +} #endif #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.h b/src/utils/sdlhelper.h index 328c093cd..92fcaba65 100644 --- a/src/utils/sdlhelper.h +++ b/src/utils/sdlhelper.h @@ -60,6 +60,8 @@ namespace SDL void *createGLContext(SDL_Surface *const window A_UNUSED, const int major, const int minor); + + void makeCurrentContext(void *const context); } // namespace SDL #endif // USE_SDL2 |