Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Best way to convert or load custom texture format


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 REspawn   Members   -  Reputation: 144

Like
0Likes
Like

Posted 04 February 2013 - 05:29 PM

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



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13899

Like
0Likes
Like

Posted 04 February 2013 - 06:33 PM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 Jason Z   Crossbones+   -  Reputation: 5147

Like
0Likes
Like

Posted 04 February 2013 - 09:20 PM

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!



#4 MJP   Moderators   -  Reputation: 11565

Like
0Likes
Like

Posted 05 February 2013 - 01:12 AM

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



#5 REspawn   Members   -  Reputation: 144

Like
0Likes
Like

Posted 05 February 2013 - 06:06 AM

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



#6 Jason Z   Crossbones+   -  Reputation: 5147

Like
2Likes
Like

Posted 05 February 2013 - 06:11 AM

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



#7 phantom   Moderators   -  Reputation: 7388

Like
1Likes
Like

Posted 05 February 2013 - 07:17 AM

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

#8 MJP   Moderators   -  Reputation: 11565

Like
0Likes
Like

Posted 05 February 2013 - 01:45 PM

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



#9 REspawn   Members   -  Reputation: 144

Like
0Likes
Like

Posted 05 February 2013 - 06:22 PM

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



#10 phantom   Moderators   -  Reputation: 7388

Like
0Likes
Like

Posted 05 February 2013 - 07:11 PM

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.



#11 Jason Z   Crossbones+   -  Reputation: 5147

Like
0Likes
Like

Posted 05 February 2013 - 08:07 PM

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?

 

Not really - this is really the minimum amount of work that you could possibly do, so I doubt there will be any faster way to convert them (at compile time or runtime).  As I mentioned above, you could just swizzle the channels in your shaders (which is supposedly free in GPU hardware) so that technically would be faster, but then you will be modifying your shader code based on the external formats, which isn't a good thing.

 

I would say that especially if this project is just for education, then build a standalone tool that will do the conversion for you.  This will give you some additional experience, plus some reusable code to boot.  And since nobody knows of a good program to do this already, you could throw the results up on GitHub or CodePlex and let everyone know how to do it :)



#12 REspawn   Members   -  Reputation: 144

Like
0Likes
Like

Posted 06 February 2013 - 07:21 AM

Stand alone conversion tool seems like the best and most fun way to do this. I'll update this thread when I put the code up somewhere.

Thanks for all the help.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS