[SlimDx]conversion between dxt5 to dxt1

Started by
7 comments, last by jor1980 13 years, 6 months ago
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?
Advertisement
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.
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?

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.
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.
Mike Popoloski | Journal | SlimDX
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?
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();


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);}
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

This topic is closed to new replies.

Advertisement