From eda234f5e156d376541044b351fd2e1e766700a3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 2 Jul 2014 19:33:01 +0300 Subject: Fix resize in modernopengl with own context in SDL1.2 build. --- src/render/graphics.cpp | 2 ++ src/render/graphics.h | 6 ++++++ src/render/modernopenglgraphics.cpp | 22 +++++++++++++++++----- src/render/modernopenglgraphics.h | 4 +++- 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'src/render') 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(mWidth) / 2.0f, + static_cast(mHeight) / 2.0f); } void ModernOpenGLGraphics::screenResized() { - mglUniform2f(mScreenUniform, - static_cast(mWidth) / 2.0f, - static_cast(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, -- cgit v1.2.3-70-g09d2