Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Questions about DXTn  (Read 2795 times)
0 Members and 1 Guest are viewing this topic.
Offline Eliwood

Junior Member




Stencyl


« Posted 2007-02-16 06:57:36 »

I remember oNyx mentioning something about DDS textures with DXTn compression as being a potent combination. I'm interested in researching this further, but I've got a few questions.

1) For a 2D game, how feasible would this be for large background textures along the order of 1024 x 512 or so? What I'm talking about here is purely visual quality. I don't think that it'd would be great for sprites and small things, but for something large, would it be a good choice?

2) I heard that the decompression is performed in hardware or with a software fallback but that this decompression occurs each frame, meaning that VRAM usage is lower. How intense is this decompression, and would it have any impact on framerate since it's performed every frame, particularly if the software fallback had to be used? (And in particular, for older dedicated cards)

3) What's the difference between the five DXTn compression algorithms?

4) How do I save images in this format, and which compression algorithm would be most appropriate for my use? (1024 x 512 textures, 2D game, 32-bit with alpha)

5) Finally, are there are pre-written loaders out there already for this format? (to pass right into LWJGL for example)

Thanks.

Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #1 - Posted 2007-02-16 10:50:44 »

1. I was surprised at the quality of DDS, even for sprites. Picking the correct format for your data also helps a lot.

2. IIRC, hardware decompression is done on the fly. Software fallback will do the decompression at load time so you just end up with a regular texture.

3. Image format, mostly to do with how the alpha channel is stored. DXT5 is the most general, being basically compressed RGBA. IIRC DXT1 doesn't have an alpha channel, 3 uses a pallette for alpha, and 2 and 4 are pre-multiplied alpha versions of 3 and 5.

4. nVidia has some free conversion utilities on their website. The windows thumbnail viewer is particularly helpful.

5. There was some code in the shared code forum, and I think jME has DDS loading if you want to take a peek at their code.

I ended up not using DDS / DXTn in the end (I don't usually have enough textures to warrent it) but it's a nice bit of technology. Even the rubbish intergrated intel chips support it (although I suspect it's software emulation) so it should be usable pretty much anywhere.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2007-02-16 11:09:19 »

Decompression 'every frame' (basicly: every fragment) is even faster than a sampling uncompressed textures, due to the reduced memory-fetches (factor 4 IIRC)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eliwood

Junior Member




Stencyl


« Reply #3 - Posted 2007-02-16 23:14:35 »

Thanks guys. I got this all working quicker than expected (took about 1 hour). It's all that it's cracked up to be. These things compress down to small, small sizes (8 KB for a 1024 x 864 image), and everything else said pretty much is true. Smiley

Offline Eliwood

Junior Member




Stencyl


« Reply #4 - Posted 2007-02-17 02:27:12 »

Or perhaps not. A few of users are already reporting problems.

FX5200 - Game goes down to 2-4 FPS from 75 FPS.

Radeon 9000 - Game crashes.



Any reasons for this? Did I just implement this wrong? Here's the call to OpenGL after things are loaded. I'm fairly sure that it's loading properly because I made no changes to the jME code besides making it return as a ByteBuffer rather than the internal image format they were using.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
ARBTextureCompression.glCompressedTexImage2DARB
(
   GL11.GL_TEXTURE_2D,
   0,
   format,
   width,
   height,
   0,
   textureBuffer
);


One thing to note is that I don't normalize textures to POT because that gave myself the 1282 (not 1281) error, and it apparently passed through on the FX5200 too without fault.

Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #5 - Posted 2007-02-17 04:27:21 »

You did check if they have ARBCompressedTexture right?

Also, whats your "format" parameter. Im suspecting they dont have EXT_Texture_Compression_S3TC and thus, an invalid value is being thrown...

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Eliwood

Junior Member




Stencyl


« Reply #6 - Posted 2007-02-17 07:14:53 »

I don't perform that check. I thought that support for this feature was fairly standard (otherwise I wouldn't go this path), or is this about something else?

The format values can be any one of the following:

GL_COMPRESSED_RGB_S3TC_DXT1_EXT
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT

Also, what's the difference between GL13.glCompressedTexImage2D() and ARBTextureCompression.glCompressedTexImage2DARB() if any? They both seem to do the same thing for me.

Offline Matzon

JGO Knight


Medals: 19
Projects: 2


I'm gonna wring your pants!


« Reply #7 - Posted 2007-02-17 08:27:58 »

the former is in the core - the latter in the extension.
So openGL 1.1 and 1.2 users might have it - but as an extension, while OpenGL1.3 users always have it in the core.

Offline Eliwood

Junior Member




Stencyl


« Reply #8 - Posted 2007-02-17 08:32:49 »

As requested, the code for this. Also, all textures used (well it's just 1 background texture) were DXT1, no alpha. Also, no mipmaps since this is all 2D.

1) DDSLoader.java

Identical to jME version, except that I make it return a ByteBuffer rather than a jME Image. I also add in methods to retrieve image width, height, depth and DXTn format.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public static ByteBuffer loadImage(InputStream fis, boolean flip) throws IOException {
        DDSReader reader = new DDSReader(fis);
        reader.loadHeader();
        ByteBuffer data = reader.readData(flip);
       
        pixelDepth = reader.bpp_;
        width = reader.width_;
        height = reader.height_;
        format = reader.pixelFormat_;

        return data;
    }


2) TextureLoader.java

