From 8d2e7703619205dd76ee9cc12fb0b660868c910b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 15 Nov 2024 13:37:16 +0100 Subject: [PATCH] Minor corrections in gl3/gles2 drivers --- irr/src/CNullDriver.cpp | 7 ++++--- irr/src/OpenGL/Driver.cpp | 14 +++----------- irr/src/OpenGL/MaterialRenderer.cpp | 2 +- irr/src/OpenGL3/Driver.cpp | 14 +++++++++----- irr/src/OpenGLES2/Driver.cpp | 18 ++++++++++++++---- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/irr/src/CNullDriver.cpp b/irr/src/CNullDriver.cpp index 46a2d9f7b..acce8383b 100644 --- a/irr/src/CNullDriver.cpp +++ b/irr/src/CNullDriver.cpp @@ -936,9 +936,10 @@ void CNullDriver::setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enab setTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED, false); } - // set flag - TextureCreationFlags = (TextureCreationFlags & (~flag)) | - ((((u32)!enabled) - 1) & flag); + if (enabled) + TextureCreationFlags |= flag; + else + TextureCreationFlags &= ~flag; } //! Returns if a texture creation flag is enabled or disabled. diff --git a/irr/src/OpenGL/Driver.cpp b/irr/src/OpenGL/Driver.cpp index 4f3ac627a..4b85b1345 100644 --- a/irr/src/OpenGL/Driver.cpp +++ b/irr/src/OpenGL/Driver.cpp @@ -144,7 +144,7 @@ void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum s ll = ELL_ERROR; else if (severity == GL_DEBUG_SEVERITY_MEDIUM) ll = ELL_WARNING; - char buf[256]; + char buf[300]; snprintf_irr(buf, sizeof(buf), "%04x %04x %.*s", source, type, length, message); os::Printer::log("GL", buf, ll); } @@ -700,15 +700,7 @@ void COpenGL3DriverBase::drawVertexPrimitiveList(const void *vertices, u32 verte break; } case (EIT_32BIT): { -#ifdef GL_OES_element_index_uint -#ifndef GL_UNSIGNED_INT -#define GL_UNSIGNED_INT 0x1405 -#endif - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_element_index_uint]) - indexSize = GL_UNSIGNED_INT; - else -#endif - indexSize = GL_UNSIGNED_SHORT; + indexSize = GL_UNSIGNED_INT; break; } } @@ -1683,7 +1675,7 @@ ITexture *COpenGL3DriverBase::addRenderTargetTextureCubemap(const irr::u32 sideL //! Returns the maximum amount of primitives u32 COpenGL3DriverBase::getMaximalPrimitiveCount() const { - return 65535; + return Version.Spec == OpenGLSpec::ES ? 65535 : 0x7fffffff; } bool COpenGL3DriverBase::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) diff --git a/irr/src/OpenGL/MaterialRenderer.cpp b/irr/src/OpenGL/MaterialRenderer.cpp index 3c32ba318..d5bf9004a 100644 --- a/irr/src/OpenGL/MaterialRenderer.cpp +++ b/irr/src/OpenGL/MaterialRenderer.cpp @@ -411,7 +411,7 @@ bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const s32 *ints bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const u32 *ints, int count) { - os::Printer::log("Unsigned int support needs at least GLES 3.0", ELL_WARNING); + os::Printer::log("Unsigned int support is unimplemented", ELL_WARNING); return false; } diff --git a/irr/src/OpenGL3/Driver.cpp b/irr/src/OpenGL3/Driver.cpp index a58e1542f..ac0816445 100644 --- a/irr/src/OpenGL3/Driver.cpp +++ b/irr/src/OpenGL3/Driver.cpp @@ -4,6 +4,7 @@ #include "Driver.h" #include +#include #include "mt_opengl.h" namespace irr @@ -18,7 +19,7 @@ E_DRIVER_TYPE COpenGL3Driver::getDriverType() const OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const { - GLint major, minor, profile; + GLint major = 0, minor = 0, profile = 0; GL.GetIntegerv(GL_MAJOR_VERSION, &major); GL.GetIntegerv(GL_MINOR_VERSION, &minor); GL.GetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile); @@ -35,18 +36,21 @@ OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const void COpenGL3Driver::initFeatures() { if (Version.Spec != OpenGLSpec::Compat) { - os::Printer::log("OpenGL 3 driver requires Compatibility Mode", ELL_ERROR); - throw std::exception(); + auto msg = "OpenGL 3 driver requires Compatibility context"; + os::Printer::log(msg, ELL_ERROR); + throw std::runtime_error(msg); } if (!isVersionAtLeast(3, 2)) { - os::Printer::log("OpenGL 3 driver requires OpenGL >= 3.2 ", ELL_ERROR); - throw std::exception(); + auto msg = "OpenGL 3 driver requires OpenGL >= 3.2"; + os::Printer::log(msg, ELL_ERROR); + throw std::runtime_error(msg); } 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 TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; // WARNING: may not be renderable + // FIXME: shouldn't this simply be GL_UNSIGNED_BYTE? TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}; TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; diff --git a/irr/src/OpenGLES2/Driver.cpp b/irr/src/OpenGLES2/Driver.cpp index e423abb2e..430be736d 100644 --- a/irr/src/OpenGLES2/Driver.cpp +++ b/irr/src/OpenGLES2/Driver.cpp @@ -3,8 +3,10 @@ // For conditions of distribution and use, see copyright notice in Irrlicht.h #include "Driver.h" +#include #include -#include +#include "mt_opengl.h" +#include "CColorConverter.h" namespace irr { @@ -19,7 +21,7 @@ E_DRIVER_TYPE COpenGLES2Driver::getDriverType() const OpenGLVersion COpenGLES2Driver::getVersionFromOpenGL() const { auto version_string = reinterpret_cast(GL.GetString(GL_VERSION)); - int major, minor; + int major = 0, minor = 0; if (sscanf(version_string, "OpenGL ES %d.%d", &major, &minor) != 2) { os::Printer::log("Failed to parse OpenGL ES version string", version_string, ELL_ERROR); return {OpenGLSpec::ES, 0, 0, 0}; @@ -29,8 +31,16 @@ OpenGLVersion COpenGLES2Driver::getVersionFromOpenGL() const void COpenGLES2Driver::initFeatures() { - assert(Version.Spec == OpenGLSpec::ES); - assert(Version.Major >= 2); + if (Version.Spec != OpenGLSpec::ES) { + auto msg = "Context isn't OpenGL ES"; + os::Printer::log(msg, ELL_ERROR); + throw std::runtime_error(msg); + } + if (!isVersionAtLeast(2, 0)) { + auto msg = "Open GL ES 2.0 is required"; + os::Printer::log(msg, ELL_ERROR); + throw std::runtime_error(msg); + } initExtensions(); static const GLenum BGRA8_EXT = 0x93A1;