June 26, 2019, 08:11:09 PM

Author Topic: .DDS (DirectDrawSurface) texture support?  (Read 451 times)

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 237
  • Whoop-de-doo-ba-dooo!
.DDS (DirectDrawSurface) texture support?
« on: April 02, 2019, 11:16:43 PM »
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.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #1 on: April 03, 2019, 12:05:40 AM »
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.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 237
  • Whoop-de-doo-ba-dooo!
Re: .DDS (DirectDrawSurface) texture support?
« Reply #2 on: April 03, 2019, 12:39:54 AM »
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.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #3 on: April 07, 2019, 07:13:38 PM »
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.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 237
  • Whoop-de-doo-ba-dooo!
Re: .DDS (DirectDrawSurface) texture support?
« Reply #4 on: April 07, 2019, 09:47:50 PM »
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.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #5 on: April 25, 2019, 04:38:08 AM »
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.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 237
  • Whoop-de-doo-ba-dooo!
Re: .DDS (DirectDrawSurface) texture support?
« Reply #6 on: April 25, 2019, 05:14:48 AM »
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.


Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #7 on: May 06, 2019, 03:23:27 AM »
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.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #8 on: May 13, 2019, 02:04:02 AM »
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.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 237
  • Whoop-de-doo-ba-dooo!
Re: .DDS (DirectDrawSurface) texture support?
« Reply #9 on: May 13, 2019, 04:05:26 PM »
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?

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #10 on: May 15, 2019, 01:17:46 PM »
@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.


Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #11 on: May 21, 2019, 01:12:00 PM »
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.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 237
  • Whoop-de-doo-ba-dooo!
Re: .DDS (DirectDrawSurface) texture support?
« Reply #12 on: May 21, 2019, 06:47:29 PM »
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.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 390
Re: .DDS (DirectDrawSurface) texture support?
« Reply #13 on: May 22, 2019, 12:00:08 AM »
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.