From 0020c3ef152041998e04a3e2d227e719509f2a63 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 13 Dec 2015 02:30:25 +0300 Subject: Allow resize nacl window with OpenGL without recreating context. --- src/render/graphics.cpp | 42 ++++++++++++++++++++++++++++++++---------- src/render/naclfunctions.h | 35 +++++++++++++++++++++++++++++++++++ src/render/naclgles.cpp | 4 ++++ src/render/naclgles.h | 2 -- 4 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 src/render/naclfunctions.h (limited to 'src/render') diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp index ca97e86ee..16e28b5fe 100644 --- a/src/render/graphics.cpp +++ b/src/render/graphics.cpp @@ -78,6 +78,7 @@ #ifdef USE_OPENGL #include "resources/openglimagehelper.h" #if defined(__native_client__) +#include "render/naclfunctions.h" #include "render/naclgles.h" #endif #endif @@ -512,7 +513,7 @@ bool Graphics::resizeScreen(const int width, const int height) // Setup OpenGL glViewport(0, 0, mActualWidth, mActualHeight); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); -#else +#else // USE_OPENGL // +++ need impliment resize in soft mode #endif // USE_OPENGL @@ -520,23 +521,44 @@ bool Graphics::resizeScreen(const int width, const int height) beginDraw(); return true; -#else +#else // USE_SDL2 + const int prevWidth = mWidth; const int prevHeight = mHeight; endDraw(); - const bool success = setVideoMode(width, height, mScale, mBpp, - mFullscreen, mHWAccel, mEnableResize, mNoFrame); + const bool success = true; +#ifdef __native_client__ + if (mOpenGL != RENDER_SOFTWARE) + { + mRect.w = static_cast(width / mScale); + mRect.h = static_cast(height / mScale); + mWidth = width / mScale; + mHeight = height / mScale; + mActualWidth = width; + mActualHeight = height; +#ifdef USE_OPENGL + naclResizeBuffers(mActualWidth, mActualHeight); + glViewport(0, 0, mActualWidth, mActualHeight); +#endif // USE_OPENGL - // If it didn't work, try to restore the previous size. If that didn't - // work either, bail out (but then we're in deep trouble). - if (!success) + } + else +#endif // __native_client__ { - if (!setVideoMode(prevWidth, prevHeight, mScale, mBpp, - mFullscreen, mHWAccel, mEnableResize, mNoFrame)) + bool success = setVideoMode(width, height, mScale, mBpp, + mFullscreen, mHWAccel, mEnableResize, mNoFrame); + + // If it didn't work, try to restore the previous size. If that didn't + // work either, bail out (but then we're in deep trouble). + if (!success) { - return false; + if (!setVideoMode(prevWidth, prevHeight, mScale, mBpp, + mFullscreen, mHWAccel, mEnableResize, mNoFrame)) + { + return false; + } } } diff --git a/src/render/naclfunctions.h b/src/render/naclfunctions.h new file mode 100644 index 000000000..940d02015 --- /dev/null +++ b/src/render/naclfunctions.h @@ -0,0 +1,35 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef RENDER_NACLFUNCTIONS_H +#define RENDER_NACLFUNCTIONS_H + +#if defined(__native_client__) && defined(USE_OPENGL) + +#include + +extern const struct PPB_Graphics3D_1_0 *graphics3dInterface; +extern PP_Resource gles2Context; + +#define naclResizeBuffers(...) \ + graphics3dInterface->ResizeBuffers(gles2Context, __VA_ARGS__) + +#endif // defined(__native_client__) && defined(USE_OPENGL) +#endif // RENDER_NACLFUNCTIONS_H diff --git a/src/render/naclgles.cpp b/src/render/naclgles.cpp index ef53e6849..6451b6a36 100644 --- a/src/render/naclgles.cpp +++ b/src/render/naclgles.cpp @@ -28,6 +28,7 @@ #include +#include #include #include @@ -36,11 +37,14 @@ const struct PPB_OpenGLES2* gles2Interface = nullptr; PP_Resource gles2Context = nullptr; +const struct PPB_Graphics3D_1_0 *graphics3dInterface = nullptr; void NaclGles::initGles() { gles2Interface = static_cast( PSGetInterface(PPB_OPENGLES2_INTERFACE)); + graphics3dInterface = static_cast( + PSGetInterface(PPB_GRAPHICS_3D_INTERFACE_1_0)); gles2Context = glGetCurrentContextPPAPI(); logger->log("InitGles: %p, %d", gles2Interface, gles2Context); diff --git a/src/render/naclgles.h b/src/render/naclgles.h index 44b1a1f97..aaa4459d2 100644 --- a/src/render/naclgles.h +++ b/src/render/naclgles.h @@ -23,8 +23,6 @@ #if defined(__native_client__) && defined(USE_OPENGL) -#include - namespace NaclGles { void initGles(); -- cgit v1.2.3-60-g2f50