Best way to convert or load custom texture format

Started by
10 comments, last by REspawn 11 years, 2 months ago

Hi,

I'm writing a texture loader for game files for my own education and fun.

The game has some texture formats that are not standard for DirectX. I'm wondering what's the best way to load them for rendering as a texture?

Any advice or help would be great. Thanks,

Dave

Advertisement
Use an open-source library such as leptonica (I guess? Never used an open-source image library so someone else would better at suggesting which one you should use) and save it as a format that Direct3D can use, which maybe easily be your own custom format that you have designed so that it can be sent to Direct3D as-is once you load it to memory.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

When you say 'not standard for DirectX', what exactly do you mean? Have you check all of the formats that are listed in the DXGI_FORMAT enumeration? If your texture doesn't map to one of those types in a fairly intuitive way, then you will have trouble trying to render with them - these are the only formats that are available!

When you say "texture format" do you mean "image file format" (as in JPEG, PNG, etc.) or just a file format for storing texture data (as in your own version of DDS)?

Thanks for the replies.

When I say non standard I mean that it's not in the D3DFORMAT enum, so I can create a texture in that format and then memcpy the data in.

So for example one of the formats the game stores it's files in is ABGR8888. In the D3DFORMAT enum there is D3DFMT_A8R8G8B8.

So would the best way to read this texture in be to create a D3DFMT_A8R8G8B8 texture, lock the texture and manually copy in each pixel of data? Or is there a better / faster way to go from one format to another?

Hope that makes it easier to understand my question.

Thanks,

Dave

You could always copy the data into the texture resource as is, and then simply perform swizzling on the channels when you look it up. However, I suspect that would get old pretty fast, and I would recommend just writing a small program to do the conversion for you before runtime. Depending on how often the texture data changes, you could even run your tool as a part of your build process to make everything integrated.

I haven't come across an easy to use tool for channel swapping...

I would recommend just writing a small program to do the conversion for you before runtime.

This.
100000000x this.

Your game/engine/runtime should NOT be dicking about converting image (or any other data) at run time; your texture payload should match the D3D supported ones so that you can simply load the data in and hand it off directly.

Doing the conversion every time you load and run the program is just wasteful...

FYI, there is a D3DFMT_A8B8G8R8 format. So you shouldn't actually need to convert in this particular case.

Thanks for the replies. Yep, this is just for a tool / my own education, so I don't mind the extra processing step.

@MJP - Yea that's what I thought too, but the channels are switched. So I'll need to switch them.

So from doing some reading and testing, looks like the best option is read the data from the file into a buffer, create my texture, lock the rect and then switch the channels as needed. I can't seem to find anything here or on Google that suggests a better way.

It produces the correct texture data and it's not too slow. Is there a better way?

Thanks,

Dave

Yes, the better way is do not do it at run time.

This operation you've just done; file -> buffer -> transcode -> buffer

Well it's the same regardless of if you do it in memory every time you load the data or if you do it once before hand, save the result and then load that.

The latter being the method that should be used.

This topic is closed to new replies.

Advertisement