2015-03-22 19:32:14 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2015-03-22 19:32:14 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* OpenGL extensions:
|
|
|
|
* We use global function pointer for any extension function we want to use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2016-02-11 03:25:52 +00:00
|
|
|
#include <SDL.h>
|
2015-03-22 19:32:14 +00:00
|
|
|
|
|
|
|
#include "ogl_extensions.h"
|
|
|
|
#include "console.h"
|
|
|
|
|
2015-03-25 01:59:20 +00:00
|
|
|
#include "dxxsconf.h"
|
2016-03-19 19:08:10 +00:00
|
|
|
#include "dsx-ns.h"
|
2020-05-02 21:18:42 +00:00
|
|
|
#include <array>
|
2015-03-25 01:59:20 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2015-03-22 19:32:14 +00:00
|
|
|
/* GL_ARB_sync */
|
|
|
|
bool ogl_have_ARB_sync = false;
|
|
|
|
PFNGLFENCESYNCPROC glFenceSyncFunc = NULL;
|
|
|
|
PFNGLDELETESYNCPROC glDeleteSyncFunc = NULL;
|
|
|
|
PFNGLCLIENTWAITSYNCPROC glClientWaitSyncFunc = NULL;
|
|
|
|
|
2016-11-03 20:59:11 +00:00
|
|
|
/* GL_EXT_texture_filter_anisotropic */
|
|
|
|
GLfloat ogl_maxanisotropy = 0.0f;
|
|
|
|
|
2020-05-02 21:18:42 +00:00
|
|
|
static std::array<long, 2> parse_version_str(const char *v)
|
2015-03-22 19:32:14 +00:00
|
|
|
{
|
2020-05-02 21:18:42 +00:00
|
|
|
std::array<long, 2> version;
|
2015-03-22 19:32:14 +00:00
|
|
|
version[0]=1;
|
|
|
|
version[1]=0;
|
|
|
|
if (v) {
|
|
|
|
char *ptr;
|
2016-11-03 20:59:11 +00:00
|
|
|
if (v[0] == 'O') {
|
|
|
|
// OpenGL ES uses the format "OpenGL ES-xx major.minor"
|
2016-11-05 18:16:30 +00:00
|
|
|
const auto &prefix_gles = "OpenGL ES-";
|
|
|
|
if (!strncmp(v, prefix_gles, sizeof(prefix_gles)-1)) {
|
2016-11-03 20:59:11 +00:00
|
|
|
// skip the prefix
|
2016-11-05 18:16:30 +00:00
|
|
|
v += sizeof(prefix_gles)-1;
|
2016-11-03 20:59:11 +00:00
|
|
|
// skip the profile marker
|
|
|
|
if (v[0] && v[1]) {
|
|
|
|
v +=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-22 19:32:14 +00:00
|
|
|
version[0]=strtol(v,&ptr,10);
|
|
|
|
if (ptr[0])
|
|
|
|
version[1]=strtol(ptr+1,NULL,10);
|
|
|
|
}
|
2015-03-25 01:59:20 +00:00
|
|
|
return version;
|
2015-03-22 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_ext_supported(const char *extensions, const char *name)
|
|
|
|
{
|
|
|
|
if (extensions && name) {
|
|
|
|
const char *found=strstr(extensions, name);
|
|
|
|
if (found) {
|
|
|
|
// check that the name is actually complete */
|
|
|
|
char c = found[strlen(name)];
|
|
|
|
if (c == ' ' || c == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum support_mode {
|
|
|
|
NO_SUPPORT=0,
|
|
|
|
SUPPORT_CORE=1,
|
|
|
|
SUPPORT_EXT=2
|
|
|
|
};
|
|
|
|
|
2020-05-02 21:18:42 +00:00
|
|
|
static support_mode is_supported(const char *extensions, const std::array<long, 2> &version, const char *name, long major, long minor, long major_es, long minor_es)
|
2015-03-22 19:32:14 +00:00
|
|
|
{
|
2016-11-03 20:59:11 +00:00
|
|
|
#if DXX_USE_OGLES
|
|
|
|
static_cast<void>(major);
|
|
|
|
static_cast<void>(minor);
|
|
|
|
if ( (major_es > 0) && ((version[0] > major_es) || (version[0] == major_es && version[1] >= minor_es)) )
|
2015-03-22 19:32:14 +00:00
|
|
|
return SUPPORT_CORE;
|
2016-11-03 20:59:11 +00:00
|
|
|
#else
|
|
|
|
static_cast<void>(major_es);
|
|
|
|
static_cast<void>(minor_es);
|
|
|
|
if ( (major > 0) && ((version[0] > major) || (version[0] == major && version[1] >= minor)) )
|
|
|
|
return SUPPORT_CORE;
|
|
|
|
#endif
|
2015-03-22 19:32:14 +00:00
|
|
|
|
|
|
|
if (is_ext_supported(extensions, name))
|
|
|
|
return SUPPORT_EXT;
|
|
|
|
return NO_SUPPORT;
|
|
|
|
}
|
|
|
|
|
2015-03-25 01:59:21 +00:00
|
|
|
void ogl_extensions_init()
|
2015-03-22 19:32:14 +00:00
|
|
|
{
|
2016-11-05 18:16:30 +00:00
|
|
|
const auto version_str = reinterpret_cast<const char *>(glGetString(GL_VERSION));
|
2015-03-22 19:32:14 +00:00
|
|
|
if (!version_str) {
|
2017-12-05 05:29:55 +00:00
|
|
|
con_puts(CON_URGENT, "DXX-Rebirth: no valid OpenGL context when querying GL extensions!");
|
2015-03-25 01:59:21 +00:00
|
|
|
return;
|
2015-03-22 19:32:14 +00:00
|
|
|
}
|
2015-03-25 01:59:20 +00:00
|
|
|
const auto version = parse_version_str(version_str);
|
2016-11-03 20:59:11 +00:00
|
|
|
const auto extension_str = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
|
|
|
|
|
|
|
|
#if DXX_USE_OGLES
|
2016-11-05 18:16:30 +00:00
|
|
|
#define DXX_OGL_STRING " ES"
|
2016-11-03 20:59:11 +00:00
|
|
|
#else
|
2016-11-05 18:16:30 +00:00
|
|
|
#define DXX_OGL_STRING ""
|
2016-11-03 20:59:11 +00:00
|
|
|
#endif
|
2017-08-26 19:47:51 +00:00
|
|
|
con_printf(CON_VERBOSE, "DXX-Rebirth: OpenGL" DXX_OGL_STRING ": version %ld.%ld (%s)", version[0], version[1], version_str);
|
2016-11-05 18:16:30 +00:00
|
|
|
#undef DXX_OGL_STRING
|
2016-11-03 20:59:11 +00:00
|
|
|
|
|
|
|
/* GL_EXT_texture_filter_anisotropic */
|
|
|
|
if (is_supported(extension_str, version, "GL_EXT_texture_filter_anisotropic", -1, -1, -1, -1)) {
|
|
|
|
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &ogl_maxanisotropy);
|
2017-08-26 19:47:51 +00:00
|
|
|
con_printf(CON_VERBOSE, "DXX-Rebirth: OpenGL: GL_EXT_texture_filter_anisotropic available, max anisotropy: %f", ogl_maxanisotropy);
|
2016-11-03 20:59:11 +00:00
|
|
|
} else {
|
|
|
|
ogl_maxanisotropy=0.0f;
|
2017-08-26 19:47:51 +00:00
|
|
|
con_puts(CON_VERBOSE, "DXX-Rebirth: OpenGL: GL_EXT_texture_filter_anisotropic not available");
|
2016-11-03 20:59:11 +00:00
|
|
|
}
|
2015-03-22 19:32:14 +00:00
|
|
|
|
|
|
|
/* GL_ARB_sync */
|
2016-11-03 20:59:11 +00:00
|
|
|
if (is_supported(extension_str, version, "GL_ARB_sync", 3, 2, 3, 0)) {
|
2015-03-23 19:06:23 +00:00
|
|
|
glFenceSyncFunc = reinterpret_cast<PFNGLFENCESYNCPROC>(SDL_GL_GetProcAddress("glFenceSync"));
|
|
|
|
glDeleteSyncFunc = reinterpret_cast<PFNGLDELETESYNCPROC>(SDL_GL_GetProcAddress("glDeleteSync"));
|
|
|
|
glClientWaitSyncFunc = reinterpret_cast<PFNGLCLIENTWAITSYNCPROC>(SDL_GL_GetProcAddress("glClientWaitSync"));
|
2015-03-22 19:32:14 +00:00
|
|
|
|
|
|
|
}
|
2017-08-26 19:47:51 +00:00
|
|
|
const char *s;
|
2015-03-22 19:32:14 +00:00
|
|
|
if (glFenceSyncFunc && glDeleteSyncFunc && glClientWaitSyncFunc) {
|
|
|
|
ogl_have_ARB_sync=true;
|
2017-08-26 19:47:51 +00:00
|
|
|
s = "DXX-Rebirth: OpenGL: GL_ARB_sync available";
|
2015-03-22 19:32:14 +00:00
|
|
|
} else {
|
2017-08-26 19:47:51 +00:00
|
|
|
s = "DXX-Rebirth: OpenGL: GL_ARB_sync not available";
|
2015-03-22 19:32:14 +00:00
|
|
|
}
|
2017-08-26 19:47:51 +00:00
|
|
|
con_puts(CON_VERBOSE, s);
|
2015-03-22 19:32:14 +00:00
|
|
|
}
|
2015-12-05 22:57:24 +00:00
|
|
|
|
|
|
|
}
|