2012-04-29 16:28:15 +03:00
|
|
|
/*
|
|
|
|
|
* The ManaPlus Client
|
2024-03-29 02:16:00 +01:00
|
|
|
* Copyright (C) 2012-2019 The ManaPlus Developers
|
2012-04-29 16:28:15 +03:00
|
|
|
*
|
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "graphicsmanager.h"
|
|
|
|
|
|
2012-10-01 23:32:51 +03:00
|
|
|
#ifdef USE_OPENGL
|
2012-08-11 23:11:07 +03:00
|
|
|
#ifndef WIN32
|
2014-06-23 19:10:33 +03:00
|
|
|
|
2012-10-17 02:24:54 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
#include <GLES/glext.h>
|
|
|
|
|
#include <EGL/egl.h>
|
2015-03-15 22:03:17 +03:00
|
|
|
|
2013-09-22 19:24:18 +03:00
|
|
|
#ifndef USE_SDL2
|
2017-06-20 03:06:00 +03:00
|
|
|
PRAGMA48(GCC diagnostic push)
|
|
|
|
|
PRAGMA48(GCC diagnostic ignored "-Wshadow")
|
2013-06-03 21:28:49 +03:00
|
|
|
#include <SDL_android.h>
|
2017-06-20 03:06:00 +03:00
|
|
|
PRAGMA48(GCC diagnostic pop)
|
2014-06-23 19:10:33 +03:00
|
|
|
#endif // USE_SDL2
|
2015-12-01 20:48:52 +03:00
|
|
|
#elif defined(__native_client__)
|
|
|
|
|
#include <GL/Regal.h>
|
2015-12-20 16:32:22 +03:00
|
|
|
#include "render/opengl/naclglfunctions.h"
|
2014-06-23 19:10:33 +03:00
|
|
|
#else // ANDROID
|
2016-04-30 18:02:24 +03:00
|
|
|
#ifdef USE_X11
|
2014-06-03 18:58:01 +03:00
|
|
|
#include <GL/glx.h>
|
2016-04-30 18:02:24 +03:00
|
|
|
#endif // USE_X11
|
2014-06-23 19:10:33 +03:00
|
|
|
#endif // ANDROID
|
2015-03-15 22:03:17 +03:00
|
|
|
#endif // WIN32
|
2014-06-23 19:10:33 +03:00
|
|
|
#endif // USE_OPENGL
|
2012-10-17 02:24:54 +03:00
|
|
|
|
2014-06-07 22:33:10 +03:00
|
|
|
#include "settings.h"
|
2013-08-31 20:38:42 +03:00
|
|
|
|
2015-03-15 22:03:17 +03:00
|
|
|
#ifdef USE_OPENGL
|
2015-12-10 01:28:03 +03:00
|
|
|
#include "render/mobileopengl2graphics.h"
|
2013-09-09 21:52:19 +03:00
|
|
|
#include "render/mobileopenglgraphics.h"
|
2014-06-08 01:36:38 +03:00
|
|
|
#include "render/modernopenglgraphics.h"
|
2013-09-09 21:52:19 +03:00
|
|
|
#include "render/normalopenglgraphics.h"
|
|
|
|
|
#include "render/safeopenglgraphics.h"
|
2015-12-20 16:32:22 +03:00
|
|
|
|
|
|
|
|
#include "render/opengl/mgl.h"
|
|
|
|
|
#include "render/opengl/mglcheck.h"
|
|
|
|
|
#include "render/opengl/mglemu.h"
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
|
|
|
|
|
2013-08-31 20:38:42 +03:00
|
|
|
#include "render/sdlgraphics.h"
|
2012-04-29 16:28:15 +03:00
|
|
|
|
2015-03-15 22:03:17 +03:00
|
|
|
#ifdef USE_OPENGL
|
2012-06-10 16:54:18 +03:00
|
|
|
#include "resources/openglimagehelper.h"
|
2015-12-16 01:03:19 +03:00
|
|
|
#include "resources/openglscreenshothelper.h"
|
2015-12-15 18:57:03 +03:00
|
|
|
#ifndef ANDROID
|
2015-12-16 20:39:17 +03:00
|
|
|
#include "resources/mobileopenglscreenshothelper.h"
|
2015-12-15 18:57:03 +03:00
|
|
|
#include "resources/safeopenglimagehelper.h"
|
|
|
|
|
#endif // ANDROID
|
2015-12-20 16:32:22 +03:00
|
|
|
#include "render/opengl/mglfunctions.h"
|
2015-12-15 18:57:03 +03:00
|
|
|
#endif // USE_OPENGL
|
2015-03-15 22:03:17 +03:00
|
|
|
|
|
|
|
|
#include "resources/sdlimagehelper.h"
|
2015-12-16 01:03:19 +03:00
|
|
|
#include "resources/sdlscreenshothelper.h"
|
2014-06-23 19:10:33 +03:00
|
|
|
|
2013-09-09 21:52:19 +03:00
|
|
|
#ifdef USE_SDL2
|
|
|
|
|
#include "render/sdl2softwaregraphics.h"
|
|
|
|
|
|
|
|
|
|
#include "resources/sdl2softwareimagehelper.h"
|
2015-12-16 02:04:52 +03:00
|
|
|
#include "resources/sdl2softwarescreenshothelper.h"
|
2013-08-25 13:19:23 +03:00
|
|
|
#include "resources/surfaceimagehelper.h"
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_SDL2
|
2012-04-29 16:28:15 +03:00
|
|
|
|
2014-06-07 23:21:18 +03:00
|
|
|
#include "utils/delete2.h"
|
2013-08-22 00:19:17 +03:00
|
|
|
#include "utils/sdlhelper.h"
|
2012-04-29 16:28:15 +03:00
|
|
|
|
2015-03-15 22:03:17 +03:00
|
|
|
#ifdef USE_OPENGL
|
2012-05-18 01:57:27 +03:00
|
|
|
#include "test/testmain.h"
|
2016-05-31 02:40:00 +03:00
|
|
|
#else // USE_OPENGL
|
|
|
|
|
#include "configuration.h"
|
|
|
|
|
|
|
|
|
|
#include "render/renderers.h"
|
|
|
|
|
#endif // USE_OPENGL
|
2012-05-18 01:57:27 +03:00
|
|
|
|
2017-06-20 03:06:00 +03:00
|
|
|
PRAGMA48(GCC diagnostic push)
|
|
|
|
|
PRAGMA48(GCC diagnostic ignored "-Wshadow")
|
2013-06-03 21:28:49 +03:00
|
|
|
#include <SDL_syswm.h>
|
2017-06-20 03:06:00 +03:00
|
|
|
PRAGMA48(GCC diagnostic pop)
|
2012-08-14 12:43:25 +03:00
|
|
|
|
2012-04-29 16:28:15 +03:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
2012-10-08 19:48:26 +03:00
|
|
|
#ifdef USE_OPENGL
|
2012-10-04 22:52:29 +03:00
|
|
|
#ifndef GL_MAX_RENDERBUFFER_SIZE
|
|
|
|
|
#define GL_MAX_RENDERBUFFER_SIZE 0x84E8
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // GL_MAX_RENDERBUFFER_SIZE
|
2014-08-18 13:46:54 +03:00
|
|
|
#define useCompression(name) \
|
2018-11-26 00:51:57 +03:00
|
|
|
{ \
|
|
|
|
|
OpenGLImageHelper::setInternalTextureType(name); \
|
|
|
|
|
logger->log("using " #name " texture compression"); \
|
|
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2012-10-01 17:51:43 +03:00
|
|
|
|
2012-04-29 16:28:15 +03:00
|
|
|
GraphicsManager graphicsManager;
|
|
|
|
|
|
2014-05-27 21:47:06 +03:00
|
|
|
RenderType openGLMode = RENDER_SOFTWARE;
|
|
|
|
|
|
2015-12-16 01:03:19 +03:00
|
|
|
ScreenshotHelper *screenshortHelper = nullptr;
|
|
|
|
|
|
2013-04-30 22:32:38 +03:00
|
|
|
const int densitySize = 6;
|
|
|
|
|
|
|
|
|
|
const std::string densityNames[] =
|
|
|
|
|
{
|
|
|
|
|
"low",
|
|
|
|
|
"medium",
|
|
|
|
|
"tv",
|
|
|
|
|
"high",
|
|
|
|
|
"xhigh",
|
|
|
|
|
"xxhigh"
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-25 17:50:46 +03:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
|
GLenum GraphicsManager::mLastError(GL_NO_ERROR);
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2014-05-25 17:50:46 +03:00
|
|
|
|
2012-05-19 18:54:56 +03:00
|
|
|
GraphicsManager::GraphicsManager() :
|
2013-04-20 16:40:24 +03:00
|
|
|
mExtensions(),
|
|
|
|
|
mPlatformExtensions(),
|
|
|
|
|
mGlVersionString(),
|
|
|
|
|
mGlVendor(),
|
|
|
|
|
mGlRenderer(),
|
2014-06-25 18:35:05 +03:00
|
|
|
mGlShaderVersionString(),
|
2012-05-19 18:54:56 +03:00
|
|
|
mMinor(0),
|
2012-08-14 20:37:36 +03:00
|
|
|
mMajor(0),
|
2014-06-25 18:35:05 +03:00
|
|
|
mSLMinor(0),
|
|
|
|
|
mSLMajor(0),
|
2012-08-14 20:37:36 +03:00
|
|
|
mPlatformMinor(0),
|
2012-09-09 13:09:20 +03:00
|
|
|
mPlatformMajor(0),
|
2012-08-13 22:18:03 +03:00
|
|
|
mMaxVertices(500),
|
2012-10-04 22:52:29 +03:00
|
|
|
mMaxFboSize(0),
|
2013-04-30 22:32:38 +03:00
|
|
|
mMaxWidth(0),
|
|
|
|
|
mMaxHeight(0),
|
|
|
|
|
mWidthMM(0),
|
|
|
|
|
mHeightMM(0),
|
|
|
|
|
mDensity(-1),
|
2012-10-01 23:32:51 +03:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
|
mUseTextureSampler(true),
|
|
|
|
|
mTextureSampler(0),
|
2012-10-23 03:51:06 +03:00
|
|
|
mSupportDebug(0),
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl(false),
|
2015-12-16 23:58:02 +03:00
|
|
|
mGles(false),
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2012-08-13 22:18:03 +03:00
|
|
|
mUseAtlases(false)
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GraphicsManager::~GraphicsManager()
|
|
|
|
|
{
|
2012-10-01 23:32:51 +03:00
|
|
|
#ifdef USE_OPENGL
|
2014-07-12 21:35:44 +03:00
|
|
|
if (isGLNotNull(mglGenSamplers) && mTextureSampler)
|
2012-10-01 23:32:51 +03:00
|
|
|
mglDeleteSamplers(1, &mTextureSampler);
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2012-04-29 16:28:15 +03:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 19:48:26 +03:00
|
|
|
#ifdef USE_OPENGL
|
2012-10-08 17:11:06 +03:00
|
|
|
TestMain *GraphicsManager::startDetection()
|
2012-05-18 01:57:27 +03:00
|
|
|
{
|
2017-03-10 16:40:52 +03:00
|
|
|
TestMain *const test = new TestMain;
|
2012-05-18 01:57:27 +03:00
|
|
|
test->exec(false);
|
2012-10-08 17:11:06 +03:00
|
|
|
return test;
|
2012-05-18 01:57:27 +03:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 17:11:06 +03:00
|
|
|
int GraphicsManager::detectGraphics()
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("start detecting best mode...");
|
|
|
|
|
logger->log1("enable opengl mode");
|
2012-10-08 17:11:06 +03:00
|
|
|
int textureSampler = 0;
|
|
|
|
|
int compressTextures = 0;
|
2020-04-23 11:16:31 +02:00
|
|
|
#if !defined(ANDROID) && !defined(__native_client__) && !defined(__SWITCH__)
|
2013-09-15 13:06:42 +03:00
|
|
|
mainGraphics = new NormalOpenGLGraphics;
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // !defined(ANDROID) && !defined(__native_client__)
|
|
|
|
|
|
2013-09-15 13:06:42 +03:00
|
|
|
SDL_Window *const window = createWindow(100, 100, 0,
|
|
|
|
|
SDL_ANYFORMAT | SDL_OPENGL);
|
|
|
|
|
mainGraphics->setWindow(window, 100, 100);
|
2016-09-03 02:31:07 +03:00
|
|
|
mainGraphics->createGLContext(false);
|
2012-05-11 21:55:28 +03:00
|
|
|
|
2012-09-09 13:09:20 +03:00
|
|
|
initOpenGL();
|
2012-10-08 13:21:45 +03:00
|
|
|
logVersion();
|
2012-05-11 21:55:28 +03:00
|
|
|
|
2013-10-22 01:30:47 +03:00
|
|
|
RenderType mode = RENDER_NORMAL_OPENGL;
|
2012-05-11 21:55:28 +03:00
|
|
|
|
|
|
|
|
// detecting features by known renderers or vendors
|
2012-10-08 13:21:45 +03:00
|
|
|
if (findI(mGlRenderer, "gdi generic") != std::string::npos)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
|
|
|
|
// windows gdi OpenGL emulation
|
|
|
|
|
logger->log("detected gdi drawing");
|
|
|
|
|
logger->log("disable OpenGL");
|
2013-10-22 01:30:47 +03:00
|
|
|
mode = RENDER_SOFTWARE;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
2012-10-08 13:21:45 +03:00
|
|
|
else if (findI(mGlRenderer, "Software Rasterizer") != std::string::npos)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
|
|
|
|
// software OpenGL emulation
|
|
|
|
|
logger->log("detected software drawing");
|
|
|
|
|
logger->log("disable OpenGL");
|
2013-10-22 01:30:47 +03:00
|
|
|
mode = RENDER_SOFTWARE;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
2012-10-08 13:21:45 +03:00
|
|
|
else if (findI(mGlRenderer, "Indirect") != std::string::npos)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
|
|
|
|
// indirect OpenGL drawing
|
|
|
|
|
logger->log("detected indirect drawing");
|
|
|
|
|
logger->log("disable OpenGL");
|
2013-10-22 01:30:47 +03:00
|
|
|
mode = RENDER_SOFTWARE;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
2012-10-08 13:21:45 +03:00
|
|
|
else if (findI(mGlVendor, "VMWARE") != std::string::npos)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
|
|
|
|
// vmware emulation
|
|
|
|
|
logger->log("detected VMWARE driver");
|
|
|
|
|
logger->log("disable OpenGL");
|
2013-10-22 01:30:47 +03:00
|
|
|
mode = RENDER_SOFTWARE;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
2012-10-08 13:21:45 +03:00
|
|
|
else if (findI(mGlVendor, "NVIDIA") != std::string::npos)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
|
|
|
|
// hope it can work well
|
|
|
|
|
logger->log("detected NVIDIA driver");
|
2012-10-08 13:29:42 +03:00
|
|
|
config.setValue("useTextureSampler", true);
|
2012-10-08 17:11:06 +03:00
|
|
|
textureSampler = 1;
|
2013-10-22 01:30:47 +03:00
|
|
|
mode = RENDER_NORMAL_OPENGL;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// detecting feature based on OpenGL version
|
|
|
|
|
if (!checkGLVersion(1, 1))
|
|
|
|
|
{
|
|
|
|
|
// very old OpenGL version
|
|
|
|
|
logger->log("OpenGL version too old");
|
2013-10-22 01:30:47 +03:00
|
|
|
mode = RENDER_SOFTWARE;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
|
|
|
|
|
2014-05-08 22:48:11 +03:00
|
|
|
if (mode != RENDER_SOFTWARE && findI(mGlVersionString, "Mesa")
|
|
|
|
|
!= std::string::npos)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
2012-12-21 19:24:43 +03:00
|
|
|
// Mesa detected. In latest Mesa look like compression broken.
|
|
|
|
|
config.setValue("compresstextures", false);
|
|
|
|
|
compressTextures = 0;
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
|
|
|
|
|
2016-02-07 16:18:13 +03:00
|
|
|
config.setValue("opengl", CAST_S32(mode));
|
2012-05-11 21:55:28 +03:00
|
|
|
config.setValue("videoconfigured", true);
|
2012-10-08 14:22:49 +03:00
|
|
|
config.write();
|
2012-05-11 21:55:28 +03:00
|
|
|
|
|
|
|
|
logger->log("detection complete");
|
2016-02-07 16:18:13 +03:00
|
|
|
return CAST_U32(mode)
|
2014-05-08 22:48:11 +03:00
|
|
|
| (1024 * textureSampler) | (2048 * compressTextures);
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
|
|
|
|
|
2015-12-12 23:48:21 +03:00
|
|
|
#ifdef USE_SDL2
|
|
|
|
|
#define RENDER_SOFTWARE_INIT \
|
|
|
|
|
imageHelper = new SDL2SoftwareImageHelper; \
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
2015-12-16 01:03:19 +03:00
|
|
|
mainGraphics = new SDL2SoftwareGraphics; \
|
2015-12-16 02:04:52 +03:00
|
|
|
screenshortHelper = new Sdl2SoftwareScreenshotHelper;
|
2015-12-12 23:48:21 +03:00
|
|
|
#define RENDER_SDL2_DEFAULT_INIT \
|
|
|
|
|
imageHelper = new SDLImageHelper; \
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
|
|
|
|
mainGraphics = new SDLGraphics; \
|
2015-12-16 01:03:19 +03:00
|
|
|
screenshortHelper = new SdlScreenshotHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
mainGraphics->setRendererFlags(SDL_RENDERER_ACCELERATED); \
|
|
|
|
|
mUseTextureSampler = false;
|
|
|
|
|
#else // USE_SDL2
|
|
|
|
|
#define RENDER_SOFTWARE_INIT \
|
|
|
|
|
imageHelper = new SDLImageHelper; \
|
|
|
|
|
surfaceImageHelper = imageHelper; \
|
2015-12-16 01:03:19 +03:00
|
|
|
mainGraphics = new SDLGraphics; \
|
|
|
|
|
screenshortHelper = new SdlScreenshotHelper;
|
2015-12-12 23:48:21 +03:00
|
|
|
#define RENDER_SDL2_DEFAULT_INIT
|
|
|
|
|
#endif // USE_SDL2
|
|
|
|
|
|
2020-04-23 11:16:31 +02:00
|
|
|
#if defined(ANDROID) || defined(__native_client__) || defined(__SWITCH__)
|
2015-12-12 23:48:21 +03:00
|
|
|
#define RENDER_NORMAL_OPENGL_INIT
|
|
|
|
|
#define RENDER_MODERN_OPENGL_INIT
|
|
|
|
|
#else // defined(ANDROID) || defined(__native_client__)
|
|
|
|
|
#define RENDER_NORMAL_OPENGL_INIT \
|
|
|
|
|
imageHelper = new OpenGLImageHelper; \
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
|
|
|
|
mainGraphics = new NormalOpenGLGraphics; \
|
2015-12-16 01:03:19 +03:00
|
|
|
screenshortHelper = new OpenGLScreenshotHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
mUseTextureSampler = true;
|
|
|
|
|
#define RENDER_MODERN_OPENGL_INIT \
|
|
|
|
|
imageHelper = new OpenGLImageHelper; \
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
|
|
|
|
mainGraphics = new ModernOpenGLGraphics; \
|
2015-12-16 01:03:19 +03:00
|
|
|
screenshortHelper = new OpenGLScreenshotHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
mUseTextureSampler = true;
|
|
|
|
|
#endif // defined(ANDROID) || defined(__native_client__)
|
|
|
|
|
|
|
|
|
|
#if defined(ANDROID)
|
|
|
|
|
#define RENDER_SAFE_OPENGL_INIT
|
|
|
|
|
#define RENDER_GLES2_OPENGL_INIT
|
|
|
|
|
#else // defined(ANDROID)
|
2020-04-23 11:16:31 +02:00
|
|
|
#ifdef __SWITCH__
|
|
|
|
|
#define RENDER_SAFE_OPENGL_INIT
|
|
|
|
|
#else
|
2015-12-12 23:48:21 +03:00
|
|
|
#define RENDER_SAFE_OPENGL_INIT \
|
2015-12-15 18:57:03 +03:00
|
|
|
imageHelper = new SafeOpenGLImageHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
|
|
|
|
mainGraphics = new SafeOpenGLGraphics; \
|
2015-12-16 01:03:19 +03:00
|
|
|
screenshortHelper = new OpenGLScreenshotHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
mUseTextureSampler = false;
|
2020-04-23 11:16:31 +02:00
|
|
|
#endif
|
2015-12-12 23:48:21 +03:00
|
|
|
#define RENDER_GLES2_OPENGL_INIT \
|
|
|
|
|
imageHelper = new OpenGLImageHelper; \
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
|
|
|
|
mainGraphics = new MobileOpenGL2Graphics; \
|
2015-12-16 20:39:17 +03:00
|
|
|
screenshortHelper = new MobileOpenGLScreenshotHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
mUseTextureSampler = false;
|
|
|
|
|
#endif // defined(ANDROID)
|
|
|
|
|
|
2020-04-23 11:16:31 +02:00
|
|
|
#if defined(__native_client__) || defined(__SWITCH__)
|
2015-12-12 23:48:21 +03:00
|
|
|
#define RENDER_GLES_OPENGL_INIT
|
|
|
|
|
#else // defined(__native_client__)
|
|
|
|
|
#define RENDER_GLES_OPENGL_INIT \
|
|
|
|
|
imageHelper = new OpenGLImageHelper; \
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper; \
|
|
|
|
|
mainGraphics = new MobileOpenGLGraphics; \
|
2015-12-16 01:03:19 +03:00
|
|
|
screenshortHelper = new OpenGLScreenshotHelper; \
|
2015-12-12 23:48:21 +03:00
|
|
|
mUseTextureSampler = false;
|
|
|
|
|
#endif // defined(__native_client__)
|
|
|
|
|
|
2014-06-07 22:33:10 +03:00
|
|
|
void GraphicsManager::createRenderers()
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2013-09-01 00:50:45 +03:00
|
|
|
RenderType useOpenGL = RENDER_SOFTWARE;
|
2014-06-07 22:33:10 +03:00
|
|
|
if (!settings.options.noOpenGL)
|
2014-06-14 16:31:01 +03:00
|
|
|
{
|
|
|
|
|
if (settings.options.renderer < 0)
|
2014-06-24 12:40:55 +03:00
|
|
|
{
|
2014-06-14 16:31:01 +03:00
|
|
|
useOpenGL = intToRenderType(config.getIntValue("opengl"));
|
2016-02-07 16:18:13 +03:00
|
|
|
settings.options.renderer = CAST_S32(useOpenGL);
|
2014-06-24 12:40:55 +03:00
|
|
|
}
|
2014-06-14 16:31:01 +03:00
|
|
|
else
|
2014-06-24 12:40:55 +03:00
|
|
|
{
|
2014-06-14 16:31:01 +03:00
|
|
|
useOpenGL = intToRenderType(settings.options.renderer);
|
2014-06-24 12:40:55 +03:00
|
|
|
}
|
2014-06-14 16:31:01 +03:00
|
|
|
}
|
2012-04-29 16:28:15 +03:00
|
|
|
|
|
|
|
|
// Setup image loading for the right image format
|
2013-09-13 15:56:56 +03:00
|
|
|
ImageHelper::setOpenGlMode(useOpenGL);
|
2012-04-29 16:28:15 +03:00
|
|
|
|
|
|
|
|
// Create the graphics context
|
|
|
|
|
switch (useOpenGL)
|
|
|
|
|
{
|
2013-09-01 00:50:45 +03:00
|
|
|
case RENDER_SOFTWARE:
|
2015-12-12 23:48:21 +03:00
|
|
|
RENDER_SOFTWARE_INIT
|
2012-10-01 23:32:51 +03:00
|
|
|
mUseTextureSampler = false;
|
2012-04-29 16:28:15 +03:00
|
|
|
break;
|
2013-09-13 19:10:50 +03:00
|
|
|
case RENDER_LAST:
|
|
|
|
|
case RENDER_NULL:
|
2012-04-29 16:28:15 +03:00
|
|
|
default:
|
2015-12-12 23:48:21 +03:00
|
|
|
break;
|
|
|
|
|
case RENDER_NORMAL_OPENGL:
|
|
|
|
|
RENDER_NORMAL_OPENGL_INIT
|
2012-04-29 16:28:15 +03:00
|
|
|
break;
|
2013-09-01 00:50:45 +03:00
|
|
|
case RENDER_SAFE_OPENGL:
|
2015-12-12 23:48:21 +03:00
|
|
|
RENDER_SAFE_OPENGL_INIT
|
2012-04-29 16:28:15 +03:00
|
|
|
break;
|
2014-06-08 01:36:38 +03:00
|
|
|
case RENDER_MODERN_OPENGL:
|
2015-12-12 23:48:21 +03:00
|
|
|
RENDER_MODERN_OPENGL_INIT
|
2014-06-08 01:36:38 +03:00
|
|
|
break;
|
2015-12-10 01:28:03 +03:00
|
|
|
case RENDER_GLES2_OPENGL:
|
2015-12-12 23:48:21 +03:00
|
|
|
RENDER_GLES2_OPENGL_INIT
|
2015-12-10 01:28:03 +03:00
|
|
|
break;
|
2013-09-01 00:50:45 +03:00
|
|
|
case RENDER_GLES_OPENGL:
|
2015-12-12 23:48:21 +03:00
|
|
|
RENDER_GLES_OPENGL_INIT
|
2012-10-25 21:43:32 +03:00
|
|
|
break;
|
2013-09-01 17:40:11 +03:00
|
|
|
case RENDER_SDL2_DEFAULT:
|
2015-12-12 23:48:21 +03:00
|
|
|
RENDER_SDL2_DEFAULT_INIT
|
2013-09-01 17:40:11 +03:00
|
|
|
break;
|
2018-11-26 00:51:57 +03:00
|
|
|
}
|
2015-12-10 01:28:03 +03:00
|
|
|
mUseAtlases = (useOpenGL == RENDER_NORMAL_OPENGL ||
|
|
|
|
|
useOpenGL == RENDER_SAFE_OPENGL ||
|
|
|
|
|
useOpenGL == RENDER_MODERN_OPENGL ||
|
|
|
|
|
useOpenGL == RENDER_GLES_OPENGL ||
|
|
|
|
|
useOpenGL == RENDER_GLES2_OPENGL) &&
|
|
|
|
|
config.getBoolValue("useAtlases");
|
2013-09-13 15:56:56 +03:00
|
|
|
|
|
|
|
|
#else // USE_OPENGL
|
|
|
|
|
|
2014-06-07 22:33:10 +03:00
|
|
|
void GraphicsManager::createRenderers()
|
2012-10-08 19:48:26 +03:00
|
|
|
{
|
2013-09-13 15:56:56 +03:00
|
|
|
RenderType useOpenGL = RENDER_SOFTWARE;
|
2014-06-07 22:33:10 +03:00
|
|
|
if (!settings.options.noOpenGL)
|
2013-09-13 15:56:56 +03:00
|
|
|
useOpenGL = intToRenderType(config.getIntValue("opengl"));
|
|
|
|
|
|
|
|
|
|
// Setup image loading for the right image format
|
|
|
|
|
ImageHelper::setOpenGlMode(useOpenGL);
|
|
|
|
|
|
2012-04-29 16:28:15 +03:00
|
|
|
// Create the graphics context
|
2013-09-13 15:56:56 +03:00
|
|
|
switch (useOpenGL)
|
|
|
|
|
{
|
|
|
|
|
case RENDER_SOFTWARE:
|
|
|
|
|
case RENDER_SAFE_OPENGL:
|
|
|
|
|
case RENDER_GLES_OPENGL:
|
2015-12-10 01:28:03 +03:00
|
|
|
case RENDER_GLES2_OPENGL:
|
2014-06-08 01:04:33 +03:00
|
|
|
case RENDER_MODERN_OPENGL:
|
2013-09-13 15:56:56 +03:00
|
|
|
case RENDER_NORMAL_OPENGL:
|
2013-09-13 19:10:50 +03:00
|
|
|
case RENDER_NULL:
|
|
|
|
|
case RENDER_LAST:
|
2013-09-13 15:56:56 +03:00
|
|
|
default:
|
|
|
|
|
#ifndef USE_SDL2
|
|
|
|
|
case RENDER_SDL2_DEFAULT:
|
|
|
|
|
imageHelper = new SDLImageHelper;
|
|
|
|
|
surfaceImageHelper = imageHelper;
|
|
|
|
|
mainGraphics = new SDLGraphics;
|
2015-12-16 02:04:52 +03:00
|
|
|
screenshortHelper = new SdlScreenshotHelper;
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // USE_SDL2
|
|
|
|
|
|
|
|
|
|
imageHelper = new SDL2SoftwareImageHelper;
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper;
|
|
|
|
|
mainGraphics = new SDL2SoftwareGraphics;
|
|
|
|
|
screenshortHelper = new Sdl2SoftwareScreenshotHelper;
|
|
|
|
|
|
|
|
|
|
#endif // USE_SDL2
|
|
|
|
|
|
2013-09-13 15:56:56 +03:00
|
|
|
break;
|
|
|
|
|
#ifdef USE_SDL2
|
|
|
|
|
case RENDER_SDL2_DEFAULT:
|
|
|
|
|
imageHelper = new SDLImageHelper;
|
|
|
|
|
surfaceImageHelper = new SurfaceImageHelper;
|
|
|
|
|
mainGraphics = new SDLGraphics;
|
|
|
|
|
mainGraphics->setRendererFlags(SDL_RENDERER_ACCELERATED);
|
2015-12-16 02:04:52 +03:00
|
|
|
screenshortHelper = new SdlScreenshotHelper;
|
2013-09-13 15:56:56 +03:00
|
|
|
break;
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_SDL2
|
2013-09-13 15:56:56 +03:00
|
|
|
};
|
|
|
|
|
#endif // USE_OPENGL
|
2012-04-29 16:28:15 +03:00
|
|
|
}
|
|
|
|
|
|
2014-06-07 23:21:18 +03:00
|
|
|
void GraphicsManager::deleteRenderers()
|
|
|
|
|
{
|
2018-11-26 00:51:57 +03:00
|
|
|
delete2(mainGraphics)
|
2014-06-07 23:21:18 +03:00
|
|
|
if (imageHelper != surfaceImageHelper)
|
|
|
|
|
delete surfaceImageHelper;
|
|
|
|
|
surfaceImageHelper = nullptr;
|
2018-11-26 00:51:57 +03:00
|
|
|
delete2(imageHelper)
|
2014-06-07 23:21:18 +03:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 19:48:26 +03:00
|
|
|
void GraphicsManager::setVideoMode()
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2012-10-08 19:48:26 +03:00
|
|
|
const int bpp = 0;
|
|
|
|
|
const bool fullscreen = config.getBoolValue("screen");
|
|
|
|
|
const bool hwaccel = config.getBoolValue("hwaccel");
|
|
|
|
|
const bool enableResize = config.getBoolValue("enableresize");
|
|
|
|
|
const bool noFrame = config.getBoolValue("noframe");
|
2017-09-12 23:07:39 +03:00
|
|
|
const bool allowHighDPI = config.getBoolValue("allowHighDPI");
|
2012-10-08 19:48:26 +03:00
|
|
|
|
2012-10-27 03:35:10 +03:00
|
|
|
#ifdef ANDROID
|
2013-09-25 20:32:12 +03:00
|
|
|
// int width = config.getValue("screenwidth", 0);
|
|
|
|
|
// int height = config.getValue("screenheight", 0);
|
2012-10-27 03:35:10 +03:00
|
|
|
StringVect videoModes;
|
2013-08-22 00:19:17 +03:00
|
|
|
SDL::getAllVideoModes(videoModes);
|
2013-09-25 20:32:12 +03:00
|
|
|
if (videoModes.empty())
|
|
|
|
|
logger->error("no video modes detected");
|
2017-07-14 01:31:22 +03:00
|
|
|
STD_VECTOR<int> res;
|
2013-09-25 20:32:12 +03:00
|
|
|
splitToIntVector(res, videoModes[0], 'x');
|
|
|
|
|
if (res.size() != 2)
|
|
|
|
|
logger->error("no video modes detected");
|
|
|
|
|
|
|
|
|
|
int width = res[0];
|
|
|
|
|
int height = res[1];
|
2013-11-04 19:33:58 +04:00
|
|
|
#elif defined __native_client__
|
2013-11-08 14:52:18 +03:00
|
|
|
#ifdef USE_SDL2
|
2016-11-11 19:21:51 +03:00
|
|
|
// not implemented
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // USE_SDL2
|
|
|
|
|
|
2013-11-08 14:52:18 +03:00
|
|
|
const SDL_VideoInfo* info = SDL_GetVideoInfo();
|
|
|
|
|
int width = info->current_w;
|
|
|
|
|
int height = info->current_h;
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_SDL2
|
2020-04-22 18:19:18 +02:00
|
|
|
#elif defined __SWITCH__
|
|
|
|
|
int width = 1280;
|
|
|
|
|
int height = 720;
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // defined __native_client__
|
|
|
|
|
|
2012-10-30 19:15:19 +03:00
|
|
|
int width = config.getIntValue("screenwidth");
|
|
|
|
|
int height = config.getIntValue("screenheight");
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // defined __native_client__
|
|
|
|
|
|
2014-01-29 00:55:06 +03:00
|
|
|
const int scale = config.getIntValue("scale");
|
2014-01-28 00:30:51 +03:00
|
|
|
|
2012-10-08 19:48:26 +03:00
|
|
|
// Try to set the desired video mode
|
2014-01-28 00:30:51 +03:00
|
|
|
if (!mainGraphics->setVideoMode(width, height, scale, bpp,
|
2017-09-12 23:07:39 +03:00
|
|
|
fullscreen, hwaccel, enableResize, noFrame, allowHighDPI))
|
2012-10-08 19:48:26 +03:00
|
|
|
{
|
|
|
|
|
logger->log(strprintf("Couldn't set %dx%dx%d video mode: %s",
|
|
|
|
|
width, height, bpp, SDL_GetError()));
|
|
|
|
|
|
|
|
|
|
const int oldWidth = config.getValueInt("oldscreenwidth", -1);
|
|
|
|
|
const int oldHeight = config.getValueInt("oldscreenheight", -1);
|
|
|
|
|
const int oldFullscreen = config.getValueInt("oldscreen", -1);
|
|
|
|
|
if (oldWidth != -1 && oldHeight != -1 && oldFullscreen != -1)
|
|
|
|
|
{
|
|
|
|
|
config.deleteKey("oldscreenwidth");
|
|
|
|
|
config.deleteKey("oldscreenheight");
|
|
|
|
|
config.deleteKey("oldscreen");
|
|
|
|
|
|
|
|
|
|
config.setValueInt("screenwidth", oldWidth);
|
|
|
|
|
config.setValueInt("screenheight", oldHeight);
|
|
|
|
|
config.setValue("screen", oldFullscreen == 1);
|
2017-09-12 23:07:39 +03:00
|
|
|
if (!mainGraphics->setVideoMode(oldWidth, oldHeight,
|
|
|
|
|
scale,
|
|
|
|
|
bpp,
|
|
|
|
|
oldFullscreen != 0,
|
|
|
|
|
hwaccel,
|
|
|
|
|
enableResize,
|
|
|
|
|
noFrame,
|
|
|
|
|
allowHighDPI))
|
2012-10-08 19:48:26 +03:00
|
|
|
{
|
|
|
|
|
logger->safeError(strprintf("Couldn't restore %dx%dx%d "
|
|
|
|
|
"video mode: %s", oldWidth, oldHeight, bpp,
|
|
|
|
|
SDL_GetError()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 22:33:10 +03:00
|
|
|
void GraphicsManager::initGraphics()
|
2014-05-27 21:47:06 +03:00
|
|
|
{
|
|
|
|
|
openGLMode = intToRenderType(config.getIntValue("opengl"));
|
|
|
|
|
#ifdef USE_OPENGL
|
|
|
|
|
OpenGLImageHelper::setBlur(config.getBoolValue("blur"));
|
2020-04-23 11:16:31 +02:00
|
|
|
#if !defined(ANDROID) && !defined(__SWITCH__)
|
2015-12-15 18:57:03 +03:00
|
|
|
SafeOpenGLImageHelper::setBlur(config.getBoolValue("blur"));
|
|
|
|
|
#endif // ANDROID
|
2014-05-27 21:47:06 +03:00
|
|
|
SurfaceImageHelper::SDLSetEnableAlphaCache(
|
2016-12-10 16:46:55 +03:00
|
|
|
config.getBoolValue("alphaCache") &&
|
2016-12-10 21:10:07 +03:00
|
|
|
openGLMode == RENDER_SOFTWARE);
|
2015-10-25 18:03:20 +03:00
|
|
|
ImageHelper::setEnableAlpha((config.getFloatValue("guialpha") != 1.0F ||
|
2016-12-10 21:10:07 +03:00
|
|
|
openGLMode != RENDER_SOFTWARE) &&
|
2016-12-10 16:46:55 +03:00
|
|
|
config.getBoolValue("enableGuiOpacity"));
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // USE_OPENGL
|
2014-05-27 21:47:06 +03:00
|
|
|
SurfaceImageHelper::SDLSetEnableAlphaCache(
|
|
|
|
|
config.getBoolValue("alphaCache"));
|
2015-10-25 18:03:20 +03:00
|
|
|
ImageHelper::setEnableAlpha(config.getFloatValue("guialpha") != 1.0F &&
|
|
|
|
|
config.getBoolValue("enableGuiOpacity"));
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2014-06-07 22:33:10 +03:00
|
|
|
createRenderers();
|
|
|
|
|
setVideoMode();
|
2017-09-07 02:28:14 +03:00
|
|
|
detectPixelSize();
|
2014-06-07 23:21:18 +03:00
|
|
|
#ifdef USE_OPENGL
|
2016-04-21 01:59:00 +03:00
|
|
|
if (config.getBoolValue("checkOpenGLVersion") == true)
|
2014-06-08 01:04:33 +03:00
|
|
|
{
|
2016-04-21 01:59:00 +03:00
|
|
|
const RenderType oldOpenGLMode = openGLMode;
|
|
|
|
|
if (openGLMode == RENDER_MODERN_OPENGL)
|
2014-06-08 01:04:33 +03:00
|
|
|
{
|
2016-04-21 01:59:00 +03:00
|
|
|
if (!mSupportModernOpengl || !checkGLVersion(3, 0))
|
|
|
|
|
{
|
|
|
|
|
logger->log("Fallback to normal OpenGL mode");
|
|
|
|
|
openGLMode = RENDER_NORMAL_OPENGL;
|
|
|
|
|
}
|
2014-06-08 01:04:33 +03:00
|
|
|
}
|
2016-04-21 01:59:00 +03:00
|
|
|
if (openGLMode == RENDER_NORMAL_OPENGL)
|
2014-06-07 23:21:18 +03:00
|
|
|
{
|
2016-04-21 01:59:00 +03:00
|
|
|
if (!checkGLVersion(2, 0))
|
|
|
|
|
{
|
|
|
|
|
logger->log("Fallback to safe OpenGL mode");
|
|
|
|
|
openGLMode = RENDER_SAFE_OPENGL;
|
|
|
|
|
}
|
2014-06-07 23:21:18 +03:00
|
|
|
}
|
2016-04-21 01:59:00 +03:00
|
|
|
if (openGLMode == RENDER_GLES_OPENGL)
|
2015-12-19 19:15:46 +03:00
|
|
|
{
|
2016-04-21 01:59:00 +03:00
|
|
|
if (!checkGLVersion(2, 0) && !checkGLesVersion(1, 0))
|
|
|
|
|
{
|
|
|
|
|
logger->log("Fallback to safe OpenGL mode");
|
|
|
|
|
openGLMode = RENDER_SAFE_OPENGL;
|
|
|
|
|
}
|
2015-12-19 19:15:46 +03:00
|
|
|
}
|
2016-04-21 01:59:00 +03:00
|
|
|
if (openGLMode == RENDER_GLES2_OPENGL)
|
2015-12-10 01:28:03 +03:00
|
|
|
{
|
2016-11-11 19:21:51 +03:00
|
|
|
// +++ here need check also not implemented gles flag
|
2016-04-21 01:59:00 +03:00
|
|
|
if (!checkGLVersion(2, 0))
|
|
|
|
|
{
|
|
|
|
|
logger->log("Fallback to software mode");
|
|
|
|
|
openGLMode = RENDER_SOFTWARE;
|
|
|
|
|
}
|
2015-12-10 01:28:03 +03:00
|
|
|
}
|
2015-12-12 15:22:15 +03:00
|
|
|
|
2016-04-21 01:59:00 +03:00
|
|
|
if (openGLMode != oldOpenGLMode)
|
|
|
|
|
{
|
|
|
|
|
deleteRenderers();
|
|
|
|
|
settings.options.renderer = CAST_S32(openGLMode);
|
|
|
|
|
config.setValue("opengl", settings.options.renderer);
|
|
|
|
|
createRenderers();
|
|
|
|
|
setVideoMode();
|
2017-09-07 02:28:14 +03:00
|
|
|
detectPixelSize();
|
2016-04-21 01:59:00 +03:00
|
|
|
}
|
2014-06-08 01:04:33 +03:00
|
|
|
}
|
2014-07-16 21:10:58 +03:00
|
|
|
#if !defined(ANDROID) && !defined(__APPLE__)
|
|
|
|
|
const std::string str = config.getStringValue("textureSize");
|
2017-07-14 01:31:22 +03:00
|
|
|
STD_VECTOR<int> sizes;
|
2014-07-16 21:10:58 +03:00
|
|
|
splitToIntVector(sizes, str, ',');
|
2016-02-07 16:18:13 +03:00
|
|
|
const size_t pos = CAST_SIZE(openGLMode);
|
2014-07-16 21:10:58 +03:00
|
|
|
if (sizes.size() <= pos)
|
|
|
|
|
settings.textureSize = 1024;
|
|
|
|
|
else
|
|
|
|
|
settings.textureSize = sizes[pos];
|
2014-07-18 18:40:59 +03:00
|
|
|
logger->log("Detected max texture size: %u", settings.textureSize);
|
2014-07-16 21:10:58 +03:00
|
|
|
#endif // !defined(ANDROID) && !defined(__APPLE__)
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2014-05-27 21:47:06 +03:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 19:54:08 +03:00
|
|
|
#ifdef USE_SDL2
|
2013-08-21 22:45:39 +03:00
|
|
|
SDL_Window *GraphicsManager::createWindow(const int w, const int h,
|
2014-04-30 19:54:08 +03:00
|
|
|
const int bpp A_UNUSED,
|
|
|
|
|
const int flags)
|
2013-08-21 22:45:39 +03:00
|
|
|
{
|
2024-03-29 02:16:00 +01:00
|
|
|
return SDL_CreateWindow("ManaPlus", SDL_WINDOWPOS_UNDEFINED,
|
2013-08-21 23:58:06 +03:00
|
|
|
SDL_WINDOWPOS_UNDEFINED, w, h, flags);
|
2013-08-21 22:45:39 +03:00
|
|
|
}
|
|
|
|
|
|
2013-08-22 14:47:53 +03:00
|
|
|
SDL_Renderer *GraphicsManager::createRenderer(SDL_Window *const window,
|
|
|
|
|
const int flags)
|
|
|
|
|
{
|
2017-09-13 21:54:39 +03:00
|
|
|
SDL::setRendererHint(config.getStringValue("sdlDriver"));
|
2013-08-25 19:36:20 +03:00
|
|
|
SDL_Renderer *const renderer = SDL_CreateRenderer(window, -1, flags);
|
|
|
|
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
|
|
|
|
return renderer;
|
2013-08-22 14:47:53 +03:00
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // USE_SDL2
|
|
|
|
|
|
2014-04-30 19:54:08 +03:00
|
|
|
SDL_Window *GraphicsManager::createWindow(const int w, const int h,
|
|
|
|
|
const int bpp, const int flags)
|
|
|
|
|
{
|
|
|
|
|
return SDL_SetVideoMode(w, h, bpp, flags);
|
|
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_SDL2
|
2013-08-22 14:47:53 +03:00
|
|
|
|
2012-08-16 00:00:57 +03:00
|
|
|
#ifdef USE_OPENGL
|
2012-10-08 19:48:26 +03:00
|
|
|
void GraphicsManager::updateExtensions()
|
|
|
|
|
{
|
2012-04-29 16:28:15 +03:00
|
|
|
mExtensions.clear();
|
2012-08-14 01:09:49 +03:00
|
|
|
logger->log1("opengl extensions: ");
|
|
|
|
|
if (checkGLVersion(3, 0))
|
|
|
|
|
{ // get extensions in new way
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction2(glGetStringi, "glGetStringi")
|
2012-08-14 01:09:49 +03:00
|
|
|
std::string extList;
|
|
|
|
|
int num = 0;
|
|
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &num);
|
|
|
|
|
for (int f = 0; f < num; f ++)
|
|
|
|
|
{
|
|
|
|
|
std::string str = reinterpret_cast<const char*>(
|
|
|
|
|
mglGetStringi(GL_EXTENSIONS, f));
|
|
|
|
|
mExtensions.insert(str);
|
2013-02-25 03:35:52 +03:00
|
|
|
extList.append(str).append(" ");
|
2012-08-14 01:09:49 +03:00
|
|
|
}
|
|
|
|
|
logger->log1(extList.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // get extensions in old way
|
|
|
|
|
char const *extensions = reinterpret_cast<char const *>(
|
2015-12-12 00:31:20 +03:00
|
|
|
mglGetString(GL_EXTENSIONS));
|
2013-10-27 14:12:28 +03:00
|
|
|
if (extensions)
|
|
|
|
|
{
|
|
|
|
|
logger->log1(extensions);
|
|
|
|
|
splitToStringSet(mExtensions, extensions, ' ');
|
|
|
|
|
}
|
2012-08-14 01:09:49 +03:00
|
|
|
}
|
2012-04-29 16:28:15 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-14 12:43:25 +03:00
|
|
|
void GraphicsManager::updatePlanformExtensions()
|
|
|
|
|
{
|
|
|
|
|
SDL_SysWMinfo info;
|
2018-11-26 00:51:57 +03:00
|
|
|
SDL_VERSION(&info.version)
|
2013-08-24 14:51:24 +03:00
|
|
|
if (SDL::getWindowWMInfo(mainGraphics->getWindow(), &info))
|
2012-08-14 12:43:25 +03:00
|
|
|
{
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
if (!mwglGetExtensionsString)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-14 19:44:44 -07:00
|
|
|
#ifdef USE_SDL2
|
|
|
|
|
HDC hdc = GetDC(info.info.win.window);
|
|
|
|
|
#else
|
2012-08-14 12:43:25 +03:00
|
|
|
HDC hdc = GetDC(info.window);
|
2022-07-14 19:44:44 -07:00
|
|
|
#endif // USE_SDL2
|
2012-08-14 20:37:36 +03:00
|
|
|
if (hdc)
|
2012-08-14 12:43:25 +03:00
|
|
|
{
|
2013-04-14 11:27:04 +03:00
|
|
|
const char *const extensions = mwglGetExtensionsString(hdc);
|
2012-08-14 12:43:25 +03:00
|
|
|
if (extensions)
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("wGL extensions:");
|
2012-08-14 12:43:25 +03:00
|
|
|
logger->log1(extensions);
|
|
|
|
|
splitToStringSet(mPlatformExtensions, extensions, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#elif defined USE_X11
|
2013-02-28 15:22:00 +03:00
|
|
|
Display *const display = info.info.x11.display;
|
2012-08-14 12:43:25 +03:00
|
|
|
if (display)
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
Screen *const screen = XDefaultScreenOfDisplay(display);
|
2012-08-14 12:43:25 +03:00
|
|
|
if (!screen)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
const int screenNum = XScreenNumberOfScreen(screen);
|
|
|
|
|
const char *const extensions = glXQueryExtensionsString(
|
2012-08-14 12:43:25 +03:00
|
|
|
display, screenNum);
|
|
|
|
|
if (extensions)
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("glx extensions:");
|
2012-08-14 12:43:25 +03:00
|
|
|
logger->log1(extensions);
|
|
|
|
|
splitToStringSet(mPlatformExtensions, extensions, ' ');
|
|
|
|
|
}
|
|
|
|
|
glXQueryVersion(display, &mPlatformMajor, &mPlatformMinor);
|
|
|
|
|
if (checkPlatformVersion(1, 1))
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
const char *const vendor1 = glXQueryServerString(
|
2012-08-14 12:43:25 +03:00
|
|
|
display, screenNum, GLX_VENDOR);
|
|
|
|
|
if (vendor1)
|
|
|
|
|
logger->log("glx server vendor: %s", vendor1);
|
2013-02-28 15:22:00 +03:00
|
|
|
const char *const version1 = glXQueryServerString(
|
2012-08-14 12:43:25 +03:00
|
|
|
display, screenNum, GLX_VERSION);
|
|
|
|
|
if (version1)
|
|
|
|
|
logger->log("glx server version: %s", version1);
|
2013-02-28 15:22:00 +03:00
|
|
|
const char *const extensions1 = glXQueryServerString(
|
2012-08-14 12:43:25 +03:00
|
|
|
display, screenNum, GLX_EXTENSIONS);
|
|
|
|
|
if (extensions1)
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("glx server extensions:");
|
2012-08-14 12:43:25 +03:00
|
|
|
logger->log1(extensions1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
const char *const vendor2 = glXGetClientString(
|
|
|
|
|
display, GLX_VENDOR);
|
2012-08-14 12:43:25 +03:00
|
|
|
if (vendor2)
|
|
|
|
|
logger->log("glx client vendor: %s", vendor2);
|
2013-02-28 15:22:00 +03:00
|
|
|
const char *const version2 = glXGetClientString(
|
2012-08-14 12:43:25 +03:00
|
|
|
display, GLX_VERSION);
|
|
|
|
|
if (version2)
|
|
|
|
|
logger->log("glx client version: %s", version2);
|
2013-02-28 15:22:00 +03:00
|
|
|
const char *const extensions2 = glXGetClientString(
|
2012-08-14 12:43:25 +03:00
|
|
|
display, GLX_EXTENSIONS);
|
|
|
|
|
if (extensions2)
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("glx client extensions:");
|
2012-08-14 12:43:25 +03:00
|
|
|
logger->log1(extensions2);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-30 22:32:38 +03:00
|
|
|
logger->log("width=%d", DisplayWidth(display, screenNum));
|
2012-08-14 12:43:25 +03:00
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // WIN32
|
2012-08-14 12:43:25 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
bool GraphicsManager::supportExtension(const std::string &ext) const
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
|
|
|
|
return mExtensions.find(ext) != mExtensions.end();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-09 19:56:58 +03:00
|
|
|
void GraphicsManager::updateTextureCompressionFormat() const
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2013-01-26 01:31:38 +03:00
|
|
|
const int compressionFormat = config.getIntValue("compresstextures");
|
2014-06-29 01:41:41 +03:00
|
|
|
// using extensions if can
|
2015-12-16 23:58:02 +03:00
|
|
|
if (checkGLVersion(3, 1) ||
|
2015-12-18 21:11:43 +03:00
|
|
|
checkGLesVersion(2, 0) ||
|
2015-12-16 23:58:02 +03:00
|
|
|
supportExtension("GL_ARB_texture_compression"))
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2014-06-29 01:41:41 +03:00
|
|
|
GLint num = 0;
|
2015-12-16 23:58:02 +03:00
|
|
|
mglGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num);
|
2014-06-29 01:41:41 +03:00
|
|
|
logger->log("support %d compressed formats", num);
|
|
|
|
|
GLint *const formats = new GLint[num > 10
|
2016-02-07 16:18:13 +03:00
|
|
|
? CAST_SIZE(num) : 10];
|
2015-12-16 23:58:02 +03:00
|
|
|
mglGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
|
2014-06-29 01:41:41 +03:00
|
|
|
for (int f = 0; f < num; f ++)
|
2016-02-07 16:18:13 +03:00
|
|
|
logger->log(" 0x%x", CAST_U32(formats[f]));
|
2014-06-29 01:41:41 +03:00
|
|
|
|
|
|
|
|
if (compressionFormat)
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2014-08-18 02:12:42 +03:00
|
|
|
for (int f = 0; f < num; f ++)
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2014-08-18 02:12:42 +03:00
|
|
|
switch (formats[f])
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2014-08-18 02:12:42 +03:00
|
|
|
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
|
|
|
|
if (compressionFormat == 1)
|
|
|
|
|
{
|
|
|
|
|
delete []formats;
|
2018-11-26 00:51:57 +03:00
|
|
|
useCompression(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
|
2014-08-18 02:12:42 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GL_COMPRESSED_RGBA_FXT1_3DFX:
|
|
|
|
|
if (compressionFormat == 2)
|
|
|
|
|
{
|
|
|
|
|
delete []formats;
|
2018-11-26 00:51:57 +03:00
|
|
|
useCompression(GL_COMPRESSED_RGBA_FXT1_3DFX)
|
2014-08-18 02:12:42 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GL_COMPRESSED_RGBA_BPTC_UNORM_ARB:
|
|
|
|
|
if (compressionFormat == 4)
|
|
|
|
|
{
|
|
|
|
|
delete []formats;
|
2018-11-26 00:51:57 +03:00
|
|
|
useCompression(GL_COMPRESSED_RGBA_BPTC_UNORM_ARB)
|
2014-08-18 02:12:42 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2013-01-26 01:31:38 +03:00
|
|
|
}
|
2012-05-17 22:31:39 +03:00
|
|
|
}
|
2014-08-18 02:12:42 +03:00
|
|
|
if (compressionFormat == 3)
|
2012-05-17 22:31:39 +03:00
|
|
|
{
|
2015-03-23 18:43:02 +03:00
|
|
|
delete []formats;
|
2018-11-26 00:51:57 +03:00
|
|
|
useCompression(GL_COMPRESSED_RGBA_ARB)
|
2014-08-18 02:12:42 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// workaround for MESA bptc compression detection
|
|
|
|
|
if (compressionFormat == 4
|
|
|
|
|
&& supportExtension("GL_ARB_texture_compression_bptc"))
|
|
|
|
|
{
|
2015-03-23 18:43:02 +03:00
|
|
|
delete []formats;
|
2018-11-26 00:51:57 +03:00
|
|
|
useCompression(GL_COMPRESSED_RGBA_BPTC_UNORM_ARB)
|
2014-08-18 02:12:42 +03:00
|
|
|
return;
|
2012-04-29 16:28:15 +03:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-23 18:43:02 +03:00
|
|
|
delete []formats;
|
2015-08-09 19:56:58 +03:00
|
|
|
if (compressionFormat)
|
|
|
|
|
logger->log1("no correct compression format found");
|
2014-06-29 01:41:41 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-09 19:56:58 +03:00
|
|
|
if (compressionFormat)
|
|
|
|
|
logger->log1("no correct compression format found");
|
2012-04-29 16:28:15 +03:00
|
|
|
}
|
2015-08-09 19:56:58 +03:00
|
|
|
}
|
2012-05-17 22:31:39 +03:00
|
|
|
|
2016-01-15 20:21:16 +03:00
|
|
|
void GraphicsManager::updateTextureFormat()
|
2015-08-09 19:56:58 +03:00
|
|
|
{
|
2014-06-24 12:40:55 +03:00
|
|
|
const int renderer = settings.options.renderer;
|
|
|
|
|
|
2012-05-17 22:31:39 +03:00
|
|
|
// using default formats
|
2015-12-10 01:28:03 +03:00
|
|
|
if (renderer == RENDER_MODERN_OPENGL ||
|
|
|
|
|
renderer == RENDER_GLES_OPENGL ||
|
|
|
|
|
renderer == RENDER_GLES2_OPENGL ||
|
|
|
|
|
config.getBoolValue("newtextures"))
|
2012-05-17 22:31:39 +03:00
|
|
|
{
|
2012-06-10 16:54:18 +03:00
|
|
|
OpenGLImageHelper::setInternalTextureType(GL_RGBA);
|
2020-04-23 11:16:31 +02:00
|
|
|
#if !defined(ANDROID) && !defined(__SWITCH__)
|
2015-12-15 18:57:03 +03:00
|
|
|
SafeOpenGLImageHelper::setInternalTextureType(GL_RGBA);
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // ANDROID
|
|
|
|
|
|
2012-05-17 22:31:39 +03:00
|
|
|
logger->log1("using RGBA texture format");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-06-10 16:54:18 +03:00
|
|
|
OpenGLImageHelper::setInternalTextureType(4);
|
2020-04-23 11:16:31 +02:00
|
|
|
#if !defined(ANDROID) && !defined(__SWITCH__)
|
2015-12-15 18:57:03 +03:00
|
|
|
SafeOpenGLImageHelper::setInternalTextureType(4);
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // ANDROID
|
|
|
|
|
|
2012-05-17 22:31:39 +03:00
|
|
|
logger->log1("using 4 texture format");
|
|
|
|
|
}
|
2012-04-29 16:28:15 +03:00
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
void GraphicsManager::logString(const char *const format, const int num)
|
2012-04-29 16:28:15 +03:00
|
|
|
{
|
2015-12-12 00:31:20 +03:00
|
|
|
const char *str = reinterpret_cast<const char*>(mglGetString(num));
|
2012-04-29 16:28:15 +03:00
|
|
|
if (!str)
|
|
|
|
|
logger->log(format, "?");
|
|
|
|
|
else
|
|
|
|
|
logger->log(format, str);
|
|
|
|
|
}
|
2012-04-30 23:15:23 +03:00
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
std::string GraphicsManager::getGLString(const int num)
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
2015-12-12 00:31:20 +03:00
|
|
|
const char *str = reinterpret_cast<const char*>(mglGetString(num));
|
2012-10-08 19:48:26 +03:00
|
|
|
return str ? str : "";
|
2012-05-11 21:55:28 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-11 23:02:52 +03:00
|
|
|
void GraphicsManager::setGLVersion()
|
|
|
|
|
{
|
2012-10-08 13:21:45 +03:00
|
|
|
mGlVersionString = getGLString(GL_VERSION);
|
2015-12-01 22:58:27 +03:00
|
|
|
std::string version = mGlVersionString;
|
2015-12-16 23:58:02 +03:00
|
|
|
if (findCutFirst(version, "OpenGL ES "))
|
|
|
|
|
mGles = true;
|
2015-12-01 22:58:27 +03:00
|
|
|
sscanf(version.c_str(), "%5d.%5d", &mMajor, &mMinor);
|
|
|
|
|
logger->log("Detected gl version: %d.%d", mMajor, mMinor);
|
2012-10-08 13:21:45 +03:00
|
|
|
mGlVendor = getGLString(GL_VENDOR);
|
|
|
|
|
mGlRenderer = getGLString(GL_RENDERER);
|
2014-06-25 18:35:05 +03:00
|
|
|
mGlShaderVersionString = getGLString(GL_SHADING_LANGUAGE_VERSION);
|
2015-12-01 22:58:27 +03:00
|
|
|
version = mGlShaderVersionString;
|
|
|
|
|
cutFirst(version, "OpenGL ES GLSL ES ");
|
|
|
|
|
cutFirst(version, "OpenGL ES GLSL ");
|
|
|
|
|
cutFirst(version, "OpenGL ES ");
|
|
|
|
|
sscanf(version.c_str(), "%5d.%5d", &mSLMajor, &mSLMinor);
|
|
|
|
|
logger->log("Detected glsl version: %d.%d", mSLMajor, mSLMinor);
|
2015-12-19 19:15:46 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
|
if (!mMajor && !mMinor)
|
|
|
|
|
{
|
|
|
|
|
logger->log("Overriding detected OpenGL version on Android to 1.0");
|
|
|
|
|
mGles = true;
|
|
|
|
|
mMajor = 1;
|
|
|
|
|
mMinor = 0;
|
|
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // ANDROID
|
2012-10-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
void GraphicsManager::logVersion() const
|
2012-10-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
|
logger->log("gl vendor: " + mGlVendor);
|
|
|
|
|
logger->log("gl renderer: " + mGlRenderer);
|
|
|
|
|
logger->log("gl version: " + mGlVersionString);
|
2014-06-25 18:35:05 +03:00
|
|
|
logger->log("glsl version: " + mGlShaderVersionString);
|
2012-08-11 23:02:52 +03:00
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
bool GraphicsManager::checkGLVersion(const int major, const int minor) const
|
2012-05-11 21:55:28 +03:00
|
|
|
{
|
|
|
|
|
return mMajor > major || (mMajor == major && mMinor >= minor);
|
|
|
|
|
}
|
2012-08-11 17:49:09 +03:00
|
|
|
|
2014-06-25 18:35:05 +03:00
|
|
|
bool GraphicsManager::checkSLVersion(const int major, const int minor) const
|
|
|
|
|
{
|
|
|
|
|
return mSLMajor > major || (mSLMajor == major && mSLMinor >= minor);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 23:58:02 +03:00
|
|
|
bool GraphicsManager::checkGLesVersion(const int major, const int minor) const
|
|
|
|
|
{
|
|
|
|
|
return mGles && (mMajor > major || (mMajor == major && mMinor >= minor));
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 16:00:26 +03:00
|
|
|
bool GraphicsManager::checkPlatformVersion(const int major,
|
|
|
|
|
const int minor) const
|
2012-08-14 12:43:25 +03:00
|
|
|
{
|
|
|
|
|
return mPlatformMajor > major || (mPlatformMajor == major
|
|
|
|
|
&& mPlatformMinor >= minor);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
void GraphicsManager::createFBO(const int width, const int height,
|
|
|
|
|
FBOInfo *const fbo)
|
2012-08-11 17:49:09 +03:00
|
|
|
{
|
|
|
|
|
if (!fbo)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// create a texture object
|
|
|
|
|
glGenTextures(1, &fbo->textureId);
|
2012-08-11 01:52:35 +03:00
|
|
|
glBindTexture(OpenGLImageHelper::mTextureType, fbo->textureId);
|
2012-08-14 20:37:36 +03:00
|
|
|
glTexParameterf(OpenGLImageHelper::mTextureType,
|
|
|
|
|
GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
glTexParameterf(OpenGLImageHelper::mTextureType,
|
|
|
|
|
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
glTexParameterf(OpenGLImageHelper::mTextureType,
|
|
|
|
|
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexParameterf(OpenGLImageHelper::mTextureType,
|
|
|
|
|
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexImage2D(OpenGLImageHelper::mTextureType, 0, GL_RGBA8, width, height,
|
|
|
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
2012-08-11 01:52:35 +03:00
|
|
|
glBindTexture(OpenGLImageHelper::mTextureType, 0);
|
2012-08-11 17:49:09 +03:00
|
|
|
|
|
|
|
|
// create a renderbuffer object to store depth info
|
2012-08-11 23:02:52 +03:00
|
|
|
mglGenRenderbuffers(1, &fbo->rboId);
|
|
|
|
|
mglBindRenderbuffer(GL_RENDERBUFFER, fbo->rboId);
|
|
|
|
|
mglRenderbufferStorage(GL_RENDERBUFFER,
|
2012-08-11 17:49:09 +03:00
|
|
|
GL_DEPTH_COMPONENT, width, height);
|
2012-08-11 23:02:52 +03:00
|
|
|
mglBindRenderbuffer(GL_RENDERBUFFER, 0);
|
2012-08-11 17:49:09 +03:00
|
|
|
|
|
|
|
|
// create a framebuffer object
|
2012-08-11 23:02:52 +03:00
|
|
|
mglGenFramebuffers(1, &fbo->fboId);
|
|
|
|
|
mglBindFramebuffer(GL_FRAMEBUFFER, fbo->fboId);
|
2012-08-11 17:49:09 +03:00
|
|
|
|
|
|
|
|
// attach the texture to FBO color attachment point
|
2012-08-11 23:02:52 +03:00
|
|
|
mglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
2012-08-11 01:52:35 +03:00
|
|
|
OpenGLImageHelper::mTextureType, fbo->textureId, 0);
|
2012-08-11 17:49:09 +03:00
|
|
|
|
|
|
|
|
// attach the renderbuffer to depth attachment point
|
2012-08-11 23:02:52 +03:00
|
|
|
mglFramebufferRenderbuffer(GL_FRAMEBUFFER,
|
|
|
|
|
GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->rboId);
|
2012-08-11 17:49:09 +03:00
|
|
|
|
2012-08-11 23:02:52 +03:00
|
|
|
mglBindFramebuffer(GL_FRAMEBUFFER, fbo->fboId);
|
2012-08-11 17:49:09 +03:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
void GraphicsManager::deleteFBO(FBOInfo *const fbo)
|
2012-08-11 17:49:09 +03:00
|
|
|
{
|
|
|
|
|
if (!fbo)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-08-11 23:11:07 +03:00
|
|
|
mglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2012-08-11 17:49:09 +03:00
|
|
|
if (fbo->fboId)
|
|
|
|
|
{
|
2012-08-11 23:11:07 +03:00
|
|
|
mglDeleteFramebuffers(1, &fbo->fboId);
|
2012-08-11 17:49:09 +03:00
|
|
|
fbo->fboId = 0;
|
|
|
|
|
}
|
2012-08-11 23:11:07 +03:00
|
|
|
mglBindRenderbuffer(GL_RENDERBUFFER, 0);
|
2012-08-11 17:49:09 +03:00
|
|
|
if (fbo->rboId)
|
|
|
|
|
{
|
2012-08-11 23:11:07 +03:00
|
|
|
mglDeleteRenderbuffers(1, &fbo->rboId);
|
2012-08-11 17:49:09 +03:00
|
|
|
fbo->rboId = 0;
|
|
|
|
|
}
|
|
|
|
|
if (fbo->textureId)
|
|
|
|
|
{
|
|
|
|
|
glDeleteTextures(1, &fbo->textureId);
|
|
|
|
|
fbo->textureId = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-11 23:02:52 +03:00
|
|
|
|
|
|
|
|
void GraphicsManager::initOpenGLFunctions()
|
|
|
|
|
{
|
2015-12-08 21:48:20 +03:00
|
|
|
#ifdef __native_client__
|
2016-05-09 20:04:16 +03:00
|
|
|
emulateFunction(glTextureSubImage2DEXT);
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // __native_client__
|
|
|
|
|
|
2014-06-19 00:16:36 +03:00
|
|
|
const bool is10 = checkGLVersion(1, 0);
|
|
|
|
|
const bool is11 = checkGLVersion(1, 1);
|
2014-06-21 20:29:35 +03:00
|
|
|
const bool is12 = checkGLVersion(1, 2);
|
2015-12-10 17:56:00 +03:00
|
|
|
const bool is13 = checkGLVersion(1, 3);
|
2014-06-22 01:16:02 +03:00
|
|
|
const bool is15 = checkGLVersion(1, 5);
|
2014-06-19 00:16:36 +03:00
|
|
|
const bool is20 = checkGLVersion(2, 0);
|
|
|
|
|
const bool is21 = checkGLVersion(2, 1);
|
2014-06-22 22:44:36 +03:00
|
|
|
const bool is30 = checkGLVersion(3, 0);
|
2014-06-24 15:36:16 +03:00
|
|
|
const bool is33 = checkGLVersion(3, 3);
|
|
|
|
|
const bool is41 = checkGLVersion(4, 1);
|
|
|
|
|
const bool is42 = checkGLVersion(4, 2);
|
|
|
|
|
const bool is43 = checkGLVersion(4, 3);
|
|
|
|
|
const bool is44 = checkGLVersion(4, 4);
|
2014-08-17 17:57:51 +03:00
|
|
|
const bool is45 = checkGLVersion(4, 5);
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl = true;
|
2014-06-19 00:16:36 +03:00
|
|
|
|
2012-10-23 00:41:25 +03:00
|
|
|
// Texture sampler
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is10 && (is33 || supportExtension("GL_ARB_sampler_objects")))
|
2012-10-23 00:41:25 +03:00
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("found GL_ARB_sampler_objects");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glGenSamplers)
|
|
|
|
|
assignFunction(glDeleteSamplers)
|
|
|
|
|
assignFunction(glBindSampler)
|
|
|
|
|
assignFunction(glSamplerParameteri)
|
2014-07-12 21:35:44 +03:00
|
|
|
if (isGLNotNull(mglGenSamplers)
|
|
|
|
|
&& config.getBoolValue("useTextureSampler"))
|
|
|
|
|
{
|
2012-10-23 00:41:25 +03:00
|
|
|
mUseTextureSampler &= true;
|
2014-07-12 21:35:44 +03:00
|
|
|
}
|
2012-10-23 00:41:25 +03:00
|
|
|
else
|
2014-07-12 21:35:44 +03:00
|
|
|
{
|
2012-10-23 00:41:25 +03:00
|
|
|
mUseTextureSampler = false;
|
2014-07-12 21:35:44 +03:00
|
|
|
}
|
2012-10-23 00:41:25 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("texture sampler not found");
|
2012-10-23 00:41:25 +03:00
|
|
|
mUseTextureSampler = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 00:16:36 +03:00
|
|
|
if (!is11)
|
2014-07-05 18:41:14 +03:00
|
|
|
{
|
|
|
|
|
mSupportModernOpengl = false;
|
2016-05-09 20:04:16 +03:00
|
|
|
emulateFunction(glTextureSubImage2DEXT);
|
2012-08-11 23:02:52 +03:00
|
|
|
return;
|
2014-07-05 18:41:14 +03:00
|
|
|
}
|
2012-08-11 23:02:52 +03:00
|
|
|
|
2016-05-09 20:04:16 +03:00
|
|
|
/*
|
2015-08-20 23:56:17 +03:00
|
|
|
if (findI(mGlVendor, "NVIDIA") != std::string::npos ||
|
|
|
|
|
mGlVersionString.find("Mesa 10.6.") != std::string::npos ||
|
2016-02-13 00:36:20 +03:00
|
|
|
mGlVersionString.find("Mesa 11.1.1") != std::string::npos ||
|
2016-02-27 15:35:58 +03:00
|
|
|
mGlVersionString.find("Mesa 11.1.2") != std::string::npos ||
|
2016-05-04 23:49:04 +03:00
|
|
|
mGlVersionString.find("Mesa 11.1.3") != std::string::npos ||
|
2016-05-09 18:34:54 +03:00
|
|
|
mGlVersionString.find("Mesa 11.2") != std::string::npos ||
|
2015-08-21 00:30:26 +03:00
|
|
|
(findI(mGlRenderer, "AMD Radeon HD") != std::string::npos &&
|
2015-09-08 01:09:50 +03:00
|
|
|
(mGlVersionString.find(
|
|
|
|
|
"Compatibility Profile Context 14.") != std::string::npos ||
|
|
|
|
|
mGlVersionString.find(
|
|
|
|
|
"Compatibility Profile Context 15.") != std::string::npos)))
|
2015-08-20 23:56:17 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("Not checked for DSA because on "
|
|
|
|
|
"NVIDIA or AMD or in Mesa it broken");
|
2016-05-09 20:04:16 +03:00
|
|
|
emulateFunction(glTextureSubImage2DEXT);
|
2015-08-20 23:56:17 +03:00
|
|
|
}
|
|
|
|
|
else
|
2016-05-09 20:04:16 +03:00
|
|
|
*/
|
2015-07-19 22:09:35 +03:00
|
|
|
{ // not for NVIDIA. in NVIDIA atleast in windows drivers DSA is broken
|
2015-07-29 02:04:28 +03:00
|
|
|
// Mesa 10.6.3 show support for DSA, but it broken. Works in 10.7 dev
|
2017-04-25 15:59:05 +03:00
|
|
|
if (config.getBoolValue("enableDSA") == true)
|
2015-07-19 22:09:35 +03:00
|
|
|
{
|
2017-04-25 15:59:05 +03:00
|
|
|
if (is45)
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_EXT_direct_state_access");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glTextureSubImage2D)
|
2017-04-25 15:59:05 +03:00
|
|
|
}
|
|
|
|
|
else if (supportExtension("GL_EXT_direct_state_access"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_EXT_direct_state_access");
|
|
|
|
|
assignFunctionEmu2(glTextureSubImage2DEXT,
|
2018-11-26 00:51:57 +03:00
|
|
|
"glTextureSubImage2DEXT")
|
2017-04-25 15:59:05 +03:00
|
|
|
}
|
|
|
|
|
else if (supportExtension("GL_ARB_direct_state_access"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_direct_state_access");
|
|
|
|
|
logger->log1("GL_EXT_direct_state_access not found");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glTextureSubImage2D)
|
2017-04-25 15:59:05 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_EXT_direct_state_access not found");
|
|
|
|
|
logger->log1("GL_ARB_direct_state_access not found");
|
|
|
|
|
emulateFunction(glTextureSubImage2DEXT);
|
|
|
|
|
}
|
2015-07-19 22:09:35 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-04-25 15:59:05 +03:00
|
|
|
logger->log1("Direct state access disabled in settings");
|
2016-05-09 20:04:16 +03:00
|
|
|
emulateFunction(glTextureSubImage2DEXT);
|
2015-07-19 22:09:35 +03:00
|
|
|
}
|
2014-07-02 23:04:19 +03:00
|
|
|
}
|
|
|
|
|
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is12 && (is42 || supportExtension("GL_ARB_texture_storage")))
|
2014-06-21 20:29:35 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_texture_storage");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glTexStorage2D)
|
2014-06-21 20:29:35 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_texture_storage not found");
|
|
|
|
|
}
|
2015-12-10 17:56:00 +03:00
|
|
|
|
|
|
|
|
if (is13 || supportExtension("GL_ARB_multitexture"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_multitexture or OpenGL 1.3");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glActiveTexture)
|
2015-12-10 17:56:00 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
emulateFunction(glActiveTexture);
|
|
|
|
|
logger->log1("GL_ARB_multitexture not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is20 || supportExtension("GL_ARB_explicit_attrib_location"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_explicit_attrib_location or OpenGL 2.0");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glBindAttribLocation)
|
2015-12-10 17:56:00 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_explicit_attrib_location not found");
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is30 || supportExtension("GL_ARB_framebuffer_object"))
|
2012-08-11 23:02:52 +03:00
|
|
|
{ // frame buffer supported
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("found GL_ARB_framebuffer_object");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glGenRenderbuffers)
|
|
|
|
|
assignFunction(glBindRenderbuffer)
|
|
|
|
|
assignFunction(glRenderbufferStorage)
|
|
|
|
|
assignFunction(glGenFramebuffers)
|
|
|
|
|
assignFunction(glBindFramebuffer)
|
|
|
|
|
assignFunction(glFramebufferTexture2D)
|
|
|
|
|
assignFunction(glFramebufferRenderbuffer)
|
|
|
|
|
assignFunction(glDeleteFramebuffers)
|
|
|
|
|
assignFunction(glDeleteRenderbuffers)
|
|
|
|
|
assignFunction(glCheckFramebufferStatus)
|
2012-08-11 23:02:52 +03:00
|
|
|
}
|
|
|
|
|
else if (supportExtension("GL_EXT_framebuffer_object"))
|
|
|
|
|
{ // old frame buffer extension
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("found GL_EXT_framebuffer_object");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunctionEXT(glGenRenderbuffers)
|
|
|
|
|
assignFunctionEXT(glBindRenderbuffer)
|
|
|
|
|
assignFunctionEXT(glRenderbufferStorage)
|
|
|
|
|
assignFunctionEXT(glGenFramebuffers)
|
|
|
|
|
assignFunctionEXT(glBindFramebuffer)
|
|
|
|
|
assignFunctionEXT(glFramebufferTexture2D)
|
|
|
|
|
assignFunctionEXT(glFramebufferRenderbuffer)
|
|
|
|
|
assignFunctionEXT(glDeleteFramebuffers)
|
|
|
|
|
assignFunctionEXT(glDeleteRenderbuffers)
|
2012-08-11 23:02:52 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // no frame buffer support
|
2014-06-19 00:16:36 +03:00
|
|
|
logger->log1("GL_ARB_framebuffer_object or "
|
|
|
|
|
"GL_EXT_framebuffer_object not found");
|
2012-08-11 23:02:52 +03:00
|
|
|
config.setValue("usefbo", false);
|
|
|
|
|
}
|
2012-08-14 01:09:49 +03:00
|
|
|
|
2012-10-23 00:41:25 +03:00
|
|
|
// debug extensions
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is43 || supportExtension("GL_KHR_debug"))
|
2012-10-01 17:51:43 +03:00
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("found GL_KHR_debug");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glDebugMessageControl)
|
|
|
|
|
assignFunction(glDebugMessageCallback)
|
|
|
|
|
assignFunction(glPushDebugGroup)
|
|
|
|
|
assignFunction(glPopDebugGroup)
|
|
|
|
|
assignFunction(glObjectLabel)
|
2012-10-23 03:51:06 +03:00
|
|
|
mSupportDebug = 2;
|
2012-10-23 00:41:25 +03:00
|
|
|
}
|
|
|
|
|
else if (supportExtension("GL_ARB_debug_output"))
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("found GL_ARB_debug_output");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunctionARB(glDebugMessageControl)
|
|
|
|
|
assignFunctionARB(glDebugMessageCallback)
|
2012-10-23 03:51:06 +03:00
|
|
|
mSupportDebug = 1;
|
2012-10-01 23:32:51 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("debug extensions not found");
|
2012-10-23 03:51:06 +03:00
|
|
|
mSupportDebug = 0;
|
2012-10-01 17:51:43 +03:00
|
|
|
}
|
2012-08-14 12:43:25 +03:00
|
|
|
|
2014-04-07 12:01:47 +03:00
|
|
|
if (supportExtension("GL_GREMEDY_frame_terminator"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_GREMEDY_frame_terminator");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction2(glFrameTerminator, "glFrameTerminatorGREMEDY")
|
2014-04-07 12:01:47 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_GREMEDY_frame_terminator not found");
|
|
|
|
|
}
|
2014-08-17 17:57:51 +03:00
|
|
|
if (is44 || supportExtension("GL_EXT_debug_label"))
|
2014-04-07 21:57:33 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("found GL_EXT_debug_label");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction2(glLabelObject, "glObjectLabel")
|
2014-07-12 21:35:44 +03:00
|
|
|
if (isGLNull(mglLabelObject))
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunctionEXT(glLabelObject)
|
|
|
|
|
assignFunctionEXT(glGetObjectLabel)
|
2014-04-07 21:57:33 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_EXT_debug_label not found");
|
|
|
|
|
}
|
2014-04-08 01:32:02 +03:00
|
|
|
if (supportExtension("GL_GREMEDY_string_marker"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_GREMEDY_string_marker");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction2(glPushGroupMarker, "glStringMarkerGREMEDY")
|
2014-04-08 01:32:02 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_GREMEDY_string_marker not found");
|
|
|
|
|
}
|
|
|
|
|
if (supportExtension("GL_EXT_debug_marker"))
|
2014-04-08 01:21:55 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("found GL_EXT_debug_marker");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunctionEXT(glInsertEventMarker)
|
|
|
|
|
assignFunctionEXT(glPushGroupMarker)
|
|
|
|
|
assignFunctionEXT(glPopGroupMarker)
|
2014-04-08 01:21:55 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_EXT_debug_marker not found");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is15 && (is30 || supportExtension("GL_EXT_timer_query")))
|
2014-06-22 01:16:02 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("found GL_EXT_timer_query");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glGenQueries)
|
|
|
|
|
assignFunction(glBeginQuery)
|
|
|
|
|
assignFunction(glEndQuery)
|
|
|
|
|
assignFunction(glDeleteQueries)
|
|
|
|
|
assignFunction(glGetQueryObjectiv)
|
|
|
|
|
assignFunctionEXT(glGetQueryObjectui64v)
|
2014-06-22 01:16:02 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_EXT_timer_query not supported");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is20 && (is43 || supportExtension("GL_ARB_invalidate_subdata")))
|
2014-06-19 13:39:09 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_invalidate_subdata");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glInvalidateTexImage)
|
2014-06-19 13:39:09 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_invalidate_subdata not supported");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is21 && (is30 || supportExtension("GL_ARB_vertex_array_object")))
|
2014-06-04 17:08:36 +03:00
|
|
|
{
|
2014-06-04 22:29:34 +03:00
|
|
|
logger->log1("found GL_ARB_vertex_array_object");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glGenVertexArrays)
|
|
|
|
|
assignFunction(glBindVertexArray)
|
|
|
|
|
assignFunction(glDeleteVertexArrays)
|
|
|
|
|
assignFunction(glVertexAttribPointer)
|
|
|
|
|
assignFunction(glEnableVertexAttribArray)
|
|
|
|
|
assignFunction(glDisableVertexAttribArray)
|
|
|
|
|
assignFunction(glVertexAttribIPointer)
|
2014-06-04 17:08:36 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl = false;
|
2014-06-08 00:05:01 +03:00
|
|
|
logger->log1("GL_ARB_vertex_array_object not found");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is20 || supportExtension("GL_ARB_vertex_buffer_object"))
|
2014-06-04 17:55:58 +03:00
|
|
|
{
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glGenBuffers)
|
|
|
|
|
assignFunction(glDeleteBuffers)
|
|
|
|
|
assignFunction(glBindBuffer)
|
|
|
|
|
assignFunction(glBufferData)
|
|
|
|
|
assignFunction(glIsBuffer)
|
2014-06-04 17:55:58 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl = false;
|
2014-06-08 00:05:01 +03:00
|
|
|
logger->log1("buffers extension not found");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is43 || supportExtension("GL_ARB_copy_image"))
|
2014-06-19 17:15:34 +03:00
|
|
|
{
|
2014-08-10 01:25:12 +03:00
|
|
|
logger->log1("found GL_ARB_copy_image");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glCopyImageSubData)
|
2014-06-19 17:15:34 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_copy_image not found");
|
|
|
|
|
}
|
2014-08-10 01:25:12 +03:00
|
|
|
if (is44 || supportExtension("GL_ARB_clear_texture"))
|
|
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_clear_texture");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glClearTexImage)
|
|
|
|
|
assignFunction(glClearTexSubImage)
|
2014-08-10 01:25:12 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_clear_texture not found");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is20 || supportExtension("GL_ARB_shader_objects"))
|
2014-06-04 21:04:12 +03:00
|
|
|
{
|
2014-08-10 01:25:12 +03:00
|
|
|
logger->log1("found GL_ARB_shader_objects");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glCreateShader)
|
|
|
|
|
assignFunction(glDeleteShader)
|
|
|
|
|
assignFunction(glGetShaderiv)
|
|
|
|
|
assignFunction(glGetShaderInfoLog)
|
|
|
|
|
assignFunction(glGetShaderSource)
|
|
|
|
|
assignFunction(glShaderSource)
|
|
|
|
|
assignFunction(glCompileShader)
|
|
|
|
|
assignFunction(glLinkProgram)
|
|
|
|
|
assignFunction(glGetProgramInfoLog)
|
|
|
|
|
assignFunction(glDeleteProgram)
|
|
|
|
|
assignFunction(glCreateProgram)
|
|
|
|
|
assignFunction(glAttachShader)
|
|
|
|
|
assignFunction(glDetachShader)
|
|
|
|
|
assignFunction(glGetAttachedShaders)
|
|
|
|
|
assignFunction(glGetUniformLocation)
|
|
|
|
|
assignFunction(glGetActiveUniform)
|
|
|
|
|
assignFunction(glGetProgramiv)
|
|
|
|
|
assignFunction(glUseProgram)
|
|
|
|
|
assignFunction(glValidateProgram)
|
|
|
|
|
assignFunction(glGetAttribLocation)
|
|
|
|
|
assignFunction(glUniform1f)
|
|
|
|
|
assignFunction(glUniform2f)
|
|
|
|
|
assignFunction(glUniform3f)
|
|
|
|
|
assignFunction(glUniform4f)
|
2014-06-08 00:05:01 +03:00
|
|
|
|
2014-06-22 22:44:36 +03:00
|
|
|
if (is30 || supportExtension("GL_EXT_gpu_shader4"))
|
2014-06-08 00:05:01 +03:00
|
|
|
{
|
2014-08-10 01:25:12 +03:00
|
|
|
logger->log1("found GL_EXT_gpu_shader4");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glBindFragDataLocation)
|
2014-06-08 00:05:01 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl = false;
|
2014-06-19 13:39:09 +03:00
|
|
|
logger->log1("GL_EXT_gpu_shader4 not supported");
|
2014-06-08 00:05:01 +03:00
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is41 || supportExtension("GL_ARB_separate_shader_objects"))
|
2014-06-10 18:43:08 +03:00
|
|
|
{
|
2014-06-11 12:04:01 +03:00
|
|
|
logger->log1("found GL_ARB_separate_shader_objects");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glProgramUniform1f)
|
|
|
|
|
assignFunction(glProgramUniform2f)
|
|
|
|
|
assignFunction(glProgramUniform3f)
|
|
|
|
|
assignFunction(glProgramUniform4f)
|
2014-06-10 18:43:08 +03:00
|
|
|
}
|
2014-06-11 12:04:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_separate_shader_objects not supported");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is43 || supportExtension("GL_ARB_vertex_attrib_binding"))
|
2014-06-10 22:30:02 +03:00
|
|
|
{
|
2014-06-11 12:04:01 +03:00
|
|
|
logger->log1("found GL_ARB_vertex_attrib_binding");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glBindVertexBuffer)
|
|
|
|
|
assignFunction(glVertexAttribBinding)
|
|
|
|
|
assignFunction(glVertexAttribFormat)
|
|
|
|
|
assignFunction(glVertexAttribIFormat)
|
2014-06-10 22:30:02 +03:00
|
|
|
}
|
2014-06-11 12:04:01 +03:00
|
|
|
else
|
|
|
|
|
{
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl = false;
|
2014-06-11 12:04:01 +03:00
|
|
|
logger->log1("GL_ARB_vertex_attrib_binding not supported");
|
|
|
|
|
}
|
2014-06-24 15:36:16 +03:00
|
|
|
if (is44 || supportExtension("GL_ARB_multi_bind"))
|
2014-06-11 12:04:01 +03:00
|
|
|
{
|
|
|
|
|
logger->log1("found GL_ARB_multi_bind");
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunction(glBindVertexBuffers)
|
2014-06-11 12:04:01 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->log1("GL_ARB_multi_bind not supported");
|
|
|
|
|
}
|
2014-06-04 21:04:12 +03:00
|
|
|
}
|
2014-06-08 00:05:01 +03:00
|
|
|
else
|
2014-06-04 21:04:12 +03:00
|
|
|
{
|
2014-06-19 00:30:56 +03:00
|
|
|
mSupportModernOpengl = false;
|
2014-06-08 00:05:01 +03:00
|
|
|
logger->log1("shaders not supported");
|
2014-06-04 21:04:12 +03:00
|
|
|
}
|
2014-06-04 17:08:36 +03:00
|
|
|
|
2012-08-14 12:43:25 +03:00
|
|
|
#ifdef WIN32
|
2018-11-26 00:51:57 +03:00
|
|
|
assignFunctionARB(wglGetExtensionsString)
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // WIN32
|
|
|
|
|
#endif // __native_client__
|
2012-08-11 23:02:52 +03:00
|
|
|
}
|
2012-09-09 13:09:20 +03:00
|
|
|
|
|
|
|
|
void GraphicsManager::updateLimits()
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
GLint value = 0;
|
2015-12-11 19:46:33 +03:00
|
|
|
#ifdef __native_client__
|
|
|
|
|
mMaxVertices = 500;
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // __native_client__
|
|
|
|
|
|
2012-09-09 13:09:20 +03:00
|
|
|
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &value);
|
|
|
|
|
logger->log("GL_MAX_ELEMENTS_VERTICES: %d", value);
|
|
|
|
|
|
|
|
|
|
mMaxVertices = value;
|
|
|
|
|
|
2012-10-04 22:52:29 +03:00
|
|
|
value = 0;
|
2012-09-09 13:09:20 +03:00
|
|
|
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &value);
|
|
|
|
|
logger->log("GL_MAX_ELEMENTS_INDICES: %d", value);
|
|
|
|
|
if (value < mMaxVertices)
|
|
|
|
|
mMaxVertices = value;
|
2015-12-01 22:58:27 +03:00
|
|
|
if (!mMaxVertices)
|
|
|
|
|
{
|
|
|
|
|
logger->log("Got 0 max amount of vertices or indicies. "
|
|
|
|
|
"Overriding to 500");
|
|
|
|
|
mMaxVertices = 500;
|
|
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // __native_client__
|
2012-10-04 22:52:29 +03:00
|
|
|
|
|
|
|
|
value = 0;
|
|
|
|
|
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &value);
|
|
|
|
|
logger->log("Max FBO size: %d", value);
|
|
|
|
|
mMaxFboSize = value;
|
2012-09-09 13:09:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GraphicsManager::initOpenGL()
|
|
|
|
|
{
|
|
|
|
|
setGLVersion();
|
|
|
|
|
updateExtensions();
|
2012-10-01 17:51:43 +03:00
|
|
|
initOpenGLFunctions();
|
2012-09-09 13:09:20 +03:00
|
|
|
updatePlanformExtensions();
|
2012-10-23 03:51:06 +03:00
|
|
|
updateDebugLog();
|
2012-10-01 23:32:51 +03:00
|
|
|
createTextureSampler();
|
2012-09-09 13:09:20 +03:00
|
|
|
updateLimits();
|
|
|
|
|
}
|
2012-10-01 23:32:51 +03:00
|
|
|
|
|
|
|
|
void GraphicsManager::createTextureSampler()
|
|
|
|
|
{
|
2012-10-30 01:19:46 +03:00
|
|
|
GLenum err = getLastError();
|
|
|
|
|
if (err)
|
|
|
|
|
logger->log(errorToString(err));
|
2012-10-01 23:32:51 +03:00
|
|
|
if (mUseTextureSampler)
|
|
|
|
|
{
|
2012-10-30 01:19:46 +03:00
|
|
|
logger->log1("using texture sampler");
|
2012-10-01 23:32:51 +03:00
|
|
|
mglGenSamplers(1, &mTextureSampler);
|
|
|
|
|
if (getLastError() != GL_NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
mUseTextureSampler = false;
|
2012-10-30 01:19:46 +03:00
|
|
|
logger->log1("texture sampler error");
|
2012-10-05 14:25:52 +03:00
|
|
|
OpenGLImageHelper::setUseTextureSampler(mUseTextureSampler);
|
2012-10-01 23:32:51 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
OpenGLImageHelper::initTextureSampler(mTextureSampler);
|
|
|
|
|
mglBindSampler(0, mTextureSampler);
|
|
|
|
|
if (getLastError() != GL_NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
mUseTextureSampler = false;
|
2012-10-30 01:19:46 +03:00
|
|
|
logger->log1("texture sampler error");
|
2012-10-01 23:32:51 +03:00
|
|
|
}
|
|
|
|
|
}
|
2012-10-05 14:25:52 +03:00
|
|
|
OpenGLImageHelper::setUseTextureSampler(mUseTextureSampler);
|
2020-04-23 11:16:31 +02:00
|
|
|
#if !defined(ANDROID) && !defined(__SWITCH__)
|
2015-12-15 18:57:03 +03:00
|
|
|
SafeOpenGLImageHelper::setUseTextureSampler(false);
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // ANDROID
|
2012-10-01 23:32:51 +03:00
|
|
|
}
|
|
|
|
|
|
2012-10-30 01:19:46 +03:00
|
|
|
GLenum GraphicsManager::getLastError()
|
2012-10-01 23:32:51 +03:00
|
|
|
{
|
|
|
|
|
GLenum tmp = glGetError();
|
|
|
|
|
GLenum error = GL_NO_ERROR;
|
|
|
|
|
while (tmp != GL_NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
error = tmp;
|
2014-05-25 17:50:46 +03:00
|
|
|
mLastError = tmp;
|
2012-10-01 23:32:51 +03:00
|
|
|
tmp = glGetError();
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2012-10-08 17:11:06 +03:00
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
std::string GraphicsManager::errorToString(const GLenum error)
|
2012-10-23 13:44:37 +03:00
|
|
|
{
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
2013-09-25 13:48:24 +03:00
|
|
|
std::string errmsg("Unknown error");
|
2012-10-23 13:44:37 +03:00
|
|
|
switch (error)
|
|
|
|
|
{
|
|
|
|
|
case GL_INVALID_ENUM:
|
|
|
|
|
errmsg = "GL_INVALID_ENUM";
|
|
|
|
|
break;
|
|
|
|
|
case GL_INVALID_VALUE:
|
|
|
|
|
errmsg = "GL_INVALID_VALUE";
|
|
|
|
|
break;
|
|
|
|
|
case GL_INVALID_OPERATION:
|
|
|
|
|
errmsg = "GL_INVALID_OPERATION";
|
|
|
|
|
break;
|
|
|
|
|
case GL_STACK_OVERFLOW:
|
|
|
|
|
errmsg = "GL_STACK_OVERFLOW";
|
|
|
|
|
break;
|
|
|
|
|
case GL_STACK_UNDERFLOW:
|
|
|
|
|
errmsg = "GL_STACK_UNDERFLOW";
|
|
|
|
|
break;
|
|
|
|
|
case GL_OUT_OF_MEMORY:
|
|
|
|
|
errmsg = "GL_OUT_OF_MEMORY";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-04-25 16:55:35 +03:00
|
|
|
return "OpenGL error: " + errmsg;
|
2012-10-23 13:44:37 +03:00
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 12:41:20 +03:00
|
|
|
void GraphicsManager::logError()
|
|
|
|
|
{
|
|
|
|
|
const GLenum error = GraphicsManager::getLastError();
|
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
|
logger->log(errorToString(error));
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 17:11:06 +03:00
|
|
|
void GraphicsManager::detectVideoSettings()
|
|
|
|
|
{
|
|
|
|
|
config.setValue("videodetected", true);
|
2013-02-28 15:22:00 +03:00
|
|
|
TestMain *const test = startDetection();
|
2012-10-08 17:11:06 +03:00
|
|
|
|
|
|
|
|
if (test)
|
|
|
|
|
{
|
|
|
|
|
const Configuration &conf = test->getConfig();
|
|
|
|
|
int val = conf.getValueInt("opengl", -1);
|
2016-02-07 16:18:13 +03:00
|
|
|
if (val >= 0 && val < CAST_S32(RENDER_LAST))
|
2012-10-08 17:11:06 +03:00
|
|
|
{
|
|
|
|
|
config.setValue("opengl", val);
|
|
|
|
|
val = conf.getValue("useTextureSampler", -1);
|
|
|
|
|
if (val != -1)
|
|
|
|
|
config.setValue("useTextureSampler", val);
|
|
|
|
|
val = conf.getValue("compresstextures", -1);
|
|
|
|
|
if (val != -1)
|
|
|
|
|
config.setValue("compresstextures", val);
|
|
|
|
|
}
|
2014-07-16 21:10:58 +03:00
|
|
|
config.setValue("textureSize", conf.getValue("textureSize",
|
2014-07-19 18:03:03 +03:00
|
|
|
"1024,1024,1024,1024,1024,1024"));
|
2014-05-25 21:24:46 +03:00
|
|
|
config.setValue("testInfo", conf.getValue("testInfo", ""));
|
2017-03-09 20:29:33 +03:00
|
|
|
config.setValue("sound", conf.getValue("sound", 0));
|
2012-10-08 17:11:06 +03:00
|
|
|
delete test;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-23 03:51:06 +03:00
|
|
|
|
2018-04-01 05:03:50 +03:00
|
|
|
static CALLBACK void debugCallback(GLenum source,
|
|
|
|
|
GLenum type,
|
|
|
|
|
GLuint id,
|
|
|
|
|
GLenum severity,
|
|
|
|
|
GLsizei length,
|
|
|
|
|
const GLchar *text,
|
|
|
|
|
GLvoid *userParam A_UNUSED)
|
2012-10-23 03:51:06 +03:00
|
|
|
{
|
|
|
|
|
std::string message("OPENGL:");
|
|
|
|
|
switch (source)
|
|
|
|
|
{
|
|
|
|
|
case GL_DEBUG_SOURCE_API:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" API");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" WM");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" SHADERS");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" THIRD_PARTY");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_APPLICATION:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" APP");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_OTHER:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" OTHER");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
default:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" ?").append(toString(source));
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case GL_DEBUG_TYPE_ERROR:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" ERROR");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" DEPRECATED");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" UNDEFINED");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_PORTABILITY:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" PORTABILITY");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_PERFORMANCE:
|
2013-08-20 20:09:52 +03:00
|
|
|
message.append(" PERFORMANCE");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_OTHER:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" OTHER");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_MARKER:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" MARKER");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
2014-06-19 19:56:27 +03:00
|
|
|
case GL_DEBUG_TYPE_PUSH_GROUP:
|
|
|
|
|
message.append(" PUSH GROUP");
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_POP_GROUP:
|
|
|
|
|
message.append(" POP GROUP");
|
|
|
|
|
break;
|
2012-10-23 03:51:06 +03:00
|
|
|
default:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" ?").append(toString(type));
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
}
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" ").append(toString(id));
|
2012-10-23 03:51:06 +03:00
|
|
|
switch (severity)
|
|
|
|
|
{
|
|
|
|
|
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" N");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SEVERITY_HIGH:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" H");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SEVERITY_MEDIUM:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" M");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SEVERITY_LOW:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" L");
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
default:
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" ?").append(toString(type));
|
2012-10-23 03:51:06 +03:00
|
|
|
break;
|
|
|
|
|
}
|
2016-02-07 16:18:13 +03:00
|
|
|
char *const buf = new char[CAST_SIZE(length + 1)];
|
2013-04-14 11:27:04 +03:00
|
|
|
memcpy(buf, text, length);
|
2012-10-23 03:51:06 +03:00
|
|
|
buf[length] = 0;
|
2013-02-25 03:35:52 +03:00
|
|
|
message.append(" ").append(buf);
|
2012-10-23 03:51:06 +03:00
|
|
|
delete [] buf;
|
|
|
|
|
logger->log(message);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 15:22:00 +03:00
|
|
|
void GraphicsManager::updateDebugLog() const
|
2012-10-23 03:51:06 +03:00
|
|
|
{
|
|
|
|
|
if (mSupportDebug && config.getIntValue("debugOpenGL"))
|
|
|
|
|
{
|
2013-02-28 15:22:00 +03:00
|
|
|
logger->log1("Enable OpenGL debug log");
|
2012-10-23 03:51:06 +03:00
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
|
|
|
|
|
|
mglDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE,
|
|
|
|
|
0, nullptr, GL_TRUE);
|
|
|
|
|
mglDebugMessageCallback(&debugCallback, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_OPENGL
|
2013-04-30 22:32:38 +03:00
|
|
|
|
|
|
|
|
void GraphicsManager::detectPixelSize()
|
|
|
|
|
{
|
|
|
|
|
SDL_SysWMinfo info;
|
2018-11-26 00:51:57 +03:00
|
|
|
SDL_VERSION(&info.version)
|
2013-08-24 14:51:24 +03:00
|
|
|
if (SDL::getWindowWMInfo(mainGraphics->getWindow(), &info))
|
2013-04-30 22:32:38 +03:00
|
|
|
{
|
|
|
|
|
#ifdef WIN32
|
2022-07-14 19:44:44 -07:00
|
|
|
#ifdef USE_SDL2
|
|
|
|
|
HDC hdc = GetDC(info.info.win.window);
|
|
|
|
|
#else
|
2013-04-30 22:32:38 +03:00
|
|
|
HDC hdc = GetDC(info.window);
|
2022-07-14 19:44:44 -07:00
|
|
|
#endif // USE_SDL2
|
2013-04-30 22:32:38 +03:00
|
|
|
if (hdc)
|
|
|
|
|
{
|
|
|
|
|
// SetProcessDPIAware();
|
|
|
|
|
mMaxWidth = GetDeviceCaps(hdc, HORZRES);
|
|
|
|
|
mMaxHeight = GetDeviceCaps(hdc, VERTRES);
|
|
|
|
|
mWidthMM = GetDeviceCaps(hdc, HORZSIZE);
|
|
|
|
|
mHeightMM = GetDeviceCaps(hdc, VERTSIZE);
|
|
|
|
|
}
|
|
|
|
|
#elif defined USE_X11
|
|
|
|
|
Display *const display = info.info.x11.display;
|
|
|
|
|
if (display)
|
|
|
|
|
{
|
|
|
|
|
Screen *const screen = XDefaultScreenOfDisplay(display);
|
|
|
|
|
if (!screen)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int screenNum = XScreenNumberOfScreen(screen);
|
|
|
|
|
mMaxWidth = DisplayWidth(display, screenNum);
|
|
|
|
|
mMaxHeight = DisplayHeight(display, screenNum);
|
|
|
|
|
mWidthMM = DisplayWidthMM(display, screenNum);
|
|
|
|
|
mHeightMM = DisplayHeightMM(display, screenNum);
|
|
|
|
|
}
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // WIN32
|
2013-04-30 22:32:38 +03:00
|
|
|
}
|
|
|
|
|
#if defined ANDROID
|
2013-09-21 21:46:17 +03:00
|
|
|
#ifdef USE_SDL2
|
2013-09-26 00:47:35 +03:00
|
|
|
const int dpi = atoi(getenv("DISPLAY_DPI"));
|
|
|
|
|
if (dpi <= 120)
|
|
|
|
|
mDensity = 0;
|
|
|
|
|
else if (dpi <= 160)
|
|
|
|
|
mDensity = 1;
|
|
|
|
|
else if (dpi <= 213)
|
|
|
|
|
mDensity = 2;
|
|
|
|
|
else if (dpi <= 240)
|
|
|
|
|
mDensity = 3;
|
|
|
|
|
else if (dpi <= 320)
|
|
|
|
|
mDensity = 4;
|
|
|
|
|
// else if (dpi <= 480)
|
|
|
|
|
else
|
|
|
|
|
mDensity = 5;
|
|
|
|
|
mMaxWidth = atoi(getenv("DISPLAY_RESOLUTION_WIDTH"));
|
|
|
|
|
mMaxHeight = atoi(getenv("DISPLAY_RESOLUTION_HEIGHT"));
|
|
|
|
|
mWidthMM = atoi(getenv("DISPLAY_WIDTH_MM"));
|
|
|
|
|
mHeightMM = atoi(getenv("DISPLAY_HEIGHT_MM"));
|
2016-09-23 22:01:44 +03:00
|
|
|
#else // USE_SDL2
|
|
|
|
|
|
2013-04-30 22:32:38 +03:00
|
|
|
SDL_ANDROID_GetMetrics(&mMaxWidth, &mMaxHeight,
|
|
|
|
|
&mWidthMM, &mHeightMM, &mDensity);
|
2016-09-23 22:01:44 +03:00
|
|
|
#endif // USE_SDL2
|
|
|
|
|
#endif // defined ANDROID
|
|
|
|
|
|
2014-05-31 17:01:38 +03:00
|
|
|
logger->log("screen size in pixels: %ux%u", mMaxWidth, mMaxHeight);
|
|
|
|
|
logger->log("screen size in millimeters: %ux%u", mWidthMM, mHeightMM);
|
2013-05-01 17:05:28 +03:00
|
|
|
logger->log("actual screen density: " + getDensityString());
|
|
|
|
|
const int density = config.getIntValue("screenDensity");
|
|
|
|
|
if (density > 0 && density <= densitySize)
|
|
|
|
|
{
|
|
|
|
|
mDensity = density - 1;
|
|
|
|
|
logger->log("selected screen density: " + getDensityString());
|
|
|
|
|
}
|
2013-04-30 22:32:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GraphicsManager::getDensityString() const
|
|
|
|
|
{
|
|
|
|
|
if (mDensity >= 0 && mDensity < densitySize)
|
|
|
|
|
return densityNames[mDensity];
|
|
|
|
|
return "";
|
|
|
|
|
}
|