loading texture info

Started by
6 comments, last by feal87 15 years ago
Hi guys! I have a few questions about loading and using textures in D3D. a) I've read all around that using square pow2 textures is actually better: is this always true? should I really choose them at all costs? And again, are "small" textures better? b) is D3DXCreate*** the best way to create a textures? I mean, do famous game companies (or do YOU) use these functions or do they have their own methods? (I'm not aiming to their level, I'm just a bit curious, since I heard that assembly can help with performance). c) Does D3DXCreateTextureFromFileEx create and store a mip map for free? (since it has a "MipLevels" parameter in it). How can I actually use a mipmap and can I avoid its creation? d) finally, how can I pack together multiple textures in a single "crypted" file? I mean... I should prevent the user from touching my textures easily, doing so I'd like to create a .something (.dat maybe?) file that stores every texture (this will also minimize the amount of texture files in the directory, etc) Hope this won't bother you! Thanks in advance
Advertisement
1) It is more compatible with older cards, but with DX10 and recent cards I don't think it makes difference...
2) I don't know about big companies sorry, and anyway I doubt this will in any way impact your performance. The texture load is generally done on cut-scenes or levelloading screen, rarely while playing.
3) For "free"? Well the mip levels DOES consume memory so they are not for free, but yes they are automatically generated and managed. If you select 1 as miplevels you prevent them from being created.
4) Create a package format like i've done (you decide the rules for your format and the data to attach, it is useful if you need like me some collateral data), or use ZIP or any other compressing format. Its not really related to DirectX.
thanks for the reply. I always think my questions will be so stupid that no one will answer ~.~.

a) that's the point, thanks!

b) thanks again, that was a stupid question of mine.

c) aside from memory usage they are free, that's what I meant 8). Thanks again, but how can I use a mipmap? They are used for filtering "distant" objects, right? (like anisotropic etc). Can I assume that D3D will use the best mip map level at run time for every object? And, again, how many "levels" should I create?

d) I think I'd like some "collateral" data as well but as you said it's not really DirectX related. But really I have no clues about how to create my own package format. Any advice?

c) It also takes some time to create the mipmaps when loading the texture as Direc3D has to create downscaled mipmap versions of the source image.
And yes, Direct3D automatically uses the mipmaps if you use a texture filter that makes use of them (you can look here for a short tutorial on how to do that.
Also, if you don't exactly know what you are doing, you should always create a full mipmap chain, that is all mipmaps down until either width or height is 1.
I think, if you pass D3DX_DEFAULT or some other special value to D3DXCreateTextureFromFile* D3DX will create a full mipmap chain automatically. Just have a look at the docs for that function.

d) To create your own package file format you would have to put all your data files into a single file and add some sort of directory structure to it. I.e. what files are stored in the pack and where they are stored. For example the .pak file format used by Quake1 and 2 has a header that contains the offset where the directory of the pak is stored. That directory than stores an entry for each contained file that stores: the name of the file, the offset inside the pak file where the local file starts and the length in bytes of that data file.
thanks!
Currently I'm "developing" a 2D scrolling game (touhou-like) so I'm wondering if mipmaps are really necessary since I have no magnification or any other Zbuffer related effect. Anyway this will be useful for future tasks. Thanks again.

"d) To create your own package file format you would have to put all your data files into a single file and add some sort of directory structure to it. I.e. what files are stored in the pack and where they are stored. For example the .pak file format used by Quake1 and 2 has a header that contains the offset where the directory of the pak is stored. That directory than stores an entry for each contained file that stores: the name of the file, the offset inside the pak file where the local file starts and the length in bytes of that data file."

Now it's clearer, but I've never tried such a thing and I have no idea on how to really make it with code (cpp or java). I'll google out something ;) it will be funny ;)

Any other advise is welcome!
For a 2D game without magnification or Z Effects miplevels are not necessary. :)
The MINIMUM basic things you need for your package format are :

1) Header section (some bytes that identify your format)
2) Table section (the data contained in the package) with at least :
a) name of the resource
b) offset of the resource
c) size of the resource
3) Data section, in which all the resources are without any separators.

As long as you get out with the Add and Remove functionality (with table updates) the rest is cakewalk.
thx for the info :)
I'll try this out asap. I'll post any further problem it may occur.

By the way...
is there a "better" (in a relative way) format for textures? I commonly use .png for alpha channel but it makes images quite big. Is mixing formats (jpg, dds, png) a good thing?
If the result you get is accettable for you any format is fine. Generally non-lossy format are better for quality, but "anything goes". :)

This topic is closed to new replies.

Advertisement