.DDS (DirectDrawSurface) texture support?

Started by Yellownakji, April 02, 2019, 23:16:43

Previous topic - Next topic

Yellownakji

Does BlitzMaxNG natively support .DDS images?   I see Loaders for PNG, which is what i normally use, JPEGand TARGA (yuck.).

I'm wondering if there is also support for DDS or perhaps a module that has been previously published for DDS support?  I'm pretty happy with PNG in terms of performance however DDS would be even more optimal, if supported.

markcwm

#1
Hi,

there is a texture loader for DDS in C++ for Openb3dmax, I've been planning on writing a loader for Blitzmax so we can have DDS texture streams, but I might as well write a pixmap loader module and then it can be used for images too.

I already have a STB Image pixmap factory loader module which supports TGA, PNG (32-bit only), BMP (no RLE), JPG (no progressive), also: GIF, PSD, HDR, PIC. The BRL JPG and PNG loaders are the best but Openb3dmax STBI TGA and BMP loaders are more stable. Brucey has an STBI loader module in NG but his version crashes on most TGAs, it seems when STBI got a rewrite TGAs were broken so Openb3dmax uses the older v1.35.

Yellownakji

Quote from: markcwm on April 03, 2019, 00:05:40
Hi,

there is a texture loader for DDS in C++ for Openb3dmax, I've been planning on writing a loader for Blitzmax so we can have DDS texture streams, but I might as well write a pixmap loader module and then it can be used for images too.

I already have a STB Image pixmap factory loader module which supports TGA, PNG (32-bit only), BMP (no RLE), JPG (no progressive), also: GIF, PSD, HDR, PIC. The BRL JPG and PNG loaders are the best but Openb3dmax STBI TGA and BMP loaders are more stable. Brucey has an STBI loader module in NG but his version crashes on most TGAs, it seems when STBI got a rewrite TGAs were broken so Openb3dmax uses the older v1.35.

I see, thanks for this information.   I was thinking of DDS since it has GPU advantages but it's not too different from PNG.  My main issue is the different modes of DDS and just recently, several new compression types were introduced and some phased out.  Even Paint.net does not support all of them so it's kind of messy.   DDS support would be handy though, especially for 3D applications.   By the way, if i'm not mistaken, isn't PNG open source?  I've been trying for sometime now to find a file system for PNG.  I'm curious to see how PNG works and how to write a PNG loader/saver.   I know NG has one internally but i'm curious as to seeing how it works myself.

markcwm

Hi Yellownakji,

thanks for this, yes I now see the advantages you are talking about: first compressed textures in VRAM save memory, second compressed textures also improve GPU performance, third pre-processed mipmaps save loading times.

The DDS loader I'm working on uses glCompressedTexImage2D which it seems does create a compressed texture in VRAM, the code will also loads mipmaps from file. I have just finished getting the loader working along with a LoadImageDDS function but haven't added these optimizations yet as I've only just realized what they are for. I'll update the code to do this where it's possible.

Yellownakji

Quote from: markcwm on April 07, 2019, 19:13:38
Hi Yellownakji,

thanks for this, yes I now see the advantages you are talking about: first compressed textures in VRAM save memory, second compressed textures also improve GPU performance, third pre-processed mipmaps save loading times.

The DDS loader I'm working on uses glCompressedTexImage2D which it seems does create a compressed texture in VRAM, the code will also loads mipmaps from file. I have just finished getting the loader working along with a LoadImageDDS function but haven't added these optimizations yet as I've only just realized what they are for. I'll update the code to do this where it's possible.

Sounds good.  DDS support for max2d_d9x and max2d_gl would be great.  For modern applications, it would be a reallllyyyy useful format.   It should also work well on older CPUs like a Penium 4 etc.

markcwm

#5
Well I've an update out for this but it's really just for compressed textures, I spent a lot of time getting anim textures working, this was then applied to cubic environment maps, and also LoadAnimImageDDS but images are not compressed as Max2D doesn't support it, so I will have to modify brl.glmax2d which doesn't look like it requires much work. I won't be able to mod brl.d3d9max2d though as I don't know much about Direct3D.

Yellownakji

