Allow custom CJ clothing textures of any size and format (DXT, up to 1024×1024)#4958
Open
TheCrazy17 wants to merge 1 commit into
Open
Allow custom CJ clothing textures of any size and format (DXT, up to 1024×1024)#4958TheCrazy17 wants to merge 1 commit into
TheCrazy17 wants to merge 1 commit into
Conversation
GTA SA builds CJ clothing by compositing several textures together on the CPU (body skin + fat/muscle variants + clothing design) into one texture per body part, via CClothesBuilder. That CPU compositing assumes every texture taking part has identical dimensions and is uncompressed 32bpp. So, unlike normal model/vehicle textures (which the GPU samples directly in any format), a custom clothing texture imported with engineImportTXD had to be exactly 256x256 32bpp - anything else corrupted the composite or wrote past the destination buffer and silently crashed the game. This reimplements the five clothes texture compositing primitives (CopyTexture, PlaceTextureOnTopOfTexture and the three BlendTextures variants) in a resolution- and format-agnostic way: - Sizes are equalized per composite: the owned accumulator raster is grown in place and shared source textures are resampled into temporaries, so the composite runs at a common resolution of min(max(all sizes), 1024). An all-vanilla ped stays 256x256 with no extra cost; it only grows when a larger texture is actually used. - Non-32bpp sources (e.g. DXT1/3/5) are decompressed to A8R8G8B8 on the fly, in memory, only at composite time. The replacement TXD is therefore stored and streamed as-is, exactly like any other engineImportTXD - no up-front re-encoding and no temporary files on disk. Details: - New CRenderWareSA.ClothesTextures.cpp with the reimplemented primitives, installed from StaticSetClothesReplacingHooks. - CGraphics::ResizeTextureData gains an optional target format and uses D3DXLoadSurfaceFromMemory to decode/decompress the source in one step. - CreateResizedTexture extracted from RightSizeTexture; the conversion case builds the texture directly via RwRasterCreate. - Add RwRasterDestroy to the RenderWare function table. - Remove the now-redundant CopyTexture null-check hook from CMultiplayerSA_ClothesSpeedUp.cpp (folded into the new CopyTexture).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
You can now import custom CJ clothing textures of any size (up to 1024×1024) and any format (DXT1/DXT3/DXT5, raster, etc.) with
engineImportTXD, just like any other texture. Before, clothing textures had to be exactly the vanilla 256×256 — anything else showed up garbled or silently crashed the game.Motivation
Resolves the silent crash when importing custom CJ clothing textures (Fixes #4417).
Normal textures (vehicles, objects, etc.) are handed straight to the GPU, so they accept any size or format. CJ clothing is special: the game mixes several textures together into one before putting it on the model, and that mixing only worked when every texture was the exact same size and uncompressed. So a bigger or compressed clothing texture broke it — or crashed the game outright.
This makes the clothing textures get resized and decompressed automatically when needed, so importing them now works like any other texture.
Why the 1024×1024 limit? It's just a safe default and can be raised easily. Bigger clothing textures use noticeably more memory, so a cap avoids problems on lower-end setups. It's not unlimited for the same reason — a huge texture could eat too much memory. Normal clothing isn't affected: it only uses more memory when you actually import something bigger.
Test plan
engineImportTXD— any size (up to 1024×1024) and any format (normal/raster or DXT1/DXT3/DXT5) — and equip it on a CJ. The texture should show correctly and the game should no longer crash.player.imgand import everything at once — it should not crash.Checklist