Sign in to follow this  
jor1980

[SlimDx]conversion between dxt5 to dxt1

Recommended Posts

Hi i am using SlimDx to convert textures allocated in memorystream form one texture type to another. I can convert the textures from many types to dds but now i need to convert those textures to an especifal compression either dxt5 or dxt1 but i don´t know how can i do this.

I made my conversions using texture.tostream but i only see availabe ImageFileFormat.Dds , Are there ImageFileFormat.DXT1 or ImageFileFormat.DXT5 in Slimdx?

if they doesn´t exist how can i made the conversions to dxt1 or dxt5?

Share this post


Link to post
Share on other sites
I don't think there's a built in mechanism for converting textures to DXT5 or DXT1. You'll need to write your own routines for writing DXT5/1.

Share this post


Link to post
Share on other sites
Quote:
Original post by Flimflam
I don't think there's a built in mechanism for converting textures to DXT5 or DXT1. You'll need to write your own routines for writing DXT5/1.


That sounds very complex or are there any simple way to do that?

Share this post


Link to post
Share on other sites
Is this something you have to do at runtime? There are plenty of offline tools that can do it for you.

If you really need to do it at runtime, the D3DX library has the D3DXLoadSurfaceFromSurface from function. I'm not sure if SlimDX exposes it, but if not you should be able to pinvoke it since it's a free function.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
Is this something you have to do at runtime? There are plenty of offline tools that can do it for you.

If you really need to do it at runtime, the D3DX library has the D3DXLoadSurfaceFromSurface from function. I'm not sure if SlimDX exposes it, but if not you should be able to pinvoke it since it's a free function.


Exposed as Surface.FromSurface.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
Is this something you have to do at runtime? There are plenty of offline tools that can do it for you.

If you really need to do it at runtime, the D3DX library has the D3DXLoadSurfaceFromSurface from function. I'm not sure if SlimDX exposes it, but if not you should be able to pinvoke it since it's a free function.


I am using Surface.FromSurface but i don´t see the posibilitie to transform to an special dxt compression, How must i do this?

Share this post


Link to post
Share on other sites
Got it [grin].

You can use D3DX to do the conversion. The trick is to use Pool.SystemMemory for both source and target texture, otherwise you likely get a "CreateRenderTarget failed" error. Here's a proof of concept with SlimDX which loads a Texture and converts the first level to DXT1:

    ImageInformation info = ImageInformation.FromFile(origFileName);
Texture texture = Texture.FromFile(device, origFileName, Usage.None, Pool.SystemMemory);
Texture output = new Texture(device, info.Width, info.Height, 1,
Usage.None, SlimDX.Direct3D9.Format.Dxt1, Pool.SystemMemory);

Surface dest = output.GetSurfaceLevel(0);
Surface source = texture.GetSurfaceLevel(0);
Surface.FromSurface(dest, source, SlimDX.Direct3D9.Filter.Point, 0);
Surface.ToFile(dest, outputFileName, ImageFileFormat.Dds);

source.Dispose();
dest.Dispose();
output.Dispose();
texture.Dispose();


Share this post


Link to post
Share on other sites
I'm bored, so...


var info = ImageInformation.FromFile(origFileName);
using (var texture = Texture.FromFile(device, origFileName, Usage.None, Pool.SystemMemory))
using (var output = new Texture(device, info.Width, info.Height, 1, Usage.None, SlimDX.Direct3D9.Format.Dxt1, Pool.SystemMemory))
using (var dest = output.GetSurfaceLevel(0))
using (var source = texture.GetSurfaceLevel(0))
{
Surface.FromSurface(dest, source, SlimDX.Direct3D9.Filter.Point, 0);
Surface.ToFile(dest, outputFileName, ImageFileFormat.Dds);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by unbird
Got it [grin].

You can use D3DX to do the conversion. The trick is to use Pool.SystemMemory for both source and target texture, otherwise you likely get a "CreateRenderTarget failed" error. Here's a proof of concept with SlimDX which loads a Texture and converts the first level to DXT1:

*** Source Snippet Removed ***


Using the code you posted could i also convert the texture to an specific number of mipmaps?Thank´s

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this