28 #include <GLES2/gl2.h>
29 #include <GLES/glext.h>
34 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
35 #include <SDL_android.h>
38 #elif defined(__native_client__)
98 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
99 #include <SDL_syswm.h>
105 #ifndef GL_MAX_RENDERBUFFER_SIZE
106 #define GL_MAX_RENDERBUFFER_SIZE 0x84E8
108 #define useCompression(name) \
110 OpenGLImageHelper::setInternalTextureType(name); \
111 logger->log("using " #name " texture compression"); \
139 mPlatformExtensions(),
143 mGlShaderVersionString(),
158 mUseTextureSampler(true),
161 mSupportModernOpengl(false),
188 int textureSampler = 0;
189 int compressTextures = 0;
190 #if !defined(ANDROID) && !defined(__native_client__) && !defined(__SWITCH__)
195 SDL_ANYFORMAT | SDL_OPENGL);
215 logger->
log(
"detected software drawing");
222 logger->
log(
"detected indirect drawing");
251 != std::string::npos)
255 compressTextures = 0;
264 | (1024 * textureSampler) | (2048 * compressTextures);
268 #define RENDER_SOFTWARE_INIT \
269 imageHelper = new SDL2SoftwareImageHelper; \
270 surfaceImageHelper = new SurfaceImageHelper; \
271 mainGraphics = new SDL2SoftwareGraphics; \
272 screenshortHelper = new Sdl2SoftwareScreenshotHelper;
273 #define RENDER_SDL2_DEFAULT_INIT \
274 imageHelper = new SDLImageHelper; \
275 surfaceImageHelper = new SurfaceImageHelper; \
276 mainGraphics = new SDLGraphics; \
277 screenshortHelper = new SdlScreenshotHelper; \
278 mainGraphics->setRendererFlags(SDL_RENDERER_ACCELERATED); \
279 mUseTextureSampler = false;
281 #define RENDER_SOFTWARE_INIT \
282 imageHelper = new SDLImageHelper; \
283 surfaceImageHelper = imageHelper; \
284 mainGraphics = new SDLGraphics; \
285 screenshortHelper = new SdlScreenshotHelper;
286 #define RENDER_SDL2_DEFAULT_INIT
289 #if defined(ANDROID) || defined(__native_client__) || defined(__SWITCH__)
290 #define RENDER_NORMAL_OPENGL_INIT
291 #define RENDER_MODERN_OPENGL_INIT
293 #define RENDER_NORMAL_OPENGL_INIT \
294 imageHelper = new OpenGLImageHelper; \
295 surfaceImageHelper = new SurfaceImageHelper; \
296 mainGraphics = new NormalOpenGLGraphics; \
297 screenshortHelper = new OpenGLScreenshotHelper; \
298 mUseTextureSampler = true;
299 #define RENDER_MODERN_OPENGL_INIT \
300 imageHelper = new OpenGLImageHelper; \
301 surfaceImageHelper = new SurfaceImageHelper; \
302 mainGraphics = new ModernOpenGLGraphics; \
303 screenshortHelper = new OpenGLScreenshotHelper; \
304 mUseTextureSampler = true;
308 #define RENDER_SAFE_OPENGL_INIT
309 #define RENDER_GLES2_OPENGL_INIT
312 #define RENDER_SAFE_OPENGL_INIT
314 #define RENDER_SAFE_OPENGL_INIT \
315 imageHelper = new SafeOpenGLImageHelper; \
316 surfaceImageHelper = new SurfaceImageHelper; \
317 mainGraphics = new SafeOpenGLGraphics; \
318 screenshortHelper = new OpenGLScreenshotHelper; \
319 mUseTextureSampler = false;
321 #define RENDER_GLES2_OPENGL_INIT \
322 imageHelper = new OpenGLImageHelper; \
323 surfaceImageHelper = new SurfaceImageHelper; \
324 mainGraphics = new MobileOpenGL2Graphics; \
325 screenshortHelper = new MobileOpenGLScreenshotHelper; \
326 mUseTextureSampler = false;
329 #if defined(__native_client__) || defined(__SWITCH__)
330 #define RENDER_GLES_OPENGL_INIT
332 #define RENDER_GLES_OPENGL_INIT \
333 imageHelper = new OpenGLImageHelper; \
334 surfaceImageHelper = new SurfaceImageHelper; \
335 mainGraphics = new MobileOpenGLGraphics; \
336 screenshortHelper = new OpenGLScreenshotHelper; \
337 mUseTextureSampler = false;
440 mainGraphics->setRendererFlags(SDL_RENDERER_ACCELERATED);
471 if (videoModes.empty())
480 #elif defined __native_client__
485 const SDL_VideoInfo*
info = SDL_GetVideoInfo();
486 int width =
info->current_w;
487 int height =
info->current_h;
489 #elif defined __SWITCH__
502 fullscreen, hwaccel, enableResize, noFrame, allowHighDPI))
505 width, height, bpp, SDL_GetError()));
510 if (oldWidth != -1 && oldHeight != -1 && oldFullscreen != -1)
529 "video mode: %s", oldWidth, oldHeight, bpp,
541 #if !defined(ANDROID) && !defined(__SWITCH__)
544 SurfaceImageHelper::SDLSetEnableAlphaCache(
551 SurfaceImageHelper::SDLSetEnableAlphaCache(
567 logger->
log(
"Fallback to normal OpenGL mode");
575 logger->
log(
"Fallback to safe OpenGL mode");
583 logger->
log(
"Fallback to safe OpenGL mode");
592 logger->
log(
"Fallback to software mode");
607 #if !defined(ANDROID) && !defined(__APPLE__)
609 STD_VECTOR<int> sizes;
612 if (sizes.size() <= pos)
626 return SDL_CreateWindow(
"ManaPlus", SDL_WINDOWPOS_UNDEFINED,
627 SDL_WINDOWPOS_UNDEFINED, w, h, flags);
630 SDL_Renderer *GraphicsManager::createRenderer(
SDL_Window *
const window,
634 SDL_Renderer *
const renderer = SDL_CreateRenderer(window, -1, flags);
635 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
641 const int bpp,
const int flags)
643 return SDL_SetVideoMode(w, h, bpp, flags);
658 for (
int f = 0; f < num; f ++)
660 std::string str =
reinterpret_cast<const char*
>(
661 mglGetStringi(GL_EXTENSIONS, f));
663 extList.append(str).append(
" ");
669 char const *extensions =
reinterpret_cast<char const *
>(
682 SDL_VERSION(&
info.version)
686 if (!mwglGetExtensionsString)
689 HDC hdc = GetDC(
info.window);
692 const char *
const extensions = mwglGetExtensionsString(hdc);
700 #elif defined USE_X11
701 Display *
const display =
info.info.x11.display;
704 Screen *
const screen = XDefaultScreenOfDisplay(display);
708 const int screenNum = XScreenNumberOfScreen(screen);
709 const char *
const extensions = glXQueryExtensionsString(
720 const char *
const vendor1 = glXQueryServerString(
721 display, screenNum, GLX_VENDOR);
723 logger->
log(
"glx server vendor: %s", vendor1);
724 const char *
const version1 = glXQueryServerString(
725 display, screenNum, GLX_VERSION);
727 logger->
log(
"glx server version: %s", version1);
728 const char *
const extensions1 = glXQueryServerString(
729 display, screenNum, GLX_EXTENSIONS);
736 const char *
const vendor2 = glXGetClientString(
737 display, GLX_VENDOR);
739 logger->
log(
"glx client vendor: %s", vendor2);
740 const char *
const version2 = glXGetClientString(
741 display, GLX_VERSION);
743 logger->
log(
"glx client version: %s", version2);
744 const char *
const extensions2 = glXGetClientString(
745 display, GLX_EXTENSIONS);
752 logger->
log(
"width=%d", DisplayWidth(display, screenNum));
773 logger->
log(
"support %d compressed formats", num);
774 GLint *
const formats =
new GLint[num > 10
777 for (
int f = 0; f < num; f ++)
780 if (compressionFormat)
782 for (
int f = 0; f < num; f ++)
787 if (compressionFormat == 1)
795 if (compressionFormat == 2)
803 if (compressionFormat == 4)
814 if (compressionFormat == 3)
822 if (compressionFormat == 4
831 if (compressionFormat)
832 logger->
log1(
"no correct compression format found");
836 if (compressionFormat)
837 logger->
log1(
"no correct compression format found");
852 #if !defined(ANDROID) && !defined(__SWITCH__)
861 #if !defined(ANDROID) && !defined(__SWITCH__)
871 const char *str =
reinterpret_cast<const char*
>(
mglGetString(num));
880 const char *str =
reinterpret_cast<const char*
>(
mglGetString(num));
881 return str ? str :
"";
896 cutFirst(version,
"OpenGL ES GLSL ES ");
897 cutFirst(version,
"OpenGL ES GLSL ");
904 logger->
log(
"Overriding detected OpenGL version on Android to 1.0");
936 const int minor)
const
949 glGenTextures(1, &fbo->textureId);
952 GL_TEXTURE_MAG_FILTER, GL_LINEAR);
954 GL_TEXTURE_MIN_FILTER, GL_LINEAR);
956 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
958 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
960 0, GL_RGBA, GL_UNSIGNED_BYTE,
nullptr);
964 mglGenRenderbuffers(1, &fbo->rboId);
967 GL_DEPTH_COMPONENT, width, height);
971 mglGenFramebuffers(1, &fbo->fboId);
983 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
994 mglDeleteFramebuffers(1, &fbo->fboId);
1000 mglDeleteRenderbuffers(1, &fbo->rboId);
1005 glDeleteTextures(1, &fbo->textureId);
1012 #ifdef __native_client__
1035 logger->
log1(
"found GL_ARB_sampler_objects");
1088 logger->
log1(
"found GL_EXT_direct_state_access");
1093 logger->
log1(
"found GL_EXT_direct_state_access");
1095 "glTextureSubImage2DEXT")
1099 logger->
log1(
"found GL_ARB_direct_state_access");
1100 logger->
log1(
"GL_EXT_direct_state_access not found");
1105 logger->
log1(
"GL_EXT_direct_state_access not found");
1106 logger->
log1(
"GL_ARB_direct_state_access not found");
1112 logger->
log1(
"Direct state access disabled in settings");
1119 logger->
log1(
"found GL_ARB_texture_storage");
1124 logger->
log1(
"GL_ARB_texture_storage not found");
1129 logger->
log1(
"found GL_ARB_multitexture or OpenGL 1.3");
1135 logger->
log1(
"GL_ARB_multitexture not found");
1140 logger->
log1(
"found GL_ARB_explicit_attrib_location or OpenGL 2.0");
1145 logger->
log1(
"GL_ARB_explicit_attrib_location not found");
1150 logger->
log1(
"found GL_ARB_framebuffer_object");
1164 logger->
log1(
"found GL_EXT_framebuffer_object");
1178 "GL_EXT_framebuffer_object not found");
1208 logger->
log1(
"found GL_GREMEDY_frame_terminator");
1213 logger->
log1(
"GL_GREMEDY_frame_terminator not found");
1225 logger->
log1(
"GL_EXT_debug_label not found");
1229 logger->
log1(
"found GL_GREMEDY_string_marker");
1234 logger->
log1(
"GL_GREMEDY_string_marker not found");
1245 logger->
log1(
"GL_EXT_debug_marker not found");
1259 logger->
log1(
"GL_EXT_timer_query not supported");
1263 logger->
log1(
"found GL_ARB_invalidate_subdata");
1268 logger->
log1(
"GL_ARB_invalidate_subdata not supported");
1272 logger->
log1(
"found GL_ARB_vertex_array_object");
1284 logger->
log1(
"GL_ARB_vertex_array_object not found");
1316 logger->
log1(
"GL_ARB_clear_texture not found");
1354 logger->
log1(
"GL_EXT_gpu_shader4 not supported");
1358 logger->
log1(
"found GL_ARB_separate_shader_objects");
1366 logger->
log1(
"GL_ARB_separate_shader_objects not supported");
1370 logger->
log1(
"found GL_ARB_vertex_attrib_binding");
1379 logger->
log1(
"GL_ARB_vertex_attrib_binding not supported");
1388 logger->
log1(
"GL_ARB_multi_bind not supported");
1406 #ifdef __native_client__
1411 logger->
log(
"GL_MAX_ELEMENTS_VERTICES: %d", value);
1417 logger->
log(
"GL_MAX_ELEMENTS_INDICES: %d", value);
1422 logger->
log(
"Got 0 max amount of vertices or indicies. "
1423 "Overriding to 500");
1429 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &value);
1470 #if !defined(ANDROID) && !defined(__SWITCH__)
1477 GLenum tmp = glGetError();
1478 GLenum
error = GL_NO_ERROR;
1479 while (tmp != GL_NO_ERROR)
1492 std::string errmsg(
"Unknown error");
1495 case GL_INVALID_ENUM:
1496 errmsg =
"GL_INVALID_ENUM";
1498 case GL_INVALID_VALUE:
1499 errmsg =
"GL_INVALID_VALUE";
1501 case GL_INVALID_OPERATION:
1502 errmsg =
"GL_INVALID_OPERATION";
1504 case GL_STACK_OVERFLOW:
1505 errmsg =
"GL_STACK_OVERFLOW";
1507 case GL_STACK_UNDERFLOW:
1508 errmsg =
"GL_STACK_UNDERFLOW";
1510 case GL_OUT_OF_MEMORY:
1511 errmsg =
"GL_OUT_OF_MEMORY";
1516 return "OpenGL error: " + errmsg;
1524 if (
error != GL_NO_ERROR)
1540 val = conf.
getValue(
"useTextureSampler", -1);
1543 val = conf.
getValue(
"compresstextures", -1);
1548 "1024,1024,1024,1024,1024,1024"));
1563 std::string message(
"OPENGL:");
1567 message.append(
" API");
1570 message.append(
" WM");
1573 message.append(
" SHADERS");
1576 message.append(
" THIRD_PARTY");
1579 message.append(
" APP");
1582 message.append(
" OTHER");
1585 message.append(
" ?").append(
toString(source));
1591 message.append(
" ERROR");
1594 message.append(
" DEPRECATED");
1597 message.append(
" UNDEFINED");
1600 message.append(
" PORTABILITY");
1603 message.append(
" PERFORMANCE");
1606 message.append(
" OTHER");
1609 message.append(
" MARKER");
1612 message.append(
" PUSH GROUP");
1615 message.append(
" POP GROUP");
1618 message.append(
" ?").append(
toString(type));
1621 message.append(
" ").append(
toString(
id));
1625 message.append(
" N");
1628 message.append(
" H");
1631 message.append(
" M");
1634 message.append(
" L");
1637 message.append(
" ?").append(
toString(type));
1640 char *
const buf =
new char[
CAST_SIZE(length + 1)];
1641 memcpy(buf, text, length);
1643 message.append(
" ").append(buf);
1656 mglDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE,
1657 0,
nullptr, GL_TRUE);
1666 SDL_VERSION(&
info.version)
1670 HDC hdc = GetDC(
info.window);
1674 mMaxWidth = GetDeviceCaps(hdc, HORZRES);
1676 mWidthMM = GetDeviceCaps(hdc, HORZSIZE);
1677 mHeightMM = GetDeviceCaps(hdc, VERTSIZE);
1679 #elif defined USE_X11
1680 Display *
const display =
info.info.x11.display;
1683 Screen *
const screen = XDefaultScreenOfDisplay(display);
1687 const int screenNum = XScreenNumberOfScreen(screen);
1688 mMaxWidth = DisplayWidth(display, screenNum);
1689 mMaxHeight = DisplayHeight(display, screenNum);
1690 mWidthMM = DisplayWidthMM(display, screenNum);
1691 mHeightMM = DisplayHeightMM(display, screenNum);
1697 const int dpi = atoi(getenv(
"DISPLAY_DPI"));
1700 else if (dpi <= 160)
1702 else if (dpi <= 213)
1704 else if (dpi <= 240)
1706 else if (dpi <= 320)
1711 mMaxWidth = atoi(getenv(
"DISPLAY_RESOLUTION_WIDTH"));
1712 mMaxHeight = atoi(getenv(
"DISPLAY_RESOLUTION_HEIGHT"));
1713 mWidthMM = atoi(getenv(
"DISPLAY_WIDTH_MM"));
1714 mHeightMM = atoi(getenv(
"DISPLAY_HEIGHT_MM"));
int getValueInt(const std::string &key, const int deflt) const
std::string getValue(const std::string &key, const std::string &deflt) const
void deleteKey(const std::string &key)
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
float getFloatValue(const std::string &key) const
void setValue(const std::string &key, const std::string &value)
void setValueInt(const std::string &key, const int value)
int getIntValue(const std::string &key) const
bool checkPlatformVersion(const int major, const int minor) const
static GLenum getLastError()
std::set< std::string > mPlatformExtensions
std::string getDensityString() const
static void deleteFBO(FBOInfo *const fbo)
static void updateTextureFormat()
static void deleteRenderers()
bool checkGLVersion(const int major, const int minor) const
void initOpenGLFunctions()
static std::string getGLString(const int num)
static void createFBO(const int width, const int height, FBOInfo *const fbo)
void createTextureSampler()
static void logString(const char *const format, const int num)
bool supportExtension(const std::string &ext) const
std::string mGlVersionString
void updateTextureCompressionFormat() const
static SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
void detectVideoSettings()
void updatePlanformExtensions()
void updateDebugLog() const
static void setVideoMode()
bool checkGLesVersion(const int major, const int minor) const
static std::string errorToString(const GLenum error)
std::set< std::string > mExtensions
TestMain * startDetection()
bool mSupportModernOpengl
bool checkSLVersion(const int major, const int minor) const
std::string mGlShaderVersionString
virtual bool setVideoMode(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)=0
virtual void createGLContext(const bool custom)
void setWindow(SDL_Surface *const window, const int width, const int height)
SDL_Surface * getWindow() const
static void setEnableAlpha(const bool n)
static void setOpenGlMode(const RenderType useOpenGL)
void log(const char *const log_text,...)
void log1(const char *const log_text)
void safeError(const std::string &error_text) __attribute__((noreturn))
void error(const std::string &error_text) __attribute__((noreturn))
static void setInternalTextureType(const int n)
static void setBlur(const bool n)
static void initTextureSampler(const GLint id)
static void setUseTextureSampler(const bool b)
static void setBlur(const bool n)
static void setUseTextureSampler(const bool b)
static void setInternalTextureType(const int n)
int exec(const bool testAudio=true)
Configuration & getConfig()
const std::string densityNames[]
#define RENDER_SOFTWARE_INIT
#define RENDER_GLES2_OPENGL_INIT
#define RENDER_GLES_OPENGL_INIT
#define RENDER_SAFE_OPENGL_INIT
GraphicsManager graphicsManager
#define RENDER_SDL2_DEFAULT_INIT
#define RENDER_MODERN_OPENGL_INIT
#define RENDER_NORMAL_OPENGL_INIT
ScreenshotHelper * screenshortHelper
#define useCompression(name)
static void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *text, GLvoid *userParam)
ImageHelper * imageHelper
ImageHelper * surfaceImageHelper
#define mglGetString(...)
#define mglGetIntegerv(...)
#define isGLNotNull(func)
#define GL_DEBUG_TYPE_MARKER
#define GL_DEBUG_SEVERITY_LOW
#define GL_DEBUG_SOURCE_THIRD_PARTY
#define GL_DEBUG_TYPE_PORTABILITY
#define GL_DEBUG_TYPE_OTHER
#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR
#define GL_DEBUG_TYPE_PUSH_GROUP
#define GL_COLOR_ATTACHMENT0
#define GL_DEBUG_SOURCE_APPLICATION
#define GL_DEBUG_SOURCE_OTHER
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
#define GL_DEBUG_SEVERITY_MEDIUM
#define GL_DEBUG_SOURCE_SHADER_COMPILER
#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR
#define GL_DEBUG_SEVERITY_NOTIFICATION
#define GL_DEBUG_TYPE_POP_GROUP
#define GL_DEBUG_SOURCE_WINDOW_SYSTEM
#define GL_MAX_ELEMENTS_INDICES
#define GL_DEBUG_SOURCE_API
#define GL_COMPRESSED_RGBA_ARB
#define GL_DEBUG_TYPE_ERROR
#define GL_MAX_ELEMENTS_VERTICES
#define GL_DEBUG_SEVERITY_HIGH
#define GL_DEBUG_OUTPUT_SYNCHRONOUS
#define GL_DEPTH_ATTACHMENT
#define GL_COMPRESSED_RGBA_FXT1_3DFX
#define GL_DEBUG_TYPE_PERFORMANCE
#define GL_NUM_EXTENSIONS
#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
#define assignFunction2(func, name)
#define assignFunctionEmu2(func, name)
#define assignFunctionARB(func)
#define assignFunctionEXT(func)
#define assignFunction(func)
#define emulateFunction(func)
bool error(InputEvent &event) __attribute__((noreturn))
bool info(InputEvent &event)
std::string toString(T const &value)
converts any type to a string
bool getWindowWMInfo(const SDL_Surface *const window, SDL_SysWMinfo *const info)
bool getAllVideoModes(StringVect &modeList)
RenderType intToRenderType(const int mode)
#define SurfaceImageHelper
void cutFirst(std::string &str1, const std::string &str2)
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)
std::string strprintf(const char *const format,...)
bool findCutFirst(std::string &str1, const std::string &str2)
size_t findI(std::string str, std::string subStr)
void splitToStringSet(std::set< std::string > &tokens, const std::string &text, const char separator)
std::vector< std::string > StringVect