Quote from: markcwm on April 25, 2019, 04:38:08
Well I've an update out for this but it's really just for compressed textures, I spent a lot of time getting anim textures working, this was then applied to cubic environment maps, and also LoadAnimImageDDS but images are not compressed as Max2D doesn't support it, so I will have to modify brl.glmax2d which doesn't look like it requires much work. I won't be able to mod brl.d3d9max2d though as I don't know much about Direct3D.

Awesome work!  I'm glad you're following up to this.   Yeah, i figured Max2D wouldn't be with compression, but it's fine.  Still light on the GPU.


markcwm

#7
Hi Yellownakji,

I've got a tweak to glMax2d for BRL (vanilla/legacy) Blitzmax but not NG yet. It's working well although it can crash in GL 2.0 if any normal images are loaded before dds images, I couldn't figure out why. [SOLVED]

So you've to get the latest version of Maxmods brl.mod and pub.mod which have the glmax2d compressed textures tweak and of course openb3dmax.mod and openb3dmax.docs, see standard/load_dds_2d.bmx.

The example scales the images down as this shows the mipmaps were loaded, mipmaps are always loaded for dds. Also DrawPixmap doesn't work for dds. Only standard dxt1/3/5 formats are supported. That's about it.

markcwm

#8
Okay, this is probably a final update on this, I have forked brl.mod NG which has the dds tweak for versions 0.87, 0.93, 0.99 and 0.105.

Changes to Openb3dmax are (in no particular order) - independent module, so you only need to import ddsloader now; fixed random crash in GL 2.0 due to memfree (fix is check width/height>0); load dds from cpp library - full support for anim textures and my any-order cubic environment map. I haven't managed to load textures without mipmaps, but I may have another go at that later.

Yellownakji

Quote from: markcwm on May 13, 2019, 02:04:02
Okay, this is probably a final update on this, I have forked brl.mod NG which has the dds tweak for versions 0.87, 0.93, 0.99 and 0.105.

Changes to Openb3dmax are (in no particular order) - independent module, so you only need to import ddsloader now; fixed random crash in GL 2.0 due to memfree (fix is check width/height>0); load dds from cpp library - full support for anim textures and my any-order cubic environment map. I haven't managed to load textures without mipmaps, but I may have another go at that later.

Thanks for the efforts, Mark!  ^-^   I personally don't use mipmaps, so i hope to see that at some point.  Maybe one day, like you said.

Animation support, as well.  I very much appreciate that.

Woah, 0.105?  I need to check this out. Any idea whats different?

markcwm

#10
@Yellownakji, no I've no idea what's new in v0.105.

My brl.mod-NG fork has been merged with the latest bmx-ng/brl.mod but if you want to use an older NG release (0.93, 0.99, 0.105) you can find the required modules archived in openb3dmax.docs/mod.


markcwm

#11
Well the ddsloader now has the option of no mipmaps, but for some reason mipmapped images break in GL2.0 (and probably lower) I tried fixing it but it seems too buggy, basically images are broken by what was loaded before them and if a mipmap fails the whole texture does too. Saying as non-mipmaps work perfectly and this is probably all people will want for 2d I've given up trying to fix it.

Yellownakji

Quote from: markcwm on May 21, 2019, 13:12:00
Well the ddsloader now has the option of no mipmaps, but for some reason mipmapped images break in GL2.0 (and probably lower) I tried fixing it but it seems too buggy, basically images are broken by what was loaded before them and if a mipmap fails the whole texture does too. Saying as non-mipmaps work perfectly and this is probably all people will want for 2d I've given up trying to fix it.

Yes, i didn't plan on using DDS for 3D.  I'm not really interested in 3D.

markcwm

Yes, I know 2d is what most indie developers work in, making a polished 3d game is much harder than a 2d game, it's the sensible choice unless you really know what you're doing, and have at least one artist and one coder. I just do this as a hobby because I enjoy it more than actually making a game.

Another update but just to the docs, this is just to fix issues in GL 2.0 (see examples standard/load_dds and blitz3d/LoadAnimTexture). One was a random crash due to an empty filter list from ClearTextureFilters. The other was mipmaps from the previous texture could be used instead, this happened when I set TextureFilter after loading the mesh.