From 4aae31ad5e093308d10bbc956f42a6bfe98e516d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 8 Nov 2024 12:27:51 +0100 Subject: [PATCH] Add support for ECF_D24 texture format and prefer it over D32 for our depth buffer, this can have performance benefits --- irr/include/IImage.h | 3 +++ irr/include/SColor.h | 4 ++++ irr/src/OpenGL3/Driver.cpp | 1 + irr/src/OpenGLES2/Driver.cpp | 1 + src/client/render/plain.cpp | 4 ++-- src/client/render/secondstage.cpp | 4 ++++ 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/irr/include/IImage.h b/irr/include/IImage.h index f3c29b71d..47349ed1a 100644 --- a/irr/include/IImage.h +++ b/irr/include/IImage.h @@ -328,6 +328,8 @@ public: return 32; case ECF_D16: return 16; + case ECF_D24: + return 32; case ECF_D32: return 32; case ECF_D24S8: @@ -378,6 +380,7 @@ public: { switch (format) { case ECF_D16: + case ECF_D24: case ECF_D32: case ECF_D24S8: return true; diff --git a/irr/include/SColor.h b/irr/include/SColor.h index 284ab3351..a2dd52603 100644 --- a/irr/include/SColor.h +++ b/irr/include/SColor.h @@ -77,6 +77,9 @@ enum ECOLOR_FORMAT //! 16 bit format using 16 bits for depth. ECF_D16, + //! 32 bit(?) format using 24 bits for depth. + ECF_D24, + //! 32 bit format using 32 bits for depth. ECF_D32, @@ -104,6 +107,7 @@ const c8 *const ColorFormatNames[ECF_UNKNOWN + 2] = { "R16", "R16G16", "D16", + "D24", "D32", "D24S8", "UNKNOWN", diff --git a/irr/src/OpenGL3/Driver.cpp b/irr/src/OpenGL3/Driver.cpp index 53cb8c7ed..a58e1542f 100644 --- a/irr/src/OpenGL3/Driver.cpp +++ b/irr/src/OpenGL3/Driver.cpp @@ -59,6 +59,7 @@ void COpenGL3Driver::initFeatures() TextureFormats[ECF_R16] = {GL_R16, GL_RED, GL_UNSIGNED_SHORT}; TextureFormats[ECF_R16G16] = {GL_RG16, GL_RG, GL_UNSIGNED_SHORT}; TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D24] = {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; // WARNING: may not be renderable (?!) TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; diff --git a/irr/src/OpenGLES2/Driver.cpp b/irr/src/OpenGLES2/Driver.cpp index 9a99601fd..e423abb2e 100644 --- a/irr/src/OpenGLES2/Driver.cpp +++ b/irr/src/OpenGLES2/Driver.cpp @@ -50,6 +50,7 @@ void COpenGLES2Driver::initFeatures() TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D24] = {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) diff --git a/src/client/render/plain.cpp b/src/client/render/plain.cpp index 22b167518..fd3e0b9ba 100644 --- a/src/client/render/plain.cpp +++ b/src/client/render/plain.cpp @@ -162,8 +162,8 @@ video::ECOLOR_FORMAT selectColorFormat(video::IVideoDriver *driver) video::ECOLOR_FORMAT selectDepthFormat(video::IVideoDriver *driver) { - if (driver->queryTextureFormat(video::ECF_D32)) - return video::ECF_D32; + if (driver->queryTextureFormat(video::ECF_D24)) + return video::ECF_D24; if (driver->queryTextureFormat(video::ECF_D24S8)) return video::ECF_D24S8; return video::ECF_D16; // fallback depth format diff --git a/src/client/render/secondstage.cpp b/src/client/render/secondstage.cpp index 212074535..26ce6888e 100644 --- a/src/client/render/secondstage.cpp +++ b/src/client/render/secondstage.cpp @@ -90,6 +90,10 @@ RenderStep *addPostProcessing(RenderPipeline *pipeline, RenderStep *previousStep video::ECOLOR_FORMAT color_format = selectColorFormat(driver); video::ECOLOR_FORMAT depth_format = selectDepthFormat(driver); + verbosestream << "addPostProcessing(): color = " + << video::ColorFormatNames[color_format] << " depth = " + << video::ColorFormatNames[depth_format] << std::endl; + // init post-processing buffer static const u8 TEXTURE_COLOR = 0; static const u8 TEXTURE_DEPTH = 1;