From 03affa1bbb9211011350a4a8f3ece1ed8963ee2b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 31 Mar 2025 18:01:51 +0200 Subject: [PATCH] Some minor code cleanups --- .../shaders/nodes_shader/opengl_vertex.glsl | 2 - irr/include/IImage.h | 1 - irr/include/ITexture.h | 40 +------------------ irr/include/vector3d.h | 20 ---------- irr/src/CGUIFont.cpp | 4 +- irr/src/CImage.cpp | 5 ++- irr/src/CNullDriver.cpp | 16 ++------ irr/src/COpenGLCoreTexture.h | 20 ++++------ irr/src/OpenGL3/Driver.cpp | 3 +- irr/src/OpenGLES2/Driver.cpp | 2 +- src/client/content_mapblock.cpp | 2 +- src/client/mapblock_mesh.cpp | 2 +- src/client/meshgen/collector.cpp | 2 +- src/irrlicht_changes/CGUITTFont.cpp | 2 + src/irrlicht_changes/CGUITTFont.h | 6 ++- 15 files changed, 29 insertions(+), 98 deletions(-) diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index 0f508dc6a..6fe7acd85 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -44,8 +44,6 @@ centroid varying float nightRatio; varying float perspective_factor; #endif -varying float area_enable_parallax; - varying highp vec3 eyeVec; // Color of the light emitted by the light sources. const vec3 artificialLight = vec3(1.04, 1.04, 1.04); diff --git a/irr/include/IImage.h b/irr/include/IImage.h index a303201a9..a0adae506 100644 --- a/irr/include/IImage.h +++ b/irr/include/IImage.h @@ -56,7 +56,6 @@ public: //! Returns bits per pixel. u32 getBitsPerPixel() const { - return getBitsPerPixelFromFormat(Format); } diff --git a/irr/include/ITexture.h b/irr/include/ITexture.h index 869a325e0..fec69e4b1 100644 --- a/irr/include/ITexture.h +++ b/irr/include/ITexture.h @@ -68,30 +68,12 @@ enum E_TEXTURE_CREATION_FLAG not recommended to enable this flag. */ ETCF_NO_ALPHA_CHANNEL = 0x00000020, - //! Allow the Driver to use Non-Power-2-Textures - /** BurningVideo can handle Non-Power-2 Textures in 2D (GUI), but not in 3D. */ - ETCF_ALLOW_NON_POWER_2 = 0x00000040, - //! Allow the driver to keep a copy of the texture in memory /** Enabling this makes calls to ITexture::lock a lot faster, but costs main memory. This is disabled by default. */ ETCF_ALLOW_MEMORY_COPY = 0x00000080, - //! Enable automatic updating mip maps when the base texture changes. - /** Default is true. - This flag is only used when ETCF_CREATE_MIP_MAPS is also enabled and if the driver supports it. - Please note: - - On D3D (and maybe older OGL?) you can no longer manually set mipmap data when enabled - (for example mips from image loading will be ignored). - - On D3D (and maybe older OGL?) texture locking for mipmap levels usually won't work anymore. - - On new OGL this flag is ignored. - - When disabled you do _not_ get hardware mipmaps on D3D, so mipmap generation can be slower. - - When disabled you can still update your mipmaps when the texture changed by manually calling regenerateMipMapLevels. - - You can still call regenerateMipMapLevels when this flag is enabled (it will be a hint on d3d to update mips immediately) - */ - ETCF_AUTO_GENERATE_MIP_MAPS = 0x00000100, - /** This flag is never used, it only forces the compiler to compile these enumeration values to 32 bit. */ ETCF_FORCE_32_BIT_DO_NOT_USE = 0x7fffffff @@ -137,19 +119,6 @@ enum E_TEXTURE_LOCK_FLAGS ETLF_FLIP_Y_UP_RTT = 1 }; -//! Where did the last IVideoDriver::getTexture call find this texture -enum E_TEXTURE_SOURCE -{ - //! IVideoDriver::getTexture was never called (texture created otherwise) - ETS_UNKNOWN, - - //! Texture has been found in cache - ETS_FROM_CACHE, - - //! Texture had to be loaded - ETS_FROM_FILE -}; - //! Enumeration describing the type of ITexture. enum E_TEXTURE_TYPE { @@ -178,7 +147,7 @@ public: //! constructor ITexture(const io::path &name, E_TEXTURE_TYPE type) : NamedPath(name), DriverType(EDT_NULL), OriginalColorFormat(ECF_UNKNOWN), - ColorFormat(ECF_UNKNOWN), Pitch(0), HasMipMaps(false), IsRenderTarget(false), Source(ETS_UNKNOWN), Type(type) + ColorFormat(ECF_UNKNOWN), Pitch(0), HasMipMaps(false), IsRenderTarget(false), Type(type) { } @@ -275,12 +244,6 @@ public: //! Get name of texture (in most cases this is the filename) const io::SNamedPath &getName() const { return NamedPath; } - //! Check where the last IVideoDriver::getTexture found this texture - E_TEXTURE_SOURCE getSource() const { return Source; } - - //! Used internally by the engine to update Source status on IVideoDriver::getTexture calls. - void updateSource(E_TEXTURE_SOURCE source) { Source = source; } - //! Returns if the texture has an alpha channel bool hasAlpha() const { @@ -329,7 +292,6 @@ protected: u32 Pitch; bool HasMipMaps; bool IsRenderTarget; - E_TEXTURE_SOURCE Source; E_TEXTURE_TYPE Type; }; diff --git a/irr/include/vector3d.h b/irr/include/vector3d.h index 562efb2d6..9bacf977e 100644 --- a/irr/include/vector3d.h +++ b/irr/include/vector3d.h @@ -464,26 +464,6 @@ public: forwards.Z * pseudoMatrix[8])); } - //! Fills an array of 4 values with the vector data (usually floats). - /** Useful for setting in shader constants for example. The fourth value - will always be 0. */ - void getAs4Values(T *array) const - { - array[0] = X; - array[1] = Y; - array[2] = Z; - array[3] = 0; - } - - //! Fills an array of 3 values with the vector data (usually floats). - /** Useful for setting in shader constants for example.*/ - void getAs3Values(T *array) const - { - array[0] = X; - array[1] = Y; - array[2] = Z; - } - //! X coordinate of the vector T X; diff --git a/irr/src/CGUIFont.cpp b/irr/src/CGUIFont.cpp index 951304476..9d8b1d488 100644 --- a/irr/src/CGUIFont.cpp +++ b/irr/src/CGUIFont.cpp @@ -71,18 +71,16 @@ void CGUIFont::setMaxHeight() void CGUIFont::pushTextureCreationFlags(bool (&flags)[3]) { - flags[0] = Driver->getTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2); + flags[0] = false; flags[1] = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); flags[2] = Driver->getTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY); - Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, true); Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); Driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, true); } void CGUIFont::popTextureCreationFlags(const bool (&flags)[3]) { - Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, flags[0]); Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flags[1]); Driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, flags[2]); } diff --git a/irr/src/CImage.cpp b/irr/src/CImage.cpp index 0c6d705f3..de4df0c0f 100644 --- a/irr/src/CImage.cpp +++ b/irr/src/CImage.cpp @@ -20,7 +20,10 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d &size, void *d IImage(format, size, deleteMemory) { if (ownForeignMemory) { - Data = (u8 *)data; + _IRR_DEBUG_BREAK_IF(!data) + Data = reinterpret_cast(data); + if (reinterpret_cast(data) % sizeof(u32) != 0) + os::Printer::log("CImage created with foreign memory that's not aligned", ELL_WARNING); } else { const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height); const u32 allocSize = align_next(dataSize, 16); diff --git a/irr/src/CNullDriver.cpp b/irr/src/CNullDriver.cpp index 6f44fc4e6..59487c5b0 100644 --- a/irr/src/CNullDriver.cpp +++ b/irr/src/CNullDriver.cpp @@ -71,7 +71,6 @@ CNullDriver::CNullDriver(io::IFileSystem *io, const core::dimension2d &scre setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true); setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true); - setTextureCreationFlag(ETCF_AUTO_GENERATE_MIP_MAPS, true); setTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY, false); ViewPort = core::rect(core::position2d(0, 0), core::dimension2di(screenSize)); @@ -406,17 +405,13 @@ ITexture *CNullDriver::getTexture(const io::path &filename) const io::path absolutePath = FileSystem->getAbsolutePath(filename); ITexture *texture = findTexture(absolutePath); - if (texture) { - texture->updateSource(ETS_FROM_CACHE); + if (texture) return texture; - } // Then try the raw filename, which might be in an Archive texture = findTexture(filename); - if (texture) { - texture->updateSource(ETS_FROM_CACHE); + if (texture) return texture; - } // Now try to open the file using the complete path. io::IReadFile *file = FileSystem->createAndOpenFile(absolutePath); @@ -430,7 +425,6 @@ ITexture *CNullDriver::getTexture(const io::path &filename) // Re-check name for actual archive names texture = findTexture(file->getFileName()); if (texture) { - texture->updateSource(ETS_FROM_CACHE); file->drop(); return texture; } @@ -439,7 +433,6 @@ ITexture *CNullDriver::getTexture(const io::path &filename) file->drop(); if (texture) { - texture->updateSource(ETS_FROM_FILE); addTexture(texture); texture->drop(); // drop it because we created it, one grab too much } else @@ -459,15 +452,12 @@ ITexture *CNullDriver::getTexture(io::IReadFile *file) if (file) { texture = findTexture(file->getFileName()); - if (texture) { - texture->updateSource(ETS_FROM_CACHE); + if (texture) return texture; - } texture = loadTextureFromFile(file); if (texture) { - texture->updateSource(ETS_FROM_FILE); addTexture(texture); texture->drop(); // drop it because we created it, one grab too much } diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h index 1b02c9234..506d078cb 100644 --- a/irr/src/COpenGLCoreTexture.h +++ b/irr/src/COpenGLCoreTexture.h @@ -51,7 +51,7 @@ public: _IRR_DEBUG_BREAK_IF(srcImages.empty()) DriverType = Driver->getDriverType(); - _IRR_DEBUG_BREAK_IF(Type == ETT_2D_MS); // not supported by this constructor + _IRR_DEBUG_BREAK_IF(Type == ETT_2D_MS) // not supported by this constructor TextureType = TextureTypeIrrToGL(Type); HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); KeepImage = Driver->getTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY); @@ -60,7 +60,6 @@ public: if (!InternalFormat) return; -#ifdef _DEBUG char lbuf[128]; snprintf_irr(lbuf, sizeof(lbuf), "COpenGLCoreTexture: Type = %d Size = %dx%d (%dx%d) ColorFormat = %d (%d)%s -> %#06x %#06x %#06x%s", @@ -70,7 +69,6 @@ public: InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : "" ); os::Printer::log(lbuf, ELL_DEBUG); -#endif const auto *tmpImages = &srcImages; @@ -111,7 +109,6 @@ public: GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); -#ifdef GL_GENERATE_MIPMAP_HINT if (HasMipMaps) { if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); @@ -120,8 +117,6 @@ public: else GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); } -#endif - TEST_GL_ERROR(Driver); for (size_t i = 0; i < tmpImages->size(); ++i) @@ -189,7 +184,6 @@ public: } #endif -#ifdef _DEBUG char lbuf[100]; snprintf_irr(lbuf, sizeof(lbuf), "COpenGLCoreTexture: RTT Type = %d Size = %dx%d ColorFormat = %d -> %#06x %#06x %#06x%s", @@ -197,7 +191,6 @@ public: InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : "" ); os::Printer::log(lbuf, ELL_DEBUG); -#endif GL.GenTextures(1, &TextureName); TEST_GL_ERROR(Driver); @@ -218,10 +211,7 @@ public: GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - -#if defined(GL_VERSION_1_2) GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); -#endif StatesCache.WrapU = ETC_CLAMP_TO_EDGE; StatesCache.WrapV = ETC_CLAMP_TO_EDGE; @@ -258,6 +248,9 @@ public: GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); break; + default: + _IRR_DEBUG_BREAK_IF(1) + break; } if (!name.empty()) @@ -306,6 +299,7 @@ public: if (!LockImage) { core::dimension2d lockImageSize(IImage::getMipMapsSize(Size, MipLevelStored)); + _IRR_DEBUG_BREAK_IF(lockImageSize.Width == 0 || lockImageSize.Height == 0) // note: we save mipmap data also in the image because IImage doesn't allow saving single mipmap levels to the mipmap data LockImage = Driver->createImage(ColorFormat, lockImageSize); @@ -321,7 +315,7 @@ public: if (use_gl_impl) { - IImage *tmpImage = LockImage; // not sure yet if the size required by glGetTexImage is always correct, if not we might have to allocate a different tmpImage and convert colors later on. + IImage *tmpImage = LockImage; Driver->getCacheHandler()->getTextureCache().set(0, this); TEST_GL_ERROR(Driver); @@ -620,6 +614,7 @@ protected: TEST_GL_ERROR(Driver); break; default: + _IRR_DEBUG_BREAK_IF(1) break; } @@ -637,6 +632,7 @@ protected: TEST_GL_ERROR(Driver); break; default: + _IRR_DEBUG_BREAK_IF(1) break; } } diff --git a/irr/src/OpenGL3/Driver.cpp b/irr/src/OpenGL3/Driver.cpp index 7a62f4a12..43ee9ba45 100644 --- a/irr/src/OpenGL3/Driver.cpp +++ b/irr/src/OpenGL3/Driver.cpp @@ -50,8 +50,7 @@ void COpenGL3Driver::initFeatures() 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_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}; TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; diff --git a/irr/src/OpenGLES2/Driver.cpp b/irr/src/OpenGLES2/Driver.cpp index 6b234842a..7c98fca8d 100644 --- a/irr/src/OpenGLES2/Driver.cpp +++ b/irr/src/OpenGLES2/Driver.cpp @@ -146,7 +146,7 @@ void COpenGLES2Driver::initFeatures() MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); if (LODBiasSupported) GL.GetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); - GL.GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... + GL.GetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); GL.GetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); } diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 71068d13e..f5b528287 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -103,7 +103,7 @@ void MapblockMeshGenerator::getSpecialTile(int index, TileSpec *tile_ret, bool a for (auto &layernum : tile_ret->layers) { TileLayer *layer = &layernum; - if (layer->texture_id == 0) + if (layer->empty()) continue; top_layer = layer; if (!layer->has_color) diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index a53a5c073..a84747188 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -347,7 +347,7 @@ void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, tile = f.tiles[tileindex]; bool has_crack = p == data->m_crack_pos_relative; for (TileLayer &layer : tile.layers) { - if (layer.texture_id == 0) + if (layer.empty()) continue; if (!layer.has_color) mn.getColor(f, &(layer.color)); diff --git a/src/client/meshgen/collector.cpp b/src/client/meshgen/collector.cpp index 5a4fb8489..c8b726cde 100644 --- a/src/client/meshgen/collector.cpp +++ b/src/client/meshgen/collector.cpp @@ -12,7 +12,7 @@ void MeshCollector::append(const TileSpec &tile, const video::S3DVertex *vertice { for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) { const TileLayer *layer = &tile.layers[layernum]; - if (layer->texture_id == 0) + if (layer->empty()) continue; append(*layer, vertices, numVertices, indices, numIndices, layernum, tile.world_aligned); diff --git a/src/irrlicht_changes/CGUITTFont.cpp b/src/irrlicht_changes/CGUITTFont.cpp index 4c07da140..ab5aeb091 100644 --- a/src/irrlicht_changes/CGUITTFont.cpp +++ b/src/irrlicht_changes/CGUITTFont.cpp @@ -897,6 +897,8 @@ video::IImage* CGUITTFont::createTextureFromChar(const char32_t& ch) // Acquire a read-only lock of the corresponding page texture. void* ptr = tex->lock(video::ETLM_READ_ONLY); + if (!ptr) + return nullptr; video::ECOLOR_FORMAT format = tex->getColorFormat(); core::dimension2du tex_size = tex->getOriginalSize(); diff --git a/src/irrlicht_changes/CGUITTFont.h b/src/irrlicht_changes/CGUITTFont.h index ffdd6a6ca..082942856 100644 --- a/src/irrlicht_changes/CGUITTFont.h +++ b/src/irrlicht_changes/CGUITTFont.h @@ -200,9 +200,13 @@ namespace gui //! Updates the texture atlas with new glyphs. void updateTexture() { - if (!dirty) return; + if (!dirty) + return; void* ptr = texture->lock(); + if (!ptr) + return; + video::ECOLOR_FORMAT format = texture->getColorFormat(); core::dimension2du size = texture->getOriginalSize(); video::IImage* pageholder = driver->createImageFromData(format, size, ptr, true, false);