Really similar to the Space Invaders tutorial code except for the last line.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
   int textureID = createTextureID();
   Texture texture = new Texture(target, textureID);

   GL11.glBindTexture(target, textureID);

   ByteBuffer textureBuffer;
   int width;
   int height;
   boolean hasAlpha;

   try
   {
      textureBuffer = DDSLoader.loadImage(new BufferedInputStream(
               MediaManager.instance().getKitResourceAsStream(
                     background.getKitName(),
                     DirectoryListing.BACKGROUNDS + background.getID()
                           + "-" + 0 +
                           ".dds")));

      width = DDSLoader.getLastWidth();
      height = DDSLoader.getLastHeight();
      hasAlpha = DDSLoader.getLastDepth() == 32;
         
      texture.setTextureWidth(width);
      texture.setTextureHeight(height);
      texture.setWidth(width);
      texture.setHeight(height);

      if(target == GL11.GL_TEXTURE_2D)
      {
         GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
         GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
      }
         
      int format = 0;
         
      switch(DDSLoader.getFormat())
      {
         case DXT1_NATIVE:
            format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
            break;
               
         case DXT1A_NATIVE:
            format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
            break;
               
         case DXT3_NATIVE:
            format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
            break;
               
         case DXT5_NATIVE:
            format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
            break;
      }
         
      checkCompressedTextureExtensions();
         
      GL13.glCompressedTexImage2D
      (
         GL11.GL_TEXTURE_2D,
         0,
         format,
         width,
         height,
         0,
         textureBuffer
      );


Since it was requested, the code for drawing an image. Again, taken straight from a tutorial.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
//A "Fake Image" is passed in that contains data for grabbing the desired image from the cache. The reason is that GTGE forces a Graphics2D like interface onto LWJGL, so I pass in an Image with no image data.
texture = textureLoader.getTexture(img);
texture.bind();

float tx0 = ((float) sx1 / texture.getTextureWidth());
float tx1 = ((float) sx2 / texture.getTextureWidth());
float ty0 = ((float) sy1 / texture.getTextureHeight());
float ty1 = ((float) sy2 / texture.getTextureHeight());

GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(tx0, ty0);
GL11.glVertex2f(dx1, dy1);

GL11.glTexCoord2f(tx1, ty0);
GL11.glVertex2f(dx2, dy1);

GL11.glTexCoord2f(tx1, ty1);
GL11.glVertex2f(dx2, dy2);

GL11.glTexCoord2f(tx0, ty1);
GL11.glVertex2f(dx1, dy2);
GL11.glEnd();

Offline Eliwood

Junior Member




Stencyl


« Reply #9 - Posted 2007-02-17 21:30:19 »

It might be worth mentioning that for the people who it didn't work for (everybody minus myself and MatthiasM - we both have the same card, 7800's), the CPU usage was very high (50%).

