D3DXCreateTextureFromFileEx

This topic is 2651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

The total size of those jpg images is about 20MB.
But post loading those files, the memory taken by my program becomes 700MB.

I have tried to remove everything else and just load these textures, it is still taking that much memory,

ANy help would be greatly appreciated.

Share on other sites
The GPU doesn't work with compressed images (Except for DDS), so any compressed file you load will be uncompressed when loaded to a texture.

You can choose the format you load the images as if you use D3DXCreateTextureFromFileEx, and specify a value for Format. The Compressed Formats may be of use.

Share on other sites
Are you using 300 texture at the same time? If not ( I hope so ) I recommend loading these texture at run time. For instance load 100 etc at first time. At this first load you use textures which are likely used most. Then you load other textures at the time when you need it.

As far as I know DirectX also has compressed texture format ( 4x4 texel compressed format) Check DirectX SDK out.

Share on other sites
Quote:
 Original post by Evil SteveThe GPU doesn't work with compressed images (Except for DDS), so any compressed file you load will be uncompressed when loaded to a texture.You can choose the format you load the images as if you use D3DXCreateTextureFromFileEx, and specify a value for Format. The Compressed Formats may be of use.

Thank you a lot for the guidance, using a different format has made significant difference. It has brought down the memory usage by about 40%.

I am still aimiing to bring it down another 25-30% so am still looking at further methods.

Share on other sites
Quote:
 Original post by onozkanAre you using 300 texture at the same time? If not ( I hope so ) I recommend loading these texture at run time. For instance load 100 etc at first time. At this first load you use textures which are likely used most. Then you load other textures at the time when you need it.As far as I know DirectX also has compressed texture format ( 4x4 texel compressed format) Check DirectX SDK out.

Unfortunately I have to load all the 300 textures at the begining and am unable to defer their loading in batches. Still using the compressed format D3DFMT_DXT4 has helped reduce the memory usage by a significant amount.

But i am still aiming for better results.

Share on other sites
There's 2 ways you can reduce your memory usage further:
1. Compress the data further
2. Use less data

For #1, you can use DXT1 if you don't require alpha in your image (Which I assume is the case since you're using JPEG images as a source). DXT1 is half the size of DXT4.

For #2, you can resize the images you're loading, create the textures without mipmaps (Specify 1 for the MipLevels parameter), or load fewer of them, and stream them in as required.

Apart from that, there's no way to reduce the memory usage - there's a fixed amount of data, it takes a fixed amount of space.

Share on other sites
If you have many small textures for one item that only use UV between 0 and 1, place them into a large texture atlas to make editing textures simpler, improve performance and reduce the number of resource views.

If you have the same texture in many different colors, use this blending formula in the shader after sampling the diffuse texture so that special colors can be changed per instance.
vFinalDiffuse = (vOriginalDiffuse.r) + (m_vPrimaryColor * (vOriginalDiffuse.g - vOriginalDiffuse.r)) + (m_vSecondaryColor * (vOriginalDiffuse.b - vOriginalDiffuse.r));

Documentation from my engine:
//Primary and secondary colors//	It is a system for using the same models and textures for different instances with different colors.//	This is the mathematical formula that makes it possible to use 2 special colors on each instance without having their own polygons or skins.//		Complex notation//			Output = Input.r + (PrimaryColor * (Input.g - Input.r)) + (SecondaryColor * (Input.b - Input.r));//		Simple notation//			Output.r = Input.r + (PrimaryColor.r * (Input.g - Input.r)) + (SecondaryColor.r * (Input.b - Input.r));//			Output.g = Input.r + (PrimaryColor.g * (Input.g - Input.r)) + (SecondaryColor.g * (Input.b - Input.r));//			Output.b = Input.r + (PrimaryColor.b * (Input.g - Input.r)) + (SecondaryColor.b * (Input.b - Input.r));//	It works by using the red channel as a grayscale and adding each special color multiplied with the brightness above the red base.//		PrimaryColor sets the color of green areas and SecondaryColor sets the color of blue areas.//		Setting PrimaryColor to green and SecondaryColor to blue will not make a difference because green will remain green and blue will remain blue.//		Mixing green and blue will show a mix of the selected PrimaryColor and SecondaryColor.//		Using extra bright colors is allowed and can be used for flashing a lamp in different colors.//		Setting both colors to black will only show the red channel as a grayscale.//	To draw a texture for the blending system, start with a grayscale image and paint//	  with green and blue as if you had chosen green and blue as the final colors.//	Just remember not to use any other color since they will mess up the image.