Jump to content
  • Advertisement
Sign in to follow this  
REspawn

Best way to convert or load custom texture format

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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)?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!