mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Deduplicate GL extension detection
This commit is contained in:
parent
472742266b
commit
6303334cc2
@ -12,47 +12,14 @@
|
||||
#include "os.h"
|
||||
#include <mt_opengl.h>
|
||||
|
||||
// FIXME: this basically duplicates what mt_opengl.h already does
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video
|
||||
{
|
||||
void COpenGL3ExtensionHandler::initExtensionsOld()
|
||||
{
|
||||
auto extensions_string = reinterpret_cast<const char *>(GL.GetString(GL_EXTENSIONS));
|
||||
const char *pos = extensions_string;
|
||||
while (const char *next = strchr(pos, ' ')) {
|
||||
addExtension(std::string{pos, next});
|
||||
pos = next + 1;
|
||||
}
|
||||
addExtension(pos);
|
||||
extensionsLoaded();
|
||||
}
|
||||
|
||||
void COpenGL3ExtensionHandler::initExtensionsNew()
|
||||
void COpenGL3ExtensionHandler::initExtensions()
|
||||
{
|
||||
int ext_count = GetInteger(GL_NUM_EXTENSIONS);
|
||||
for (int k = 0; k < ext_count; k++)
|
||||
addExtension(reinterpret_cast<const char *>(GL.GetStringi(GL_EXTENSIONS, k)));
|
||||
extensionsLoaded();
|
||||
}
|
||||
|
||||
void COpenGL3ExtensionHandler::addExtension(std::string &&name)
|
||||
{
|
||||
Extensions.emplace(std::move(name));
|
||||
}
|
||||
|
||||
bool COpenGL3ExtensionHandler::queryExtension(const std::string &name) const noexcept
|
||||
{
|
||||
return Extensions.find(name) != Extensions.end();
|
||||
}
|
||||
|
||||
void COpenGL3ExtensionHandler::extensionsLoaded()
|
||||
{
|
||||
os::Printer::log((std::string("Loaded ") + std::to_string(Extensions.size()) + " extensions:").c_str(), ELL_DEBUG);
|
||||
for (const auto &it : Extensions)
|
||||
os::Printer::log((std::string(" ") + it).c_str(), ELL_DEBUG);
|
||||
// reading extensions happens in mt_opengl.cpp
|
||||
for (size_t j = 0; j < IRR_OGLES_Feature_Count; ++j)
|
||||
FeatureAvailable[j] = queryExtension(getFeatureString(j));
|
||||
}
|
||||
|
@ -28,11 +28,13 @@ public:
|
||||
COpenGL3ExtensionHandler() :
|
||||
COGLESCoreExtensionHandler() {}
|
||||
|
||||
void initExtensionsOld();
|
||||
void initExtensionsNew();
|
||||
void initExtensions();
|
||||
|
||||
/// Checks whether a named extension is present
|
||||
bool queryExtension(const std::string &name) const noexcept;
|
||||
inline bool queryExtension(const std::string &name) const noexcept
|
||||
{
|
||||
return GL.IsExtensionPresent(name);
|
||||
}
|
||||
|
||||
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
|
||||
{
|
||||
@ -159,12 +161,6 @@ public:
|
||||
|
||||
bool AnisotropicFilterSupported = false;
|
||||
bool BlendMinMaxSupported = false;
|
||||
|
||||
private:
|
||||
void addExtension(std::string &&name);
|
||||
void extensionsLoaded();
|
||||
|
||||
std::unordered_set<std::string> Extensions;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void COpenGL3Driver::initFeatures()
|
||||
{
|
||||
assert(Version.Spec == OpenGLSpec::Compat);
|
||||
assert(isVersionAtLeast(3, 2));
|
||||
initExtensionsNew();
|
||||
initExtensions();
|
||||
|
||||
TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable
|
||||
TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; // GL_RGB565 is an extension until 4.1
|
||||
|
@ -31,10 +31,7 @@ void COpenGLES2Driver::initFeatures()
|
||||
{
|
||||
assert(Version.Spec == OpenGLSpec::ES);
|
||||
assert(Version.Major >= 2);
|
||||
if (Version.Major >= 3)
|
||||
initExtensionsNew();
|
||||
else
|
||||
initExtensionsOld();
|
||||
initExtensions();
|
||||
|
||||
static const GLenum BGRA8_EXT = 0x93A1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user