Jump to content
  • Advertisement
Sign in to follow this  
GoodFun

[SlimDX] 16 bit float textures

This topic is 3654 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 there, I have a question regarding 16 bit float textures. How do I go about filling data into that texture given that C# doesn't seem to have a 16 bit float type? I'm using R16_Float format to create the texture. To fill in data, I use DataRectangle textureData = _texture.Map(0, D3D10.MapMode.WriteDiscard, D3D10.MapFlags.None); for (int y = 0; y < _textureHeight; y++) { for (int x = 0; x < _textureWidth; x++) { textureData.Data.Write<???>(???); } } What datatype would I use in the Write command? If I use a 32bit float, will Write change it to a 16bit one or is there a data type that will allow me to write 16bit float data to this texture map? Thanks Marcel

Share this post


Link to post
Share on other sites
Advertisement
SlimDX provides a Half type that you should be able to use to get by. Let me know if that works or not.

Share this post


Link to post
Share on other sites
From what I see, this is a struct... if I write that using
textureData.Data.Write<Half>(new Half(resizedData[x, y]));

would that write a 16bit float to the texture map???

also, creating a new struct for each call seems a tad expensive... can I use a typecast from a float instead? Or any other idea on how to use this efficiently?

Thanks for the quick response

Marcel

Share this post


Link to post
Share on other sites
That should work correctly.
Quote:
creating a new struct for each call seems a tad expensive...
Not exactly. This is an odd syntactical detail of C#. Because it's a struct, it's a value type and not created on the heap. Even though you're calling new, there's no creation happening. It's being written to another temporary on the stack. Half just wraps a System.UInt16 (ushort in C#) internally.

By the way, you do know that you don't need to provide the generic type parameter to Write? This will work:
textureData.Data.Write(new Half(resizedData[x, y]));

Share this post


Link to post
Share on other sites
You can use the provided conversion operators to make it look like a cast, but underneath the same thing is happening anyway. Still, it may make your code look nicer. Example:


// both do the same thing
Half half = new Half(myFloat);
Half half = (Half)myFloat;

// the only way to get a float from a half is through the implicit conversion operator
float myFloat = half;

Share this post


Link to post
Share on other sites
Yeah I think I prefer the cast over the 'new', makes it look a bit neater...

Thanks for the quick response, you guys rock

Marcel

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!