From 4ee1ab261eb88b07dfc7e9d539a29d5ba75c0318 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 18:11:08 +0300 Subject: [PATCH] OpenGL3: Add driver-dependent feature checks --- source/Irrlicht/OpenGL/Driver.cpp | 2 +- source/Irrlicht/OpenGL/Driver.h | 2 + source/Irrlicht/OpenGL/ExtensionHandler.cpp | 67 ++++++++------------- source/Irrlicht/OpenGL/ExtensionHandler.h | 12 +++- source/Irrlicht/OpenGL3/Driver.cpp | 27 +++++++++ source/Irrlicht/OpenGL3/Driver.h | 1 + source/Irrlicht/OpenGLES2/Driver.cpp | 35 +++++++++++ source/Irrlicht/OpenGLES2/Driver.h | 1 + 8 files changed, 102 insertions(+), 45 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index e47fc73..4148657 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -217,7 +217,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) { initVersion(); - initExtensions(); + initFeatures(); // reset cache handler delete CacheHandler; diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 1122c79..b0ba42b 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -288,6 +288,8 @@ namespace video void initVersion(); virtual OpenGLVersion getVersionFromOpenGL() const = 0; + virtual void initFeatures() = 0; + void chooseMaterial2D(); ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index b9cb75a..f9858be 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -15,52 +15,33 @@ namespace irr { namespace video { - void COpenGL3ExtensionHandler::initExtensions() + void COpenGL3ExtensionHandler::initExtensionsOld() { - GLint major, minor; - glGetIntegerv(GL_MAJOR_VERSION, &major); - glGetIntegerv(GL_MINOR_VERSION, &minor); - Version = 100 * major + 10 * minor; - - GLint ext_count = 0; - GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); - for (int k = 0; k < ext_count; k++) { - auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k); - for (size_t j=0; j(glGetString(GL_EXTENSIONS)); + const char *pos = extensions_string; + while (const char *next = strchr(pos, ' ')) { + std::string name{pos, next}; + addExtension(name.c_str()); + pos = next + 1; } - - GLint val=0; - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val); - Feature.MaxTextureUnits = static_cast(val); - - #ifdef GL_EXT_texture_filter_anisotropic - if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) - { - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val); - MaxAnisotropy = static_cast(val); - } - #endif - #ifdef GL_MAX_ELEMENTS_INDICES - glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val); - MaxIndices=val; - #endif - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val); - MaxTextureSize=static_cast(val); - #ifdef GL_EXT_texture_lod_bias - if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias]) - glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias); - #endif - glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); - glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); - - Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast(MATERIAL_MAX_TEXTURES)); - Feature.ColorAttachment = 1; + addExtension(pos); } + void COpenGL3ExtensionHandler::initExtensionsNew() + { + GLint ext_count = 0; + GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); + for (int k = 0; k < ext_count; k++) + addExtension(reinterpret_cast(GL.GetStringi(GL_EXTENSIONS, k))); + } + + void COpenGL3ExtensionHandler::addExtension(const char *name) { + for (size_t j=0; j= 3); + initExtensionsNew(); + + // COGLESCoreExtensionHandler::Feature + static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); + Feature.BlendOperation = true; + Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; + Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + + // COGLESCoreExtensionHandler + if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) + MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); + DimAliasedPoint[0] = 1.0f; + DimAliasedPoint[1] = 1.0f; + + GLint val = 0; + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val); + StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT; + } + IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { os::Printer::log("Using COpenGL3Driver", ELL_INFORMATION); diff --git a/source/Irrlicht/OpenGL3/Driver.h b/source/Irrlicht/OpenGL3/Driver.h index 66dc01b..ca9e94a 100644 --- a/source/Irrlicht/OpenGL3/Driver.h +++ b/source/Irrlicht/OpenGL3/Driver.h @@ -19,6 +19,7 @@ namespace video { protected: OpenGLVersion getVersionFromOpenGL() const override; + void initFeatures() override; }; } diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 2e293fe..085b445 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -21,6 +21,41 @@ namespace video { return {OpenGLSpec::ES, (u8)major, (u8)minor, 0}; } + void COpenGLES2Driver::initFeatures() { + assert (Version.Major >= 2); + if (Version.Major >= 3) + initExtensionsNew(); + else + initExtensionsOld(); + + // COGLESCoreExtensionHandler::Feature + static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed"); + Feature.BlendOperation = true; + Feature.ColorAttachment = 1; + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers]) + Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers]) + Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + + // COGLESCoreExtensionHandler + if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) + MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_range_elements]) + MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias]) + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); + + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_ARB_framebuffer_object]) { + GLint val = 0; + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val); + StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT; + } + } + IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { os::Printer::log("Using COpenGLES2Driver", ELL_INFORMATION); diff --git a/source/Irrlicht/OpenGLES2/Driver.h b/source/Irrlicht/OpenGLES2/Driver.h index 3dc234d..327b4cf 100644 --- a/source/Irrlicht/OpenGLES2/Driver.h +++ b/source/Irrlicht/OpenGLES2/Driver.h @@ -19,6 +19,7 @@ namespace video { protected: OpenGLVersion getVersionFromOpenGL() const override; + void initFeatures() override; }; }