Extended support for dds textures in the JME-SDK

The engine can load dds textures, but the SDK cannot display, open and edit them.
However, I think that the dds texture format is one of the most important formats for textures, because it can be directly loaded into the GPU memory.
Therefore, I’ve added support for these textures in the sdk.

These code changes come in four steps:

  1. Relax restrictions in the dds loader in the core engine
  2. Add libraries to load and store dds textures for the SDK
  3. Extend the module Texture-Editor
  4. Add a dialog that can convert textures

1. Relax restrictions in the dds loader
The dds loader tests if the flag “DDSCAPS_TEXTURE” is set. However, there exists many vaild textures without these flags (valid because they can be loaded by the official dds loader). Especially the libraries in the next step create textures without that flag.

diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java b/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java index 8ea46a7..8aa6749 100644 --- a/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java +++ b/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java @@ -203,9 +203,10 @@ public class DDSLoader implements AssetLoader { texture3D = false;
     if (!directx10) {
  •        if (!is(caps1, DDSCAPS_TEXTURE)) {
    
  •            throw new IOException("File is not a texture");
    
  •        }
    
  •   	//ignore it, there exists many valid textures that have not this flag set
    

+// if (!is(caps1, DDSCAPS_TEXTURE)) {
+// throw new IOException(“File is not a texture”);
+// }

         if (depth <= 0) {
             depth = 1;

2. Add libraries to load and store dds textures for the SDK
I use the library https://code.google.com/p/java-dds/ for reading
and GitHub - Dahie/DDS-Utils: Java Utilities for DirectDrawSurface texture management for writing.
These libraries are a bit old and buggy, but the best I could find.

3. Extend the module Texture-Editor
In this main step, the texture editor is extended, so that dds textures are recognized as textures and can be read and written.

This commit is a little bit bigger, so I do not show it here, see it on github (pull request)

4. Add a dialog that can convert textures

The last step is an addon that allows to convert textures to a different format and also allows to compress the dds textures.
The SDK already support the texture compression tool, but it requires the tool from NVIDIA to be installed. This dialog has limited functionallity,
but it does not need additional executables. It is also directly integrated into the node structure.

This dialog looks like:

These changes are available as pull-request on github.

4 Likes

I don’t use DDS myself (because Windows) but this is good stuff :slight_smile:

Looking very nice but as said on GitHub, we will have to check the licensing issues around DDS, the format itself is copyright protected (even if some code to generate it might be OSS)

Btw, nasa worldwind is opensource and has dds writing and reading capabilities. I use a small suppart of it for converting my own textures to dds. It supports dxt1 and dxt5 + a few never used ones ^^.