Is there another way to go about this?

I have attached a play-only version of one of Stencyl's games below if you are curious to test this out and see whether it works or not.
http://www.stencyl.com/Backups/Releases/Demo.zip
http://www.stencyl.com/Backups/Releases/Demo.tar.gz

Arrow Keys = Move
Q = Jump
W = Dash

For this version, I switched from DXT1 to DXT5 and downsized the texture to 512x512. The original version had it in DXT1 and 1024x1024. Please only comment on this feature alone and not the game itself.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #10 - Posted 2007-02-17 23:19:21 »

I doubt i'll be much help with this check, but it works on my pooter (7900GT)....

50% isn't that high at all, 100% is what you should be aiming for really, if you dont have 100% CPU utilisation, your just not putting enough features in Tongue

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Eliwood

Junior Member




Stencyl


« Reply #11 - Posted 2007-02-17 23:39:30 »

I doubt i'll be much help with this check, but it works on my pooter (7900GT)....

50% isn't that high at all, 100% is what you should be aiming for really, if you dont have 100% CPU utilisation, your just not putting enough features in Tongue

DP

Well, think about it like this. CPU usage on my computer is around 3%, and normal CPU usage for that particular user is around 10-20%, so when it leaps up like that, something's wrong.

Is there something going wrong in my code or in my saving process? I am using the Photoshop plugin from NVIDIA's site. I save as DXT1 or DXT5. I turn off mip maps. I wonder why this is not working for anybody except high end NVIDIA cards. (it flopped on an ATI X1900 XTX)

Offline Kova

Senior Member





« Reply #12 - Posted 2007-02-18 11:45:18 »

works here, radeon x800, 3-4% cpu usage

btw. I noticed sometimes you can fall (pixel or two) into the ground and then cannot move.
Offline Eliwood

Junior Member




Stencyl


« Reply #13 - Posted 2007-03-09 23:13:29 »

One final question. How can I support people who have no support for this? These are people with OpenGL 1.1 but no S3TC extension.

Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #14 - Posted 2007-03-10 04:30:10 »

Shocked

Even the 9200se which is *the* shittest card in the world supports OGL 1.3...Trust me, dont worry about it.

If you are really adminant, you need to decompress textures on init and upload via glTexImage2D.

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Eliwood

Junior Member




Stencyl


« Reply #15 - Posted 2007-03-10 06:37:46 »

Shocked

Even the 9200se which is *the* shittest card in the world supports OGL 1.3...Trust me, dont worry about it.

If you are really adminant, you need to decompress textures on init and upload via glTexImage2D.

DP

I'm actually talking about people with older, year 2000-era Intel graphics (a 9200 would already be low-mid range in my book when speaking about my target audience).

So how do I do this software decompression anyways?

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #16 - Posted 2007-03-10 07:18:42 »

There is some software decompression code over at that JSquish thread:
http://www.java-gaming.org/forums/index.php?topic=15186.0

弾幕 ☆ @mahonnaiseblog
Offline Eliwood

Junior Member




Stencyl


« Reply #17 - Posted 2007-03-10 19:15:54 »

For some reason, I was under the impression that it only did compression. Thanks for the heads up. I'll let you know how this goes on those few setups.

Offline Eliwood

Junior Member




Stencyl


« Reply #18 - Posted 2007-03-11 00:26:45 »

Worked like a charm (on my setup at least, but I have to double-check now on the setups where this actually matters), and I didn't even notice any time spent decompressing. Thanks for the tip!

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (22 views)
2014-04-15 18:08:23

BurntPizza (17 views)
2014-04-15 03:46:01

UprightPath (31 views)
2014-04-14 17:39:50

UprightPath (15 views)
2014-04-14 17:35:47

Porlus (31 views)
2014-04-14 15:48:38

tom_mai78101 (57 views)
2014-04-10 04:04:31

BurntPizza (115 views)
2014-04-08 23:06:04

tom_mai78101 (214 views)
2014-04-05 13:34:39

trollwarrior1 (182 views)
2014-04-04 12:06:45

CJLetsGame (189 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!